// Copy the four editable files into Astro's ignored content directory. // --ensure seeds only a fresh checkout; an incomplete existing set fails loudly. import { cpSync, existsSync, mkdirSync, readFileSync } from 'node:fs'; import { resolve, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const root = fileURLToPath(new URL('../', import.meta.url)); const examples = JSON.parse(readFileSync(join(root, 'src/data/examples.json'), 'utf8')); const ensure = process.argv.includes('--ensure'); const source = resolve(process.argv[2] && !ensure ? process.argv[2] : join(root, 'sample-content')); const pages = join(root, 'src/content/pages'); const uploads = join(root, 'public/uploads'); function validate(directory) { for (const { slug } of examples) { if (!existsSync(join(directory, `${slug}.md`))) { throw new Error(`Missing ${join(directory, `${slug}.md`)}. Run npm run content:setup or npm run content:sync -- .`); } } } if (ensure && existsSync(pages)) { validate(pages); } else { validate(join(source, 'pages')); if (!existsSync(join(source, 'uploads'))) throw new Error(`Missing uploads directory in ${source}`); mkdirSync(pages, { recursive: true }); mkdirSync(uploads, { recursive: true }); for (const { slug } of examples) { cpSync(join(source, 'pages', `${slug}.md`), join(pages, `${slug}.md`)); } cpSync(join(source, 'uploads'), uploads, { recursive: true }); console.log(`Example content copied from ${source}`); }