import {readFile,writeFile,mkdir} from 'node:fs/promises';
import {join} from 'node:path';
const root=process.cwd();
await mkdir(join(root,'assets/js/data'),{recursive:true});
for(const [name,target] of [['site-config','siteConfig'],['projects','projects'],['posts','posts'],['translations','translations']]){
  const data=JSON.parse(await readFile(join(root,`content/${name}.json`),'utf8'));
  const text=`window.IUS_TEMPLATE_DATA=window.IUS_TEMPLATE_DATA||{};window.IUS_TEMPLATE_DATA.${target}=${JSON.stringify(data)};\n`;
  await writeFile(join(root,`assets/js/data/${name}.js`),text);
}
console.log('Browser data files synchronised.');
