muse/book-reading-clip-lamp

A tscircuit package created by muse.

Version
0.4.6
License
unset
Stars
0

render-sheets.cjs

const fs = require('fs');
const {convertCircuitJsonToSchematicSvg,convertCircuitJsonToStackedSchematicSheetsSvg}=require('circuit-to-svg');
const sharp=require('/Users/rishabhgupta/.bun/install/global/node_modules/sharp');
(async()=>{
const circuit=JSON.parse(fs.readFileSync('dist/index/circuit.json'));
const sheets=circuit.filter(x=>x.type==='schematic_sheet').sort((a,b)=>a.sheet_index-b.sheet_index);
fs.mkdirSync('schematic-sheets',{recursive:true});
for(const old of fs.readdirSync('schematic-sheets')) if (/^\d{2}-.*\.(svg|png)$/.test(old)) fs.unlinkSync('schematic-sheets/'+old);
for (const sheet of sheets){
 const filename=`${String(sheet.sheet_index+1).padStart(2,'0')}-${sheet.name.toLowerCase()}`;
 const svg=convertCircuitJsonToSchematicSvg(circuit,{schematicSheetId:sheet.schematic_sheet_id,width:1600,height:1040});
 fs.writeFileSync(`schematic-sheets/${filename}.svg`,svg);
 await sharp(Buffer.from(svg)).png().toFile(`schematic-sheets/${filename}.png`);
}
fs.writeFileSync('schematic.svg',convertCircuitJsonToStackedSchematicSheetsSvg(circuit,{width:1600,height:1040}));
console.log(sheets.map(x=>({name:x.name,index:x.sheet_index,id:x.schematic_sheet_id})));
})();