gen-compound-liver.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env node
  2. // ==============================================================================
  3. // 江中肝纯片 · 产品复合体 HTML 报告生成器
  4. // 用法:node scripts/tools/gen-compound-liver.js
  5. // 输出:reports/jiangzhong-liver-compound-report.html
  6. // 依赖:
  7. // - data/jiangzhong-liver-voc.json (VOC 原始数据)
  8. // - scripts/tools/voc-analyze.js (分析层)
  9. // - scripts/tools/compound-liver-render.js (渲染层,分批次扩展)
  10. // ==============================================================================
  11. const fs = require('fs');
  12. const path = require('path');
  13. const { analyze } = require('./voc-analyze.js');
  14. const { buildHTML, TOTAL_SLIDES, CHAPTERS } = require('./compound-liver-render.js');
  15. const INPUT = path.join('data', 'jiangzhong-liver-voc.json');
  16. const OUTPUT = path.join('reports', 'jiangzhong-liver-compound-report.html');
  17. function mtimeStr(fp) {
  18. try {
  19. const d = new Date(fs.statSync(fp).mtime);
  20. return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0');
  21. } catch { return '—'; }
  22. }
  23. console.log(`╔═══════════════════════════════════════════════════════════╗`);
  24. console.log(`║ 江中肝纯片 · 产品复合体 HTML 报告生成 ║`);
  25. console.log(`╚═══════════════════════════════════════════════════════════╝`);
  26. console.log(` 输入: ${INPUT}`);
  27. console.log(` 输出: ${OUTPUT}`);
  28. console.log(` 章节: ${CHAPTERS.length} 大维度`);
  29. console.log(` slide 总数: ${TOTAL_SLIDES}`);
  30. if (!fs.existsSync(INPUT)) {
  31. console.error(`\n ❌ VOC 数据不存在:${INPUT}`);
  32. process.exit(1);
  33. }
  34. const t0 = Date.now();
  35. const voc = JSON.parse(fs.readFileSync(INPUT, 'utf-8'));
  36. const A = analyze(voc);
  37. const collectedAt = mtimeStr(INPUT);
  38. const html = buildHTML({ product: '江中肝纯片', A, collectedAt });
  39. fs.mkdirSync(path.dirname(OUTPUT), { recursive: true });
  40. fs.writeFileSync(OUTPUT, html, 'utf-8');
  41. const size = fs.statSync(OUTPUT).size;
  42. const ms = Date.now() - t0;
  43. console.log(`\n ✅ 生成完成`);
  44. console.log(` 路径: ${OUTPUT}`);
  45. console.log(` 大小: ${(size / 1024).toFixed(1)} KB`);
  46. console.log(` 耗时: ${ms} ms`);
  47. console.log(` VOC: ${A.metrics.notes} 笔记 / ${A.metrics.sampleComments} 评论 / Amazon ${A.amazon?.total || 0} 款\n`);