mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-06 07:11:55 +09:00
95 lines
3.1 KiB
TypeScript
95 lines
3.1 KiB
TypeScript
import { join } from "node:path";
|
|
import { readFile, rm } from "node:fs/promises";
|
|
import type { WsComponentMeta } from "@webstudio-is/sdk";
|
|
import { generateRemixRoute } from "@webstudio-is/react-sdk";
|
|
import * as baseComponentMetas from "@webstudio-is/sdk-components-react/metas";
|
|
import * as animationComponentMetas from "@webstudio-is/sdk-components-animation/metas";
|
|
import * as radixComponentMetas from "@webstudio-is/sdk-components-react-radix/metas";
|
|
import type { Framework } from "./framework";
|
|
|
|
export const createFramework = async (): Promise<Framework> => {
|
|
const routeTemplatesDir = join("app", "route-templates");
|
|
|
|
const htmlTemplate = await readFile(
|
|
join(routeTemplatesDir, "html.tsx"),
|
|
"utf8"
|
|
);
|
|
const xmlTemplate = await readFile(
|
|
join(routeTemplatesDir, "xml.tsx"),
|
|
"utf8"
|
|
);
|
|
const textTemplate = await readFile(
|
|
join(routeTemplatesDir, "text.tsx"),
|
|
"utf8"
|
|
);
|
|
const defaultSitemapTemplate = await readFile(
|
|
join(routeTemplatesDir, "default-sitemap.tsx"),
|
|
"utf8"
|
|
);
|
|
// cleanup route templates after reading to not bloat generated code
|
|
await rm(routeTemplatesDir, { recursive: true, force: true });
|
|
|
|
const base = "@webstudio-is/sdk-components-react/components";
|
|
const remix = "@webstudio-is/sdk-components-react-remix";
|
|
const reactRadix = "@webstudio-is/sdk-components-react-radix";
|
|
const animation = "@webstudio-is/sdk-components-animation";
|
|
const components: Record<string, string> = {};
|
|
const metas: Record<string, WsComponentMeta> = {};
|
|
for (const [name, meta] of Object.entries(baseComponentMetas)) {
|
|
components[name] = `${base}:${name}`;
|
|
metas[name] = meta;
|
|
}
|
|
for (const name of ["Body", "Link", "RichTextLink", "Form", "RemixForm"]) {
|
|
components[name] = `${remix}:${name}`;
|
|
}
|
|
for (const [name, meta] of Object.entries(radixComponentMetas)) {
|
|
components[`${reactRadix}:${name}`] = `${reactRadix}:${name}`;
|
|
metas[`${reactRadix}:${name}`] = meta;
|
|
}
|
|
for (const [name, meta] of Object.entries(animationComponentMetas)) {
|
|
components[`${animation}:${name}`] = `${animation}:${name}`;
|
|
metas[`${animation}:${name}`] = meta;
|
|
}
|
|
|
|
return {
|
|
metas,
|
|
components,
|
|
tags: {
|
|
textarea: `${base}:Textarea`,
|
|
input: `${base}:Input`,
|
|
select: `${base}:Select`,
|
|
body: `${remix}:Body`,
|
|
a: `${remix}:Link`,
|
|
form: `${remix}:RemixForm`,
|
|
},
|
|
html: ({ pagePath }: { pagePath: string }) => [
|
|
{
|
|
file: join("app", "routes", `${generateRemixRoute(pagePath)}.tsx`),
|
|
template: htmlTemplate,
|
|
},
|
|
],
|
|
xml: ({ pagePath }: { pagePath: string }) => [
|
|
{
|
|
file: join("app", "routes", `${generateRemixRoute(pagePath)}.tsx`),
|
|
template: xmlTemplate,
|
|
},
|
|
],
|
|
text: ({ pagePath }: { pagePath: string }) => [
|
|
{
|
|
file: join("app", "routes", `${generateRemixRoute(pagePath)}.tsx`),
|
|
template: textTemplate,
|
|
},
|
|
],
|
|
defaultSitemap: () => [
|
|
{
|
|
file: join(
|
|
"app",
|
|
"routes",
|
|
`${generateRemixRoute("/sitemap.xml")}.tsx`
|
|
),
|
|
template: defaultSitemapTemplate,
|
|
},
|
|
],
|
|
};
|
|
};
|