refactor: 重构模板叠加式编译产物
This commit is contained in:
1 parent
c46297b13b
commit
25d1fe983c
93 files changed
+870
-2467
No files matched your search
@@ -10,6 +10,13 @@ const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "
|
||||
const workspaceRoot = path.resolve(packageRoot, "../..");
|
||||
const compiler = path.join(packageRoot, "src/cli.mjs");
|
||||
|
||||
function assertPageBundle(output, app) {
|
||||
for (const page of app.pages) {
|
||||
for (const extension of [".js", ".json", ".wxml", ".wxss"])
|
||||
assert.equal(fs.existsSync(path.join(output, page + extension)), true, `${page}${extension}`);
|
||||
}
|
||||
}
|
||||
|
||||
test("compiler generates an isolated Acheng runtime manifest", () => {
|
||||
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
|
||||
execFileSync(process.execPath, [compiler, "--template", "acheng-campus-food", "--out", output], {
|
||||
@@ -20,58 +27,24 @@ test("compiler generates an isolated Acheng runtime manifest", () => {
|
||||
const runtime = JSON.parse(fs.readFileSync(path.join(output, "template.runtime.json"), "utf8"));
|
||||
assert.equal(app.window.navigationBarTitleText, "阿成校园餐");
|
||||
assert.equal(runtime.packageKey, "acheng-campus-food");
|
||||
assert.equal(runtime.renderers.home, "acheng-home");
|
||||
assert.match(fs.readFileSync(path.join(output, "app.js"), "utf8"), /default-brand/);
|
||||
assert.equal(runtime.entrypoints.home, "pages/index/index");
|
||||
assert.match(fs.readFileSync(path.join(output, "runtime-config.js"), "utf8"), /default-brand/);
|
||||
assert.equal(runtime.navigation.length, 5);
|
||||
assert.equal(runtime.navigation[2].page, "service");
|
||||
assert.equal(
|
||||
JSON.parse(fs.readFileSync(path.join(output, "app.json"), "utf8")).tabBar.list.length,
|
||||
5,
|
||||
);
|
||||
assertPageBundle(output, app);
|
||||
assert.equal(fs.existsSync(path.join(output, "components/runtime-tab-bar")), false);
|
||||
assert.equal(
|
||||
fs
|
||||
.readFileSync(path.join(output, "pages/index/index.wxml"), "utf8")
|
||||
.includes("runtime-tab-bar"),
|
||||
false,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "components/templates/linjing-home")), false);
|
||||
assert.equal(
|
||||
fs.existsSync(path.join(output, "components/templates/acheng-home/acheng-home.wxml")),
|
||||
false,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "components/template-pages/home/home.wxml")), true);
|
||||
assert.equal(fs.existsSync(path.join(output, "components/templates")), false);
|
||||
assert.match(
|
||||
fs.readFileSync(path.join(output, "pages/index/index.wxml"), "utf8"),
|
||||
/<template-home/,
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
fs.readFileSync(path.join(output, "pages/index/index.wxml"), "utf8"),
|
||||
/acheng-home/,
|
||||
);
|
||||
assert.equal(
|
||||
fs.readFileSync(path.join(output, "pages/index/index.wxml"), "utf8").trim().length > 20,
|
||||
true,
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
fs.readFileSync(path.join(output, "pages/index/index.wxml"), "utf8"),
|
||||
/pageRenderer ===/,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/stall-service/index.wxml")), true);
|
||||
assert.match(
|
||||
fs.readFileSync(path.join(output, "pages/services/index.wxml"), "utf8"),
|
||||
/<template-offerings/,
|
||||
);
|
||||
assert.match(
|
||||
fs.readFileSync(path.join(output, "pages/bookings/index.wxml"), "utf8"),
|
||||
/<template-profile/,
|
||||
);
|
||||
assert.equal(
|
||||
fs
|
||||
.readFileSync(path.join(output, "pages/inquiry/index.wxml"), "utf8")
|
||||
.includes("runtime-tab-bar"),
|
||||
false,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/booking/index.wxml")), true);
|
||||
assert.equal(fs.existsSync(path.join(output, "assets/tab/booking.png")), true);
|
||||
});
|
||||
|
||||
test("compiler generates the Linjing navigation contract", () => {
|
||||
@@ -82,9 +55,10 @@ test("compiler generates the Linjing navigation contract", () => {
|
||||
});
|
||||
const runtime = JSON.parse(fs.readFileSync(path.join(output, "template.runtime.json"), "utf8"));
|
||||
assert.equal(runtime.packageKey, "linjing-editorial");
|
||||
assert.equal(runtime.renderers.home, "linjing-home");
|
||||
assert.equal(runtime.renderers.offerings, "linjing-offerings");
|
||||
assert.match(fs.readFileSync(path.join(output, "app.js"), "utf8"), /linjing-doors/);
|
||||
assert.equal(runtime.entrypoints.home, "pages/index/index");
|
||||
assert.match(fs.readFileSync(path.join(output, "runtime-config.js"), "utf8"), /linjing-doors/);
|
||||
const app = JSON.parse(fs.readFileSync(path.join(output, "app.json"), "utf8"));
|
||||
assertPageBundle(output, app);
|
||||
assert.equal(runtime.navigation.length, 3);
|
||||
assert.equal(runtime.navigation[0].iconPath, "assets/tab/home.png");
|
||||
assert.equal(
|
||||
@@ -94,7 +68,7 @@ test("compiler generates the Linjing navigation contract", () => {
|
||||
assert.equal(fs.existsSync(path.join(output, "assets/tab/works.png")), true);
|
||||
assert.equal(
|
||||
fs.existsSync(path.join(output, "components/templates/linjing-home/linjing-home.wxml")),
|
||||
false,
|
||||
true,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/stall-service")), false);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/booking")), false);
|
||||
@@ -102,10 +76,7 @@ test("compiler generates the Linjing navigation contract", () => {
|
||||
fs.readFileSync(path.join(output, "app.json"), "utf8"),
|
||||
/stall-service|booking\/index/,
|
||||
);
|
||||
assert.match(
|
||||
fs.readFileSync(path.join(output, "pages/services/index.wxml"), "utf8"),
|
||||
/<template-offerings/,
|
||||
);
|
||||
assert.equal(fs.existsSync(path.join(output, "pages/services/index.wxml")), true);
|
||||
});
|
||||
|
||||
test("release manifest pins every workspace template version", () => {
|
||||
@@ -124,3 +95,38 @@ test("release manifest pins every workspace template version", () => {
|
||||
assert.equal(manifest.runtimeContract, releaseConfig.runtimeContract);
|
||||
}
|
||||
});
|
||||
|
||||
test("compiler rejects production builds without deployment parameters", () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
[compiler, "--template", "linjing-editorial", "--env", "prod"],
|
||||
{ cwd: workspaceRoot },
|
||||
),
|
||||
/Production build requires --brand, --appid, --api/,
|
||||
);
|
||||
});
|
||||
|
||||
test("compiler rejects unknown capabilities before copying layers", () => {
|
||||
const templateDirectory = fs.mkdtempSync(
|
||||
path.join(os.tmpdir(), "personal-brand-template-package-"),
|
||||
);
|
||||
fs.cpSync(path.join(workspaceRoot, "packages/template-linjing-editorial"), templateDirectory, {
|
||||
recursive: true,
|
||||
});
|
||||
const manifestPath = path.join(templateDirectory, "template.json");
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
manifest.requiredCapabilities.push("missing");
|
||||
fs.writeFileSync(manifestPath, JSON.stringify(manifest));
|
||||
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
|
||||
assert.throws(
|
||||
() =>
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
[compiler, "--template-dir", templateDirectory, "--out", output],
|
||||
{ cwd: workspaceRoot },
|
||||
),
|
||||
/requires unknown capability: missing/,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user