Files
novalon-website/scripts/acceptance/contact-sheet.mjs
T
zhangxiang 763e159ac4 docs(acceptance): 两轮全站验收读数 + 复现脚本 + 企微资产包入库(OPEN-12)
按「这条结论怎么来的必须入库,排查当时的截图只服务当时」的既有口径,
把此前一直悬在 git status 里、归属未定的产物逐组落定:

入库(7.2MB):
- docs/acceptance/2026-10-21-full-qa/、2026-10-24-full-qa/ 的文字与结构化读数
  (README / defects*.json / sweep/summary.json / axe evidence / lighthouse /
  report.json 逐 run 原始读数 / tools 复现脚本)
- docs/acceptance/2026-11-26-axe/ 本轮 axe 复跑证据(35 路由 × 4 组合 140 rows 全 0)
- scripts/acceptance/{sweep-routes,contact-sheet}.mjs —— 两轮 README 里被引用的
  复现脚本,不提交则结论不可复算
- deliverables/.../wecom-pack.cjs + check-wecom.py + WECOM-MANIFEST.md +
  assets-wecom/pack-report.json(生成器/校验器/清单;18 张 PNG 可由脚本从已入库
  SVG 重新栅格化,故仍按既有规则忽略)

忽略(不提交,已写进 .gitignore 并注明归属):
- 两轮验收的逐页截图(172MB):只在排查当时有用
- infra/cicd/gitea{,-custom}/ + 2026-10-22-gitea-branding/(340KB):
  归 feature/gitea-branding,逐文件 sha256 与该分支 50/50 完全一致,
  在本分支提交会造成同一批文件的两份历史

判据:提交后 git status -uall 只剩被忽略项;每条 ?? 都能回答「归谁、为什么在这里」。
2026-11-26 20:03:46 +08:00

74 lines
3.2 KiB
JavaScript

// 把 sweep 产出的 hero 截图拼成 contact sheet,便于逐页人工/vision 过目。
// 用法:node scripts/acceptance/contact-sheet.mjs <截图目录> <输出目录> [前缀]
import fs from 'fs';
import path from 'path';
import sharp from 'sharp';
const DIR = process.argv[2] || 'docs/acceptance/2026-10-21-full-qa/screenshots/public';
const OUT = process.argv[3] || 'docs/acceptance/2026-10-21-full-qa/contact-sheets';
const PREFIX = process.argv[4] || 'public';
fs.mkdirSync(OUT, { recursive: true });
const COLS = 6;
const CELL_W = 360;
const GAP = 8;
const LABEL_H = 26;
const escapeXml = (s) => s.replace(/[<>&'"]/g, (c) => ({ '<': '&lt;', '>': '&gt;', '&': '&amp;', "'": '&apos;', '"': '&quot;' }[c]));
async function buildSheet(groupKey, files) {
const tiles = [];
for (const file of files.sort()) {
const src = await sharp(path.join(DIR, file)).resize({ width: CELL_W, withoutEnlargement: true }).jpeg({ quality: 74 }).toBuffer();
const meta = await sharp(src).metadata();
const label = Buffer.from(
`<svg width="${CELL_W}" height="${LABEL_H}" xmlns="http://www.w3.org/2000/svg">`
+ `<rect width="${CELL_W}" height="${LABEL_H}" fill="#ffffff"/>`
+ `<text x="4" y="17" font-family="Helvetica,Arial,sans-serif" font-size="11" fill="#111">${escapeXml(file.replace('__hero.jpg', ''))}</text>`
+ '</svg>',
);
const tile = await sharp({ create: { width: CELL_W, height: meta.height + LABEL_H, channels: 3, background: '#ffffff' } })
.composite([{ input: src, top: 0, left: 0 }, { input: label, top: meta.height, left: 0 }])
.jpeg({ quality: 76 })
.toBuffer();
tiles.push(tile);
}
const rows = [];
for (let i = 0; i < tiles.length; i += COLS) rows.push(tiles.slice(i, i + COLS));
const rowHeights = [];
for (const row of rows) {
rowHeights.push(Math.max(...(await Promise.all(row.map(async (buf) => (await sharp(buf).metadata()).height)))));
}
const width = COLS * CELL_W + (COLS - 1) * GAP;
const height = rowHeights.reduce((sum, h) => sum + h, 0) + (rows.length - 1) * GAP;
const composites = [];
let y = 0;
for (let r = 0; r < rows.length; r += 1) {
let x = 0;
for (const tile of rows[r]) {
composites.push({ input: tile, top: y, left: x });
x += CELL_W + GAP;
}
y += rowHeights[r] + GAP;
}
const out = path.join(OUT, `${PREFIX}-${groupKey}.jpg`);
await sharp({ create: { width, height, channels: 3, background: '#ffffff' } }).composite(composites).jpeg({ quality: 78 }).toFile(out);
return { out, tiles: tiles.length, width, height };
}
const files = fs.readdirSync(DIR).filter((f) => f.endsWith('__hero.jpg'));
const groups = new Map();
for (const file of files) {
const m = file.match(/__(\d+)__([a-z]+)__([a-z]+)__hero\.jpg$/);
if (!m) continue;
const key = `${m[1]}-${m[2]}-${m[3]}`;
if (!groups.has(key)) groups.set(key, []);
groups.get(key).push(file);
}
const summary = [];
for (const [key, groupFiles] of [...groups.entries()].sort()) {
summary.push(await buildSheet(key, groupFiles));
console.log(`sheet ${key}: ${summary[summary.length - 1].tiles} tiles -> ${summary[summary.length - 1].out}`);
}
fs.writeFileSync(path.join(OUT, `${PREFIX}-index.json`), JSON.stringify(summary, null, 2));