import { copyFile, mkdir } from 'fs/promises';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';

const __dir = dirname(fileURLToPath(import.meta.url));
const root  = resolve(__dir, '..');
const dest  = resolve(root, 'fonts');
const nm    = resolve(root, 'node_modules');

const files = [
  ['@fontsource/cormorant-garamond/files/cormorant-garamond-latin-300-italic.woff2', 'cormorant-garamond-300-italic.woff2'],
  ['@fontsource/cormorant-garamond/files/cormorant-garamond-latin-400-normal.woff2', 'cormorant-garamond-400-normal.woff2'],
  ['@fontsource/cormorant-garamond/files/cormorant-garamond-latin-400-italic.woff2', 'cormorant-garamond-400-italic.woff2'],
  ['@fontsource/cormorant-garamond/files/cormorant-garamond-latin-600-italic.woff2', 'cormorant-garamond-600-italic.woff2'],
  ['@fontsource/lora/files/lora-latin-400-normal.woff2',  'lora-400-normal.woff2'],
  ['@fontsource/lora/files/lora-latin-400-italic.woff2',  'lora-400-italic.woff2'],
  ['@fontsource/lora/files/lora-latin-500-normal.woff2',  'lora-500-normal.woff2'],
];

await mkdir(dest, { recursive: true });

for (const [src, name] of files) {
  await copyFile(resolve(nm, src), resolve(dest, name));
}

console.log(`Fonts copied to fonts/ (${files.length} files)`);
