Files
persionalBrand/scripts/validate-template-packages.cjs
que01andClaude Opus 5.5 a97cc860cf feat: 补齐模板编译扩展性门禁与演练模板
- 新增第二行业演练模板 drill-consultant,验证新增行业无需修改编译器和运行���
- 补充 override 冲突与显式覆盖测试,产物校验覆盖 wxss
- 修复 --template-dir 模板被误判引用其他模板组件的问题
- 修复运行时排除规则误删 TDesign 深层 src 目录,增加 miniprogram_npm 完整性回归
- 模板目录校验统一复用 template-contract,新增 template:check 并接入 pnpm check
- tabBar 配色归属模板包,清理编译器过期排除项和旧 fixture
- ADR 0015 明确对 0005/0008/0009 的替换范围

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 06:55:56 +08:00

54 lines
2.2 KiB
JavaScript

const fs = require("node:fs");
const path = require("node:path");
const { pathToFileURL } = require("node:url");
const root = path.resolve(__dirname, "..");
require(path.join(root, "scripts/generate-template-catalog.cjs"));
const workspacePackageRoot = path.join(root, "packages");
const contractEntry = path.join(workspacePackageRoot, "template-contract/src/index.ts");
const workspaceTemplates = fs
.readdirSync(workspacePackageRoot, { withFileTypes: true })
.filter(
(entry) =>
entry.isDirectory() &&
entry.name.startsWith("template-") &&
fs.existsSync(path.join(workspacePackageRoot, entry.name, "template.json")),
);
async function main() {
// manifest 规则只在 template-contract 中维护;这里只补充依赖文件系统的检查。
const { validateTemplatePackageManifest } = await import(pathToFileURL(contractEntry).href);
const errors = [];
for (const entry of workspaceTemplates) {
const packageDir = path.join(workspacePackageRoot, entry.name);
let manifest;
try {
manifest = JSON.parse(fs.readFileSync(path.join(packageDir, "template.json"), "utf8"));
} catch (error) {
errors.push(`${entry.name}: invalid template.json (${error.message})`);
continue;
}
for (const error of validateTemplatePackageManifest(manifest))
errors.push(`${entry.name}: ${error}`);
if (![entry.name, entry.name.replace(/^template-/, "")].includes(manifest.packageKey))
errors.push(`${entry.name}: packageKey must match directory name or template key`);
for (const page of manifest.pages || []) {
if (!fs.existsSync(path.join(packageDir, "miniapp", page + ".js")))
errors.push(`${entry.name}: declared page is missing: ${page}`);
}
for (const item of manifest.navigation || []) {
for (const asset of [item.iconPath, item.selectedIconPath]) {
if (asset && !fs.existsSync(path.join(packageDir, "miniapp", asset)))
errors.push(`${entry.name}: navigation asset is missing: ${asset}`);
}
}
}
if (errors.length) {
console.error(errors.join("\n"));
process.exit(1);
}
console.log(`Workspace template packages validated: ${workspaceTemplates.length}`);
}
main();