-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: isolate remix specifics in cli
We wanna support other frameworks than remix. At least to support SSG we need to additionally deploy vike.dev. Here split all remix specifics into separate module. It provides the list of components (including overrides) and templates getter. Templates allow to provide multiple module per route which is essential for many frameworks like svelte and vike which do not rely on treeshaking for client/server splitting.
- Loading branch information
Showing
3 changed files
with
157 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { join } from "node:path"; | ||
import { readFile, rm } from "node:fs/promises"; | ||
import { | ||
generateRemixRoute, | ||
namespaceMeta, | ||
WsComponentMeta, | ||
} from "@webstudio-is/react-sdk"; | ||
import * as baseComponentMetas from "@webstudio-is/sdk-components-react/metas"; | ||
import * as remixComponentMetas from "@webstudio-is/sdk-components-react-remix/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 defaultSitemapTemplate = await readFile( | ||
join(routeTemplatesDir, "default-sitemap.tsx"), | ||
"utf8" | ||
); | ||
const redirectTemplate = await readFile( | ||
join(routeTemplatesDir, "redirect.tsx"), | ||
"utf8" | ||
); | ||
|
||
// cleanup route templates after reading to not bloat generated code | ||
await rm(routeTemplatesDir, { recursive: true, force: true }); | ||
|
||
const radixComponentNamespacedMetas: Record<string, WsComponentMeta> = {}; | ||
for (const [name, meta] of Object.entries(radixComponentMetas)) { | ||
const namespace = "@webstudio-is/sdk-components-react-radix"; | ||
radixComponentNamespacedMetas[`${namespace}:${name}`] = namespaceMeta( | ||
meta, | ||
namespace, | ||
new Set(Object.keys(radixComponentMetas)) | ||
); | ||
} | ||
|
||
return { | ||
components: [ | ||
{ | ||
source: "@webstudio-is/sdk-components-react", | ||
metas: baseComponentMetas, | ||
}, | ||
{ | ||
source: "@webstudio-is/sdk-components-react-radix", | ||
metas: radixComponentNamespacedMetas, | ||
}, | ||
{ | ||
source: "@webstudio-is/sdk-components-react-remix", | ||
metas: remixComponentMetas, | ||
}, | ||
], | ||
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, | ||
}, | ||
], | ||
redirect: ({ pagePath }: { pagePath: string }) => [ | ||
{ | ||
file: join("app", "routes", `${generateRemixRoute(pagePath)}.ts`), | ||
template: redirectTemplate, | ||
}, | ||
], | ||
defaultSitemap: () => [ | ||
{ | ||
file: join( | ||
"app", | ||
"routes", | ||
`${generateRemixRoute("/sitemap.xml")}.tsx` | ||
), | ||
template: defaultSitemapTemplate, | ||
}, | ||
], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { WsComponentMeta } from "@webstudio-is/react-sdk"; | ||
|
||
type FrameworkComponentEntry = { | ||
source: string; | ||
metas: Record<string, WsComponentMeta>; | ||
}; | ||
|
||
type FrameworkTemplateEntry = { | ||
file: string; | ||
template: string; | ||
}; | ||
|
||
export type Framework = { | ||
components: FrameworkComponentEntry[]; | ||
html: (params: { pagePath: string }) => FrameworkTemplateEntry[]; | ||
xml: (params: { pagePath: string }) => FrameworkTemplateEntry[]; | ||
redirect: (params: { pagePath: string }) => FrameworkTemplateEntry[]; | ||
defaultSitemap: () => FrameworkTemplateEntry[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters