feat: 按视觉模板 manifest 驱动小程序运行时
This commit is contained in:
1 parent
031c81a7c1
commit
ce958fc1ae
17 files changed
+149
-26
No files matched your search
@@ -44,19 +44,57 @@ function resolveModule(module) {
|
||||
};
|
||||
}
|
||||
|
||||
const MANIFEST_TYPE_ALIASES = {
|
||||
"brand-identity": "founder-card",
|
||||
hero: "brand-hero",
|
||||
trust: "trust-proof",
|
||||
"inquiry-form": "inquiry",
|
||||
"success-summary": "success-summary",
|
||||
"records-list": "records",
|
||||
};
|
||||
|
||||
function resolveManifest(workspace) {
|
||||
const manifest = workspace && workspace.visualTemplateManifest;
|
||||
if (!manifest || !Array.isArray(manifest.pages)) return null;
|
||||
const pages = {};
|
||||
for (const page of manifest.pages) {
|
||||
pages[page.key] = (page.modules || []).map((module) => ({
|
||||
...module,
|
||||
type: MANIFEST_TYPE_ALIASES[module.type] || module.type,
|
||||
variant: module.variant || "default",
|
||||
}));
|
||||
}
|
||||
return { ...manifest, pages };
|
||||
}
|
||||
|
||||
function resolveRuntime(workspace) {
|
||||
const modules = Array.isArray(workspace && workspace.modules) ? workspace.modules : [];
|
||||
const manifest = resolveManifest(workspace);
|
||||
const manifestHome = manifest && manifest.pages.home;
|
||||
const manifestModules = manifestHome || [];
|
||||
const resolved = modules.map(resolveModule);
|
||||
const home =
|
||||
workspace && workspace.layout && Array.isArray(workspace.layout.home)
|
||||
const resolvedTypes = new Set(resolved.map((item) => item.type));
|
||||
for (const module of manifestModules) {
|
||||
if (!resolvedTypes.has(module.type)) {
|
||||
resolved.push(resolveModule(module));
|
||||
resolvedTypes.add(module.type);
|
||||
}
|
||||
}
|
||||
const home = manifestHome?.length
|
||||
? manifestHome.map((item) => item.type)
|
||||
: workspace && workspace.layout && Array.isArray(workspace.layout.home)
|
||||
? workspace.layout.home
|
||||
: resolved.map((item) => item.type);
|
||||
const moduleVariants = {};
|
||||
for (const item of manifestHome || []) moduleVariants[item.type] = item.variant;
|
||||
return {
|
||||
theme: workspace && workspace.theme ? workspace.theme : FALLBACK_THEME,
|
||||
theme: manifest?.tokens || (workspace && workspace.theme ? workspace.theme : FALLBACK_THEME),
|
||||
modules: resolved,
|
||||
layout: { home: home.filter((key) => resolved.some((item) => item.type === key)) },
|
||||
moduleVariants,
|
||||
visualManifest: manifest,
|
||||
capabilities: workspace && Array.isArray(workspace.capabilities) ? workspace.capabilities : [],
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { CORE_MODULES, FALLBACK_THEME, resolveRuntime };
|
||||
module.exports = { CORE_MODULES, FALLBACK_THEME, resolveManifest, resolveRuntime };
|
||||
Reference in new issue
Block a user