@devlusoft/devix 0.2.0 → 0.2.1

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.
Files changed (85) hide show
  1. package/dist/cli/build.js +30 -308
  2. package/dist/cli/build.js.map +3 -3
  3. package/dist/cli/dev.js +32 -395
  4. package/dist/cli/dev.js.map +3 -3
  5. package/dist/cli/generate.js +30 -434
  6. package/dist/cli/generate.js.map +3 -3
  7. package/dist/cli/index.js +33 -698
  8. package/dist/cli/index.js.map +3 -3
  9. package/dist/cli/start.js +1 -89
  10. package/dist/cli/start.js.map +2 -2
  11. package/dist/config.js +1 -16
  12. package/dist/config.js.map +2 -2
  13. package/dist/runtime/api-context.js +1 -17
  14. package/dist/runtime/api-context.js.map +2 -2
  15. package/dist/runtime/client-router.js +1 -58
  16. package/dist/runtime/client-router.js.map +2 -2
  17. package/dist/runtime/context.js +1 -14
  18. package/dist/runtime/context.js.map +2 -2
  19. package/dist/runtime/error-boundary.js +1 -36
  20. package/dist/runtime/error-boundary.js.map +2 -2
  21. package/dist/runtime/fetch.js +1 -34
  22. package/dist/runtime/fetch.js.map +2 -2
  23. package/dist/runtime/head.js +1 -68
  24. package/dist/runtime/head.js.map +2 -2
  25. package/dist/runtime/index.d.ts +1 -0
  26. package/dist/runtime/index.js +1 -367
  27. package/dist/runtime/index.js.map +3 -3
  28. package/dist/runtime/link.js +1 -42
  29. package/dist/runtime/link.js.map +2 -2
  30. package/dist/runtime/metadata.js +1 -21
  31. package/dist/runtime/metadata.js.map +2 -2
  32. package/dist/runtime/router-provider.js +1 -258
  33. package/dist/runtime/router-provider.js.map +2 -2
  34. package/dist/server/api-router.js +1 -64
  35. package/dist/server/api-router.js.map +2 -2
  36. package/dist/server/api.js +1 -123
  37. package/dist/server/api.js.map +2 -2
  38. package/dist/server/collect-css.js +1 -14
  39. package/dist/server/collect-css.js.map +2 -2
  40. package/dist/server/index.js +1 -132
  41. package/dist/server/index.js.map +2 -2
  42. package/dist/server/pages-router.js +1 -63
  43. package/dist/server/pages-router.js.map +2 -2
  44. package/dist/server/render.js +1 -305
  45. package/dist/server/render.js.map +2 -2
  46. package/dist/server/routes.js +1 -41
  47. package/dist/server/routes.js.map +2 -2
  48. package/dist/utils/async.js +1 -13
  49. package/dist/utils/async.js.map +2 -2
  50. package/dist/utils/banner.js +1 -33
  51. package/dist/utils/banner.js.map +2 -2
  52. package/dist/utils/cookies.js +1 -28
  53. package/dist/utils/cookies.js.map +2 -2
  54. package/dist/utils/duration.js +1 -21
  55. package/dist/utils/duration.js.map +2 -2
  56. package/dist/utils/env.js +1 -13
  57. package/dist/utils/env.js.map +2 -2
  58. package/dist/utils/html.js +1 -11
  59. package/dist/utils/html.js.map +2 -2
  60. package/dist/utils/patterns.js +1 -7
  61. package/dist/utils/patterns.js.map +2 -2
  62. package/dist/utils/response.d.ts +4 -1
  63. package/dist/utils/response.js +1 -9
  64. package/dist/utils/response.js.map +3 -3
  65. package/dist/vite/codegen/api.js +6 -12
  66. package/dist/vite/codegen/api.js.map +2 -2
  67. package/dist/vite/codegen/client-routes.js +6 -12
  68. package/dist/vite/codegen/client-routes.js.map +2 -2
  69. package/dist/vite/codegen/context.js +2 -8
  70. package/dist/vite/codegen/context.js.map +2 -2
  71. package/dist/vite/codegen/entry-client.js +4 -10
  72. package/dist/vite/codegen/entry-client.js.map +2 -2
  73. package/dist/vite/codegen/extract-methods.js +1 -15
  74. package/dist/vite/codegen/extract-methods.js.map +2 -2
  75. package/dist/vite/codegen/render.js +6 -12
  76. package/dist/vite/codegen/render.js.map +2 -2
  77. package/dist/vite/codegen/routes-dts.js +11 -49
  78. package/dist/vite/codegen/routes-dts.js.map +3 -3
  79. package/dist/vite/codegen/scan-api.js +1 -77
  80. package/dist/vite/codegen/scan-api.js.map +3 -3
  81. package/dist/vite/codegen/write-routes-dts.js +1 -16
  82. package/dist/vite/codegen/write-routes-dts.js.map +2 -2
  83. package/dist/vite/index.js +30 -247
  84. package/dist/vite/index.js.map +3 -3
  85. package/package.json +2 -2
