import {cp,mkdir,rm} from 'node:fs/promises';import {join} from 'node:path';import {spawn} from 'node:child_process';
const root=process.cwd(),dist=join(root,'dist');
const run=(command,args)=>new Promise((resolve,reject)=>{const child=spawn(command,args,{cwd:root,stdio:'inherit'});child.on('exit',code=>code===0?resolve():reject(new Error(`${command} exited ${code}`)))});
await run('node',['scripts/sync-data.mjs']);
await run('node',['scripts/validate.mjs']);
await rm(dist,{recursive:true,force:true});await mkdir(dist,{recursive:true});
for(const entry of ['index.html','404.html','license.html','LICENSE.md','assets','manifest.webmanifest','edition.json','netlify.toml','vercel.json'])await cp(join(root,entry),join(dist,entry),{recursive:true});
await run('node',['scripts/generate-post-pages.mjs','dist']);
await run('node',['scripts/generate-publishing.mjs','dist']);
console.log('Production build created in dist/.');
