camox 0.33.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/AuthGate.js +5 -4
- package/dist/core/createBlock.js +19 -19
- package/dist/core/defineDocument.d.ts +7 -0
- package/dist/core/defineDocument.js +7 -0
- package/dist/features/agent-chat/components/AgentChatSidebar.js +3 -3
- package/dist/features/agent-chat/components/AgentChatThread.js +10 -11
- package/dist/features/navigation/navigation.d.ts +39 -0
- package/dist/features/navigation/navigation.js +231 -0
- package/dist/features/preview/CamoxPreview.d.ts +3 -0
- package/dist/features/preview/CamoxPreview.js +12 -12
- package/dist/features/preview/components/AddBlockSidebar.js +4 -4
- package/dist/features/preview/components/AssetLightbox.js +10 -9
- package/dist/features/preview/components/CreatePageModal.js +3 -3
- package/dist/features/preview/components/FieldToolbar.js +1 -1
- package/dist/features/preview/components/PageInfoSidebar.js +23 -23
- package/dist/features/preview/components/PageNavigatorSidebar.js +6 -6
- package/dist/features/preview/components/PagePicker.js +1 -1
- package/dist/features/preview/components/PreviewToolbar.js +3 -3
- package/dist/features/preview/components/useUpdateBlockPosition.js +3 -3
- package/dist/features/provider/CamoxProvider.js +10 -8
- package/dist/features/routes/pageRuntime.js +6 -0
- package/dist/features/runtime/pageApp.js +75 -0
- package/dist/features/runtime/pageClient.d.ts +7 -0
- package/dist/features/runtime/pageClient.js +37 -0
- package/dist/features/runtime/pageNavigation.js +170 -0
- package/dist/features/runtime/pageServer.d.ts +9 -0
- package/dist/features/runtime/pageServer.js +18 -0
- package/dist/features/runtime/runtime.d.ts +24 -0
- package/dist/features/runtime/runtime.js +44 -0
- package/dist/features/runtime/studioApp.d.ts +15 -0
- package/dist/features/runtime/studioApp.js +117 -0
- package/dist/features/runtime/studioNavigation.js +115 -0
- package/dist/features/runtime/studioServer.d.ts +9 -0
- package/dist/features/runtime/studioServer.js +18 -0
- package/dist/features/studio/CamoxStudio.js +3 -3
- package/dist/features/studio/components/Navbar.js +7 -7
- package/dist/features/studio/components/ProjectMenu.js +9 -9
- package/dist/features/studio/components/UserButton.js +3 -3
- package/dist/features/vite/appGeneration.js +16 -5
- package/dist/features/vite/blockBoilerplate.js +1 -1
- package/dist/features/vite/definitionsSync.js +4 -4
- package/dist/features/vite/routeGeneration.js +9 -156
- package/dist/features/vite/runtimeDev.js +270 -0
- package/dist/features/vite/utils.js +3 -1
- package/dist/features/vite/vite.d.ts +22 -3
- package/dist/features/vite/vite.js +36 -19
- package/dist/hooks/use-file-upload.js +3 -1
- package/dist/lib/api-client.js +6 -3
- package/dist/lib/auth.js +45 -68
- package/dist/lib/queries.js +6 -4
- package/dist/lib/telemetry.js +1 -24
- package/dist/lib/utils.js +1 -1
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/Matches.d.ts +114 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/RouterProvider.d.ts +25 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/config.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/defer.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/fileRoute.d.ts +20 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/global.d.ts +8 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/hash-scroll.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/index.d.ts +18 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/link.d.ts +161 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/load-matches.d.ts +6 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/location.d.ts +54 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/lru-cache.d.ts +8 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/manifest.d.ts +32 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/new-process-route-tree.d.ts +115 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/not-found.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/redirect.d.ts +49 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/rewrite.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/root.d.ts +6 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/route.d.ts +343 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/routeInfo.d.ts +48 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/router.d.ts +695 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/scroll-restoration.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/searchMiddleware.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/searchParams.d.ts +5 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/ssr/serializer/RawStream.d.ts +38 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/ssr/serializer/seroval-plugins.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/ssr/serializer/transformer.d.ts +65 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/stores.d.ts +69 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/structuralSharing.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/typePrimitives.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/useLoaderData.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/useLoaderDeps.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/useNavigate.d.ts +10 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/useParams.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/useRouteContext.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/useSearch.d.ts +1 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/utils.d.ts +28 -0
- package/dist/node_modules/.pnpm/@tanstack_router-core@1.168.14/node_modules/@tanstack/router-core/dist/esm/validators.d.ts +49 -0
- package/package.json +34 -12
- package/skills/camox-block/SKILL.md +4 -4
- package/skills/camox-cli/SKILL.md +3 -3
- package/skills/camox-layout/SKILL.md +2 -2
- package/dist/features/routes/ogRoute.d.ts +0 -12
- package/dist/features/routes/ogRoute.js +0 -20
- package/dist/features/routes/pageRoute.d.ts +0 -48
- package/dist/features/routes/pageRoute.js +0 -254
- package/dist/lib/api-client.d.ts +0 -7
- package/dist/lib/queries.d.ts +0 -12
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { Link as Link$1 } from "../../navigation/navigation.js";
|
|
1
2
|
import { AuthContext } from "../../../lib/auth.js";
|
|
2
3
|
import { projectQueries } from "../../../lib/queries.js";
|
|
3
4
|
import { c } from "react/compiler-runtime";
|
|
4
5
|
import { useQuery } from "@tanstack/react-query";
|
|
5
|
-
import { Link } from "@tanstack/react-router";
|
|
6
6
|
import * as React from "react";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
import { Button } from "@camox/ui/button";
|
|
@@ -13,9 +13,9 @@ import { Skeleton } from "@camox/ui/skeleton";
|
|
|
13
13
|
//#region src/features/studio/components/ProjectMenu.tsx
|
|
14
14
|
const Favicon = (t0) => {
|
|
15
15
|
const $ = c(19);
|
|
16
|
-
if ($[0] !== "
|
|
16
|
+
if ($[0] !== "5b6284d7940526e6093811e0cb2663e0916c58abe0f07e36b7140e4a9eb93d0f") {
|
|
17
17
|
for (let $i = 0; $i < 19; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
18
|
-
$[0] = "
|
|
18
|
+
$[0] = "5b6284d7940526e6093811e0cb2663e0916c58abe0f07e36b7140e4a9eb93d0f";
|
|
19
19
|
}
|
|
20
20
|
const { size: t1 } = t0;
|
|
21
21
|
const size = t1 === void 0 ? 16 : t1;
|
|
@@ -113,9 +113,9 @@ const Favicon = (t0) => {
|
|
|
113
113
|
};
|
|
114
114
|
const ProjectMenu = () => {
|
|
115
115
|
const $ = c(41);
|
|
116
|
-
if ($[0] !== "
|
|
116
|
+
if ($[0] !== "5b6284d7940526e6093811e0cb2663e0916c58abe0f07e36b7140e4a9eb93d0f") {
|
|
117
117
|
for (let $i = 0; $i < 41; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
118
|
-
$[0] = "
|
|
118
|
+
$[0] = "5b6284d7940526e6093811e0cb2663e0916c58abe0f07e36b7140e4a9eb93d0f";
|
|
119
119
|
}
|
|
120
120
|
const authCtx = React.useContext(AuthContext);
|
|
121
121
|
let t0;
|
|
@@ -172,7 +172,7 @@ const ProjectMenu = () => {
|
|
|
172
172
|
$[9] = t3;
|
|
173
173
|
$[10] = t5;
|
|
174
174
|
} else t5 = $[10];
|
|
175
|
-
const t6 = authCtx ? `${authCtx.authenticationUrl}
|
|
175
|
+
const t6 = authCtx ? `${authCtx.authenticationUrl}/${project.organizationSlug}/${project.slug}/overview` : "#";
|
|
176
176
|
let t7;
|
|
177
177
|
if ($[11] !== t6) {
|
|
178
178
|
t7 = /* @__PURE__ */ jsx("a", {
|
|
@@ -211,7 +211,7 @@ const ProjectMenu = () => {
|
|
|
211
211
|
$[17] = project.organizationSlug;
|
|
212
212
|
$[18] = t11;
|
|
213
213
|
} else t11 = $[18];
|
|
214
|
-
const t12 = authCtx ? `${authCtx.authenticationUrl}
|
|
214
|
+
const t12 = authCtx ? `${authCtx.authenticationUrl}/${project.organizationSlug}/team` : "#";
|
|
215
215
|
let t13;
|
|
216
216
|
if ($[19] !== t12) {
|
|
217
217
|
t13 = /* @__PURE__ */ jsx("a", {
|
|
@@ -236,7 +236,7 @@ const ProjectMenu = () => {
|
|
|
236
236
|
$[22] = t13;
|
|
237
237
|
$[23] = t15;
|
|
238
238
|
} else t15 = $[23];
|
|
239
|
-
const t16 = authCtx ? `${authCtx.authenticationUrl}
|
|
239
|
+
const t16 = authCtx ? `${authCtx.authenticationUrl}/${project.organizationSlug}/settings` : "#";
|
|
240
240
|
let t17;
|
|
241
241
|
if ($[24] !== t16) {
|
|
242
242
|
t17 = /* @__PURE__ */ jsx("a", {
|
|
@@ -281,7 +281,7 @@ const ProjectMenu = () => {
|
|
|
281
281
|
let t22;
|
|
282
282
|
if ($[34] === Symbol.for("react.memo_cache_sentinel")) {
|
|
283
283
|
t22 = /* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
284
|
-
render: /* @__PURE__ */ jsx(Link, {
|
|
284
|
+
render: /* @__PURE__ */ jsx(Link$1, {
|
|
285
285
|
to: "https://camox.ai",
|
|
286
286
|
target: "_blank"
|
|
287
287
|
}),
|
|
@@ -10,9 +10,9 @@ import { Avatar, AvatarFallback, AvatarImage } from "@camox/ui/avatar";
|
|
|
10
10
|
//#region src/features/studio/components/UserButton.tsx
|
|
11
11
|
const UserButton = () => {
|
|
12
12
|
const $ = c(5);
|
|
13
|
-
if ($[0] !== "
|
|
13
|
+
if ($[0] !== "12e7d1da288408dfd3abde7ab7d46542026c286c39994da53885abf3ac49204c") {
|
|
14
14
|
for (let $i = 0; $i < 5; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
|
|
15
|
-
$[0] = "
|
|
15
|
+
$[0] = "12e7d1da288408dfd3abde7ab7d46542026c286c39994da53885abf3ac49204c";
|
|
16
16
|
}
|
|
17
17
|
const { isAuthenticated, isLoading } = useAuthState();
|
|
18
18
|
const { theme, setTheme } = useApplyTheme();
|
|
@@ -82,7 +82,7 @@ function AuthenticatedUserButton({ theme, setTheme }) {
|
|
|
82
82
|
}) }),
|
|
83
83
|
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
84
84
|
/* @__PURE__ */ jsxs(DropdownMenuItem, {
|
|
85
|
-
onClick: () => window.open(`${authenticationUrl}/
|
|
85
|
+
onClick: () => window.open(`${authenticationUrl}/profile`, "_blank"),
|
|
86
86
|
children: [/* @__PURE__ */ jsx(Settings, {}), /* @__PURE__ */ jsx("span", { children: "Manage account" })]
|
|
87
87
|
}),
|
|
88
88
|
/* @__PURE__ */ jsxs(DropdownMenuSub, { children: [/* @__PURE__ */ jsxs(DropdownMenuSubTrigger, { children: [
|
|
@@ -16,18 +16,29 @@ function generateCamoxApp() {
|
|
|
16
16
|
import type { Block } from 'camox/createBlock';
|
|
17
17
|
import type { Layout } from 'camox/createLayout';
|
|
18
18
|
|
|
19
|
-
// Auto-import all blocks from the blocks directory
|
|
20
|
-
const blockModules = import.meta.glob<{ block: Block }>('
|
|
19
|
+
// Auto-import all blocks from the first-class blocks directory
|
|
20
|
+
const blockModules = import.meta.glob<{ block: Block }>('../blocks/*.{ts,tsx}', {
|
|
21
21
|
eager: true,
|
|
22
22
|
});
|
|
23
|
-
const
|
|
23
|
+
const legacyBlockModules = import.meta.glob<{ block: Block }>('./blocks/*.{ts,tsx}', {
|
|
24
|
+
eager: true,
|
|
25
|
+
});
|
|
26
|
+
const blocks = [...Object.values(blockModules), ...Object.values(legacyBlockModules)].map(
|
|
27
|
+
(mod) => mod.block,
|
|
28
|
+
);
|
|
24
29
|
|
|
25
|
-
// Auto-import all layouts from the layouts directory
|
|
30
|
+
// Auto-import all layouts from the first-class layouts directory
|
|
26
31
|
const layoutModules = import.meta.glob<{ layout: Layout }>(
|
|
32
|
+
'../layouts/*.{ts,tsx}',
|
|
33
|
+
{ eager: true },
|
|
34
|
+
);
|
|
35
|
+
const legacyLayoutModules = import.meta.glob<{ layout: Layout }>(
|
|
27
36
|
'./layouts/*.{ts,tsx}',
|
|
28
37
|
{ eager: true },
|
|
29
38
|
);
|
|
30
|
-
const layouts = Object.values(layoutModules).
|
|
39
|
+
const layouts = [...Object.values(layoutModules), ...Object.values(legacyLayoutModules)].map(
|
|
40
|
+
(mod) => mod.layout,
|
|
41
|
+
);
|
|
31
42
|
|
|
32
43
|
export const camoxApp = createApp({
|
|
33
44
|
blocks,
|
|
@@ -44,7 +44,7 @@ export { ${camelName} as block };
|
|
|
44
44
|
`;
|
|
45
45
|
}
|
|
46
46
|
function watchNewBlockFiles(server) {
|
|
47
|
-
const blocksDir = resolve(server.config.root, "src/
|
|
47
|
+
const blocksDir = resolve(server.config.root, "src/blocks");
|
|
48
48
|
server.watcher.on("add", (filePath) => {
|
|
49
49
|
if (filePath.startsWith(blocksDir) && /\.tsx?$/.test(filePath) && !filePath.includes("index.")) try {
|
|
50
50
|
if (readFileSync(filePath, "utf-8").trim().length < MAX_EMPTY_BLOCK_CHARACTER_COUNT) {
|
|
@@ -141,7 +141,8 @@ async function ssrLoadModule(server, modulePath) {
|
|
|
141
141
|
}
|
|
142
142
|
async function syncDefinitions(server, options) {
|
|
143
143
|
const { projectSlug, syncSecret, apiUrl, environmentName, autoCreate } = options;
|
|
144
|
-
const
|
|
144
|
+
const blocksDirs = [path.resolve(server.config.root, "src/blocks"), path.resolve(server.config.root, "src/camox/blocks")];
|
|
145
|
+
const layoutsDirs = [path.resolve(server.config.root, "src/layouts"), path.resolve(server.config.root, "src/camox/layouts")];
|
|
145
146
|
const client = createServerApiClient(apiUrl, environmentName);
|
|
146
147
|
async function performInitialSync() {
|
|
147
148
|
const appModule = server.moduleGraph.getModuleById(CAMOX_APP_PATH);
|
|
@@ -213,12 +214,11 @@ async function syncDefinitions(server, options) {
|
|
|
213
214
|
server.config.logger.error(`[camox] Failed to sync block definitions: ${String(error)}`, { timestamp: true });
|
|
214
215
|
}
|
|
215
216
|
const debounceTimers = /* @__PURE__ */ new Map();
|
|
216
|
-
const layoutsDir = path.resolve(server.config.root, "src/camox/layouts");
|
|
217
217
|
function isBlockFile(filePath) {
|
|
218
|
-
return filePath.startsWith(blocksDir) && /\.tsx?$/.test(filePath);
|
|
218
|
+
return blocksDirs.some((blocksDir) => filePath.startsWith(blocksDir)) && /\.tsx?$/.test(filePath);
|
|
219
219
|
}
|
|
220
220
|
function isLayoutFile(filePath) {
|
|
221
|
-
return filePath.startsWith(layoutsDir) && /\.tsx?$/.test(filePath);
|
|
221
|
+
return layoutsDirs.some((layoutsDir) => filePath.startsWith(layoutsDir)) && /\.tsx?$/.test(filePath);
|
|
222
222
|
}
|
|
223
223
|
const handleBlockFileUpsert = (filePath) => {
|
|
224
224
|
if (!isBlockFile(filePath)) return;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { STUDIO_ROUTE_SEGMENT } from "../studio/routes.js";
|
|
2
|
-
import { writeIfChanged } from "./utils.js";
|
|
3
2
|
import { mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
3
|
import { relative, resolve } from "node:path";
|
|
5
4
|
|
|
@@ -16,132 +15,6 @@ const HEADER = `/* =============================================================
|
|
|
16
15
|
// @ts-nocheck
|
|
17
16
|
|
|
18
17
|
`;
|
|
19
|
-
function generatePageRoute(authenticationUrl) {
|
|
20
|
-
return HEADER + `import { createFileRoute } from "@tanstack/react-router";
|
|
21
|
-
import {
|
|
22
|
-
createMarkdownMiddleware,
|
|
23
|
-
createPageLoader,
|
|
24
|
-
createPageHead,
|
|
25
|
-
PageRouteComponent,
|
|
26
|
-
} from "camox/_internal/pageRoute";
|
|
27
|
-
import { CamoxProvider } from "camox/CamoxProvider";
|
|
28
|
-
import { camoxApp } from "@/camox/app";
|
|
29
|
-
|
|
30
|
-
const markdownMiddleware = createMarkdownMiddleware(__CAMOX_API_URL__, __CAMOX_PROJECT_SLUG__, __CAMOX_ENVIRONMENT_NAME__);
|
|
31
|
-
const loader = createPageLoader(__CAMOX_API_URL__, __CAMOX_PROJECT_SLUG__, __CAMOX_ENVIRONMENT_NAME__);
|
|
32
|
-
const head = createPageHead(camoxApp);
|
|
33
|
-
|
|
34
|
-
export const Route = createFileRoute("/(camox)/(_preview)/$")({
|
|
35
|
-
server: {
|
|
36
|
-
middleware: [markdownMiddleware],
|
|
37
|
-
},
|
|
38
|
-
component: RouteComponent,
|
|
39
|
-
notFoundComponent: () => <div>No Camox page on this path</div>,
|
|
40
|
-
loader,
|
|
41
|
-
head,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
function RouteComponent() {
|
|
45
|
-
return (
|
|
46
|
-
<CamoxProvider camoxApp={camoxApp} authenticationUrl="${authenticationUrl}" apiUrl={__CAMOX_API_URL__} projectSlug={__CAMOX_PROJECT_SLUG__} environmentName={__CAMOX_ENVIRONMENT_NAME__}>
|
|
47
|
-
<PageRouteComponent />
|
|
48
|
-
</CamoxProvider>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
`;
|
|
52
|
-
}
|
|
53
|
-
function generateOgRoute() {
|
|
54
|
-
return HEADER + `import { createFileRoute } from "@tanstack/react-router";
|
|
55
|
-
import { createOgHandler } from "camox/_internal/ogRoute";
|
|
56
|
-
import { camoxApp } from "@/camox/app";
|
|
57
|
-
|
|
58
|
-
export const Route = createFileRoute("/(camox)/(_preview)/og")({
|
|
59
|
-
server: {
|
|
60
|
-
handlers: createOgHandler(camoxApp),
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
`;
|
|
64
|
-
}
|
|
65
|
-
function generateCamoxStudio(authenticationUrl) {
|
|
66
|
-
return HEADER + `import { Outlet, createFileRoute } from "@tanstack/react-router";
|
|
67
|
-
import { CamoxProvider } from "camox/CamoxProvider";
|
|
68
|
-
import { CamoxStudio } from "camox/CamoxStudio";
|
|
69
|
-
import { camoxApp } from "@/camox/app";
|
|
70
|
-
|
|
71
|
-
export const Route = createFileRoute("/(camox)/(_studio)/${STUDIO_ROUTE_SEGMENT}")({
|
|
72
|
-
component: RouteComponent,
|
|
73
|
-
notFoundComponent: () => <div>Studio page not found</div>,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
function RouteComponent() {
|
|
77
|
-
return (
|
|
78
|
-
<CamoxProvider camoxApp={camoxApp} authenticationUrl="${authenticationUrl}" apiUrl={__CAMOX_API_URL__} projectSlug={__CAMOX_PROJECT_SLUG__} environmentName={__CAMOX_ENVIRONMENT_NAME__}>
|
|
79
|
-
<CamoxStudio>
|
|
80
|
-
<Outlet />
|
|
81
|
-
</CamoxStudio>
|
|
82
|
-
</CamoxProvider>
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
`;
|
|
86
|
-
}
|
|
87
|
-
function generateCamoxStudioCatchAll() {
|
|
88
|
-
return HEADER + `import { Outlet, createFileRoute } from "@tanstack/react-router";
|
|
89
|
-
import { CamoxStudio } from "camox/CamoxStudio";
|
|
90
|
-
|
|
91
|
-
export const Route = createFileRoute("/(camox)/(_studio)/${STUDIO_ROUTE_SEGMENT}/$")({
|
|
92
|
-
component: RouteComponent,
|
|
93
|
-
notFoundComponent: () => <div>Studio page not found</div>,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
function RouteComponent() {
|
|
97
|
-
return (
|
|
98
|
-
<CamoxStudio>
|
|
99
|
-
<Outlet />
|
|
100
|
-
</CamoxStudio>
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
`;
|
|
104
|
-
}
|
|
105
|
-
function generateCamoxStudioContent() {
|
|
106
|
-
return HEADER + `import { createFileRoute } from "@tanstack/react-router";
|
|
107
|
-
import { CamoxContent } from "camox/CamoxContent";
|
|
108
|
-
|
|
109
|
-
export const Route = createFileRoute("/(camox)/(_studio)/${STUDIO_ROUTE_SEGMENT}/content")({
|
|
110
|
-
component: RouteComponent,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
function RouteComponent() {
|
|
114
|
-
return <CamoxContent />;
|
|
115
|
-
}
|
|
116
|
-
`;
|
|
117
|
-
}
|
|
118
|
-
function getRouteFileEntries({ routesDir, authenticationUrl }) {
|
|
119
|
-
const groupDir = resolve(routesDir, "(camox)");
|
|
120
|
-
const previewDir = resolve(groupDir, "(_preview)");
|
|
121
|
-
const studioDir = resolve(groupDir, "(_studio)");
|
|
122
|
-
return [
|
|
123
|
-
{
|
|
124
|
-
path: resolve(previewDir, "$.tsx"),
|
|
125
|
-
content: generatePageRoute(authenticationUrl)
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
path: resolve(previewDir, "og.tsx"),
|
|
129
|
-
content: generateOgRoute()
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
path: resolve(studioDir, `${STUDIO_ROUTE_SEGMENT}.tsx`),
|
|
133
|
-
content: generateCamoxStudio(authenticationUrl)
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
path: resolve(studioDir, `${STUDIO_ROUTE_SEGMENT}.$.tsx`),
|
|
137
|
-
content: generateCamoxStudioCatchAll()
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
path: resolve(studioDir, `${STUDIO_ROUTE_SEGMENT}.content.tsx`),
|
|
141
|
-
content: generateCamoxStudioContent()
|
|
142
|
-
}
|
|
143
|
-
];
|
|
144
|
-
}
|
|
145
18
|
function removeObsoleteRouteFiles(routesDir) {
|
|
146
19
|
const camoxDir = resolve(routesDir, "_camox");
|
|
147
20
|
const studioDir = resolve(routesDir, "(camox)", "(_studio)");
|
|
@@ -156,7 +29,12 @@ function removeObsoleteRouteFiles(routesDir) {
|
|
|
156
29
|
resolve(studioDir, "cmx.tsx"),
|
|
157
30
|
resolve(studioDir, "cmx-studio.tsx"),
|
|
158
31
|
resolve(studioDir, "cmx-studio.$.tsx"),
|
|
159
|
-
resolve(studioDir, "cmx-studio.content.tsx")
|
|
32
|
+
resolve(studioDir, "cmx-studio.content.tsx"),
|
|
33
|
+
resolve(routesDir, "(camox)", "(_preview)", "$.tsx"),
|
|
34
|
+
resolve(routesDir, "(camox)", "(_preview)", "og.tsx"),
|
|
35
|
+
resolve(studioDir, `${STUDIO_ROUTE_SEGMENT}.tsx`),
|
|
36
|
+
resolve(studioDir, `${STUDIO_ROUTE_SEGMENT}.$.tsx`),
|
|
37
|
+
resolve(studioDir, `${STUDIO_ROUTE_SEGMENT}.content.tsx`)
|
|
160
38
|
];
|
|
161
39
|
for (const filePath of obsoletePaths) try {
|
|
162
40
|
if (!readFileSync(filePath, "utf-8").startsWith(HEADER)) continue;
|
|
@@ -166,34 +44,9 @@ function removeObsoleteRouteFiles(routesDir) {
|
|
|
166
44
|
throw error;
|
|
167
45
|
}
|
|
168
46
|
}
|
|
169
|
-
function
|
|
170
|
-
|
|
171
|
-
mkdirSync(resolve(groupDir, "(_preview)"), { recursive: true });
|
|
172
|
-
mkdirSync(resolve(groupDir, "(_studio)"), { recursive: true });
|
|
173
|
-
removeObsoleteRouteFiles(options.routesDir);
|
|
174
|
-
for (const entry of getRouteFileEntries(options)) writeIfChanged(entry.path, entry.content);
|
|
175
|
-
}
|
|
176
|
-
function watchRouteFiles(options) {
|
|
177
|
-
const { server, ...routeFilesOptions } = options;
|
|
178
|
-
const entries = getRouteFileEntries(routeFilesOptions);
|
|
179
|
-
const expectedByPath = new Map(entries.map((e) => [e.path, e.content]));
|
|
180
|
-
server.watcher.on("change", (changedPath) => {
|
|
181
|
-
const expected = expectedByPath.get(changedPath);
|
|
182
|
-
if (!expected) return;
|
|
183
|
-
if (readFileSync(changedPath, "utf-8") !== expected) {
|
|
184
|
-
const rel = relative(server.config.root, changedPath);
|
|
185
|
-
server.config.logger.warn(`Camox route file "${rel}" was modified — reverting to generated version.`, { timestamp: true });
|
|
186
|
-
writeFileSync(changedPath, expected, "utf-8");
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
server.watcher.on("unlink", (deletedPath) => {
|
|
190
|
-
const expected = expectedByPath.get(deletedPath);
|
|
191
|
-
if (!expected) return;
|
|
192
|
-
const rel = relative(server.config.root, deletedPath);
|
|
193
|
-
server.config.logger.warn(`Camox route file "${rel}" was deleted — recreating.`, { timestamp: true });
|
|
194
|
-
writeFileSync(deletedPath, expected, "utf-8");
|
|
195
|
-
});
|
|
47
|
+
function cleanupGeneratedRouteFiles(routesDir) {
|
|
48
|
+
removeObsoleteRouteFiles(routesDir);
|
|
196
49
|
}
|
|
197
50
|
|
|
198
51
|
//#endregion
|
|
199
|
-
export {
|
|
52
|
+
export { cleanupGeneratedRouteFiles };
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
//#region src/features/vite/runtimeDev.ts
|
|
6
|
+
const sdkRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
|
|
7
|
+
const VIRTUAL_CAMOX_APP = "virtual:camox/app";
|
|
8
|
+
const RESOLVED_VIRTUAL_CAMOX_APP = "\0" + VIRTUAL_CAMOX_APP;
|
|
9
|
+
const VIRTUAL_CAMOX_DOCUMENT = "virtual:camox/document";
|
|
10
|
+
const RESOLVED_VIRTUAL_CAMOX_DOCUMENT = "\0" + VIRTUAL_CAMOX_DOCUMENT;
|
|
11
|
+
const VIRTUAL_CAMOX_SERVER = "virtual:camox/server";
|
|
12
|
+
const RESOLVED_VIRTUAL_CAMOX_SERVER = "\0" + VIRTUAL_CAMOX_SERVER;
|
|
13
|
+
const VIRTUAL_CAMOX_NITRO_HANDLER = "#camox/nitro-handler";
|
|
14
|
+
const VIRTUAL_PAGE_SERVER = "virtual:camox/page-server";
|
|
15
|
+
const RESOLVED_VIRTUAL_PAGE_SERVER = "\0" + VIRTUAL_PAGE_SERVER;
|
|
16
|
+
const VIRTUAL_STUDIO_SERVER = "virtual:camox/studio-server";
|
|
17
|
+
const RESOLVED_VIRTUAL_STUDIO_SERVER = "\0" + VIRTUAL_STUDIO_SERVER;
|
|
18
|
+
const VIRTUAL_PAGE_CLIENT = "virtual:camox/page-client";
|
|
19
|
+
const RESOLVED_VIRTUAL_PAGE_CLIENT = "\0" + VIRTUAL_PAGE_CLIENT;
|
|
20
|
+
const VIRTUAL_PAGE_CLIENT_URL = "virtual:camox/page-client-url";
|
|
21
|
+
const RESOLVED_VIRTUAL_PAGE_CLIENT_URL = "\0" + VIRTUAL_PAGE_CLIENT_URL;
|
|
22
|
+
const VIRTUAL_APP_STYLESHEET_URL = "virtual:camox/app-stylesheet-url";
|
|
23
|
+
const RESOLVED_VIRTUAL_APP_STYLESHEET_URL = "\0" + VIRTUAL_APP_STYLESHEET_URL;
|
|
24
|
+
const VIRTUAL_STUDIO_CSS = "virtual:camox-studio-css";
|
|
25
|
+
const RESOLVED_VIRTUAL_STUDIO_CSS = "\0" + VIRTUAL_STUDIO_CSS;
|
|
26
|
+
const VIRTUAL_OVERLAY_CSS = "virtual:camox-overlay-css";
|
|
27
|
+
const RESOLVED_VIRTUAL_OVERLAY_CSS = "\0" + VIRTUAL_OVERLAY_CSS;
|
|
28
|
+
function normalizeImporterPath(importer) {
|
|
29
|
+
if (!importer) return "";
|
|
30
|
+
const [path] = importer.split("?");
|
|
31
|
+
if (path.startsWith("file://")) return fileURLToPath(path);
|
|
32
|
+
if (path.startsWith("/@fs/")) return path.slice(4);
|
|
33
|
+
return path;
|
|
34
|
+
}
|
|
35
|
+
function resolveSdkAlias(id, importer) {
|
|
36
|
+
if (!id.startsWith("@/")) return;
|
|
37
|
+
const normalizedImporter = normalizeImporterPath(importer).replaceAll("\\", "/");
|
|
38
|
+
const normalizedSdkSrc = resolve(sdkRoot, "src").replaceAll("\\", "/");
|
|
39
|
+
if (!normalizedImporter.includes(`${normalizedSdkSrc}/`)) return;
|
|
40
|
+
const basePath = resolve(sdkRoot, "src", id.slice(2));
|
|
41
|
+
return [
|
|
42
|
+
basePath,
|
|
43
|
+
`${basePath}.ts`,
|
|
44
|
+
`${basePath}.tsx`,
|
|
45
|
+
resolve(basePath, "index.ts")
|
|
46
|
+
].find((candidate) => existsSync(candidate));
|
|
47
|
+
}
|
|
48
|
+
function resolveCamoxSourceImport(id) {
|
|
49
|
+
return {
|
|
50
|
+
"camox/createApp": resolve(sdkRoot, "src/core/createApp.ts"),
|
|
51
|
+
"camox/createBlock": resolve(sdkRoot, "src/core/createBlock.tsx"),
|
|
52
|
+
"camox/createLayout": resolve(sdkRoot, "src/core/createLayout.tsx"),
|
|
53
|
+
"camox/document": resolve(sdkRoot, "src/core/defineDocument.ts"),
|
|
54
|
+
"camox/CamoxProvider": resolve(sdkRoot, "src/features/provider/CamoxProvider.tsx"),
|
|
55
|
+
"camox/CamoxPreview": resolve(sdkRoot, "src/features/preview/CamoxPreview.tsx"),
|
|
56
|
+
"camox/navigation": resolve(sdkRoot, "src/features/navigation/navigation.tsx"),
|
|
57
|
+
"camox/_internal/pageServer": resolve(sdkRoot, "src/features/runtime/pageServer.tsx"),
|
|
58
|
+
"camox/_internal/pageClient": resolve(sdkRoot, "src/features/runtime/pageClient.tsx"),
|
|
59
|
+
"camox/_internal/studioServer": resolve(sdkRoot, "src/features/runtime/studioServer.tsx"),
|
|
60
|
+
"camox/_internal/runtime": resolve(sdkRoot, "src/features/runtime/runtime.ts")
|
|
61
|
+
}[id];
|
|
62
|
+
}
|
|
63
|
+
function generateVirtualCamoxApp() {
|
|
64
|
+
return `import { createApp } from "camox/createApp";
|
|
65
|
+
|
|
66
|
+
const rootBlockModules = import.meta.glob("/src/blocks/*.{ts,tsx}", { eager: true });
|
|
67
|
+
const legacyBlockModules = import.meta.glob("/src/camox/blocks/*.{ts,tsx}", { eager: true });
|
|
68
|
+
const rootLayoutModules = import.meta.glob("/src/layouts/*.{ts,tsx}", { eager: true });
|
|
69
|
+
const legacyLayoutModules = import.meta.glob("/src/camox/layouts/*.{ts,tsx}", { eager: true });
|
|
70
|
+
|
|
71
|
+
const blocks = [...Object.values(rootBlockModules), ...Object.values(legacyBlockModules)]
|
|
72
|
+
.map((mod) => mod.block)
|
|
73
|
+
.filter(Boolean);
|
|
74
|
+
const layouts = [...Object.values(rootLayoutModules), ...Object.values(legacyLayoutModules)]
|
|
75
|
+
.map((mod) => mod.layout)
|
|
76
|
+
.filter(Boolean);
|
|
77
|
+
|
|
78
|
+
export const camoxApp = createApp({ blocks, layouts });
|
|
79
|
+
`;
|
|
80
|
+
}
|
|
81
|
+
function generateVirtualCamoxDocument() {
|
|
82
|
+
return `const documentModules = import.meta.glob("/src/document.{ts,tsx}", { eager: true });
|
|
83
|
+
const documents = Object.values(documentModules)
|
|
84
|
+
.map((mod) => mod.default)
|
|
85
|
+
.filter(Boolean);
|
|
86
|
+
|
|
87
|
+
export const camoxDocument = documents[0] ?? {};
|
|
88
|
+
`;
|
|
89
|
+
}
|
|
90
|
+
function generateVirtualPageServer() {
|
|
91
|
+
return `import { renderPageWithApp } from "camox/_internal/pageServer";
|
|
92
|
+
import { camoxApp } from "virtual:camox/app";
|
|
93
|
+
|
|
94
|
+
export async function renderPage(input) {
|
|
95
|
+
return renderPageWithApp({ ...input, camoxApp });
|
|
96
|
+
}
|
|
97
|
+
`;
|
|
98
|
+
}
|
|
99
|
+
function generateVirtualStudioServer() {
|
|
100
|
+
return `import { renderStudioWithApp } from "camox/_internal/studioServer";
|
|
101
|
+
import { camoxApp } from "virtual:camox/app";
|
|
102
|
+
|
|
103
|
+
export async function renderStudio(input) {
|
|
104
|
+
return renderStudioWithApp({ ...input, camoxApp });
|
|
105
|
+
}
|
|
106
|
+
`;
|
|
107
|
+
}
|
|
108
|
+
function generateVirtualPageClient() {
|
|
109
|
+
return `import { hydrateRuntimeWithApp } from "camox/_internal/pageClient";
|
|
110
|
+
import { camoxApp } from "virtual:camox/app";
|
|
111
|
+
|
|
112
|
+
hydrateRuntimeWithApp(camoxApp);
|
|
113
|
+
`;
|
|
114
|
+
}
|
|
115
|
+
function wrapViteDevId(id) {
|
|
116
|
+
return `/@id/${id.replace("\0", "__x00__")}`;
|
|
117
|
+
}
|
|
118
|
+
function generateVirtualPageClientUrl() {
|
|
119
|
+
return `export default ${JSON.stringify(wrapViteDevId(RESOLVED_VIRTUAL_PAGE_CLIENT))};`;
|
|
120
|
+
}
|
|
121
|
+
function generateVirtualAppStylesheetUrl() {
|
|
122
|
+
return `import stylesheetUrl from "/src/styles.css?url";
|
|
123
|
+
|
|
124
|
+
export default stylesheetUrl;
|
|
125
|
+
`;
|
|
126
|
+
}
|
|
127
|
+
function generateVirtualCamoxServer(runtimeBasePath) {
|
|
128
|
+
return `import { handleCamoxRequest as handleRuntimeRequest } from "camox/_internal/runtime";
|
|
129
|
+
import { camoxApp } from "virtual:camox/app";
|
|
130
|
+
import { camoxDocument } from "virtual:camox/document";
|
|
131
|
+
import appStylesheetUrl from "virtual:camox/app-stylesheet-url";
|
|
132
|
+
import pageClientEntryUrl from "virtual:camox/page-client-url";
|
|
133
|
+
import { renderPage } from "virtual:camox/page-server";
|
|
134
|
+
import { renderStudio } from "virtual:camox/studio-server";
|
|
135
|
+
|
|
136
|
+
export async function handleCamoxRequest(request) {
|
|
137
|
+
return handleRuntimeRequest(request, {
|
|
138
|
+
apiUrl: __CAMOX_API_URL__,
|
|
139
|
+
authenticationUrl: __CAMOX_AUTHENTICATION_URL__,
|
|
140
|
+
clientEntryUrl: pageClientEntryUrl,
|
|
141
|
+
environmentName: __CAMOX_ENVIRONMENT_NAME__,
|
|
142
|
+
getCamoxApp: async () => camoxApp,
|
|
143
|
+
getDocument: async () => camoxDocument,
|
|
144
|
+
projectSlug: __CAMOX_PROJECT_SLUG__,
|
|
145
|
+
renderPage,
|
|
146
|
+
renderStudio,
|
|
147
|
+
runtimeBasePath: ${JSON.stringify(runtimeBasePath)},
|
|
148
|
+
stylesheetUrl: appStylesheetUrl,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
`;
|
|
152
|
+
}
|
|
153
|
+
function generateVirtualCamoxNitroHandler(runtimeBasePath) {
|
|
154
|
+
return `import { defineHandler } from "nitro";
|
|
155
|
+
import { handleCamoxRequest } from "virtual:camox/server";
|
|
156
|
+
|
|
157
|
+
const runtimeBasePath = ${JSON.stringify(normalizeRuntimeBasePath(runtimeBasePath))};
|
|
158
|
+
|
|
159
|
+
function isDocumentRequest(request) {
|
|
160
|
+
const accept = request.headers.get("Accept") ?? request.headers.get("accept") ?? "";
|
|
161
|
+
return accept.includes("text/html") || accept.includes("*/*");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function getRuntimePathname(pathname) {
|
|
165
|
+
if (!runtimeBasePath) return pathname;
|
|
166
|
+
if (pathname === runtimeBasePath) return "/";
|
|
167
|
+
if (!pathname.startsWith(runtimeBasePath + "/")) return null;
|
|
168
|
+
return pathname.slice(runtimeBasePath.length) || "/";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function shouldHandleRequest(request) {
|
|
172
|
+
const url = new URL(request.url);
|
|
173
|
+
const pathname = getRuntimePathname(url.pathname);
|
|
174
|
+
if (!pathname) return false;
|
|
175
|
+
if (request.method !== "GET" && request.method !== "HEAD") return false;
|
|
176
|
+
if (
|
|
177
|
+
pathname === "/_camox/data" ||
|
|
178
|
+
pathname === "/_camox/health" ||
|
|
179
|
+
pathname === "/_camox/registry"
|
|
180
|
+
) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
if (pathname === "/og" || pathname === "/sitemap.xml") return true;
|
|
184
|
+
if (pathname === "/camox" || pathname.startsWith("/camox/")) return true;
|
|
185
|
+
if (/\\.[a-z0-9]+$/i.test(pathname)) return false;
|
|
186
|
+
if (pathname.startsWith("/@") || pathname.startsWith("/src/")) return false;
|
|
187
|
+
if (pathname.startsWith("/__vite")) return false;
|
|
188
|
+
if (pathname.startsWith("/node_modules/")) return false;
|
|
189
|
+
return isDocumentRequest(request);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function transformHtmlResponse(response) {
|
|
193
|
+
const contentType = response.headers.get("Content-Type") ?? response.headers.get("content-type") ?? "";
|
|
194
|
+
if (!contentType.includes("text/html")) return response;
|
|
195
|
+
if (!globalThis.__transform_html__) return response;
|
|
196
|
+
|
|
197
|
+
const headers = new Headers(response.headers);
|
|
198
|
+
headers.delete("Content-Length");
|
|
199
|
+
headers.delete("content-length");
|
|
200
|
+
|
|
201
|
+
return new Response(await globalThis.__transform_html__(await response.text()), {
|
|
202
|
+
headers,
|
|
203
|
+
status: response.status,
|
|
204
|
+
statusText: response.statusText,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export default defineHandler(async (event) => {
|
|
209
|
+
if (!shouldHandleRequest(event.req)) {
|
|
210
|
+
return new Response("Not found", { status: 404 });
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const response = await handleCamoxRequest(event.req);
|
|
214
|
+
if (response) return transformHtmlResponse(response);
|
|
215
|
+
return new Response("Not found", { status: 404 });
|
|
216
|
+
});
|
|
217
|
+
`;
|
|
218
|
+
}
|
|
219
|
+
function resolveRuntimeDevId(id, importer) {
|
|
220
|
+
const camoxSourceImport = resolveCamoxSourceImport(id);
|
|
221
|
+
if (camoxSourceImport) return camoxSourceImport;
|
|
222
|
+
const sdkAlias = resolveSdkAlias(id, importer);
|
|
223
|
+
if (sdkAlias) return sdkAlias;
|
|
224
|
+
if (id === VIRTUAL_CAMOX_APP) return RESOLVED_VIRTUAL_CAMOX_APP;
|
|
225
|
+
if (id === VIRTUAL_CAMOX_DOCUMENT) return RESOLVED_VIRTUAL_CAMOX_DOCUMENT;
|
|
226
|
+
if (id === VIRTUAL_CAMOX_SERVER) return RESOLVED_VIRTUAL_CAMOX_SERVER;
|
|
227
|
+
if (id === VIRTUAL_PAGE_SERVER) return RESOLVED_VIRTUAL_PAGE_SERVER;
|
|
228
|
+
if (id === VIRTUAL_STUDIO_SERVER) return RESOLVED_VIRTUAL_STUDIO_SERVER;
|
|
229
|
+
if (id === VIRTUAL_PAGE_CLIENT) return RESOLVED_VIRTUAL_PAGE_CLIENT;
|
|
230
|
+
if (id === VIRTUAL_PAGE_CLIENT_URL) return RESOLVED_VIRTUAL_PAGE_CLIENT_URL;
|
|
231
|
+
if (id === VIRTUAL_APP_STYLESHEET_URL) return RESOLVED_VIRTUAL_APP_STYLESHEET_URL;
|
|
232
|
+
if (id === VIRTUAL_STUDIO_CSS) return RESOLVED_VIRTUAL_STUDIO_CSS;
|
|
233
|
+
if (id === VIRTUAL_OVERLAY_CSS) return RESOLVED_VIRTUAL_OVERLAY_CSS;
|
|
234
|
+
}
|
|
235
|
+
function loadRuntimeDevModule(id, options = {}) {
|
|
236
|
+
if (id === RESOLVED_VIRTUAL_CAMOX_APP) return generateVirtualCamoxApp();
|
|
237
|
+
if (id === RESOLVED_VIRTUAL_CAMOX_DOCUMENT) return generateVirtualCamoxDocument();
|
|
238
|
+
if (id === RESOLVED_VIRTUAL_CAMOX_SERVER) return generateVirtualCamoxServer(options.runtimeBasePath);
|
|
239
|
+
if (id === VIRTUAL_CAMOX_NITRO_HANDLER) return generateVirtualCamoxNitroHandler(options.runtimeBasePath);
|
|
240
|
+
if (id === RESOLVED_VIRTUAL_PAGE_SERVER) return generateVirtualPageServer();
|
|
241
|
+
if (id === RESOLVED_VIRTUAL_STUDIO_SERVER) return generateVirtualStudioServer();
|
|
242
|
+
if (id === RESOLVED_VIRTUAL_PAGE_CLIENT) return generateVirtualPageClient();
|
|
243
|
+
if (id === RESOLVED_VIRTUAL_PAGE_CLIENT_URL) return generateVirtualPageClientUrl();
|
|
244
|
+
if (id === RESOLVED_VIRTUAL_APP_STYLESHEET_URL) return generateVirtualAppStylesheetUrl();
|
|
245
|
+
if (id === RESOLVED_VIRTUAL_STUDIO_CSS) return `export default "/@fs/${resolve(sdkRoot, "dist/studio.css")}";`;
|
|
246
|
+
if (id === RESOLVED_VIRTUAL_OVERLAY_CSS) return `export default ${JSON.stringify(readFileSync(resolve(sdkRoot, "dist/studio-overlays.css"), "utf-8"))};`;
|
|
247
|
+
}
|
|
248
|
+
function normalizeRuntimeBasePath(basePath) {
|
|
249
|
+
if (basePath === void 0) return "";
|
|
250
|
+
if (!basePath || basePath === "/") return "";
|
|
251
|
+
return basePath.startsWith("/") ? basePath.replace(/\/+$/, "") : `/${basePath.replace(/\/+$/, "")}`;
|
|
252
|
+
}
|
|
253
|
+
function installRuntimeNitroRoutes(nitro, options) {
|
|
254
|
+
const routes = options.runtimeBasePath && options.runtimeBasePath !== "/" ? [options.runtimeBasePath, `${options.runtimeBasePath}/**`] : [
|
|
255
|
+
"/",
|
|
256
|
+
"/_camox/data",
|
|
257
|
+
"/_camox/health",
|
|
258
|
+
"/_camox/registry",
|
|
259
|
+
"/og",
|
|
260
|
+
"/sitemap.xml",
|
|
261
|
+
"/camox",
|
|
262
|
+
"/camox/**",
|
|
263
|
+
"/**"
|
|
264
|
+
];
|
|
265
|
+
for (const route of routes) nitro.options.routes[route] = VIRTUAL_CAMOX_NITRO_HANDLER;
|
|
266
|
+
nitro.options.virtual[VIRTUAL_CAMOX_NITRO_HANDLER] = generateVirtualCamoxNitroHandler(options.runtimeBasePath);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
//#endregion
|
|
270
|
+
export { installRuntimeNitroRoutes, loadRuntimeDevModule, resolveRuntimeDevId };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
2
3
|
|
|
3
4
|
//#region src/features/vite/utils.ts
|
|
4
5
|
function writeIfChanged(filePath, content) {
|
|
5
6
|
if (existsSync(filePath)) {
|
|
6
7
|
if (readFileSync(filePath, "utf-8") === content) return;
|
|
7
8
|
}
|
|
9
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
8
10
|
writeFileSync(filePath, content, "utf-8");
|
|
9
11
|
}
|
|
10
12
|
|