feat: 完善模板驱动的品牌内容工作台
This commit is contained in:
1 parent
77224ea51f
commit
dd55af8d73
46 files changed
+2204
-295
No files matched your search
@@ -0,0 +1,53 @@
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const crypto = require("node:crypto");
|
||||
|
||||
const root = path.resolve(__dirname, "..");
|
||||
const packageRoot = path.join(root, "packages");
|
||||
const outputPath = path.join(root, "packages/config/src/generated-template-packages.js");
|
||||
const declarationPath = path.join(root, "packages/config/src/generated-template-packages.d.ts");
|
||||
const templates = fs
|
||||
.readdirSync(packageRoot, { withFileTypes: true })
|
||||
.filter(
|
||||
(entry) =>
|
||||
entry.isDirectory() &&
|
||||
entry.name.startsWith("template-") &&
|
||||
fs.existsSync(path.join(packageRoot, entry.name, "template.json")),
|
||||
)
|
||||
.map((entry) => {
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(path.join(packageRoot, entry.name, "template.json"), "utf8"),
|
||||
);
|
||||
return { ...manifest, visualTemplateKey: manifest.packageKey };
|
||||
})
|
||||
.sort((left, right) => left.packageKey.localeCompare(right.packageKey));
|
||||
|
||||
const canonical = (value) => {
|
||||
if (Array.isArray(value)) return value.map(canonical);
|
||||
if (!value || typeof value !== "object") return value;
|
||||
return Object.fromEntries(
|
||||
Object.keys(value)
|
||||
.sort()
|
||||
.map((key) => [key, canonical(value[key])]),
|
||||
);
|
||||
};
|
||||
const fingerprint = crypto
|
||||
.createHash("sha256")
|
||||
.update(JSON.stringify(canonical(templates)))
|
||||
.digest("hex");
|
||||
const content = `// prettier-ignore\nexport const generatedTemplatePackageRegistry = ${JSON.stringify(templates, null, 2)};\nexport const generatedTemplatePackageRegistryHash =\n "${fingerprint}";\n`;
|
||||
const declaration = `import type { TemplatePackageManifest } from "./index.js";\nexport declare const generatedTemplatePackageRegistry: readonly TemplatePackageManifest[];\nexport declare const generatedTemplatePackageRegistryHash: string;\n`;
|
||||
const write = process.argv.includes("--write");
|
||||
if (write) {
|
||||
fs.writeFileSync(outputPath, content);
|
||||
fs.writeFileSync(declarationPath, declaration);
|
||||
} else {
|
||||
const current = fs.existsSync(outputPath) ? fs.readFileSync(outputPath, "utf8") : "";
|
||||
const generatedHash = current.match(
|
||||
/generatedTemplatePackageRegistryHash\s*=\s*"([a-f0-9]+)"/,
|
||||
)?.[1];
|
||||
if (generatedHash !== fingerprint) {
|
||||
console.error("Generated template catalog is stale. Run pnpm generate:template-catalog.");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
const root = path.resolve(__dirname, "..");
|
||||
require(path.join(root, "scripts/generate-template-catalog.cjs"));
|
||||
const packageRoot = path.join(root, "templates");
|
||||
const requiredPages = ["home", "offerings", "detail", "inquiry", "success", "records", "profile"];
|
||||
const errors = [];
|
||||
@@ -74,6 +75,16 @@ for (const entry of workspaceTemplates) {
|
||||
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 (!Array.isArray(manifest.dataSlots) || !manifest.dataSlots.length)
|
||||
errors.push(`${entry.name}: dataSlots is required`);
|
||||
if (!Array.isArray(manifest.assetSlots))
|
||||
errors.push(`${entry.name}: assetSlots must be an array`);
|
||||
if (
|
||||
!manifest.admin ||
|
||||
!Array.isArray(manifest.admin.sections) ||
|
||||
!manifest.admin.sections.length
|
||||
)
|
||||
errors.push(`${entry.name}: admin.sections is required`);
|
||||
if (manifest.ownedPaths !== undefined && !Array.isArray(manifest.ownedPaths))
|
||||
errors.push(`${entry.name}: ownedPaths must be an array`);
|
||||
if (
|
||||
|
||||
Reference in new issue
Block a user