@@ -1,13 +1,6 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __esm = (fn, res) => function __init() {
3
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
4
- };
5
-
6
- // src/vite/codegen/entry-client.ts
7
- function generateEntryClient({ cssUrls }) {
8
- const cssImports = cssUrls.map((u) => `import '${u}'`).join("\n");
9
- return `
10
- ${cssImports}
1
+ var s=(t,e)=>()=>(t&&(e=t(t=0)),e);function M({cssUrls:t}){return`
2
+ ${t.map(r=>`import '${r}'`).join(`
3
+ `)}
11
4
  import "@vitejs/plugin-react/preamble"
12
5
  import React from "react"
13
6
  import {hydrateRoot, createRoot} from 'react-dom/client'
@@ -61,22 +54,12 @@ if (!window.__DEVIX__) {
61
54
  )
62
55
  }
63
56
  }
64
- `;
65
- }
66
- var init_entry_client = __esm({
67
- "src/vite/codegen/entry-client.ts"() {
68
- "use strict";
69
- }
70
- });
71
-
72
- // src/vite/codegen/client-routes.ts
73
- function generateClientRoutes({ pagesDir, matcherPath }) {
74
- return `
57
+ `}var O=s(()=>{"use strict"});function L({pagesDir:t,matcherPath:e}){return`
75
58
  import React from 'react'
76
- import { createMatcher } from '${matcherPath}'
77
- const pageFiles = import.meta.glob(['/${pagesDir}/**/*.tsx', '!**/error.tsx', '!**/layout.tsx'])
78
- const layoutFiles = import.meta.glob('/${pagesDir}/**/layout.tsx')
79
- const errorFiles = import.meta.glob('/${pagesDir}/**/error.tsx')
59
+ import { createMatcher } from '${e}'
60
+ const pageFiles = import.meta.glob(['/${t}/**/*.tsx', '!**/error.tsx', '!**/layout.tsx'])
61
+ const layoutFiles = import.meta.glob('/${t}/**/layout.tsx')
62
+ const errorFiles = import.meta.glob('/${t}/**/error.tsx')
80
63
 
81
64
  export const matchClientRoute = createMatcher(pageFiles, layoutFiles)
82
65
 
@@ -99,26 +82,16 @@ export function getDefaultErrorPage() {
99
82
  )
100
83
  }
101
84
  }
