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>
This commit is contained in:
que01andClaude Opus 5.5 committed 2026-09-27 06:55:56 +08:00
1 parent e2e2340bfe
commit a97cc860cf
31 files changed
+418 -158

No files matched your search

+14 -22
View File
@@ -29,18 +29,9 @@ const RUNTIME_EXCLUDES = new Set([
"app.json",
"project.config.json",
"runtime-config.js",
"assets",
"pages/booking",
"utils/templates.js",
"components/templates",
"components/runtime-tab-bar",
"pages/index",
"pages/services",
"pages/bookings",
"pages/stall-service",
]);
const LAYER_EXCLUDES = new Set(["node_modules", ".turbo", "dist", ".gitkeep", "app.json"]);
const PAGE_EXTENSIONS = [".js", ".json", ".wxml"];
const PAGE_EXTENSIONS = [".js", ".json", ".wxml", ".wxss"];
class CompileError extends Error {}
@@ -56,15 +47,12 @@ function toPosix(relativePath) {
return relativePath.split(path.sep).join("/");
}
/** exclude 中的条目是相对层根目录的路径,只匹配该路径本身,不匹配深层同名目录(如 TDesign 的 common/src)。 */
function listFiles(directory, exclude, base = directory) {
const files = [];
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
const entryPath = toPosix(path.relative(base, path.join(directory, entry.name)));
if (
exclude.has(entry.name) ||
[...exclude].some((value) => entryPath === value || entryPath.startsWith(value + "/"))
)
continue;
if (exclude.has(entryPath)) continue;
if (entry.name === ".gitkeep") continue;
const filePath = path.join(directory, entry.name);
if (entry.isDirectory()) files.push(...listFiles(filePath, exclude, base));
@@ -202,6 +190,7 @@ function buildAppJson(manifest, templateDirectory, capabilities) {
for (const [key, page] of Object.entries(manifest.entrypoints)) {
if (!pages.includes(page)) fail(`entrypoints.${key} (${page}) is not provided by any layer`);
}
// 颜色属于模板视觉,由模板的 miniapp/app.json 提供;这里只兜底中性色。
const tabBarStyle = templateApp.tabBar || {};
return {
...runtimeApp,
@@ -212,8 +201,8 @@ function buildAppJson(manifest, templateDirectory, capabilities) {
...(templateApp.window || {}),
},
tabBar: {
color: tabBarStyle.color || "#8b8178",
selectedColor: tabBarStyle.selectedColor || "#3b2118",
color: tabBarStyle.color || "#7a7a7a",
selectedColor: tabBarStyle.selectedColor || "#1a1a1a",
backgroundColor: tabBarStyle.backgroundColor || "#ffffff",
borderStyle: tabBarStyle.borderStyle || "white",
list: manifest.navigation.map((item) => ({
@@ -276,12 +265,15 @@ function writeGeneratedFiles(output, manifest, params, appJson, capabilities) {
);
}
function otherTemplateComponentNames(currentDirectory) {
// 按 packageKey 识别当前模板,--template-dir 指向 packages/ 之外的副本时同样成立。
function otherTemplateComponentNames(currentPackageKey) {
const names = new Set();
for (const entry of fs.readdirSync(packagesRoot, { withFileTypes: true })) {
if (!entry.isDirectory() || !entry.name.startsWith("template-")) continue;
const directory = path.join(packagesRoot, entry.name);
if (path.resolve(directory) === path.resolve(currentDirectory)) continue;
const manifestPath = path.join(directory, "template.json");
if (!fs.existsSync(manifestPath) || readJson(manifestPath).packageKey === currentPackageKey)
continue;
const componentRoot = path.join(directory, "miniapp/components/templates");
if (!fs.existsSync(componentRoot)) continue;
for (const component of fs.readdirSync(componentRoot)) names.add(component);
@@ -306,7 +298,7 @@ function resolveRequire(output, fromFile, reference) {
}
/** 校验产物可以被微信开发者工具直接打开:页面、组件、require、图标和模板隔离。 */
function validateOutput(output, appJson, templateDirectory) {
function validateOutput(output, appJson, packageKey) {
const errors = [];
const warnings = [];
for (const page of appJson.pages) {
@@ -322,7 +314,7 @@ function validateOutput(output, appJson, templateDirectory) {
}
}
const hasNpm = fs.existsSync(path.join(output, "miniprogram_npm"));
const forbiddenComponents = otherTemplateComponentNames(templateDirectory);
const forbiddenComponents = otherTemplateComponentNames(packageKey);
const sourceFiles = listFiles(output, new Set(["miniprogram_npm"])).filter((file) =>
/\.(js|json|wxml)$/.test(file),
);
@@ -393,7 +385,7 @@ export function compileTemplate(options) {
);
const appJson = buildAppJson(manifest, templateDirectory, capabilities);
writeGeneratedFiles(output, manifest, params, appJson, capabilities);
const { errors, warnings } = validateOutput(output, appJson, templateDirectory);
const { errors, warnings } = validateOutput(output, appJson, manifest.packageKey);
if (errors.length) fail(`Generated mini program is invalid:\n ${errors.join("\n ")}`);
return { output, manifest, params, warnings };
}