@torpor/build 0.1.22 → 0.1.24
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/CHANGELOG.md +12 -0
- package/dist/{Site-Df7Wivbz.d.cts → Site-BeCLcGj_.d.cts} +4 -2
- package/dist/{Site-Fbf4Xr1r.d.ts → Site-DgXPSQoO.d.ts} +4 -2
- package/dist/bin/index.cjs +7 -10
- package/dist/bin/index.cjs.map +1 -1
- package/dist/bin/index.js +1 -1
- package/dist/{chunk-K72JP24O.js → chunk-LHRCEWBG.js} +8 -11
- package/dist/chunk-LHRCEWBG.js.map +1 -0
- package/dist/index.cjs +4 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/run.cjs +7 -10
- package/dist/run.cjs.map +1 -1
- package/dist/run.d.cts +1 -1
- package/dist/run.d.ts +1 -1
- package/dist/run.js +1 -1
- package/dist/test.cjs +26 -12
- package/dist/test.cjs.map +1 -1
- package/dist/test.d.cts +1 -1
- package/dist/test.d.ts +1 -1
- package/dist/test.js +26 -12
- package/dist/test.js.map +1 -1
- package/package.json +4 -4
- package/src/site/Site.ts +4 -2
- package/src/site/clientEntry.ts +25 -15
- package/src/site/runBuild.ts +7 -10
- package/src/site/serverEntry.ts +26 -12
- package/src/test/runTest.ts +26 -12
- package/dist/chunk-K72JP24O.js.map +0 -1
package/dist/test.js
CHANGED
|
@@ -114,7 +114,7 @@ async function loadView(ev, url, handler, params, template) {
|
|
|
114
114
|
for (let layout of handler.layouts) {
|
|
115
115
|
const layoutEndPoint = (await layout.endPoint())?.default;
|
|
116
116
|
const layoutServerEndPoint = layout.serverEndPoint && (await layout.serverEndPoint())?.default;
|
|
117
|
-
const
|
|
117
|
+
const layoutResponse = await loadClientAndServerData(
|
|
118
118
|
url,
|
|
119
119
|
params,
|
|
120
120
|
serverParams,
|
|
@@ -122,10 +122,12 @@ async function loadView(ev, url, handler, params, template) {
|
|
|
122
122
|
layoutEndPoint,
|
|
123
123
|
layoutServerEndPoint
|
|
124
124
|
);
|
|
125
|
-
|
|
125
|
+
if (layoutResponse?.ok === false) {
|
|
126
|
+
return layoutResponse;
|
|
127
|
+
}
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
|
-
let
|
|
130
|
+
let endPointResponse = await loadClientAndServerData(
|
|
129
131
|
url,
|
|
130
132
|
params,
|
|
131
133
|
serverParams,
|
|
@@ -133,7 +135,9 @@ async function loadView(ev, url, handler, params, template) {
|
|
|
133
135
|
clientEndPoint,
|
|
134
136
|
serverEndPoint
|
|
135
137
|
);
|
|
136
|
-
|
|
138
|
+
if (endPointResponse?.ok === false) {
|
|
139
|
+
return endPointResponse;
|
|
140
|
+
}
|
|
137
141
|
let $props = { data };
|
|
138
142
|
let component = clientEndPoint.component;
|
|
139
143
|
let slots = void 0;
|
|
@@ -189,21 +193,31 @@ async function runAction(ev, url, handler, params, query) {
|
|
|
189
193
|
return notFound();
|
|
190
194
|
}
|
|
191
195
|
async function loadClientAndServerData(url, params, serverParams, data, clientEndPoint, serverEndPoint) {
|
|
192
|
-
let newData = {};
|
|
193
196
|
if (clientEndPoint?.load) {
|
|
194
197
|
const clientParams = buildClientParams(url, data, params);
|
|
195
|
-
const
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
+
const clientResponse = await clientEndPoint.load(clientParams);
|
|
199
|
+
if (clientResponse) {
|
|
200
|
+
if (clientResponse.ok) {
|
|
201
|
+
if (clientResponse.headers.get("Content-Type")?.includes("application/json")) {
|
|
202
|
+
Object.assign(data, await clientResponse.json());
|
|
203
|
+
}
|
|
204
|
+
} else {
|
|
205
|
+
return clientResponse;
|
|
206
|
+
}
|
|
198
207
|
}
|
|
199
208
|
}
|
|
200
209
|
if (serverEndPoint?.load) {
|
|
201
|
-
const
|
|
202
|
-
if (
|
|
203
|
-
|
|
210
|
+
const serverResponse = await serverEndPoint.load(serverParams);
|
|
211
|
+
if (serverResponse) {
|
|
212
|
+
if (serverResponse.ok) {
|
|
213
|
+
if (serverResponse.headers.get("Content-Type")?.includes("application/json")) {
|
|
214
|
+
Object.assign(data, await serverResponse.json());
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
return serverResponse;
|
|
218
|
+
}
|
|
204
219
|
}
|
|
205
220
|
}
|
|
206
|
-
return newData;
|
|
207
221
|
}
|
|
208
222
|
function buildClientParams(url, params, data) {
|
|
209
223
|
return {
|
package/dist/test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/test/runTest.ts"],"sourcesContent":["import { type ServerComponent, type ServerSlotRender } from \"@torpor/view\";\nimport path from \"node:path\";\nimport notFound from \"../response/notFound.ts\";\nimport ok from \"../response/ok.ts\";\nimport seeOther from \"../response/seeOther.ts\";\nimport ServerEvent from \"../server/ServerEvent.ts\";\nimport Router from \"../site/Router.ts\";\nimport Site from \"../site/Site\";\nimport $page from \"../state/$page.ts\";\nimport type PageEndPoint from \"../types/PageEndPoint.ts\";\nimport type PageServerEndPoint from \"../types/PageServerEndPoint.ts\";\nimport RouteHandler from \"../types/RouteHandler.ts\";\nimport {\n\tHOOK_ROUTE,\n\tHOOK_SERVER_ROUTE,\n\tLAYOUT_ROUTE,\n\tLAYOUT_SERVER_ROUTE,\n\tPAGE_ROUTE,\n\tPAGE_SERVER_ROUTE,\n\tSERVER_ROUTE,\n} from \"../types/RouteType\";\nimport type ServerEndPoint from \"../types/ServerEndPoint.ts\";\nimport type ServerHook from \"../types/ServerHook.ts\";\nimport type ServerLoadEvent from \"../types/ServerLoadEvent.ts\";\n\n/**\n * Runs a site route in test mode\n * @param site The site configuration, with routing configured\n * @param route The route path e.g. `/home`\n * @param ev An optional ServerEvent, which you can use to set test cookies and headers\n * @returns An HTTP response containing the requested data, HTML, or error status\n */\nexport default async function runTest(\n\tsite: Site,\n\troute: string,\n\tev?: ServerEvent,\n): Promise<Response> {\n\tif (!route.startsWith(\"/\")) route += \"/\";\n\tif (!ev) {\n\t\tconst req = new Request(`http://localhost${route}`);\n\t\tev = new ServerEvent(req);\n\t}\n\n\t// Build the router from the Site object created by the user\n\tconst router = new Router();\n\trouter.addPages(\n\t\tsite.routes.map((r) => ({\n\t\t\tpath: r.path,\n\t\t\ttype: r.type,\n\t\t\tendPoint: () => import(/* @vite-ignore */ path.join(site.root, r.file)),\n\t\t})),\n\t);\n\n\treturn await load(router, ev, \"%COMPONENT_HTML%\");\n}\n\n// HACK: This is a copy of serverEntry\n// TODO: Make it shared instead!\nasync function load(router: Router, ev: ServerEvent, template: string): Promise<Response> {\n\t//const url = new URL(`http://${process.env.HOST ?? \"localhost\"}${ev.request.url}`);\n\tconst url = new URL(ev.request.url);\n\tconst path = url.pathname;\n\tconst query = url.searchParams;\n\n\t//console.log(`handling ${ev.request.method} for '${path}'${query.size ? ` with ${query}` : \"\"}`);\n\n\tconst route = router.match(path, query);\n\tif (!route) {\n\t\treturn notFound();\n\t}\n\n\t// Update $page before building the components\n\t// TODO: Find somewhere better to put this\n\t$page.url = url;\n\n\tconst handler = route.handler;\n\tconst params = route.params || {};\n\n\t// TODO: Hit the server hook out here\n\t// We could maybe set data loading up as middleware on a route??????\n\n\tswitch (handler.type) {\n\t\tcase PAGE_ROUTE:\n\t\tcase LAYOUT_ROUTE: {\n\t\t\t// It's a /+page.ts or /_layout.ts endpoint\n\t\t\tif (ev.request.method === \"GET\") {\n\t\t\t\treturn await loadView(ev, url, handler, params, template);\n\t\t\t} else if (ev.request.method === \"POST\") {\n\t\t\t\treturn await runAction(ev, url, handler, params, query);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase PAGE_SERVER_ROUTE:\n\t\tcase LAYOUT_SERVER_ROUTE: {\n\t\t\t// It's a /+page.server.ts or /_layout.server.ts endpoint\n\t\t\tif (ev.request.method === \"GET\") {\n\t\t\t\treturn await loadData(ev, url, handler, \"load\", params);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase SERVER_ROUTE: {\n\t\t\t// It's a /+server.ts endpoint\n\t\t\tconst functionName = ev.request.method.toLowerCase().replace(\"delete\", \"del\");\n\t\t\treturn await loadData(ev, url, handler, functionName, params);\n\t\t}\n\t\tcase HOOK_ROUTE:\n\t\tcase HOOK_SERVER_ROUTE: {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn notFound();\n}\n\nasync function loadData(\n\tev: ServerEvent,\n\turl: URL,\n\thandler: RouteHandler,\n\tfunctionName: string,\n\tparams: Record<string, string>,\n) {\n\tconst serverEndPoint: ServerEndPoint | undefined = (await handler.endPoint()).default;\n\tif (serverEndPoint && serverEndPoint[functionName]) {\n\t\tconst serverParams = buildServerParams(ev, url, params);\n\n\t\tif (handler.serverHook) {\n\t\t\tconst serverHook: ServerHook | undefined = (await handler.serverHook()).default;\n\t\t\tif (serverHook?.handle) {\n\t\t\t\tawait serverHook.handle(serverParams);\n\t\t\t}\n\t\t}\n\n\t\tconst result = await serverEndPoint[functionName](serverParams);\n\n\t\t// If there was no response returned from load (such as errors or a\n\t\t// redirect), send an ok response\n\t\treturn result || ok();\n\t}\n\n\treturn notFound();\n}\n\nasync function loadView(\n\tev: ServerEvent,\n\turl: URL,\n\thandler: RouteHandler,\n\tparams: Record<string, string>,\n\ttemplate: string,\n) {\n\t// There must be a client endpoint with a component\n\tconst clientEndPoint: PageEndPoint | undefined = (await handler.endPoint()).default;\n\tif (!clientEndPoint?.component) {\n\t\treturn notFound();\n\t}\n\n\t// There may be a server endpoint\n\tconst serverEndPoint: PageServerEndPoint | undefined =\n\t\thandler.serverEndPoint && (await handler.serverEndPoint())?.default;\n\n\t// Maybe hit the server hook\n\tconst serverParams = buildServerParams(ev, url, params);\n\tif (handler.serverHook) {\n\t\tconst serverHook: ServerHook | undefined = (await handler.serverHook()).default;\n\t\tif (serverHook?.handle) {\n\t\t\tawait serverHook.handle(serverParams);\n\t\t}\n\t}\n\n\t// Pass the data into $props\n\t// TODO: Promise.all\n\t// NOTE: We're loading data from top to bottom, overriding as we go, and I'm not sure if this is the best way to go\n\tlet data = {};\n\tif (handler.layouts) {\n\t\tfor (let layout of handler.layouts) {\n\t\t\tconst layoutEndPoint: PageEndPoint | undefined = (await layout.endPoint())?.default;\n\t\t\tconst layoutServerEndPoint: PageServerEndPoint | undefined =\n\t\t\t\tlayout.serverEndPoint && (await layout.serverEndPoint())?.default;\n\t\t\tconst layoutData = await loadClientAndServerData(\n\t\t\t\turl,\n\t\t\t\tparams,\n\t\t\t\tserverParams,\n\t\t\t\tdata,\n\t\t\t\tlayoutEndPoint,\n\t\t\t\tlayoutServerEndPoint,\n\t\t\t);\n\t\t\tObject.assign(data, layoutData);\n\t\t}\n\t}\n\tlet endPointData = await loadClientAndServerData(\n\t\turl,\n\t\tparams,\n\t\tserverParams,\n\t\tdata,\n\t\tclientEndPoint,\n\t\tserverEndPoint,\n\t);\n\tObject.assign(data, endPointData);\n\tlet $props: Record<string, any> = { data };\n\n\t// If there are layouts, work our way upwards, pushing each component into\n\t// the default slot of its parent\n\t// TODO: Also handle layout server data\n\t// TODO: There's probably a nicer way to do this with reducers or something\n\t// TODO: Re-use parent layouts\n\tlet component = clientEndPoint.component as ServerComponent;\n\tlet slots: Record<string, ServerSlotRender> | undefined = undefined;\n\tif (handler.layouts) {\n\t\tlet slotFunctions: ServerSlotRender[] = [];\n\t\tslotFunctions[handler.layouts.length] = (_, context) =>\n\t\t\t(clientEndPoint.component as ServerComponent)($props, context);\n\t\tfor (let i = handler.layouts.length - 1; i >= 0; i--) {\n\t\t\tconst layoutEndPoint: PageEndPoint | undefined = (await handler.layouts[i].endPoint())\n\t\t\t\t?.default;\n\t\t\tif (layoutEndPoint?.component) {\n\t\t\t\tif (i === 0) {\n\t\t\t\t\tcomponent = layoutEndPoint.component as ServerComponent;\n\t\t\t\t\tslots = { _: slotFunctions[i + 1] };\n\t\t\t\t} else {\n\t\t\t\t\tslotFunctions[i] = (_, context) =>\n\t\t\t\t\t\t(layoutEndPoint.component as ServerComponent)($props, context, {\n\t\t\t\t\t\t\t_: slotFunctions[i + 1],\n\t\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlet html;\n\ttry {\n\t\thtml = component($props, undefined, slots);\n\t\thtml = template.replace(\"%COMPONENT_HTML%\", html);\n\t} catch (error) {\n\t\t// TODO: Show a proper Error component\n\t\thtml = '<span style=\"color: red\">Script syntax error</span><p>' + error + \"</p>\";\n\t\tconsole.log(error);\n\t}\n\n\treturn new Response(html, {\n\t\tstatus: 200,\n\t\theaders: {\n\t\t\t\"Content-Type\": \"text/html\",\n\t\t},\n\t});\n}\n\nasync function runAction(\n\tev: ServerEvent,\n\turl: URL,\n\thandler: RouteHandler,\n\tparams: Record<string, string>,\n\tquery: URLSearchParams,\n) {\n\tconst actionName = (Array.from(query.keys())[0] || \"default\").replace(/^\\//, \"\");\n\tconst serverEndPoint: PageServerEndPoint | undefined =\n\t\thandler.serverEndPoint && (await handler.serverEndPoint()).default;\n\tif (serverEndPoint?.actions) {\n\t\tconst action = serverEndPoint.actions[actionName];\n\t\tif (action) {\n\t\t\t// TODO: form.errors etc\n\t\t\tconst serverParams = buildServerParams(ev, url, params);\n\n\t\t\tif (handler.serverHook) {\n\t\t\t\tconst serverHook: ServerHook | undefined = (await handler.serverHook()).default;\n\t\t\t\tif (serverHook?.handle) {\n\t\t\t\t\tawait serverHook.handle(serverParams);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst result = await action(serverParams); // <--\n\n\t\t\t// If there was no response returned from the action (such as errors\n\t\t\t// or a redirect), reload the page by redirecting\n\t\t\treturn result || seeOther(url.pathname);\n\t\t}\n\t}\n\n\treturn notFound();\n}\n\nasync function loadClientAndServerData(\n\turl: URL,\n\tparams: Record<string, string>,\n\tserverParams: ServerLoadEvent,\n\tdata: Record<string, any>,\n\tclientEndPoint?: PageEndPoint,\n\tserverEndPoint?: PageServerEndPoint,\n) {\n\tlet newData = {};\n\tif (clientEndPoint?.load) {\n\t\tconst clientParams = buildClientParams(url, data, params);\n\t\tconst clientData = await clientEndPoint.load(clientParams);\n\t\tif (clientData) {\n\t\t\tObject.assign(newData, clientData);\n\t\t}\n\t}\n\tif (serverEndPoint?.load) {\n\t\tconst serverData = await serverEndPoint.load(serverParams);\n\t\tif (serverData?.ok) {\n\t\t\tObject.assign(newData, await serverData.json());\n\t\t}\n\t}\n\treturn newData;\n}\n\nfunction buildClientParams(url: URL, params: Record<string, string>, data: Record<string, any>) {\n\treturn {\n\t\turl,\n\t\tparams,\n\t\tdata,\n\t};\n}\n\nfunction buildServerParams(\n\tev: ServerEvent,\n\turl: URL,\n\tparams: Record<string, string>,\n): ServerLoadEvent {\n\treturn {\n\t\turl,\n\t\tparams,\n\t\tappData: {},\n\t\trequest: ev.request,\n\t\tcookies: ev.cookies,\n\t\theaders: ev.headers,\n\t\tadapter: ev.adapter,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,UAAU;AA+BjB,eAAO,QACN,MACA,OACA,IACoB;AACpB,MAAI,CAAC,MAAM,WAAW,GAAG,EAAG,UAAS;AACrC,MAAI,CAAC,IAAI;AACR,UAAM,MAAM,IAAI,QAAQ,mBAAmB,KAAK,EAAE;AAClD,SAAK,IAAI,YAAY,GAAG;AAAA,EACzB;AAGA,QAAM,SAAS,IAAI,OAAO;AAC1B,SAAO;AAAA,IACN,KAAK,OAAO,IAAI,CAAC,OAAO;AAAA,MACvB,MAAM,EAAE;AAAA,MACR,MAAM,EAAE;AAAA,MACR,UAAU,MAAM;AAAA;AAAA,QAA0B,KAAK,KAAK,KAAK,MAAM,EAAE,IAAI;AAAA;AAAA,IACtE,EAAE;AAAA,EACH;AAEA,SAAO,MAAM,KAAK,QAAQ,IAAI,kBAAkB;AACjD;AAIA,eAAe,KAAK,QAAgB,IAAiB,UAAqC;AAEzF,QAAM,MAAM,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;AAEA,YAAM,SAAS,MAAM,OAAO,YAAY;AAIxC,aAAO,UAAU,SAAS,IAAI,QAAQ;AAAA,IACvC;AAAA,EACD;AAEA,SAAO,SAAS;AACjB;AAEA,eAAe,wBACd,KACA,QACA,cACA,MACA,gBACA,gBACC;AACD,MAAI,UAAU,CAAC;AACf,MAAI,gBAAgB,MAAM;AACzB,UAAM,eAAe,kBAAkB,KAAK,MAAM,MAAM;AACxD,UAAM,aAAa,MAAM,eAAe,KAAK,YAAY;AACzD,QAAI,YAAY;AACf,aAAO,OAAO,SAAS,UAAU;AAAA,IAClC;AAAA,EACD;AACA,MAAI,gBAAgB,MAAM;AACzB,UAAM,aAAa,MAAM,eAAe,KAAK,YAAY;AACzD,QAAI,YAAY,IAAI;AACnB,aAAO,OAAO,SAAS,MAAM,WAAW,KAAK,CAAC;AAAA,IAC/C;AAAA,EACD;AACA,SAAO;AACR;AAEA,SAAS,kBAAkB,KAAU,QAAgC,MAA2B;AAC/F,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,SAAS,kBACR,IACA,KACA,QACkB;AAClB,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,SAAS,CAAC;AAAA,IACV,SAAS,GAAG;AAAA,IACZ,SAAS,GAAG;AAAA,IACZ,SAAS,GAAG;AAAA,IACZ,SAAS,GAAG;AAAA,EACb;AACD;","names":["path"]}
|
|
1
|
+
{"version":3,"sources":["../src/test/runTest.ts"],"sourcesContent":["import { type ServerComponent, type ServerSlotRender } from \"@torpor/view\";\nimport path from \"node:path\";\nimport notFound from \"../response/notFound.ts\";\nimport ok from \"../response/ok.ts\";\nimport seeOther from \"../response/seeOther.ts\";\nimport ServerEvent from \"../server/ServerEvent.ts\";\nimport Router from \"../site/Router.ts\";\nimport Site from \"../site/Site\";\nimport $page from \"../state/$page.ts\";\nimport type PageEndPoint from \"../types/PageEndPoint.ts\";\nimport type PageServerEndPoint from \"../types/PageServerEndPoint.ts\";\nimport RouteHandler from \"../types/RouteHandler.ts\";\nimport {\n\tHOOK_ROUTE,\n\tHOOK_SERVER_ROUTE,\n\tLAYOUT_ROUTE,\n\tLAYOUT_SERVER_ROUTE,\n\tPAGE_ROUTE,\n\tPAGE_SERVER_ROUTE,\n\tSERVER_ROUTE,\n} from \"../types/RouteType\";\nimport type ServerEndPoint from \"../types/ServerEndPoint.ts\";\nimport type ServerHook from \"../types/ServerHook.ts\";\nimport type ServerLoadEvent from \"../types/ServerLoadEvent.ts\";\n\n/**\n * Runs a site route in test mode\n * @param site The site configuration, with routing configured\n * @param route The route path e.g. `/home`\n * @param ev An optional ServerEvent, which you can use to set test cookies and headers\n * @returns An HTTP response containing the requested data, HTML, or error status\n */\nexport default async function runTest(\n\tsite: Site,\n\troute: string,\n\tev?: ServerEvent,\n): Promise<Response> {\n\tif (!route.startsWith(\"/\")) route += \"/\";\n\tif (!ev) {\n\t\tconst req = new Request(`http://localhost${route}`);\n\t\tev = new ServerEvent(req);\n\t}\n\n\t// Build the router from the Site object created by the user\n\tconst router = new Router();\n\trouter.addPages(\n\t\tsite.routes.map((r) => ({\n\t\t\tpath: r.path,\n\t\t\ttype: r.type,\n\t\t\tendPoint: () => import(/* @vite-ignore */ path.join(site.root, r.file)),\n\t\t})),\n\t);\n\n\treturn await load(router, ev, \"%COMPONENT_HTML%\");\n}\n\n// HACK: This is a copy of serverEntry\n// TODO: Make it shared instead!\nasync function load(router: Router, ev: ServerEvent, template: string): Promise<Response> {\n\t//const url = new URL(`http://${process.env.HOST ?? \"localhost\"}${ev.request.url}`);\n\tconst url = new URL(ev.request.url);\n\tconst path = url.pathname;\n\tconst query = url.searchParams;\n\n\t//console.log(`handling ${ev.request.method} for '${path}'${query.size ? ` with ${query}` : \"\"}`);\n\n\tconst route = router.match(path, query);\n\tif (!route) {\n\t\treturn notFound();\n\t}\n\n\t// Update $page before building the components\n\t// TODO: Find somewhere better to put this\n\t$page.url = url;\n\n\tconst handler = route.handler;\n\tconst params = route.params || {};\n\n\t// TODO: Hit the server hook out here\n\t// We could maybe set data loading up as middleware on a route??????\n\n\tswitch (handler.type) {\n\t\tcase PAGE_ROUTE:\n\t\tcase LAYOUT_ROUTE: {\n\t\t\t// It's a /+page.ts or /_layout.ts endpoint\n\t\t\tif (ev.request.method === \"GET\") {\n\t\t\t\treturn await loadView(ev, url, handler, params, template);\n\t\t\t} else if (ev.request.method === \"POST\") {\n\t\t\t\treturn await runAction(ev, url, handler, params, query);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase PAGE_SERVER_ROUTE:\n\t\tcase LAYOUT_SERVER_ROUTE: {\n\t\t\t// It's a /+page.server.ts or /_layout.server.ts endpoint\n\t\t\tif (ev.request.method === \"GET\") {\n\t\t\t\treturn await loadData(ev, url, handler, \"load\", params);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase SERVER_ROUTE: {\n\t\t\t// It's a /+server.ts endpoint\n\t\t\tconst functionName = ev.request.method.toLowerCase().replace(\"delete\", \"del\");\n\t\t\treturn await loadData(ev, url, handler, functionName, params);\n\t\t}\n\t\tcase HOOK_ROUTE:\n\t\tcase HOOK_SERVER_ROUTE: {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn notFound();\n}\n\nasync function loadData(\n\tev: ServerEvent,\n\turl: URL,\n\thandler: RouteHandler,\n\tfunctionName: string,\n\tparams: Record<string, string>,\n) {\n\tconst serverEndPoint: ServerEndPoint | undefined = (await handler.endPoint()).default;\n\tif (serverEndPoint && serverEndPoint[functionName]) {\n\t\tconst serverParams = buildServerParams(ev, url, params);\n\n\t\tif (handler.serverHook) {\n\t\t\tconst serverHook: ServerHook | undefined = (await handler.serverHook()).default;\n\t\t\tif (serverHook?.handle) {\n\t\t\t\tawait serverHook.handle(serverParams);\n\t\t\t}\n\t\t}\n\n\t\tconst result = await serverEndPoint[functionName](serverParams);\n\n\t\t// If there was no response returned from load (such as errors or a\n\t\t// redirect), send an ok response\n\t\treturn result || ok();\n\t}\n\n\treturn notFound();\n}\n\nasync function loadView(\n\tev: ServerEvent,\n\turl: URL,\n\thandler: RouteHandler,\n\tparams: Record<string, string>,\n\ttemplate: string,\n) {\n\t// There must be a client endpoint with a component\n\tconst clientEndPoint: PageEndPoint | undefined = (await handler.endPoint()).default;\n\tif (!clientEndPoint?.component) {\n\t\treturn notFound();\n\t}\n\n\t// There may be a server endpoint\n\tconst serverEndPoint: PageServerEndPoint | undefined =\n\t\thandler.serverEndPoint && (await handler.serverEndPoint())?.default;\n\n\t// Maybe hit the server hook\n\tconst serverParams = buildServerParams(ev, url, params);\n\tif (handler.serverHook) {\n\t\tconst serverHook: ServerHook | undefined = (await handler.serverHook()).default;\n\t\tif (serverHook?.handle) {\n\t\t\tawait serverHook.handle(serverParams);\n\t\t}\n\t}\n\n\t// Pass the data into $props\n\t// TODO: Promise.all\n\t// NOTE: We're loading data from top to bottom, overriding as we go, and I'm not sure if this is the best way to go\n\tlet data = {};\n\tif (handler.layouts) {\n\t\tfor (let layout of handler.layouts) {\n\t\t\tconst layoutEndPoint: PageEndPoint | undefined = (await layout.endPoint())?.default;\n\t\t\tconst layoutServerEndPoint: PageServerEndPoint | undefined =\n\t\t\t\tlayout.serverEndPoint && (await layout.serverEndPoint())?.default;\n\t\t\tconst layoutResponse = await loadClientAndServerData(\n\t\t\t\turl,\n\t\t\t\tparams,\n\t\t\t\tserverParams,\n\t\t\t\tdata,\n\t\t\t\tlayoutEndPoint,\n\t\t\t\tlayoutServerEndPoint,\n\t\t\t);\n\t\t\tif (layoutResponse?.ok === false) {\n\t\t\t\treturn layoutResponse;\n\t\t\t}\n\t\t}\n\t}\n\tlet endPointResponse = await loadClientAndServerData(\n\t\turl,\n\t\tparams,\n\t\tserverParams,\n\t\tdata,\n\t\tclientEndPoint,\n\t\tserverEndPoint,\n\t);\n\tif (endPointResponse?.ok === false) {\n\t\treturn endPointResponse;\n\t}\n\tlet $props: Record<string, any> = { data };\n\n\t// If there are layouts, work our way upwards, pushing each component into\n\t// the default slot of its parent\n\t// TODO: Also handle layout server data\n\t// TODO: There's probably a nicer way to do this with reducers or something\n\t// TODO: Re-use parent layouts\n\tlet component = clientEndPoint.component as ServerComponent;\n\tlet slots: Record<string, ServerSlotRender> | undefined = undefined;\n\tif (handler.layouts) {\n\t\tlet slotFunctions: ServerSlotRender[] = [];\n\t\tslotFunctions[handler.layouts.length] = (_, context) =>\n\t\t\t(clientEndPoint.component as ServerComponent)($props, context);\n\t\tfor (let i = handler.layouts.length - 1; i >= 0; i--) {\n\t\t\tconst layoutEndPoint: PageEndPoint | undefined = (await handler.layouts[i].endPoint())\n\t\t\t\t?.default;\n\t\t\tif (layoutEndPoint?.component) {\n\t\t\t\tif (i === 0) {\n\t\t\t\t\tcomponent = layoutEndPoint.component as ServerComponent;\n\t\t\t\t\tslots = { _: slotFunctions[i + 1] };\n\t\t\t\t} else {\n\t\t\t\t\tslotFunctions[i] = (_, context) =>\n\t\t\t\t\t\t(layoutEndPoint.component as ServerComponent)($props, context, {\n\t\t\t\t\t\t\t_: slotFunctions[i + 1],\n\t\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlet html;\n\ttry {\n\t\thtml = component($props, undefined, slots);\n\t\thtml = template.replace(\"%COMPONENT_HTML%\", html);\n\t} catch (error) {\n\t\t// TODO: Show a proper Error component\n\t\thtml = '<span style=\"color: red\">Script syntax error</span><p>' + error + \"</p>\";\n\t\tconsole.log(error);\n\t}\n\n\treturn new Response(html, {\n\t\tstatus: 200,\n\t\theaders: {\n\t\t\t\"Content-Type\": \"text/html\",\n\t\t},\n\t});\n}\n\nasync function runAction(\n\tev: ServerEvent,\n\turl: URL,\n\thandler: RouteHandler,\n\tparams: Record<string, string>,\n\tquery: URLSearchParams,\n) {\n\tconst actionName = (Array.from(query.keys())[0] || \"default\").replace(/^\\//, \"\");\n\tconst serverEndPoint: PageServerEndPoint | undefined =\n\t\thandler.serverEndPoint && (await handler.serverEndPoint()).default;\n\tif (serverEndPoint?.actions) {\n\t\tconst action = serverEndPoint.actions[actionName];\n\t\tif (action) {\n\t\t\t// TODO: form.errors etc\n\t\t\tconst serverParams = buildServerParams(ev, url, params);\n\n\t\t\tif (handler.serverHook) {\n\t\t\t\tconst serverHook: ServerHook | undefined = (await handler.serverHook()).default;\n\t\t\t\tif (serverHook?.handle) {\n\t\t\t\t\tawait serverHook.handle(serverParams);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst result = await action(serverParams); // <--\n\n\t\t\t// If there was no response returned from the action (such as errors\n\t\t\t// or a redirect), reload the page by redirecting\n\t\t\treturn result || seeOther(url.pathname);\n\t\t}\n\t}\n\n\treturn notFound();\n}\n\nasync function loadClientAndServerData(\n\turl: URL,\n\tparams: Record<string, string>,\n\tserverParams: ServerLoadEvent,\n\tdata: Record<string, any>,\n\tclientEndPoint?: PageEndPoint,\n\tserverEndPoint?: PageServerEndPoint,\n) {\n\tif (clientEndPoint?.load) {\n\t\tconst clientParams = buildClientParams(url, data, params);\n\t\tconst clientResponse = await clientEndPoint.load(clientParams);\n\t\tif (clientResponse) {\n\t\t\tif (clientResponse.ok) {\n\t\t\t\tif (clientResponse.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n\t\t\t\t\tObject.assign(data, await clientResponse.json());\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn clientResponse;\n\t\t\t}\n\t\t}\n\t}\n\tif (serverEndPoint?.load) {\n\t\tconst serverResponse = await serverEndPoint.load(serverParams);\n\t\tif (serverResponse) {\n\t\t\tif (serverResponse.ok) {\n\t\t\t\tif (serverResponse.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n\t\t\t\t\tObject.assign(data, await serverResponse.json());\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn serverResponse;\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction buildClientParams(url: URL, params: Record<string, string>, data: Record<string, any>) {\n\treturn {\n\t\turl,\n\t\tparams,\n\t\tdata,\n\t};\n}\n\nfunction buildServerParams(\n\tev: ServerEvent,\n\turl: URL,\n\tparams: Record<string, string>,\n): ServerLoadEvent {\n\treturn {\n\t\turl,\n\t\tparams,\n\t\tappData: {},\n\t\trequest: ev.request,\n\t\tcookies: ev.cookies,\n\t\theaders: ev.headers,\n\t\tadapter: ev.adapter,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,UAAU;AA+BjB,eAAO,QACN,MACA,OACA,IACoB;AACpB,MAAI,CAAC,MAAM,WAAW,GAAG,EAAG,UAAS;AACrC,MAAI,CAAC,IAAI;AACR,UAAM,MAAM,IAAI,QAAQ,mBAAmB,KAAK,EAAE;AAClD,SAAK,IAAI,YAAY,GAAG;AAAA,EACzB;AAGA,QAAM,SAAS,IAAI,OAAO;AAC1B,SAAO;AAAA,IACN,KAAK,OAAO,IAAI,CAAC,OAAO;AAAA,MACvB,MAAM,EAAE;AAAA,MACR,MAAM,EAAE;AAAA,MACR,UAAU,MAAM;AAAA;AAAA,QAA0B,KAAK,KAAK,KAAK,MAAM,EAAE,IAAI;AAAA;AAAA,IACtE,EAAE;AAAA,EACH;AAEA,SAAO,MAAM,KAAK,QAAQ,IAAI,kBAAkB;AACjD;AAIA,eAAe,KAAK,QAAgB,IAAiB,UAAqC;AAEzF,QAAM,MAAM,IAAI,IAAI,GAAG,QAAQ,GAAG;AAClC,QAAMA,QAAO,IAAI;AACjB,QAAM,QAAQ,IAAI;AAIlB,QAAM,QAAQ,OAAO,MAAMA,OAAM,KAAK;AACtC,MAAI,CAAC,OAAO;AACX,WAAO,SAAS;AAAA,EACjB;AAIA,eAAM,MAAM;AAEZ,QAAM,UAAU,MAAM;AACtB,QAAM,SAAS,MAAM,UAAU,CAAC;AAKhC,UAAQ,QAAQ,MAAM;AAAA,IACrB,KAAK;AAAA,IACL,KAAK,cAAc;AAElB,UAAI,GAAG,QAAQ,WAAW,OAAO;AAChC,eAAO,MAAM,SAAS,IAAI,KAAK,SAAS,QAAQ,QAAQ;AAAA,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,SAAS,kBAAkB,GAAG;AAC7E,iBAAO,OAAO,MAAM,MAAM,eAAe,KAAK,CAAC;AAAA,QAChD;AAAA,MACD,OAAO;AACN,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AACA,MAAI,gBAAgB,MAAM;AACzB,UAAM,iBAAiB,MAAM,eAAe,KAAK,YAAY;AAC7D,QAAI,gBAAgB;AACnB,UAAI,eAAe,IAAI;AACtB,YAAI,eAAe,QAAQ,IAAI,cAAc,GAAG,SAAS,kBAAkB,GAAG;AAC7E,iBAAO,OAAO,MAAM,MAAM,eAAe,KAAK,CAAC;AAAA,QAChD;AAAA,MACD,OAAO;AACN,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AACD;AAEA,SAAS,kBAAkB,KAAU,QAAgC,MAA2B;AAC/F,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,SAAS,kBACR,IACA,KACA,QACkB;AAClB,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,SAAS,CAAC;AAAA,IACV,SAAS,GAAG;AAAA,IACZ,SAAS,GAAG;AAAA,IACZ,SAAS,GAAG;AAAA,IACZ,SAAS,GAAG;AAAA,EACb;AACD;","names":["path"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@torpor/build",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "A framework for building sites and apps with Torpor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -55,15 +55,15 @@
|
|
|
55
55
|
"dotenv": "^16.5.0",
|
|
56
56
|
"vite": "^6.3.5",
|
|
57
57
|
"vite-tsconfig-paths": "^5.1.4",
|
|
58
|
-
"@torpor/
|
|
59
|
-
"@torpor/
|
|
58
|
+
"@torpor/view": "^0.1.0",
|
|
59
|
+
"@torpor/unplugin": "^0.1.11"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
|
|
63
63
|
"tsup": "^8.5.0",
|
|
64
64
|
"tsx": "^4.19.4",
|
|
65
65
|
"typescript": "^5.8.3",
|
|
66
|
-
"vitest": "^3.
|
|
66
|
+
"vitest": "^3.2.0"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"build": "tsc --noEmit && tsup",
|
package/src/site/Site.ts
CHANGED
|
@@ -40,8 +40,10 @@ export default class Site {
|
|
|
40
40
|
*/
|
|
41
41
|
inputs: string[] = [];
|
|
42
42
|
/**
|
|
43
|
-
* Vite config options
|
|
44
|
-
*
|
|
43
|
+
* Vite config options to merge with the standard Torpor build options.
|
|
44
|
+
* `plugins` and `build.rollupOptions.input` will be overridden, so you
|
|
45
|
+
* should set `Site.plugins` and `Site.inputs` instead. Other options may be
|
|
46
|
+
* overridden or incompatible, so experimentation may be required
|
|
45
47
|
*/
|
|
46
48
|
viteConfig?: UserConfig;
|
|
47
49
|
|
package/src/site/clientEntry.ts
CHANGED
|
@@ -90,24 +90,28 @@ async function navigate(url: URL, firstTime = false): Promise<boolean> {
|
|
|
90
90
|
const layoutEndPoint: PageEndPoint | undefined = (await layout.endPoint())?.default;
|
|
91
91
|
const layoutServerEndPoint: PageServerEndPoint | undefined =
|
|
92
92
|
layout.serverEndPoint && (await layout.serverEndPoint())?.default;
|
|
93
|
-
const
|
|
93
|
+
const layoutResponse = await loadClientAndServerData(
|
|
94
94
|
data,
|
|
95
95
|
document.location.origin + layoutPath,
|
|
96
96
|
params,
|
|
97
97
|
layoutEndPoint,
|
|
98
98
|
layoutServerEndPoint,
|
|
99
99
|
);
|
|
100
|
-
|
|
100
|
+
if (layoutResponse?.ok === false) {
|
|
101
|
+
return layoutResponse;
|
|
102
|
+
}
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
|
-
let
|
|
105
|
+
let endPointResponse = await loadClientAndServerData(
|
|
104
106
|
data,
|
|
105
107
|
document.location.origin + path,
|
|
106
108
|
params,
|
|
107
109
|
clientEndPoint,
|
|
108
110
|
serverEndPoint,
|
|
109
111
|
);
|
|
110
|
-
|
|
112
|
+
if (endPointResponse?.ok === false) {
|
|
113
|
+
return endPointResponse;
|
|
114
|
+
}
|
|
111
115
|
let $props: Record<string, any> = { data };
|
|
112
116
|
|
|
113
117
|
// If there are layouts, work our way upwards, pushing each component into
|
|
@@ -164,27 +168,33 @@ async function loadClientAndServerData(
|
|
|
164
168
|
clientEndPoint?: PageEndPoint,
|
|
165
169
|
serverEndPoint?: PageServerEndPoint,
|
|
166
170
|
) {
|
|
167
|
-
let newData = {};
|
|
168
171
|
if (clientEndPoint?.load) {
|
|
169
172
|
const clientUrl = new URL(document.location.href);
|
|
170
173
|
const clientParams = buildClientParams(clientUrl, params, data);
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
+
const clientResponse = await clientEndPoint.load(clientParams);
|
|
175
|
+
if (clientResponse) {
|
|
176
|
+
if (clientResponse.ok) {
|
|
177
|
+
if (clientResponse.headers.get("Content-Type")?.includes("application/json")) {
|
|
178
|
+
Object.assign(data, await clientResponse.json());
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
return clientResponse;
|
|
182
|
+
}
|
|
174
183
|
}
|
|
175
184
|
}
|
|
176
185
|
if (serverEndPoint?.load) {
|
|
177
186
|
const serverUrl = location.replace(/\/$/, "") + "/~server";
|
|
178
187
|
const serverResponse = await fetch(serverUrl);
|
|
179
|
-
if (
|
|
180
|
-
serverResponse
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
188
|
+
if (serverResponse) {
|
|
189
|
+
if (serverResponse.ok) {
|
|
190
|
+
if (serverResponse.headers.get("Content-Type")?.includes("application/json")) {
|
|
191
|
+
Object.assign(data, await serverResponse.json());
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
return serverResponse;
|
|
195
|
+
}
|
|
185
196
|
}
|
|
186
197
|
}
|
|
187
|
-
return newData;
|
|
188
198
|
}
|
|
189
199
|
|
|
190
200
|
function buildClientParams(url: URL, params: Record<string, string>, data: Record<string, any>) {
|
package/src/site/runBuild.ts
CHANGED
|
@@ -16,8 +16,8 @@ export default async function runBuild(site: Site): Promise<void> {
|
|
|
16
16
|
if (existsSync(distFolder)) {
|
|
17
17
|
await fs.rm(distFolder, { recursive: true });
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const clientFolder = path.join(distFolder, "client");
|
|
20
|
+
const serverFolder = path.join(distFolder, "server");
|
|
21
21
|
|
|
22
22
|
// HOOK: Prebuild
|
|
23
23
|
if (site.adapter.prebuild) {
|
|
@@ -34,11 +34,10 @@ export default async function runBuild(site: Site): Promise<void> {
|
|
|
34
34
|
|
|
35
35
|
// Build the client assets, including site.html and the route files
|
|
36
36
|
// EXCLUDING anything with `server.js` in the name
|
|
37
|
-
const clientConfig = site.viteConfig ?? {};
|
|
37
|
+
const clientConfig = structuredClone(site.viteConfig ?? {});
|
|
38
38
|
clientConfig.plugins = [manifest(site), torpor(), ...site.plugins];
|
|
39
39
|
clientConfig.build ??= {};
|
|
40
|
-
clientConfig.build.outDir
|
|
41
|
-
clientFolder = clientConfig.build.outDir;
|
|
40
|
+
clientConfig.build.outDir = clientFolder;
|
|
42
41
|
clientConfig.build.rollupOptions ??= {};
|
|
43
42
|
clientConfig.build.rollupOptions.input = [
|
|
44
43
|
siteHtml,
|
|
@@ -53,12 +52,10 @@ export default async function runBuild(site: Site): Promise<void> {
|
|
|
53
52
|
|
|
54
53
|
// Build the server assets, including the server entry script and the route
|
|
55
54
|
// files
|
|
56
|
-
const serverConfig = site.viteConfig ?? {};
|
|
57
|
-
serverConfig.plugins
|
|
58
|
-
serverConfig.plugins.push(manifest(site, true), torpor(), ...site.plugins);
|
|
55
|
+
const serverConfig = structuredClone(site.viteConfig ?? {});
|
|
56
|
+
serverConfig.plugins = [manifest(site, true), torpor(), ...site.plugins];
|
|
59
57
|
serverConfig.build ??= {};
|
|
60
|
-
serverConfig.build.outDir
|
|
61
|
-
serverFolder = serverConfig.build.outDir;
|
|
58
|
+
serverConfig.build.outDir = serverFolder;
|
|
62
59
|
serverConfig.build.rollupOptions ??= {};
|
|
63
60
|
serverConfig.build.rollupOptions.input = [
|
|
64
61
|
serverScript,
|
package/src/site/serverEntry.ts
CHANGED
|
@@ -148,7 +148,7 @@ async function loadView(
|
|
|
148
148
|
const layoutEndPoint: PageEndPoint | undefined = (await layout.endPoint())?.default;
|
|
149
149
|
const layoutServerEndPoint: PageServerEndPoint | undefined =
|
|
150
150
|
layout.serverEndPoint && (await layout.serverEndPoint())?.default;
|
|
151
|
-
const
|
|
151
|
+
const layoutResponse = await loadClientAndServerData(
|
|
152
152
|
url,
|
|
153
153
|
params,
|
|
154
154
|
serverParams,
|
|
@@ -156,10 +156,12 @@ async function loadView(
|
|
|
156
156
|
layoutEndPoint,
|
|
157
157
|
layoutServerEndPoint,
|
|
158
158
|
);
|
|
159
|
-
|
|
159
|
+
if (layoutResponse?.ok === false) {
|
|
160
|
+
return layoutResponse;
|
|
161
|
+
}
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
|
-
let
|
|
164
|
+
let endPointResponse = await loadClientAndServerData(
|
|
163
165
|
url,
|
|
164
166
|
params,
|
|
165
167
|
serverParams,
|
|
@@ -167,7 +169,9 @@ async function loadView(
|
|
|
167
169
|
clientEndPoint,
|
|
168
170
|
serverEndPoint,
|
|
169
171
|
);
|
|
170
|
-
|
|
172
|
+
if (endPointResponse?.ok === false) {
|
|
173
|
+
return endPointResponse;
|
|
174
|
+
}
|
|
171
175
|
let $props: Record<string, any> = { data };
|
|
172
176
|
|
|
173
177
|
// If there are layouts, work our way upwards, pushing each component into
|
|
@@ -258,21 +262,31 @@ async function loadClientAndServerData(
|
|
|
258
262
|
clientEndPoint?: PageEndPoint,
|
|
259
263
|
serverEndPoint?: PageServerEndPoint,
|
|
260
264
|
) {
|
|
261
|
-
let newData = {};
|
|
262
265
|
if (clientEndPoint?.load) {
|
|
263
266
|
const clientParams = buildClientParams(url, data, params);
|
|
264
|
-
const
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
+
const clientResponse = await clientEndPoint.load(clientParams);
|
|
268
|
+
if (clientResponse) {
|
|
269
|
+
if (clientResponse.ok) {
|
|
270
|
+
if (clientResponse.headers.get("Content-Type")?.includes("application/json")) {
|
|
271
|
+
Object.assign(data, await clientResponse.json());
|
|
272
|
+
}
|
|
273
|
+
} else {
|
|
274
|
+
return clientResponse;
|
|
275
|
+
}
|
|
267
276
|
}
|
|
268
277
|
}
|
|
269
278
|
if (serverEndPoint?.load) {
|
|
270
|
-
const
|
|
271
|
-
if (
|
|
272
|
-
|
|
279
|
+
const serverResponse = await serverEndPoint.load(serverParams);
|
|
280
|
+
if (serverResponse) {
|
|
281
|
+
if (serverResponse.ok) {
|
|
282
|
+
if (serverResponse.headers.get("Content-Type")?.includes("application/json")) {
|
|
283
|
+
Object.assign(data, await serverResponse.json());
|
|
284
|
+
}
|
|
285
|
+
} else {
|
|
286
|
+
return serverResponse;
|
|
287
|
+
}
|
|
273
288
|
}
|
|
274
289
|
}
|
|
275
|
-
return newData;
|
|
276
290
|
}
|
|
277
291
|
|
|
278
292
|
function buildClientParams(url: URL, params: Record<string, string>, data: Record<string, any>) {
|
package/src/test/runTest.ts
CHANGED
|
@@ -175,7 +175,7 @@ async function loadView(
|
|
|
175
175
|
const layoutEndPoint: PageEndPoint | undefined = (await layout.endPoint())?.default;
|
|
176
176
|
const layoutServerEndPoint: PageServerEndPoint | undefined =
|
|
177
177
|
layout.serverEndPoint && (await layout.serverEndPoint())?.default;
|
|
178
|
-
const
|
|
178
|
+
const layoutResponse = await loadClientAndServerData(
|
|
179
179
|
url,
|
|
180
180
|
params,
|
|
181
181
|
serverParams,
|
|
@@ -183,10 +183,12 @@ async function loadView(
|
|
|
183
183
|
layoutEndPoint,
|
|
184
184
|
layoutServerEndPoint,
|
|
185
185
|
);
|
|
186
|
-
|
|
186
|
+
if (layoutResponse?.ok === false) {
|
|
187
|
+
return layoutResponse;
|
|
188
|
+
}
|
|
187
189
|
}
|
|
188
190
|
}
|
|
189
|
-
let
|
|
191
|
+
let endPointResponse = await loadClientAndServerData(
|
|
190
192
|
url,
|
|
191
193
|
params,
|
|
192
194
|
serverParams,
|
|
@@ -194,7 +196,9 @@ async function loadView(
|
|
|
194
196
|
clientEndPoint,
|
|
195
197
|
serverEndPoint,
|
|
196
198
|
);
|
|
197
|
-
|
|
199
|
+
if (endPointResponse?.ok === false) {
|
|
200
|
+
return endPointResponse;
|
|
201
|
+
}
|
|
198
202
|
let $props: Record<string, any> = { data };
|
|
199
203
|
|
|
200
204
|
// If there are layouts, work our way upwards, pushing each component into
|
|
@@ -285,21 +289,31 @@ async function loadClientAndServerData(
|
|
|
285
289
|
clientEndPoint?: PageEndPoint,
|
|
286
290
|
serverEndPoint?: PageServerEndPoint,
|
|
287
291
|
) {
|
|
288
|
-
let newData = {};
|
|
289
292
|
if (clientEndPoint?.load) {
|
|
290
293
|
const clientParams = buildClientParams(url, data, params);
|
|
291
|
-
const
|
|
292
|
-
if (
|
|
293
|
-
|
|
294
|
+
const clientResponse = await clientEndPoint.load(clientParams);
|
|
295
|
+
if (clientResponse) {
|
|
296
|
+
if (clientResponse.ok) {
|
|
297
|
+
if (clientResponse.headers.get("Content-Type")?.includes("application/json")) {
|
|
298
|
+
Object.assign(data, await clientResponse.json());
|
|
299
|
+
}
|
|
300
|
+
} else {
|
|
301
|
+
return clientResponse;
|
|
302
|
+
}
|
|
294
303
|
}
|
|
295
304
|
}
|
|
296
305
|
if (serverEndPoint?.load) {
|
|
297
|
-
const
|
|
298
|
-
if (
|
|
299
|
-
|
|
306
|
+
const serverResponse = await serverEndPoint.load(serverParams);
|
|
307
|
+
if (serverResponse) {
|
|
308
|
+
if (serverResponse.ok) {
|
|
309
|
+
if (serverResponse.headers.get("Content-Type")?.includes("application/json")) {
|
|
310
|
+
Object.assign(data, await serverResponse.json());
|
|
311
|
+
}
|
|
312
|
+
} else {
|
|
313
|
+
return serverResponse;
|
|
314
|
+
}
|
|
300
315
|
}
|
|
301
316
|
}
|
|
302
|
-
return newData;
|
|
303
317
|
}
|
|
304
318
|
|
|
305
319
|
function buildClientParams(url: URL, params: Record<string, string>, data: Record<string, any>) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/site/runBuild.ts","../src/site/manifest.ts","../src/site/runDev.ts","../src/site/prepareTemplate.ts","../src/site/runPreview.ts","../src/server/contentType.ts","../src/site/run.ts"],"sourcesContent":["import torpor from \"@torpor/unplugin/vite\";\nimport { existsSync, promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { build, defineConfig } from \"vite\";\nimport Site from \"./Site.ts\";\nimport manifest from \"./manifest.ts\";\n\n// TODO: Don't cache index.html in dev?\n// TODO: Multiple hook.server locations\n// TODO: Don't reload layouts during client routing\n// TODO: Call the correct +page and +server routes when in the same folder\n\nexport default async function runBuild(site: Site): Promise<void> {\n\t// Delete the dist folder if it exists\n\tconst distFolder = path.resolve(site.root, \"dist\");\n\tif (existsSync(distFolder)) {\n\t\tawait fs.rm(distFolder, { recursive: true });\n\t}\n\tlet clientFolder = path.join(distFolder, \"client\");\n\tlet serverFolder = path.join(distFolder, \"server\");\n\n\t// HOOK: Prebuild\n\tif (site.adapter.prebuild) {\n\t\tawait site.adapter.prebuild(site);\n\t}\n\n\t// TODO: From a setting\n\tlet siteHtml = path.resolve(site.root, \"src/site.html\");\n\n\t// TODO: Is this going to be the correct path after installing from npm?\n\tconst siteFolder = path.resolve(site.root, \"./node_modules/@torpor/build/src/site/\");\n\tlet clientScript = path.join(siteFolder, \"clientEntry.ts\");\n\tlet serverScript = path.join(siteFolder, \"serverEntry.ts\");\n\n\t// Build the client assets, including site.html and the route files\n\t// EXCLUDING anything with `server.js` in the name\n\tconst clientConfig = site.viteConfig ?? {};\n\tclientConfig.plugins = [manifest(site), torpor(), ...site.plugins];\n\tclientConfig.build ??= {};\n\tclientConfig.build.outDir ??= clientFolder;\n\tclientFolder = clientConfig.build.outDir;\n\tclientConfig.build.rollupOptions ??= {};\n\tclientConfig.build.rollupOptions.input = [\n\t\tsiteHtml,\n\t\tclientScript,\n\t\t...site.routes\n\t\t\t.filter((r) => !/server\\.(ts|js)$/.test(r.file))\n\t\t\t.map((r) => path.resolve(site.root, r.file)),\n\t\t...site.inputs.filter((f) => !/server\\.(ts|js)$/.test(f)),\n\t];\n\tclientConfig.build.ssrManifest = true;\n\tawait build(defineConfig(clientConfig));\n\n\t// Build the server assets, including the server entry script and the route\n\t// files\n\tconst serverConfig = site.viteConfig ?? {};\n\tserverConfig.plugins ??= [];\n\tserverConfig.plugins.push(manifest(site, true), torpor(), ...site.plugins);\n\tserverConfig.build ??= {};\n\tserverConfig.build.outDir ??= serverFolder;\n\tserverFolder = serverConfig.build.outDir;\n\tserverConfig.build.rollupOptions ??= {};\n\tserverConfig.build.rollupOptions.input = [\n\t\tserverScript,\n\t\t...site.routes.map((r) => path.resolve(site.root, r.file)),\n\t\t...site.inputs,\n\t];\n\tserverConfig.build.ssr = serverScript;\n\tawait build(defineConfig(serverConfig));\n\n\t// Move the site.html file into /client\n\t// HACK: Should do this in Rollup if possible?\n\tsiteHtml = path.join(clientFolder, \"site.html\");\n\tawait fs.rename(path.join(clientFolder, \"src\", \"site.html\"), siteHtml);\n\tawait fs.rm(path.join(clientFolder, \"src\"), { recursive: true });\n\n\t// HOOK: Postbuild\n\tif (site.adapter.postbuild) {\n\t\tawait site.adapter.postbuild(site);\n\t}\n}\n","import { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { Plugin } from \"vite\";\nimport Site from \"./Site\";\n\nconst moduleId = \"@torpor/build/manifest\";\n\n/**\n * A Vite plugin that provides information about the app to both clientEntry and\n * serverEntry.\n */\nexport default function manifest(site: Site, server = false): Plugin {\n\treturn {\n\t\tname: \"torpor-manifest\",\n\t\tresolveId: {\n\t\t\torder: \"pre\",\n\t\t\thandler(id) {\n\t\t\t\tif (id === moduleId) {\n\t\t\t\t\treturn id;\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t// @ts-ignore\n\t\tload(id, viteOptions) {\n\t\t\tif (id === moduleId) {\n\t\t\t\tlet serverRequest = server && !!viteOptions?.ssr;\n\t\t\t\treturn `\n${!serverRequest ? \"const load = { default: { load: true } };\" : \"\"}\nexport default {\n routes: [\n ${site.routes\n\t\t\t.map((r) => {\n\t\t\t\tif (serverRequest || !/server\\.(ts|js)$/.test(r.file)) {\n\t\t\t\t\treturn `{ path: \"${r.path}\", type: ${r.type}, endPoint: ${serverRequest || !/server\\.(ts|js)$/.test(r.file) ? `() => import(/* @vite-ignore */ \"${path.join(site.root, r.file)}\")` : \"undefined\"} }`;\n\t\t\t\t} else {\n\t\t\t\t\t// On the client, for a server route, we need to check\n\t\t\t\t\t// whether there's a load function and set a dummy endPoint\n\t\t\t\t\t// if so. The correct endpoint will be hit in clientEntry\n\t\t\t\t\t// HACK: Should do this better than checking for `load:` in source...\n\t\t\t\t\tconst haveLoad = readFileSync(path.join(site.root, r.file)).includes(\"load:\");\n\t\t\t\t\treturn `{ path: \"${r.path}\", type: ${r.type}, endPoint: ${haveLoad ? \"() => load\" : \"undefined\"} }`;\n\t\t\t\t}\n\t\t\t})\n\t\t\t.join(\",\\n \")}\n ],\n};\n`;\n\t\t\t}\n\t\t},\n\t};\n}\n","import torpor from \"@torpor/unplugin/vite\";\nimport { configDotenv } from \"dotenv\";\nimport { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { createServer as createViteServer } from \"vite\";\nimport { serverError } from \"../response.ts\";\nimport Server from \"../server/Server.ts\";\nimport connectMiddleware from \"../server/connect/connectMiddleware.ts\";\nimport Site from \"./Site.ts\";\nimport manifest from \"./manifest.ts\";\nimport prepareTemplate from \"./prepareTemplate.ts\";\n\nexport default async function runDev(site: Site): Promise<void> {\n\tconst server = new Server();\n\n\t// Create the Vite server in middleware mode and configure the app type as\n\t// \"custom\", disabling Vite's own HTML serving logic so the parent server\n\t// can take control\n\tconst vite = await createViteServer({\n\t\tserver: { middlewareMode: true },\n\t\tappType: \"custom\",\n\t\tplugins: [manifest(site, true), torpor(), ...site.plugins],\n\t});\n\n\t// Read site.html\n\t// It's called site.html because @torpor/build builds the site (html, routes\n\t// etc) while the user builds the app (components etc)\n\tconst templateFile = path.resolve(site.root, \"src/site.html\");\n\tlet template = await fs.readFile(templateFile, \"utf-8\");\n\n\t// Apply Vite HTML transforms. This injects the Vite HMR client, and also\n\t// applies HTML transforms from Vite plugins. Note that we only support a\n\t// universal transform, not individual transforms for each route\n\ttemplate = await vite.transformIndexHtml(\"\", template);\n\n\t// TODO: Is this going to be the correct path after installing from npm?\n\tconst siteFolder = path.resolve(site.root, \"./node_modules/@torpor/build/src/site/\");\n\tlet clientScript = path.join(siteFolder, \"clientEntry.ts\");\n\tlet serverScript = path.join(siteFolder, \"serverEntry.ts\");\n\n\t// Prepare site.html so that we can just splice components into it\n\ttemplate = prepareTemplate(template, clientScript);\n\n\t// Use Vite's Connect instance as middleware. We need to wrap it with\n\t// createMiddlewareHandler that converts Connect middleware to\n\t// Request/Response web handlers\n\tserver.use(connectMiddleware(vite.middlewares));\n\n\t// Every request (GET, POST, etc) goes through loadEndPoint\n\tserver.add(\"*\", async (ev) => {\n\t\ttry {\n\t\t\t// Load the server entry. ssrLoadModule automatically transforms ESM\n\t\t\t// source code to be usable in Node.js. No bundling is required, and\n\t\t\t// it provides efficient invalidation similar to HMR\n\t\t\tconst { load } = await vite.ssrLoadModule(serverScript);\n\n\t\t\t// Render the app HTML (or fetch server data etc) via serverEntry's\n\t\t\t// exported `load` function\n\t\t\treturn await load(ev, template);\n\t\t} catch (e: any) {\n\t\t\t// If an error is caught, let Vite fix the stack trace so it maps\n\t\t\t// back to your actual source code\n\t\t\tvite.ssrFixStacktrace(e);\n\t\t\treturn serverError(e);\n\t\t}\n\t});\n\n\t// Load environment variables from a `.env` file, with defaults if not set\n\tconfigDotenv();\n\n\tprocess.env.PROTOCOL ??= \"http:\";\n\tprocess.env.HOST ??= \"localhost\";\n\tprocess.env.PORT ??= \"7059\";\n\n\t// Serve the site\n\tsite.adapter.serve(server, site);\n}\n","export default function prepareTemplate(template: string, clientScript: string): string {\n\tlet contentStart = regexIndexOf(template, /\\<div\\s+id=(\"app\"|'app'|app)\\s+/);\n\tcontentStart = template.indexOf(\">\", contentStart) + 1;\n\tlet contentEnd = template.indexOf(\"</div>\", contentStart);\n\tif (contentStart === -1 || contentEnd === -1) {\n\t\tthrow new Error(`Couldn't find <div id=\"app\"></div>`);\n\t}\n\treturn (\n\t\ttemplate.substring(0, contentStart) +\n\t\t\"%COMPONENT_HTML%\" +\n\t\ttemplate.substring(contentEnd) +\n\t\t`<script type=\"module\" src=\"${clientScript}\"></script>`\n\t);\n}\n\n// From https://stackoverflow.com/a/274094\nfunction regexIndexOf(string: string, regex: RegExp, position?: number) {\n\tvar indexOf = string.substring(position || 0).search(regex);\n\treturn indexOf >= 0 ? indexOf + (position || 0) : indexOf;\n}\n","import { configDotenv } from \"dotenv\";\nimport { existsSync, promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport { serverError } from \"../response.ts\";\nimport Server from \"../server/Server.ts\";\nimport contentType from \"../server/contentType.ts\";\nimport Site from \"./Site\";\nimport prepareTemplate from \"./prepareTemplate.ts\";\nimport runBuild from \"./runBuild\";\n\nexport default async function runPreview(site: Site): Promise<void> {\n\t// Build the site\n\tawait runBuild(site);\n\n\tconst distFolder = path.resolve(site.root, \"dist\");\n\tconst clientFolder = path.join(distFolder, \"client\");\n\tconst serverFolder = path.join(distFolder, \"server\");\n\n\t// Find the client script file in /assets\n\tlet clientScript = (await fs.readdir(path.join(clientFolder, \"assets\"))).find((f) =>\n\t\tf.startsWith(\"clientEntry-\"),\n\t);\n\tif (!clientScript) {\n\t\tthrow new Error(\"clientEntry.js not found\");\n\t}\n\tclientScript = `/assets/${clientScript}`;\n\n\t// Read site.html\n\t// It's called site.html because @torpor/build builds the site (html, routes\n\t// etc) while the user builds the app (components etc)\n\tlet siteHtml = path.join(clientFolder, \"site.html\");\n\tlet template = await fs.readFile(siteHtml, \"utf-8\");\n\n\t// Prepare site.html so that we can just splice components into it\n\ttemplate = prepareTemplate(template, clientScript);\n\n\t// Configure the server\n\tconst server = new Server();\n\n\t// Serve dist/client/assets statically\n\tserver.add(\"/assets/*\", async (ev) => {\n\t\ttry {\n\t\t\tconst url = new URL(ev.request.url);\n\t\t\tconst file = path.join(site.root, \"dist\", \"client\", url.pathname);\n\t\t\tif (existsSync(file)) {\n\t\t\t\t// TODO: Stream the data?\n\t\t\t\treturn new Response(await fs.readFile(file), {\n\t\t\t\t\tstatus: 200,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"Content-Type\": contentType(path.extname(file)),\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (e: any) {\n\t\t\treturn serverError(e);\n\t\t}\n\t});\n\n\t// Every request (GET, POST, etc) goes through loadEndPoint\n\tconst serverScript = path.resolve(serverFolder, \"serverEntry.js\");\n\tserver.add(\"*\", async (ev) => {\n\t\ttry {\n\t\t\t// Load the server entry\n\t\t\tconst { load } = await import(serverScript);\n\n\t\t\t// Render the app HTML (or fetch server data etc) via serverEntry's\n\t\t\t// exported `load` function\n\t\t\treturn await load(ev, template);\n\t\t} catch (e: any) {\n\t\t\treturn serverError(e);\n\t\t}\n\t});\n\n\t// Load environment variables from a `.env` file, with defaults if not set\n\tconfigDotenv();\n\n\tprocess.env.PROTOCOL ??= \"http:\";\n\tprocess.env.HOST ??= \"localhost\";\n\tprocess.env.PORT ??= \"7059\";\n\n\t// Serve the site\n\tsite.adapter.serve(server, site);\n}\n","// From https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types\n\nexport default function contentType(extension: string): string {\n\treturn types[extension] || \"application/octet-stream\";\n}\n\nconst types: Record<string, string> = {\n\t\".aac\": \"audio/aac\",\n\t\".abw\": \"application/x-abiword\",\n\t\".apng\": \"image/apng\",\n\t\".arc\": \"application/x-freearc\",\n\t\".avif\": \"image/avif\",\n\t\".avi\": \"video/x-msvideo\",\n\t\".azw\": \"application/vnd.amazon.ebook\",\n\t\".bin\": \"application/octet-stream\",\n\t\".bmp\": \"image/bmp\",\n\t\".bz\": \"application/x-bzip\",\n\t\".bz2\": \"application/x-bzip2\",\n\t\".cda\": \"application/x-cdf\",\n\t\".csh\": \"application/x-csh\",\n\t\".css\": \"text/css\",\n\t\".csv\": \"text/csv\",\n\t\".doc\": \"application/msword\",\n\t\".docx\": \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n\t\".eot\": \"application/vnd.ms-fontobject\",\n\t\".epub\": \"application/epub+zip\",\n\t\".gz\": \"application/gzip\",\n\t\".gif\": \"image/gif\",\n\t\".htm\": \"text/html\",\n\t\".html\": \"text/html\",\n\t\".ico\": \"image/vnd.microsoft.icon\",\n\t\".ics\": \"text/calendar\",\n\t\".jar\": \"application/java-archive\",\n\t\".jpeg\": \"image/jpeg\",\n\t\".jpg\": \"image/jpeg\",\n\t\".js\": \"text/javascript\",\n\t\".json\": \"application/json\",\n\t\".jsonld\": \"application/ld+json\",\n\t\".mid\": \"audio/midi\",\n\t\".midi\": \"audio/midi\",\n\t\".mjs\": \"text/javascript\",\n\t\".mp3\": \"audio/mpeg\",\n\t\".mp4\": \"video/mp4\",\n\t\".mpeg\": \"video/mpeg\",\n\t\".mpkg\": \"application/vnd.apple.installer+xml\",\n\t\".odp\": \"application/vnd.oasis.opendocument.presentation\",\n\t\".ods\": \"application/vnd.oasis.opendocument.spreadsheet\",\n\t\".odt\": \"application/vnd.oasis.opendocument.text\",\n\t\".oga\": \"audio/ogg\",\n\t\".ogv\": \"video/ogg\",\n\t\".ogx\": \"application/ogg\",\n\t\".opus\": \"audio/ogg\",\n\t\".otf\": \"font/otf\",\n\t\".png\": \"image/png\",\n\t\".pdf\": \"application/pdf\",\n\t\".php\": \"application/x-httpd-php\",\n\t\".ppt\": \"application/vnd.ms-powerpoint\",\n\t\".pptx\": \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n\t\".rar\": \"application/vnd.rar\",\n\t\".rtf\": \"application/rtf\",\n\t\".sh\": \"application/x-sh\",\n\t\".svg\": \"image/svg+xml\",\n\t\".tar\": \"application/x-tar\",\n\t\".tif\": \"image/tiff\",\n\t\".tiff\": \"image/tiff\",\n\t\".ts\": \"video/mp2t\",\n\t\".ttf\": \"font/ttf\",\n\t\".txt\": \"text/plain\",\n\t\".vsd\": \"application/vnd.visio\",\n\t\".wav\": \"audio/wav\",\n\t\".weba\": \"audio/webm\",\n\t\".webm\": \"video/webm\",\n\t\".webp\": \"image/webp\",\n\t\".woff\": \"font/woff\",\n\t\".woff2\": \"font/woff2\",\n\t\".xhtml\": \"application/xhtml+xml\",\n\t\".xls\": \"application/vnd.ms-excel\",\n\t\".xlsx\": \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n\t\".xml\": \"application/xml\",\n\t\".xul\": \"application/vnd.mozilla.xul+xml\",\n\t\".zip\": \"application/zip\",\n\t\".3gp\": \"video/3gpp\",\n\t\".3g2\": \"video/3gpp2\",\n\t\".7z\": \"application/x-7z-compressed\",\n};\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { transformWithEsbuild } from \"vite\";\nimport Site from \"./Site\";\nimport runBuild from \"./runBuild\";\nimport runDev from \"./runDev\";\nimport runPreview from \"./runPreview\";\n\nexport default async function run(\n\tfolder: string,\n\tmode: \"dev\" | \"build\" | \"preview\",\n): Promise<void> {\n\t// Look for and load a site.config.js/ts file in the working directory\n\tlet configFile = \"\";\n\tlet deleteConfigFile = false;\n\tconst jsConfigFile = path.join(folder, \"site.config.js\");\n\tconst tsConfigFile = path.join(folder, \"site.config.ts\");\n\tif (fs.existsSync(jsConfigFile)) {\n\t\t// If it's JS, we can just import it straight up\n\t\tconfigFile = jsConfigFile;\n\t} else if (fs.existsSync(tsConfigFile)) {\n\t\t// If it's TS, we need to convert it to JS\n\t\t// TODO: Put the generated file somewhere better (dist?)\n\t\tconfigFile = path.join(folder, \"site.config.temp.js\");\n\t\tlet source = fs.readFileSync(tsConfigFile, \"utf-8\");\n\t\tlet transformed = await transformWithEsbuild(source, tsConfigFile, {\n\t\t\tloader: \"ts\",\n\t\t});\n\t\tfs.writeFileSync(configFile, transformed.code);\n\t\tdeleteConfigFile = true;\n\t} else {\n\t\tthrow new Error(\"site.config file not found\");\n\t}\n\n\tconst site = (await import(configFile)).default as Site;\n\tif (!site || !site.root || !site.routes) {\n\t\tthrow new Error(\"Invalid site in config file\");\n\t}\n\tif (deleteConfigFile) {\n\t\tfs.rmSync(configFile);\n\t}\n\n\tswitch (mode) {\n\t\tcase \"dev\": {\n\t\t\tawait runDev(site);\n\t\t\tbreak;\n\t\t}\n\t\tcase \"build\": {\n\t\t\tawait runBuild(site);\n\t\t\tbreak;\n\t\t}\n\t\tcase \"preview\": {\n\t\t\tawait runPreview(site);\n\t\t\tbreak;\n\t\t}\n\t\tdefault: {\n\t\t\tconsole.log(\"No mode passed, running in dev\");\n\t\t\tawait runDev(site);\n\t\t\tbreak;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;AAAA,OAAO,YAAY;AACnB,SAAS,YAAY,YAAY,UAAU;AAC3C,OAAOA,WAAU;AACjB,SAAS,OAAO,oBAAoB;;;ACHpC,SAAS,oBAAoB;AAC7B,OAAO,UAAU;AAIjB,IAAM,WAAW;AAMF,SAAR,SAA0B,MAAY,SAAS,OAAe;AACpE,SAAO;AAAA,IACN,MAAM;AAAA,IACN,WAAW;AAAA,MACV,OAAO;AAAA,MACP,QAAQ,IAAI;AACX,YAAI,OAAO,UAAU;AACpB,iBAAO;AAAA,QACR;AAAA,MACD;AAAA,IACD;AAAA;AAAA,IAEA,KAAK,IAAI,aAAa;AACrB,UAAI,OAAO,UAAU;AACpB,YAAI,gBAAgB,UAAU,CAAC,CAAC,aAAa;AA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AW,YAAY,GAAG;AAGvC,iBAAaD,MAAK,KAAK,QAAQ,qBAAqB;AACpD,QAAI,SAASC,IAAG,aAAa,cAAc,OAAO;AAClD,QAAI,cAAc,MAAM,qBAAqB,QAAQ,cAAc;AAAA,MAClE,QAAQ;AAAA,IACT,CAAC;AACD,IAAAA,IAAG,cAAc,YAAY,YAAY,IAAI;AAC7C,uBAAmB;AAAA,EACpB,OAAO;AACN,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC7C;AAEA,QAAM,QAAQ,MAAM,OAAO,aAAa;AACxC,MAAI,CAAC,QAAQ,CAAC,KAAK,QAAQ,CAAC,KAAK,QAAQ;AACxC,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC9C;AACA,MAAI,kBAAkB;AACrB,IAAAA,IAAG,OAAO,UAAU;AAAA,EACrB;AAEA,UAAQ,MAAM;AAAA,IACb,KAAK,OAAO;AACX,YAAM,OAAO,IAAI;AACjB;AAAA,IACD;AAAA,IACA,KAAK,SAAS;AACb,YAAM,SAAS,IAAI;AACnB;AAAA,IACD;AAAA,IACA,KAAK,WAAW;AACf,YAAM,WAAW,IAAI;AACrB;AAAA,IACD;AAAA,IACA,SAAS;AACR,cAAQ,IAAI,gCAAgC;AAC5C,YAAM,OAAO,IAAI;AACjB;AAAA,IACD;AAAA,EACD;AACD;","names":["path","path","torpor","fs","path","torpor","path","fs","configDotenv","existsSync","fs","path","path","fs","existsSync","configDotenv","fs","path","path","fs"]}
|