feat: 收口多品牌与模板构建基础

This commit is contained in:
que01 committed 2026-09-25 02:55:46 +08:00
1 parent 0425a1c672
commit 77224ea51f
317 files changed
+11290 -1158

No files matched your search

+107
View File
@@ -0,0 +1,107 @@
const fs = require("node:fs");
const path = require("node:path");
const root = path.resolve(__dirname, "..");
const packageRoot = path.join(root, "templates");
const requiredPages = ["home", "offerings", "detail", "inquiry", "success", "records", "profile"];
const errors = [];
for (const entry of fs.readdirSync(packageRoot, { withFileTypes: true })) {
if (!entry.isDirectory()) continue;
const packageDir = path.join(packageRoot, entry.name);
const manifestPath = path.join(packageDir, "template.json");
if (!fs.existsSync(manifestPath)) {
errors.push(`${entry.name}: template.json is missing`);
continue;
}
let manifest;
try {
manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
} catch (error) {
errors.push(`${entry.name}: invalid template.json (${error.message})`);
continue;
}
if (manifest.packageKey !== entry.name)
errors.push(`${entry.name}: packageKey must match directory name`);
if (!manifest.version) errors.push(`${entry.name}: version is required`);
if (manifest.runtimeContract !== "1.0") errors.push(`${entry.name}: unsupported runtimeContract`);
for (const page of requiredPages) {
if (typeof manifest.entrypoints?.[page] !== "string" || !manifest.entrypoints[page]) {
errors.push(`${entry.name}: entrypoints.${page} is required`);
}
}
if (
!Array.isArray(manifest.supportedIndustryTemplates) ||
!manifest.supportedIndustryTemplates.length
) {
errors.push(`${entry.name}: supportedIndustryTemplates must not be empty`);
}
if (!Array.isArray(manifest.requiredCapabilities))
errors.push(`${entry.name}: requiredCapabilities must be an array`);
if (!fs.existsSync(path.join(packageDir, "README.md")))
errors.push(`${entry.name}: README.md is missing`);
}
if (errors.length) {
console.error(errors.join("\n"));
process.exit(1);
}
console.log(
`Template packages validated: ${fs.readdirSync(packageRoot, { withFileTypes: true }).filter((entry) => entry.isDirectory()).length}`,
);
const workspacePackageRoot = path.join(root, "packages");
const workspaceTemplates = fs
.readdirSync(workspacePackageRoot, { withFileTypes: true })
.filter(
(entry) =>
entry.isDirectory() &&
entry.name.startsWith("template-") &&
fs.existsSync(path.join(workspacePackageRoot, entry.name, "template.json")),
);
for (const entry of workspaceTemplates) {
const manifestPath = path.join(workspacePackageRoot, entry.name, "template.json");
if (!fs.existsSync(manifestPath)) errors.push(`${entry.name}: template.json is missing`);
else {
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
if (
manifest.packageKey !== entry.name &&
manifest.packageKey !== entry.name.replace(/^template-/, "")
)
errors.push(`${entry.name}: packageKey must match directory name or template key`);
if (manifest.runtimeContract !== "1.0")
errors.push(`${entry.name}: unsupported runtimeContract`);
if (!manifest.displayName) errors.push(`${entry.name}: displayName is required`);
if (!Array.isArray(manifest.navigation) || !manifest.navigation.length)
errors.push(`${entry.name}: navigation is required`);
if (manifest.ownedPaths !== undefined && !Array.isArray(manifest.ownedPaths))
errors.push(`${entry.name}: ownedPaths must be an array`);
if (
manifest.renderers !== undefined &&
(typeof manifest.renderers !== "object" || Array.isArray(manifest.renderers))
)
errors.push(`${entry.name}: renderers must be an object`);
if (
manifest.runtimeOwnedPages !== undefined &&
(!Array.isArray(manifest.runtimeOwnedPages) ||
manifest.runtimeOwnedPages.some(
(page) => !["detail", "inquiry", "success", "records"].includes(page),
))
)
errors.push(`${entry.name}: runtimeOwnedPages contains an unsupported page`);
for (const item of manifest.navigation || []) {
for (const asset of [item.iconPath, item.selectedIconPath]) {
if (asset && !fs.existsSync(path.join(workspacePackageRoot, entry.name, "miniapp", asset)))
errors.push(`${entry.name}: navigation asset is missing: ${asset}`);
}
}
for (const page of requiredPages)
if (typeof manifest.entrypoints?.[page] !== "string")
errors.push(`${entry.name}: entrypoints.${page} is required`);
}
}
if (errors.length) {
console.error(errors.join("\n"));
process.exit(1);
}
console.log(`Workspace template packages validated: ${workspaceTemplates.length}`);
+47
View File
@@ -0,0 +1,47 @@
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const { execFileSync } = require("node:child_process");
const root = path.resolve(__dirname, "..");
const buildConfig = JSON.parse(
fs.readFileSync(path.join(root, "config/template-build.json"), "utf8"),
);
const compiler = path.join(root, "packages/template-compiler/src/cli.mjs");
const failures = [];
for (const entry of buildConfig.templates) {
const packagePath = path.join(root, "packages/template-" + entry.packageKey);
const manifestPath = path.join(packagePath, "template.json");
if (!fs.existsSync(manifestPath)) {
failures.push(`${entry.packageKey}: template.json is missing`);
continue;
}
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
if (manifest.version !== entry.version)
failures.push(
`${entry.packageKey}: build version ${entry.version} != manifest ${manifest.version}`,
);
if (manifest.runtimeContract !== buildConfig.runtimeContract)
failures.push(`${entry.packageKey}: runtime contract mismatch`);
const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-release-"));
try {
execFileSync(process.execPath, [compiler, "--template", entry.packageKey, "--out", output], {
cwd: root,
stdio: "ignore",
});
const runtime = JSON.parse(fs.readFileSync(path.join(output, "template.runtime.json"), "utf8"));
if (runtime.packageKey !== entry.packageKey || runtime.version !== entry.version)
failures.push(`${entry.packageKey}: generated runtime snapshot mismatch`);
} catch (error) {
failures.push(`${entry.packageKey}: compiler failed (${error.message})`);
} finally {
fs.rmSync(output, { recursive: true, force: true });
}
}
if (failures.length) {
console.error(failures.join("\n"));
process.exit(1);
}
console.log(`Template release validation passed: ${buildConfig.templates.length} packages.`);