Files
persionalBrand/scripts/template-doctor.mjs
que01 4f0b50c7f1 fix: 收口模板契约与安全门禁
统一模板包 visual 契约并补齐完成证据;修复 release 版本一致性、管理员 token 撤销、CORS 与默认品牌配置;收敛依赖安全风险并完成全量回归验证。
2026-10-18 22:05:31 +08:00

66 lines
2.5 KiB
JavaScript

import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import {
applyCompletionEvidence,
applyManualReview,
diagnoseTemplate,
} from "./lib/template-doctor.mjs";
try {
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const args = process.argv.slice(2);
const options = {};
for (let i = 0; i < args.length; i += 2) {
if (!["--template", "--output"].includes(args[i]) || !args[i + 1])
throw new Error("Usage: template-doctor [--template key] [--output path]");
options[args[i]] = args[i + 1];
}
const reports = [];
for (const dir of fs.readdirSync(path.join(root, "packages")).sort()) {
const manifestPath = path.join(root, "packages", dir, "template.json");
if (!dir.startsWith("template-") || !fs.existsSync(manifestPath)) continue;
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
if (options["--template"] && manifest.packageKey !== options["--template"]) continue;
const renderer = path.join(root, "packages", dir, "taro/index.tsx");
if (!fs.existsSync(renderer)) throw new Error("Missing renderer: " + renderer);
reports.push(
diagnoseTemplate(manifest, fs.readFileSync(renderer, "utf8"), path.relative(root, renderer)),
);
}
if (!reports.length) throw new Error("No matching templates found");
const registryPath = path.join(
root,
".codex-tasks/template-audit-execution/raw/manual-review.json",
);
const registry = JSON.parse(fs.readFileSync(registryPath, "utf8"));
applyManualReview(reports, registry.items, registry.scope);
const evidencePath = path.join(
root,
".codex-tasks/template-audit-execution/raw/completion-evidence.json",
);
const evidence = fs.existsSync(evidencePath)
? JSON.parse(fs.readFileSync(evidencePath, "utf8"))
: undefined;
const completion = applyCompletionEvidence(reports, evidence, root);
const report = {
schemaVersion: 1,
completionStatus: completion.completionStatus,
templates: reports,
};
const output = JSON.stringify(report, null, 2) + "\n";
if (options["--output"]) {
fs.mkdirSync(path.dirname(path.resolve(options["--output"])), { recursive: true });
fs.writeFileSync(options["--output"], output);
}
process.stdout.write(output);
process.exitCode = reports.some(
(r) => r.staticStatus === "fail" || r.completionStatus === "incomplete",
)
? 1
: 0;
} catch (error) {
console.error(error.message);
process.exitCode = 2;
}