Skip to content

Commit

Permalink
prebuild xml
Browse files Browse the repository at this point in the history
  • Loading branch information
istarkov committed May 7, 2024
1 parent d2cf991 commit 63177fc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 43 additions & 10 deletions packages/cli/src/prebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,19 +556,52 @@ export const prebuild = async (options: {
}

let componentImports = "";
let passthroughComponents = "";

const pageData = siteDataByPage[pageId];
const documentType = pageData.page.meta.documentType ?? "html";

for (const [namespace, componentsSet] of namespaces.entries()) {
const specifiers = Array.from(componentsSet)
.map(
([shortName, component]) =>
`${shortName} as ${scope.getName(component, shortName)}`
)
.join(", ");
componentImports += `import { ${specifiers} } from "${namespace}";\n`;
switch (documentType) {
case "html":
{
const specifiers = Array.from(componentsSet)
.map(
([shortName, component]) =>
`${shortName} as ${scope.getName(component, shortName)}`
)
.join(", ");
componentImports += `import { ${specifiers} } from "${namespace}";\n`;
}
break;

case "xml":
{
// In case of xml it's the only component we are supporting
componentImports = `import { XmlNode } from "@webstudio-is/sdk-components-react";\n`;

// Passthrough (render children) for all components except XmlNode
passthroughComponents += Array.from(componentsSet)
.filter(
([shortName, component]) =>
scope.getName(component, shortName) !== "XmlNode"
)
.map(
([shortName, component]) =>
`const ${scope.getName(
component,
shortName
)} = (props: any) => props.children;`
)
.join("\n");
}
break;
default: {
documentType satisfies never;
}
}
}

const pageData = siteDataByPage[pageId];
const documentType = pageData.page.meta.documentType ?? "html";
const pageFontAssets = fontAssetsByPage[pageId];
const pageBackgroundImageAssets = backgroundImageAssetsByPage[pageId];

Expand Down Expand Up @@ -633,7 +666,7 @@ export const prebuild = async (options: {
export const pageBackgroundImageAssets: ImageAsset[] =
${JSON.stringify(pageBackgroundImageAssets)}
${passthroughComponents}
${pageComponent}
Expand Down

0 comments on commit 63177fc

Please sign in to comment.