102
- `;
103
- }
104
- var init_client_routes = __esm({
105
- "src/vite/codegen/client-routes.ts"() {
106
- "use strict";
107
- }
108
- });
85
+ `}var I=s(()=>{"use strict"});function k({pagesDir:t,renderPath:e}){return`
86
+ import { render as _render, runLoader as _runLoader, getStaticRoutes as _getStaticRoutes } from '${e}'
109
87
 
110
- // src/vite/codegen/render.ts
111
- function generateRender({ pagesDir, renderPath }) {
112
- return `
113
- import { render as _render, runLoader as _runLoader, getStaticRoutes as _getStaticRoutes } from '${renderPath}'
114
-
115
- const _pages = import.meta.glob(['/${pagesDir}/**/*.tsx', '!**/error.tsx', '!**/layout.tsx'])
116
- const _layouts = import.meta.glob('/${pagesDir}/**/layout.tsx')
88
+ const _pages = import.meta.glob(['/${t}/**/*.tsx', '!**/error.tsx', '!**/layout.tsx'])
89
+ const _layouts = import.meta.glob('/${t}/**/layout.tsx')
117
90
 
118
91
  const _glob = {
119
92
  pages: _pages,
120
93
  layouts: _layouts,
121
- pagesDir: '/${pagesDir}',
94
+ pagesDir: '/${t}',
122
95
  }
123
96
 
124
97
  export function render(url, request, options) {
@@ -132,420 +105,43 @@ export function runLoader(url, request, options) {
132
105
  export function getStaticRoutes() {
133
106
  return _getStaticRoutes(_glob)
134
107
  }
135
- `;
136
- }
137
- var init_render = __esm({
138
- "src/vite/codegen/render.ts"() {
139
- "use strict";
140
- }
141
- });
142
-
143
- // src/vite/codegen/api.ts
144
- function generateApi({ apiPath, appDir }) {
145
- return `
146
- import { handleApiRequest as _handleApiRequest } from '${apiPath}'
108
+ `}var U=s(()=>{"use strict"});function F({apiPath:t,appDir:e}){return`
109
+ import { handleApiRequest as _handleApiRequest } from '${t}'
147
110
 
148
- const _routes = import.meta.glob(['/${appDir}/api/**/*.ts', '!**/middleware.ts'])
149
- const _middlewares = import.meta.glob('/${appDir}/api/**/middleware.ts')
111
+ const _routes = import.meta.glob(['/${e}/api/**/*.ts', '!**/middleware.ts'])
112
+ const _middlewares = import.meta.glob('/${e}/api/**/middleware.ts')
150
113
 
151
114
  const _glob = {
152
115
  routes: _routes,
153
116
  middlewares: _middlewares,
154
- apiDir: '/${appDir}/api',
117
+ apiDir: '/${e}/api',
155
118
  }
156
119
 
157
120
  export function handleApiRequest(url, request) {
158
121
  return _handleApiRequest(url, request, _glob)
159
122
  }
160
- `;
161
- }
162
- var init_api = __esm({
163
- "src/vite/codegen/api.ts"() {
164
- "use strict";
165
- }
166
- });
167
-
168
- // src/utils/patterns.ts
169
- function routePattern(rel) {
170
- return rel.replace(/\.(tsx|ts|jsx|js)$/, "").replace(/\(.*?\)\//g, "").replace(/^index$|\/index$/, "").replace(/\[([^\]]+)]/g, ":$1") || "/";
171
- }
172
- var init_patterns = __esm({
173
- "src/utils/patterns.ts"() {
174
- "use strict";
175
- }
176
- });
177
-
178
- // src/server/pages-router.ts
179
- function invalidatePagesCache() {
180
- cache = null;
181
- }
182
- var cache;
183
- var init_pages_router = __esm({
184
- "src/server/pages-router.ts"() {
185
- "use strict";
186
- init_patterns();
187
- cache = null;
188
- }
189
- });
190
-
191
- // src/server/api-router.ts
192
- function keyToRoutePattern(key, apiDir) {
193
- const rel = key.slice(apiDir.length + 1).replace(/\\/g, "/");
194
- const pattern = routePattern(rel);
195
- return pattern === "/" ? "/api" : `/api/${pattern}`.replace("/api//", "/api/");
196
- }
197
- function invalidateApiCache() {
198
- cache2 = null;
199
- }
200
- var cache2;
201
- var init_api_router = __esm({
202
- "src/server/api-router.ts"() {
203
- "use strict";
204
- init_patterns();
205
- cache2 = null;
206
- }
207
- });
208
-
209
- // src/vite/codegen/context.ts
210
- function generateContext() {
211
- return `
123
+ `}var H=s(()=>{"use strict"});function m(t){return t.replace(/\.(tsx|ts|jsx|js)$/,"").replace(/\(.*?\)\//g,"").replace(/^index$|\/index$/,"").replace(/\[([^\]]+)]/g,":$1")||"/"}var f=s(()=>{"use strict"});function h(){ct=null}var ct,j=s(()=>{"use strict";f();ct=null});function q(t,e){let r=t.slice(e.length+1).replace(/\\/g,"/"),i=m(r);return i==="/"?"/api":`/api/${i}`.replace("/api//","/api/")}function x(){lt=null}var lt,y=s(()=>{"use strict";f();lt=null});function N(){return`
212
124
  export {RouterContext} from '@devlusoft/devix/runtime/context'
213
- `;
214
- }
215
- var init_context = __esm({
216
- "src/vite/codegen/context.ts"() {
217
- "use strict";
218
- }
219
- });
220
-
221
- // src/vite/codegen/extract-methods.ts
222
- function stripComments(content) {
223
- return content.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
224
- }
225
- function extractHttpMethods(content) {
226
- const found = /* @__PURE__ */ new Set();
227
- for (const match of stripComments(content).matchAll(METHOD_EXPORT_RE)) {
228
- found.add(match[1]);
229
- }
230
- return [...found];
231
- }
232
- var METHOD_EXPORT_RE;
233
- var init_extract_methods = __esm({
234
- "src/vite/codegen/extract-methods.ts"() {
235
- "use strict";
236
- METHOD_EXPORT_RE = /export\s+(?:const|async\s+function|function)\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g;
237
- }
238
- });
239
-
240
- // src/vite/codegen/routes-dts.ts
241
- function filePathToIdentifier(filePath, apiDir) {
242
- return "_api_" + filePath.slice(`${apiDir}/`.length).replace(/\.(ts|tsx)$/, "").replace(/[^a-zA-Z0-9]/g, "_");
243
- }
244
- function buildRouteEntry(filePath, apiDir, methods) {
245
- return {
246
- filePath,
247
- urlPattern: keyToRoutePattern(filePath, apiDir),
248
- identifier: filePathToIdentifier(filePath, apiDir),
249
- methods
250
- };
251
- }
252
- function generateRoutesDts(entries, apiDir) {
253
- if (entries.length === 0) {
254
- return `// auto-generado por devix \u2014 no editar
125
+ `}var W=s(()=>{"use strict"});function pt(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"")}function V(t){let e=new Set;for(let r of pt(t).matchAll(ut))e.add(r[1]);return[...e]}var ut,G=s(()=>{"use strict";ut=/export\s+(?:const|async\s+function|function)\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g});function dt(t,e){return"_api_"+t.slice(`${e}/`.length).replace(/\.(ts|tsx)$/,"").replace(/[^a-zA-Z0-9]/g,"_")}function J(t,e,r){return{filePath:t,urlPattern:q(t,e),identifier:dt(t,e),methods:r}}function R(t,e){if(t.length===0)return`// auto-generado por devix \u2014 no editar
255
126
  declare module '@devlusoft/devix' {
256
127
  interface ApiRoutes {}
257
128
  }
258
- `;
259
- }
260
- const imports = entries.map((e) => {
261
- const importPath = "../" + e.filePath.replace(/\.(ts|tsx)$/, "");
262
- return `import type * as ${e.identifier} from '${importPath}'`;
263
- }).join("\n");
264
- const routeLines = entries.flatMap(
265
- (e) => e.methods.map(
266
- (m) => ` '${m} ${e.urlPattern}': InferRoute<(typeof ${e.identifier})['${m}']>`
267
- )
268
- ).join("\n");
269
- return `// auto-generado por devix \u2014 no editar
270
- ${imports}
129
+ `;let r=t.map(o=>{let c="../"+o.filePath.replace(/\.(ts|tsx)$/,"");return`import type * as ${o.identifier} from '${c}'`}).join(`
130
+ `),i=t.flatMap(o=>o.methods.map(c=>` '${c} ${o.urlPattern}': InferRoute<(typeof ${o.identifier})['${c}']>`)).join(`
131
+ `);return`// auto-generado por devix \u2014 no editar
132
+ ${r}
271
133
 
134
+ type JsonResponse<T> = Response & { readonly __body: T }
272
135
  type InferRoute<T> = T extends (...args: any[]) => any
273
- ? Exclude<Awaited<ReturnType<T>>, Response | null | void>
136
+ ? Awaited<ReturnType<T>> extends JsonResponse<infer U>
137
+ ? U
138
+ : Exclude<Awaited<ReturnType<T>>, Response | null | void>
274
139
  : never
275
140
 
276
141
  declare module '@devlusoft/devix' {
277
142
  interface ApiRoutes {
278
- ${routeLines}
279
- }
280
- }
281
- `;
282
- }
283
- var init_routes_dts = __esm({
284
- "src/vite/codegen/routes-dts.ts"() {
285
- "use strict";
286
- init_api_router();
287
- }
288
- });
289
-
290
- // src/vite/codegen/scan-api.ts
291
- import { readFileSync, readdirSync, statSync } from "node:fs";
292
- import { join, relative } from "node:path";
293
- function walkDir(dir, root) {
294
- const entries = [];
295
- for (const name of readdirSync(dir)) {
296
- const full = join(dir, name);
297
- if (statSync(full).isDirectory()) {
298
- entries.push(...walkDir(full, root));
299
- } else if (/\.(ts|tsx)$/.test(name)) {
300
- entries.push(relative(root, full).replace(/\\/g, "/"));
301
- }
302
- }
303
- return entries;
304
- }
305
- function scanApiFiles(appDir, projectRoot) {
306
- const apiDir = join(projectRoot, appDir, "api");
307
- let files;
308
- try {
309
- files = walkDir(apiDir, projectRoot);
310
- } catch {
311
- return [];
312
- }
313
- return files.filter((f) => !f.endsWith("middleware.ts") && !f.endsWith("middleware.tsx")).flatMap((filePath) => {
314
- try {
315
- const content = readFileSync(join(projectRoot, filePath), "utf-8");
316
- const methods = extractHttpMethods(content);
317
- if (methods.length === 0) return [];
318
- return [buildRouteEntry(filePath, `${appDir}/api`, methods)];
319
- } catch {
320
- return [];
321
- }
322
- });
323
- }
324
- var init_scan_api = __esm({
325
- "src/vite/codegen/scan-api.ts"() {
326
- "use strict";
327
- init_extract_methods();
328
- init_routes_dts();
329
- }
330
- });
331
-
332
- // src/vite/codegen/write-routes-dts.ts
333
- import { mkdirSync, readFileSync as readFileSync2, writeFileSync, existsSync } from "node:fs";
334
- import { join as join2 } from "node:path";
335
- function writeRoutesDts(content, projectRoot) {
336
- const devixDir = join2(projectRoot, ".devix");
337
- const outPath = join2(devixDir, "routes.d.ts");
338
- mkdirSync(devixDir, { recursive: true });
339
- if (existsSync(outPath) && readFileSync2(outPath, "utf-8") === content) {
340
- return false;
341
- }
342
- writeFileSync(outPath, content, "utf-8");
343
- return true;
344
- }
345
- var init_write_routes_dts = __esm({
346
- "src/vite/codegen/write-routes-dts.ts"() {
347
- "use strict";
348
- }
349
- });
350
-
351
- // src/vite/index.ts
352
- import { mergeConfig } from "vite";
353
- import react from "@vitejs/plugin-react";
354
- import { fileURLToPath } from "node:url";
355
- import { dirname, resolve } from "node:path";
356
- function devix(config2) {
357
- const appDir = config2.appDir ?? "app";
358
- const pagesDir = `${appDir}/pages`;
359
- const cssUrls = (config2.css ?? []).map((u) => u.startsWith("/") ? u : `/${u.replace(/^\.\//, "")}`);
360
- const renderPath = resolve(__dirname, "../server/render.js").replace(/\\/g, "/");
361
- const apiPath = resolve(__dirname, "../server/api.js").replace(/\\/g, "/");
362
- const matcherPath = resolve(__dirname, "../runtime/client-router.js").replace(/\\/g, "/");
363
- const virtualPlugin = {
364
- name: "devix",
365
- enforce: "pre",
366
- resolveId(id) {
367
- if (id === VIRTUAL_ENTRY_CLIENT) return `\0${VIRTUAL_ENTRY_CLIENT}`;
368
- if (id === VIRTUAL_CLIENT_ROUTES) return `\0${VIRTUAL_CLIENT_ROUTES}`;
369
- if (id === VIRTUAL_RENDER) return `\0${VIRTUAL_RENDER}`;
370
- if (id === VIRTUAL_API) return `\0${VIRTUAL_API}`;
371
- if (id === VIRTUAL_CONTEXT) return `\0${VIRTUAL_CONTEXT}`;
372
- },
373
- load(id) {
374
- if (id === `\0${VIRTUAL_ENTRY_CLIENT}`)
375
- return generateEntryClient({ cssUrls });
376
- if (id === `\0${VIRTUAL_CLIENT_ROUTES}`)
377
- return generateClientRoutes({ pagesDir, matcherPath });
378
- if (id === `\0${VIRTUAL_RENDER}`)
379
- return generateRender({ pagesDir, renderPath });
380
- if (id === `\0${VIRTUAL_API}`)
381
- return generateApi({ apiPath, appDir });
382
- if (id === `\0${VIRTUAL_CONTEXT}`)
383
- return generateContext();
384
- },
385
- buildStart() {
386
- const root = process.cwd();
387
- const entries = scanApiFiles(appDir, root);
388
- writeRoutesDts(generateRoutesDts(entries, `${appDir}/api`), root);
389
- },
390
- configureServer(server) {
391
- const root = process.cwd();
392
- const regenerateDts = () => {
393
- const entries = scanApiFiles(appDir, root);
394
- writeRoutesDts(generateRoutesDts(entries, `${appDir}/api`), root);
395
- };
396
- server.watcher.on("add", (file) => {
397
- if (file.startsWith(resolve(root, pagesDir))) invalidatePagesCache();
398
- if (file.includes(`${appDir}/api`)) {
399
- invalidateApiCache();
400
- regenerateDts();
401
- }
402
- });
403
- server.watcher.on("unlink", (file) => {
404
- if (file.startsWith(resolve(root, pagesDir))) invalidatePagesCache();
405
- if (file.includes(`${appDir}/api`)) {
406
- invalidateApiCache();
407
- regenerateDts();
408
- }
409
- });
410
- server.watcher.on("change", (file) => {
411
- if (file.includes(`${appDir}/api`) && !file.endsWith("middleware.ts")) {
412
- regenerateDts();
413
- }
414
- });
415
- }
416
- };
417
- const base = {
418
- plugins: [react(), virtualPlugin],
419
- ssr: { noExternal: ["@devlusoft/devix"] },
420
- ...config2.envPrefix ? { envPrefix: config2.envPrefix } : {}
421
- };
422
- return mergeConfig(base, config2.vite ?? {});
423
- }
424
- var __dirname, VIRTUAL_ENTRY_CLIENT, VIRTUAL_CLIENT_ROUTES, VIRTUAL_RENDER, VIRTUAL_API, VIRTUAL_CONTEXT;
425
- var init_vite = __esm({
426
- "src/vite/index.ts"() {
427
- "use strict";
428
- init_entry_client();
429
- init_client_routes();
430
- init_render();
431
- init_api();
432
- init_pages_router();
433
- init_api_router();
434
- init_context();
435
- init_scan_api();
436
- init_routes_dts();
437
- init_write_routes_dts();
438
- __dirname = dirname(fileURLToPath(import.meta.url));
439
- VIRTUAL_ENTRY_CLIENT = "virtual:devix/entry-client";
440
- VIRTUAL_CLIENT_ROUTES = "virtual:devix/client-routes";
441
- VIRTUAL_RENDER = "virtual:devix/render";
442
- VIRTUAL_API = "virtual:devix/api";
443
- VIRTUAL_CONTEXT = "virtual:devix/context";
444
- }
445
- });
446
-
447
- // src/utils/duration.ts
448
- function parseDuration(value) {
449
- if (typeof value === "number") return value;
450
- const match = value.trim().match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h)?$/);
451
- if (!match) throw new Error(`[devix] Invalid duration: "${value}". Use a number (ms) or a string like "5s", "2m", "500ms".`);
452
- const n = parseFloat(match[1]);
453
- switch (match[2]) {
454
- case "h":
455
- return n * 36e5;
456
- case "m":
457
- return n * 6e4;
458
- case "s":
459
- return n * 1e3;
460
- case "ms":
461
- default:
462
- return n;
463
- }
464
- }
465
- var init_duration = __esm({
466
- "src/utils/duration.ts"() {
467
- "use strict";
468
- }
469
- });
470
-
471
- // src/cli/build.ts
472
- var build_exports = {};
473
- import { writeFileSync as writeFileSync2 } from "node:fs";
474
- import { resolve as resolve2 } from "node:path";
475
- import { build } from "vite";
476
- var config, baseConfig, runtimeConfig;
477
- var init_build = __esm({
478
- async "src/cli/build.ts"() {
479
- "use strict";
480
- init_vite();
481
- init_duration();
482
- config = (await import(`${process.cwd()}/devix.config.ts`)).default;
483
- baseConfig = devix(config);
484
- await build({
485
- ...baseConfig,
486
- configFile: false,
487
- build: {
488
- outDir: "dist/client",
489
- manifest: true,
490
- rolldownOptions: {
491
- input: "virtual:devix/entry-client"
492
- }
493
- }
494
- });
495
- await build({
496
- ...baseConfig,
497
- configFile: false,
498
- build: {
499
- ssr: true,
500
- outDir: "dist/server",
501
- rolldownOptions: {
502
- input: {
503
- render: "virtual:devix/render",
504
- api: "virtual:devix/api"
505
- }
506
- }
507
- }
508
- });
509
- runtimeConfig = {
510
- port: config.port ?? 3e3,
511
- host: config.host ?? false,
512
- loaderTimeout: parseDuration(config.loaderTimeout ?? 1e4),
513
- output: config.output ?? "server"
514
- };
515
- writeFileSync2(
516
- resolve2(process.cwd(), "dist/devix.config.json"),
517
- JSON.stringify(runtimeConfig, null, 2),
518
- "utf-8"
519
- );
520
- }
521
- });
522
-
523
- // src/cli/generate.ts
524
- import { readFileSync as readFileSync3, mkdirSync as mkdirSync2, writeFileSync as writeFileSync3 } from "node:fs";
525
- import { resolve as resolve3, join as join3 } from "node:path";
526
- var userConfig = (await import(`${process.cwd()}/devix.config.ts`)).default;
527
- if (userConfig.output !== "static") {
528
- console.warn('[devix] Tip: set output: "static" in devix.config.ts to skip the SSR server at runtime.');
529
- }
530
- await init_build().then(() => build_exports);
531
- var t = Date.now();
532
- var renderModule = await import(resolve3(process.cwd(), "dist/server/render.js") + `?t=${t}`);
533
- var manifest = JSON.parse(
534
- readFileSync3(resolve3(process.cwd(), "dist/client/.vite/manifest.json"), "utf-8")
535
- );
536
- var urls = await renderModule.getStaticRoutes();
537
- console.log(`[devix] Generating ${urls.length} static page${urls.length === 1 ? "" : "s"}...`);
538
- for (const url of urls) {
539
- const fullUrl = `http://localhost${url}`;
540
- const { html, statusCode } = await renderModule.render(fullUrl, new Request(fullUrl), { manifest });
541
- if (statusCode !== 200) {
542
- console.warn(`[devix] Skipping ${url} \u2014 status ${statusCode}`);
543
- continue;
143
+ ${i}
544
144
  }
545
- const outPath = url === "/" ? join3(process.cwd(), "dist/client/index.html") : join3(process.cwd(), "dist/client", url, "index.html");
546
- mkdirSync2(join3(outPath, ".."), { recursive: true });
547
- writeFileSync3(outPath, `<!DOCTYPE html>${html}`, "utf-8");
548
- console.log(` \u2713 ${url}`);
549
145
  }
550
- console.log("[devix] Generation complete.");
146
+ `}var v=s(()=>{"use strict";y()});import{readFileSync as gt,readdirSync as mt,statSync as ft}from"node:fs";import{join as w,relative as ht}from"node:path";function X(t,e){let r=[];for(let i of mt(t)){let o=w(t,i);ft(o).isDirectory()?r.push(...X(o,e)):/\.(ts|tsx)$/.test(i)&&r.push(ht(e,o).replace(/\\/g,"/"))}return r}function E(t,e){let r=w(e,t,"api"),i;try{i=X(r,e)}catch{return[]}return i.filter(o=>!o.endsWith("middleware.ts")&&!o.endsWith("middleware.tsx")).flatMap(o=>{try{let c=gt(w(e,o),"utf-8"),d=V(c);return d.length===0?[]:[J(o,`${t}/api`,d)]}catch{return[]}})}var Y=s(()=>{"use strict";G();v()});import{mkdirSync as xt,readFileSync as yt,writeFileSync as Rt,existsSync as vt}from"node:fs";import{join as z}from"node:path";function P(t,e){let r=z(e,".devix"),i=z(r,"routes.d.ts");return xt(r,{recursive:!0}),vt(i)&&yt(i,"utf-8")===t?!1:(Rt(i,t,"utf-8"),!0)}var B=s(()=>{"use strict"});import{mergeConfig as wt}from"vite";import Et from"@vitejs/plugin-react";import{fileURLToPath as Pt}from"node:url";import{dirname as $t,resolve as u}from"node:path";function Z(t){let e=t.appDir??"app",r=`${e}/pages`,i=(t.css??[]).map(n=>n.startsWith("/")?n:`/${n.replace(/^\.\//,"")}`),o=u($,"../server/render.js").replace(/\\/g,"/"),c=u($,"../server/api.js").replace(/\\/g,"/"),d=u($,"../runtime/client-router.js").replace(/\\/g,"/"),st={name:"devix",enforce:"pre",resolveId(n){if(n===_)return`\0${_}`;if(n===D)return`\0${D}`;if(n===T)return`\0${T}`;if(n===A)return`\0${A}`;if(n===C)return`\0${C}`},load(n){if(n===`\0${_}`)return M({cssUrls:i});if(n===`\0${D}`)return L({pagesDir:r,matcherPath:d});if(n===`\0${T}`)return k({pagesDir:r,renderPath:o});if(n===`\0${A}`)return F({apiPath:c,appDir:e});if(n===`\0${C}`)return N()},buildStart(){let n=process.cwd(),l=E(e,n);P(R(l,`${e}/api`),n)},configureServer(n){let l=process.cwd(),g=()=>{let a=E(e,l);P(R(a,`${e}/api`),l)};n.watcher.on("add",a=>{a.startsWith(u(l,r))&&h(),a.includes(`${e}/api`)&&(x(),g())}),n.watcher.on("unlink",a=>{a.startsWith(u(l,r))&&h(),a.includes(`${e}/api`)&&(x(),g())}),n.watcher.on("change",a=>{a.includes(`${e}/api`)&&!a.endsWith("middleware.ts")&&g()})}},at={plugins:[Et(),st],ssr:{noExternal:["@devlusoft/devix"]},...t.envPrefix?{envPrefix:t.envPrefix}:{}};return wt(at,t.vite??{})}var $,_,D,T,A,C,K=s(()=>{"use strict";O();I();U();H();j();y();W();Y();v();B();$=$t(Pt(import.meta.url)),_="virtual:devix/entry-client",D="virtual:devix/client-routes",T="virtual:devix/render",A="virtual:devix/api",C="virtual:devix/context"});function Q(t){if(typeof t=="number")return t;let e=t.trim().match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h)?$/);if(!e)throw new Error(`[devix] Invalid duration: "${t}". Use a number (ms) or a string like "5s", "2m", "500ms".`);let r=parseFloat(e[1]);switch(e[2]){case"h":return r*36e5;case"m":return r*6e4;case"s":return r*1e3;default:return r}}var tt=s(()=>{"use strict"});var At={};import{writeFileSync as _t}from"node:fs";import{resolve as Dt}from"node:path";import{build as et}from"vite";var p,rt,Tt,nt=s(async()=>{"use strict";K();tt();p=(await import(`${process.cwd()}/devix.config.ts`)).default,rt=Z(p);await et({...rt,configFile:!1,build:{outDir:"dist/client",manifest:!0,rolldownOptions:{input:"virtual:devix/entry-client"}}});await et({...rt,configFile:!1,build:{ssr:!0,outDir:"dist/server",rolldownOptions:{input:{render:"virtual:devix/render",api:"virtual:devix/api"}}}});Tt={port:p.port??3e3,host:p.host??!1,loaderTimeout:Q(p.loaderTimeout??1e4),output:p.output??"server"};_t(Dt(process.cwd(),"dist/devix.config.json"),JSON.stringify(Tt,null,2),"utf-8")});import{readFileSync as Ct,mkdirSync as St,writeFileSync as bt}from"node:fs";import{resolve as ot,join as S}from"node:path";var Mt=(await import(`${process.cwd()}/devix.config.ts`)).default;Mt.output!=="static"&&console.warn('[devix] Tip: set output: "static" in devix.config.ts to skip the SSR server at runtime.');await nt().then(()=>At);var Ot=Date.now(),it=await import(ot(process.cwd(),"dist/server/render.js")+`?t=${Ot}`),Lt=JSON.parse(Ct(ot(process.cwd(),"dist/client/.vite/manifest.json"),"utf-8")),b=await it.getStaticRoutes();console.log(`[devix] Generating ${b.length} static page${b.length===1?"":"s"}...`);for(let t of b){let e=`http://localhost${t}`,{html:r,statusCode:i}=await it.render(e,new Request(e),{manifest:Lt});if(i!==200){console.warn(`[devix] Skipping ${t} \u2014 status ${i}`);continue}let o=t==="/"?S(process.cwd(),"dist/client/index.html"):S(process.cwd(),"dist/client",t,"index.html");St(S(o,".."),{recursive:!0}),bt(o,`<!DOCTYPE html>${r}`,"utf-8"),console.log(` \u2713 ${t}`)}console.log("[devix] Generation complete.");
551
147
  //# sourceMappingURL=generate.js.map