refactor: 重构模板叠加式编译产物

This commit is contained in:
que01 committed 2026-09-26 11:21:29 +08:00
1 parent c46297b13b
commit 25d1fe983c
93 files changed
+870 -2467

No files matched your search

+21 -3
View File
@@ -1,5 +1,7 @@
const fs = require("node:fs");
const path = require("node:path");
const os = require("node:os");
const { execFileSync } = require("node:child_process");
const root = path.resolve(__dirname, "..");
const requestSource = fs.readFileSync(path.join(root, "utils/request.js"), "utf8");
const configSource = fs.readFileSync(path.join(root, "utils/config.js"), "utf8");
@@ -13,7 +15,7 @@ if (
console.error("miniapp: public requests must carry the configured brand slug");
process.exit(1);
}
if (!moduleRegistrySource.includes("Object.values(manifest?.pages || {})")) {
if (!moduleRegistrySource.includes("manifest.pages")) {
console.error("miniapp: visual page renderers must resolve from the manifest");
process.exit(1);
}
@@ -24,10 +26,11 @@ if (
console.error("miniapp: customer sessions must be brand-scoped");
process.exit(1);
}
const productionRoots = ["components/modules", "components/templates", "pages"];
const productionRoots = ["components/modules", "pages"];
const productionSources = [];
function collectSources(directory) {
const current = path.join(root, directory);
if (!fs.existsSync(current)) return;
for (const item of fs.readdirSync(current, { withFileTypes: true })) {
const itemPath = path.join(current, item.name);
if (item.isDirectory()) collectSources(path.relative(root, itemPath));
@@ -83,8 +86,23 @@ for (const fixture of fixtures) {
records: "pages/records/index",
profile: "pages/bookings/index",
};
const templateKey = fixture.templateKey.startsWith("acheng")
? "acheng-campus-food"
: "linjing-editorial";
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-fixture-"));
execFileSync(
process.execPath,
[
path.resolve(root, "../../packages/template-compiler/src/cli.mjs"),
"--template",
templateKey,
"--out",
output,
],
{ stdio: "ignore" },
);
const missingPages = fixture.pages.filter(
(key) => !fs.existsSync(path.join(root, `${pageMap[key]}.json`)),
(key) => !fs.existsSync(path.join(output, `${pageMap[key]}.json`)),
);
if (missingPages.length) {
console.error(`${fixture.templateKey}: missing page manifests: ${missingPages.join(", ")}`);