import {createRequire} from 'node:module'; import {readFile} from 'node:fs/promises'; import {fileURLToPath} from 'node:url'; import path from 'node:path'; const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..'); const require=createRequire(path.join(root,'apps/wiki/package.json')),sharp=require('sharp'); const layouts=JSON.parse(await readFile(path.join(root,'content/layout-reference/manifest.json'),'utf8')); const layers=[];let shapes=''; for(const[i,l]of layouts.entries()){ const x=52+i%6*166,y=200+Math.floor(i/6)*232; shapes+=`${l.id.toUpperCase()}`; const bytes=await sharp(path.join(root,'content/layout-reference/assets',l.id,'source.png')).resize({width:130,height:190,fit:'inside'}).png().toBuffer(); const meta=await sharp(bytes).metadata();layers.push({input:bytes,left:Math.round(x+(146-meta.width)/2),top:y+7}); } const svg=`27原图对应排版一张设计 · 一份构件清单${shapes}构件分层T 文字 113I 图位 51D 装饰 53共 217 组原裁片 / 坐标 / 代码 / 验收WIKI · TEXT + IMAGEREF-01 — REF-27`; await sharp(Buffer.from(svg)).composite(layers).png().toFile(path.join(root,'content/layout-reference/assets/router-cover.png')); console.log('Created Router cover from all 27 actual source crops.');