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:
1 parent
e2e2340bfe
commit
a97cc860cf
31 files changed
+418
-158
No files matched your search
@@ -45,6 +45,14 @@ test("compiler generates an isolated Acheng runtime manifest", () => {
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/stall-service/index.wxml")), true);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/booking/index.wxml")), true);
|
||||
assert.equal(fs.existsSync(path.join(output, "assets/tab/booking.png")), true);
|
||||
// 运行时的 npm 构建产物必须完整复制,不能被按名称排除的 src/test/dist 误伤。
|
||||
const runtimeNpm = path.join(workspaceRoot, "apps/miniapp/miniprogram_npm");
|
||||
if (fs.existsSync(runtimeNpm)) {
|
||||
for (const file of fs.readdirSync(runtimeNpm, { recursive: true })) {
|
||||
if (fs.statSync(path.join(runtimeNpm, file)).isFile())
|
||||
assert.equal(fs.existsSync(path.join(output, "miniprogram_npm", file)), true, file);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("compiler generates the Linjing navigation contract", () => {
|
||||
@@ -108,13 +116,82 @@ test("compiler rejects production builds without deployment parameters", () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("compiler rejects unknown capabilities before copying layers", () => {
|
||||
const templateDirectory = fs.mkdtempSync(
|
||||
path.join(os.tmpdir(), "personal-brand-template-package-"),
|
||||
test("a second-industry template compiles without compiler or runtime changes", () => {
|
||||
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
[
|
||||
compiler,
|
||||
"--template-dir",
|
||||
path.join(packageRoot, "test/fixtures/template-drill-consultant"),
|
||||
"--out",
|
||||
output,
|
||||
],
|
||||
{ cwd: workspaceRoot, stdio: "inherit" },
|
||||
);
|
||||
fs.cpSync(path.join(workspaceRoot, "packages/template-linjing-editorial"), templateDirectory, {
|
||||
const app = JSON.parse(fs.readFileSync(path.join(output, "app.json"), "utf8"));
|
||||
assertPageBundle(output, app);
|
||||
assert.equal(app.pages[0], "pages/index/index");
|
||||
for (const page of ["pages/offering/detail", "pages/inquiry/index", "pages/records/index"])
|
||||
assert.equal(app.pages.includes(page), true, page);
|
||||
assert.deepEqual(
|
||||
app.tabBar.list.map((item) => item.pagePath),
|
||||
["pages/index/index", "pages/services/index", "pages/profile/index"],
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/booking")), false);
|
||||
assert.deepEqual(fs.readdirSync(path.join(output, "components/templates")), ["drill-card"]);
|
||||
assert.match(fs.readFileSync(path.join(output, "runtime-config.js"), "utf8"), /drill-consultant/);
|
||||
});
|
||||
|
||||
function copyTemplate(key) {
|
||||
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-package-"));
|
||||
fs.cpSync(path.join(workspaceRoot, `packages/template-${key}`), directory, { recursive: true });
|
||||
return directory;
|
||||
}
|
||||
|
||||
test("compiler rejects template files that shadow runtime files without overrides", () => {
|
||||
const templateDirectory = copyTemplate("linjing-editorial");
|
||||
fs.cpSync(
|
||||
path.join(workspaceRoot, "apps/miniapp/pages/records"),
|
||||
path.join(templateDirectory, "miniapp/pages/records"),
|
||||
{ recursive: true },
|
||||
);
|
||||
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
|
||||
assert.throws(
|
||||
() =>
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
[compiler, "--template-dir", templateDirectory, "--out", output],
|
||||
{ cwd: workspaceRoot, stdio: "pipe" },
|
||||
),
|
||||
/conflicts with runtime at pages\/records\/index\.(js|json|wxml|wxss); declare it in overrides/,
|
||||
);
|
||||
});
|
||||
|
||||
test("compiler lets a template replace a runtime page declared in overrides", () => {
|
||||
const templateDirectory = copyTemplate("linjing-editorial");
|
||||
const pageDirectory = path.join(templateDirectory, "miniapp/pages/records");
|
||||
fs.cpSync(path.join(workspaceRoot, "apps/miniapp/pages/records"), pageDirectory, {
|
||||
recursive: true,
|
||||
});
|
||||
fs.appendFileSync(path.join(pageDirectory, "index.wxml"), "<!-- template override -->\n");
|
||||
const manifestPath = path.join(templateDirectory, "template.json");
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
manifest.overrides = [...(manifest.overrides || []), "pages/records"];
|
||||
fs.writeFileSync(manifestPath, JSON.stringify(manifest));
|
||||
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
|
||||
execFileSync(process.execPath, [compiler, "--template-dir", templateDirectory, "--out", output], {
|
||||
cwd: workspaceRoot,
|
||||
stdio: "pipe",
|
||||
});
|
||||
assert.match(
|
||||
fs.readFileSync(path.join(output, "pages/records/index.wxml"), "utf8"),
|
||||
/template override/,
|
||||
);
|
||||
});
|
||||
|
||||
test("compiler rejects unknown capabilities before copying layers", () => {
|
||||
const templateDirectory = copyTemplate("linjing-editorial");
|
||||
const manifestPath = path.join(templateDirectory, "template.json");
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
manifest.requiredCapabilities.push("missing");
|
||||
|
||||
Reference in new issue
Block a user