import{readFile}from'node:fs/promises';import{createEngine,emailText,languages}from'./core.js';
const lng=process.argv[2]||'ru',file=process.argv[3]||'fixtures/order.json';
try{if(!languages.includes(lng))throw new Error('Язык: ru, en, en-GB или ar');const raw=await readFile(file,'utf8');if(Buffer.byteLength(raw)>32768)throw new Error('JSON больше 32 КБ');const order=JSON.parse(raw);const resources=JSON.parse(await readFile(new URL('./resources.json',import.meta.url),'utf8'));const engine=await createEngine(resources,lng);process.stdout.write(JSON.stringify(emailText(engine,order,lng),null,2)+'\n');}catch(error){process.stderr.write(error.message+'\n');process.exitCode=1;}
