119 lines
4.8 KiB
JavaScript
119 lines
4.8 KiB
JavaScript
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
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");
|
|
const moduleRegistrySource = fs.readFileSync(path.join(root, "utils/module-registry.js"), "utf8");
|
|
const runtimeRequestSource = fs.readFileSync(path.join(root, "utils/request.js"), "utf8");
|
|
if (
|
|
!requestSource.includes('path.startsWith("/public/")') ||
|
|
!requestSource.includes("brandSlug") ||
|
|
!configSource.includes("brandSlug")
|
|
) {
|
|
console.error("miniapp: public requests must carry the configured brand slug");
|
|
process.exit(1);
|
|
}
|
|
if (!moduleRegistrySource.includes("Object.values(manifest?.pages || {})")) {
|
|
console.error("miniapp: visual page renderers must resolve from the manifest");
|
|
process.exit(1);
|
|
}
|
|
if (
|
|
!runtimeRequestSource.includes('path.startsWith("/customer/session/wechat")') ||
|
|
!runtimeRequestSource.includes('"customerToken:" + config.brandSlug')
|
|
) {
|
|
console.error("miniapp: customer sessions must be brand-scoped");
|
|
process.exit(1);
|
|
}
|
|
const productionRoots = ["components/modules", "components/templates", "pages"];
|
|
const productionSources = [];
|
|
function collectSources(directory) {
|
|
const current = path.join(root, directory);
|
|
for (const item of fs.readdirSync(current, { withFileTypes: true })) {
|
|
const itemPath = path.join(current, item.name);
|
|
if (item.isDirectory()) collectSources(path.relative(root, itemPath));
|
|
else if (itemPath.endsWith(".js") || itemPath.endsWith(".wxml"))
|
|
productionSources.push({ file: itemPath, content: fs.readFileSync(itemPath, "utf8") });
|
|
}
|
|
}
|
|
productionRoots.forEach(collectSources);
|
|
for (const term of ["林境门", "亲自主理量房", "拒绝流水线拼装", "linjingInquiryRecords"]) {
|
|
const leak = productionSources.find(({ content }) => content.includes(term));
|
|
if (leak) {
|
|
console.error(`miniapp: static business term ${term} leaked into ${leak.file}`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
const fixtureFiles = ["linjing-door.json", "doors-industry.json"];
|
|
const fixtures = fixtureFiles.map((file) =>
|
|
JSON.parse(fs.readFileSync(path.join(__dirname, "fixtures", file), "utf8")),
|
|
);
|
|
const doorsContent = JSON.parse(
|
|
fs.readFileSync(path.join(__dirname, "fixtures", "doors-content.json"), "utf8"),
|
|
);
|
|
if (
|
|
doorsContent.offerings.length < 3 ||
|
|
doorsContent.trustContent.length < 3 ||
|
|
doorsContent.inquiryFields.length < 3
|
|
) {
|
|
console.error("doors: content fixture must include offerings, trust content, and inquiry fields");
|
|
process.exit(1);
|
|
}
|
|
if (!doorsContent.offerings.every((item) => item.kind === "product" || item.kind === "service")) {
|
|
console.error("doors: offerings must use shared product or service kinds");
|
|
process.exit(1);
|
|
}
|
|
for (const fixture of fixtures) {
|
|
const modules = fixture.requiredModules.map((key) => path.join(root, "components/modules", key));
|
|
const missing = modules.filter(
|
|
(directory) =>
|
|
![".js", ".json", ".wxml", ".wxss"].every((extension) =>
|
|
fs.existsSync(path.join(directory, `${path.basename(directory)}${extension}`)),
|
|
),
|
|
);
|
|
if (missing.length) {
|
|
console.error(`${fixture.templateKey}: missing module files: ${missing.join(", ")}`);
|
|
process.exit(1);
|
|
}
|
|
const pageMap = {
|
|
home: "pages/index/index",
|
|
offerings: "pages/services/index",
|
|
detail: "pages/offering/detail",
|
|
inquiry: "pages/inquiry/index",
|
|
success: "pages/inquiry-success/index",
|
|
records: "pages/records/index",
|
|
profile: "pages/bookings/index",
|
|
};
|
|
const missingPages = fixture.pages.filter(
|
|
(key) => !fs.existsSync(path.join(root, `${pageMap[key]}.json`)),
|
|
);
|
|
if (missingPages.length) {
|
|
console.error(`${fixture.templateKey}: missing page manifests: ${missingPages.join(", ")}`);
|
|
process.exit(1);
|
|
}
|
|
if (!fixture.layout?.home?.length) {
|
|
console.error(`${fixture.templateKey}: missing home layout`);
|
|
process.exit(1);
|
|
}
|
|
if (
|
|
fixture.requiredCapabilities &&
|
|
fixture.requiredCapabilities.includes("inquiry") &&
|
|
!fixture.requiredModules.includes("inquiry-form")
|
|
) {
|
|
console.error(`${fixture.templateKey}: inquiry capability requires inquiry-form module`);
|
|
process.exit(1);
|
|
}
|
|
if (
|
|
fixture.visualAnchors?.home &&
|
|
JSON.stringify(fixture.layout.home) !== JSON.stringify(fixture.visualAnchors.home)
|
|
) {
|
|
console.error(`${fixture.templateKey}: home layout does not match visual anchors`);
|
|
process.exit(1);
|
|
}
|
|
console.log(
|
|
`Fixture ${fixture.templateKey}@${fixture.version} passed: ${fixture.requiredModules.length} modules.`,
|
|
);
|
|
}
|
|
console.log(
|
|
`Content fixture doors passed: ${doorsContent.offerings.length} offerings, ${doorsContent.trustContent.length} trust entries, ${doorsContent.inquiryFields.length} inquiry fields.`,
|
|
);
|