build-preview.mjs 2.0 KB

123456789101112131415161718192021222324
  1. import fs from 'node:fs';
  2. import crypto from 'node:crypto';
  3. import { renderReportHtml } from '../../skills/ksf-workshop-runtime/scripts/render-report-html.mjs';
  4. const out = 'docs/report-quality-html-20261111';
  5. const raw = JSON.parse(fs.readFileSync('docs/workshop-argument-quality-20261111/example-fixture.json', 'utf8'));
  6. const artifact = raw.artifact[0], sourceById = Object.fromEntries(raw.source.map(s => [s.objectId, s]));
  7. const report = structuredClone(artifact.report);
  8. report.subtitle += ' · 本地版式演示,沿用已有案例材料,未开展新调研或新入库';
  9. for (const entry of Object.values(report.evidence)) for (const quote of entry.quotes || []) {
  10. const source = sourceById[quote.sourceId || entry.sourceId];
  11. if (source?.sourceUrl && !quote.ref.includes(source.sourceUrl)) quote.ref += '; ' + source.sourceUrl;
  12. }
  13. const task = { title: artifact.title, stageCode: 'S5', version: 1, dataMode: 'sample', report,
  14. pendingQuestions: ['是否保留原三味组合为比较基准?现有材料不足以直接改为固定两味组合。', '需验证的是购买选择和组合取舍;本示例没有实际选择实验,不能声称已确认方案。'] };
  15. fs.writeFileSync(out + '/preview-task.json', JSON.stringify(task, null, 2) + '\n');
  16. const html = renderReportHtml(task);
  17. fs.writeFileSync(out + '/报告版式预览.html', html);
  18. const file = { id: 'preview-html-file', name: '报告版式预览.html', contentType: 'text/html', sizeBytes: Buffer.byteLength(html),
  19. sha256: crypto.createHash('sha256').update(html).digest('hex'),
  20. url: 'https://kangshifu.fmode.cn/api/functions?path=%2Fksf%2Ffile&artifactId=' + artifact.objectId + '&fileId=preview-html-file' };
  21. // Fixture endpoint is intercepted only by the browser test. It is not a published attachment.
  22. artifact.report = { ...report, attachments: [file] };
  23. fs.writeFileSync(out + '/browser-fixture.json', JSON.stringify(raw, null, 2) + '\n');
  24. console.log(JSON.stringify({ html: out + '/报告版式预览.html', source: '既有案例材料', productionWrites: 0 }));