@devlusoft/devix 0.1.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.
- package/README.md +6 -4
- package/dist/cli/build.js +39 -178
- package/dist/cli/build.js.map +4 -4
- package/dist/cli/dev.js +41 -253
- package/dist/cli/dev.js.map +4 -4
- package/dist/cli/generate.js +39 -281
- package/dist/cli/generate.js.map +4 -4
- package/dist/cli/index.js +44 -527
- package/dist/cli/index.js.map +4 -4
- package/dist/cli/start.js +1 -77
- package/dist/cli/start.js.map +4 -4
- package/dist/config.js +1 -16
- package/dist/config.js.map +2 -2
- package/dist/runtime/api-context.d.ts +3 -2
- package/dist/runtime/api-context.js +1 -17
- package/dist/runtime/api-context.js.map +3 -3
- package/dist/runtime/client-router.js +1 -58
- package/dist/runtime/client-router.js.map +2 -2
- package/dist/runtime/context.js +1 -14
- package/dist/runtime/context.js.map +2 -2
- package/dist/runtime/error-boundary.js +1 -36
- package/dist/runtime/error-boundary.js.map +2 -2
- package/dist/runtime/fetch.d.ts +19 -0
- package/dist/runtime/fetch.js +2 -0
- package/dist/runtime/fetch.js.map +7 -0
- package/dist/runtime/head.js +1 -68
- package/dist/runtime/head.js.map +2 -2
- package/dist/runtime/index.d.ts +7 -1
- package/dist/runtime/index.js +1 -299
- package/dist/runtime/index.js.map +4 -4
- package/dist/runtime/link.js +1 -42
- package/dist/runtime/link.js.map +2 -2
- package/dist/runtime/metadata.js +1 -21
- package/dist/runtime/metadata.js.map +2 -2
- package/dist/runtime/router-provider.js +1 -258
- package/dist/runtime/router-provider.js.map +2 -2
- package/dist/server/api-router.d.ts +1 -0
- package/dist/server/api-router.js +1 -63
- package/dist/server/api-router.js.map +3 -3
- package/dist/server/api.js +1 -122
- package/dist/server/api.js.map +3 -3
- package/dist/server/collect-css.js +1 -14
- package/dist/server/collect-css.js.map +2 -2
- package/dist/server/index.js +1 -132
- package/dist/server/index.js.map +3 -3
- package/dist/server/pages-router.js +1 -63
- package/dist/server/pages-router.js.map +2 -2
- package/dist/server/render.js +1 -305
- package/dist/server/render.js.map +2 -2
- package/dist/server/routes.js +1 -41
- package/dist/server/routes.js.map +2 -2
- package/dist/utils/async.js +1 -13
- package/dist/utils/async.js.map +2 -2
- package/dist/utils/banner.js +1 -33
- package/dist/utils/banner.js.map +2 -2
- package/dist/utils/cookies.d.ts +12 -0
- package/dist/utils/cookies.js +2 -0
- package/dist/utils/cookies.js.map +7 -0
- package/dist/utils/duration.js +1 -21
- package/dist/utils/duration.js.map +2 -2
- package/dist/utils/env.d.ts +1 -0
- package/dist/utils/env.js +2 -0
- package/dist/utils/env.js.map +7 -0
- package/dist/utils/html.js +1 -11
- package/dist/utils/html.js.map +2 -2
- package/dist/utils/patterns.js +1 -7
- package/dist/utils/patterns.js.map +2 -2
- package/dist/utils/response.d.ts +6 -0
- package/dist/utils/response.js +2 -0
- package/dist/utils/response.js.map +7 -0
- package/dist/vite/codegen/api.js +6 -12
- package/dist/vite/codegen/api.js.map +2 -2
- package/dist/vite/codegen/client-routes.js +6 -12
- package/dist/vite/codegen/client-routes.js.map +2 -2
- package/dist/vite/codegen/context.js +2 -8
- package/dist/vite/codegen/context.js.map +2 -2
- package/dist/vite/codegen/entry-client.js +4 -10
- package/dist/vite/codegen/entry-client.js.map +2 -2
- package/dist/vite/codegen/extract-methods.d.ts +4 -0
- package/dist/vite/codegen/extract-methods.js +2 -0
- package/dist/vite/codegen/extract-methods.js.map +7 -0
- package/dist/vite/codegen/render.js +6 -12
- package/dist/vite/codegen/render.js.map +2 -2
- package/dist/vite/codegen/routes-dts.d.ts +10 -0
- package/dist/vite/codegen/routes-dts.js +23 -0
- package/dist/vite/codegen/routes-dts.js.map +7 -0
- package/dist/vite/codegen/scan-api.d.ts +2 -0
- package/dist/vite/codegen/scan-api.js +2 -0
- package/dist/vite/codegen/scan-api.js.map +7 -0
- package/dist/vite/codegen/write-routes-dts.d.ts +1 -0
- package/dist/vite/codegen/write-routes-dts.js +2 -0
- package/dist/vite/codegen/write-routes-dts.js.map +7 -0
- package/dist/vite/index.js +41 -119
- package/dist/vite/index.js.map +4 -4
- package/package.json +2 -2
package/dist/cli/index.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// src/vite/codegen/entry-client.ts
|
|
8
|
-
function generateEntryClient({ cssUrls }) {
|
|
9
|
-
const cssImports = cssUrls.map((u) => `import '${u}'`).join("\n");
|
|
10
|
-
return `
|
|
11
|
-
${cssImports}
|
|
2
|
+
var s=(e,t)=>()=>(e&&(t=e(e=0)),t);function Q({cssUrls:e}){return`
|
|
3
|
+
${e.map(r=>`import '${r}'`).join(`
|
|
4
|
+
`)}
|
|
12
5
|
import "@vitejs/plugin-react/preamble"
|
|
13
6
|
import React from "react"
|
|
14
7
|
import {hydrateRoot, createRoot} from 'react-dom/client'
|
|
@@ -62,22 +55,12 @@ if (!window.__DEVIX__) {
|
|
|
62
55
|
)
|
|
63
56
|
}
|
|
64
57
|
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
var init_entry_client = __esm({
|
|
68
|
-
"src/vite/codegen/entry-client.ts"() {
|
|
69
|
-
"use strict";
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// src/vite/codegen/client-routes.ts
|
|
74
|
-
function generateClientRoutes({ pagesDir, matcherPath }) {
|
|
75
|
-
return `
|
|
58
|
+
`}var ee=s(()=>{"use strict"});function te({pagesDir:e,matcherPath:t}){return`
|
|
76
59
|
import React from 'react'
|
|
77
|
-
import { createMatcher } from '${
|
|
78
|
-
const pageFiles = import.meta.glob(['/${
|
|
79
|
-
const layoutFiles = import.meta.glob('/${
|
|
80
|
-
const errorFiles = import.meta.glob('/${
|
|
60
|
+
import { createMatcher } from '${t}'
|
|
61
|
+
const pageFiles = import.meta.glob(['/${e}/**/*.tsx', '!**/error.tsx', '!**/layout.tsx'])
|
|
62
|
+
const layoutFiles = import.meta.glob('/${e}/**/layout.tsx')
|
|
63
|
+
const errorFiles = import.meta.glob('/${e}/**/error.tsx')
|
|
81
64
|
|
|
82
65
|
export const matchClientRoute = createMatcher(pageFiles, layoutFiles)
|
|
83
66
|
|
|
@@ -100,26 +83,16 @@ export function getDefaultErrorPage() {
|
|
|
100
83
|
)
|
|
101
84
|
}
|
|
102
85
|
}
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
var init_client_routes = __esm({
|
|
106
|
-
"src/vite/codegen/client-routes.ts"() {
|
|
107
|
-
"use strict";
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// src/vite/codegen/render.ts
|
|
112
|
-
function generateRender({ pagesDir, renderPath }) {
|
|
113
|
-
return `
|
|
114
|
-
import { render as _render, runLoader as _runLoader, getStaticRoutes as _getStaticRoutes } from '${renderPath}'
|
|
86
|
+
`}var re=s(()=>{"use strict"});function oe({pagesDir:e,renderPath:t}){return`
|
|
87
|
+
import { render as _render, runLoader as _runLoader, getStaticRoutes as _getStaticRoutes } from '${t}'
|
|
115
88
|
|
|
116
|
-
const _pages = import.meta.glob(['/${
|
|
117
|
-
const _layouts = import.meta.glob('/${
|
|
89
|
+
const _pages = import.meta.glob(['/${e}/**/*.tsx', '!**/error.tsx', '!**/layout.tsx'])
|
|
90
|
+
const _layouts = import.meta.glob('/${e}/**/layout.tsx')
|
|
118
91
|
|
|
119
92
|
const _glob = {
|
|
120
93
|
pages: _pages,
|
|
121
94
|
layouts: _layouts,
|
|
122
|
-
pagesDir: '/${
|
|
95
|
+
pagesDir: '/${e}',
|
|
123
96
|
}
|
|
124
97
|
|
|
125
98
|
export function render(url, request, options) {
|
|
@@ -133,497 +106,47 @@ export function runLoader(url, request, options) {
|
|
|
133
106
|
export function getStaticRoutes() {
|
|
134
107
|
return _getStaticRoutes(_glob)
|
|
135
108
|
}
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
var init_render = __esm({
|
|
139
|
-
"src/vite/codegen/render.ts"() {
|
|
140
|
-
"use strict";
|
|
141
|
-
}
|
|
142
|
-
});
|
|
109
|
+
`}var ne=s(()=>{"use strict"});function ie({apiPath:e,appDir:t}){return`
|
|
110
|
+
import { handleApiRequest as _handleApiRequest } from '${e}'
|
|
143
111
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return `
|
|
147
|
-
import { handleApiRequest as _handleApiRequest } from '${apiPath}'
|
|
148
|
-
|
|
149
|
-
const _routes = import.meta.glob(['/${appDir}/api/**/*.ts', '!**/middleware.ts'])
|
|
150
|
-
const _middlewares = import.meta.glob('/${appDir}/api/**/middleware.ts')
|
|
112
|
+
const _routes = import.meta.glob(['/${t}/api/**/*.ts', '!**/middleware.ts'])
|
|
113
|
+
const _middlewares = import.meta.glob('/${t}/api/**/middleware.ts')
|
|
151
114
|
|
|
152
115
|
const _glob = {
|
|
153
116
|
routes: _routes,
|
|
154
117
|
middlewares: _middlewares,
|
|
155
|
-
apiDir: '/${
|
|
118
|
+
apiDir: '/${t}/api',
|
|
156
119
|
}
|
|
157
120
|
|
|
158
121
|
export function handleApiRequest(url, request) {
|
|
159
122
|
return _handleApiRequest(url, request, _glob)
|
|
160
123
|
}
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
var init_api = __esm({
|
|
164
|
-
"src/vite/codegen/api.ts"() {
|
|
165
|
-
"use strict";
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
// src/utils/patterns.ts
|
|
170
|
-
var init_patterns = __esm({
|
|
171
|
-
"src/utils/patterns.ts"() {
|
|
172
|
-
"use strict";
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
// src/server/pages-router.ts
|
|
177
|
-
function invalidatePagesCache() {
|
|
178
|
-
cache = null;
|
|
179
|
-
}
|
|
180
|
-
var cache;
|
|
181
|
-
var init_pages_router = __esm({
|
|
182
|
-
"src/server/pages-router.ts"() {
|
|
183
|
-
"use strict";
|
|
184
|
-
init_patterns();
|
|
185
|
-
cache = null;
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// src/server/api-router.ts
|
|
190
|
-
function invalidateApiCache() {
|
|
191
|
-
cache2 = null;
|
|
192
|
-
}
|
|
193
|
-
var cache2;
|
|
194
|
-
var init_api_router = __esm({
|
|
195
|
-
"src/server/api-router.ts"() {
|
|
196
|
-
"use strict";
|
|
197
|
-
init_patterns();
|
|
198
|
-
cache2 = null;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
// src/vite/codegen/context.ts
|
|
203
|
-
function generateContext() {
|
|
204
|
-
return `
|
|
124
|
+
`}var se=s(()=>{"use strict"});function T(e){return e.replace(/\.(tsx|ts|jsx|js)$/,"").replace(/\(.*?\)\//g,"").replace(/^index$|\/index$/,"").replace(/\[([^\]]+)]/g,":$1")||"/"}var _=s(()=>{"use strict"});function D(){Ie=null}var Ie,ae=s(()=>{"use strict";_();Ie=null});function ce(e,t){let r=e.slice(t.length+1).replace(/\\/g,"/"),n=T(r);return n==="/"?"/api":`/api/${n}`.replace("/api//","/api/")}function b(){Ue=null}var Ue,C=s(()=>{"use strict";_();Ue=null});function le(){return`
|
|
205
125
|
export {RouterContext} from '@devlusoft/devix/runtime/context'
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (id === VIRTUAL_ENTRY_CLIENT) return `\0${VIRTUAL_ENTRY_CLIENT}`;
|
|
231
|
-
if (id === VIRTUAL_CLIENT_ROUTES) return `\0${VIRTUAL_CLIENT_ROUTES}`;
|
|
232
|
-
if (id === VIRTUAL_RENDER) return `\0${VIRTUAL_RENDER}`;
|
|
233
|
-
if (id === VIRTUAL_API) return `\0${VIRTUAL_API}`;
|
|
234
|
-
if (id === VIRTUAL_CONTEXT) return `\0${VIRTUAL_CONTEXT}`;
|
|
235
|
-
},
|
|
236
|
-
load(id) {
|
|
237
|
-
if (id === `\0${VIRTUAL_ENTRY_CLIENT}`)
|
|
238
|
-
return generateEntryClient({ cssUrls });
|
|
239
|
-
if (id === `\0${VIRTUAL_CLIENT_ROUTES}`)
|
|
240
|
-
return generateClientRoutes({ pagesDir, matcherPath });
|
|
241
|
-
if (id === `\0${VIRTUAL_RENDER}`)
|
|
242
|
-
return generateRender({ pagesDir, renderPath });
|
|
243
|
-
if (id === `\0${VIRTUAL_API}`)
|
|
244
|
-
return generateApi({ apiPath, appDir });
|
|
245
|
-
if (id === `\0${VIRTUAL_CONTEXT}`)
|
|
246
|
-
return generateContext();
|
|
247
|
-
},
|
|
248
|
-
configureServer(server) {
|
|
249
|
-
server.watcher.on("add", (file) => {
|
|
250
|
-
if (file.startsWith(resolve(process.cwd(), pagesDir))) invalidatePagesCache();
|
|
251
|
-
if (file.includes(`${appDir}/api`)) invalidateApiCache();
|
|
252
|
-
});
|
|
253
|
-
server.watcher.on("unlink", (file) => {
|
|
254
|
-
if (file.startsWith(resolve(process.cwd(), pagesDir))) invalidatePagesCache();
|
|
255
|
-
if (file.includes(`${appDir}/api`)) invalidateApiCache();
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
const base = {
|
|
260
|
-
plugins: [react(), virtualPlugin],
|
|
261
|
-
ssr: { noExternal: ["@devlusoft/devix"] },
|
|
262
|
-
...config3.envPrefix ? { envPrefix: config3.envPrefix } : {}
|
|
263
|
-
};
|
|
264
|
-
return mergeConfig(base, config3.vite ?? {});
|
|
265
|
-
}
|
|
266
|
-
var __dirname, VIRTUAL_ENTRY_CLIENT, VIRTUAL_CLIENT_ROUTES, VIRTUAL_RENDER, VIRTUAL_API, VIRTUAL_CONTEXT;
|
|
267
|
-
var init_vite = __esm({
|
|
268
|
-
"src/vite/index.ts"() {
|
|
269
|
-
"use strict";
|
|
270
|
-
init_entry_client();
|
|
271
|
-
init_client_routes();
|
|
272
|
-
init_render();
|
|
273
|
-
init_api();
|
|
274
|
-
init_pages_router();
|
|
275
|
-
init_api_router();
|
|
276
|
-
init_context();
|
|
277
|
-
__dirname = dirname(fileURLToPath(import.meta.url));
|
|
278
|
-
VIRTUAL_ENTRY_CLIENT = "virtual:devix/entry-client";
|
|
279
|
-
VIRTUAL_CLIENT_ROUTES = "virtual:devix/client-routes";
|
|
280
|
-
VIRTUAL_RENDER = "virtual:devix/render";
|
|
281
|
-
VIRTUAL_API = "virtual:devix/api";
|
|
282
|
-
VIRTUAL_CONTEXT = "virtual:devix/context";
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
// src/server/routes.ts
|
|
287
|
-
function registerApiRoutes(app3, { apiModule: apiModule3, renderModule: renderModule4, loaderTimeout }) {
|
|
288
|
-
app3.all("/api/*", async (c) => {
|
|
289
|
-
try {
|
|
290
|
-
return await apiModule3.handleApiRequest(c.req.url, c.req.raw);
|
|
291
|
-
} catch (e) {
|
|
292
|
-
console.error(e);
|
|
293
|
-
return c.json({ error: "internal error" }, 500);
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
app3.get("/_data/*", async (c) => {
|
|
297
|
-
try {
|
|
298
|
-
const { pathname, search } = new URL(c.req.url, "http://localhost");
|
|
299
|
-
const url = pathname.replace(/^\/_data/, "") + search;
|
|
300
|
-
const data = await renderModule4.runLoader(url, c.req.raw, { loaderTimeout });
|
|
301
|
-
return c.json(data);
|
|
302
|
-
} catch (e) {
|
|
303
|
-
console.error(e);
|
|
304
|
-
return c.json({ error: "internal error" }, 500);
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
function registerSsrRoute(app3, { renderModule: renderModule4, manifest: manifest3, loaderTimeout }) {
|
|
309
|
-
app3.get("*", async (c) => {
|
|
310
|
-
try {
|
|
311
|
-
const { html, statusCode, headers } = await renderModule4.render(c.req.url, c.req.raw, { manifest: manifest3, loaderTimeout });
|
|
312
|
-
const res = c.html(`<!DOCTYPE html>${html}`, statusCode);
|
|
313
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
314
|
-
res.headers.set(key, value);
|
|
315
|
-
}
|
|
316
|
-
return res;
|
|
317
|
-
} catch (e) {
|
|
318
|
-
console.error(e);
|
|
319
|
-
return c.text("Internal Server Error", 500);
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
var init_routes = __esm({
|
|
324
|
-
"src/server/routes.ts"() {
|
|
325
|
-
"use strict";
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
// src/utils/banner.ts
|
|
330
|
-
import pc from "picocolors";
|
|
331
|
-
import { networkInterfaces } from "node:os";
|
|
332
|
-
import { createRequire } from "node:module";
|
|
333
|
-
function getNetworkUrl(port3) {
|
|
334
|
-
const nets = networkInterfaces();
|
|
335
|
-
for (const interfaces of Object.values(nets)) {
|
|
336
|
-
for (const net of interfaces ?? []) {
|
|
337
|
-
if (net.family === "IPv4" && !net.internal) {
|
|
338
|
-
return `http://${net.address}:${port3}/`;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return null;
|
|
343
|
-
}
|
|
344
|
-
function printDevBanner(port3) {
|
|
345
|
-
const req = createRequire(import.meta.url);
|
|
346
|
-
const version = req("../../package.json").version;
|
|
347
|
-
const networkUrl = getNetworkUrl(port3);
|
|
348
|
-
console.log();
|
|
349
|
-
console.log(` ${pc.bold(pc.yellow("devix"))} ${pc.dim(`v${version}`)}`);
|
|
350
|
-
console.log();
|
|
351
|
-
console.log(` ${pc.green("\u279C")} ${pc.bold("Local:")} ${pc.cyan(`http://localhost:${port3}/`)}`);
|
|
352
|
-
if (networkUrl) {
|
|
353
|
-
console.log(` ${pc.green("\u279C")} ${pc.bold("Network:")} ${pc.cyan(networkUrl)}`);
|
|
354
|
-
} else {
|
|
355
|
-
console.log(` ${pc.green("\u279C")} ${pc.bold("Network:")} ${pc.dim("use --host to expose")}`);
|
|
356
|
-
}
|
|
357
|
-
console.log();
|
|
358
|
-
}
|
|
359
|
-
var init_banner = __esm({
|
|
360
|
-
"src/utils/banner.ts"() {
|
|
361
|
-
"use strict";
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
// src/server/collect-css.ts
|
|
366
|
-
async function collectCss(vite2) {
|
|
367
|
-
const cssUrls = /* @__PURE__ */ new Set();
|
|
368
|
-
for (const [, mod] of vite2.moduleGraph.idToModuleMap) {
|
|
369
|
-
if (!mod.id) continue;
|
|
370
|
-
if (mod.id.endsWith(".css") || mod.id.includes(".css?")) {
|
|
371
|
-
cssUrls.add(mod.url);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
return [...cssUrls];
|
|
375
|
-
}
|
|
376
|
-
var init_collect_css = __esm({
|
|
377
|
-
"src/server/collect-css.ts"() {
|
|
378
|
-
"use strict";
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
// src/utils/duration.ts
|
|
383
|
-
function parseDuration(value) {
|
|
384
|
-
if (typeof value === "number") return value;
|
|
385
|
-
const match = value.trim().match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h)?$/);
|
|
386
|
-
if (!match) throw new Error(`[devix] Invalid duration: "${value}". Use a number (ms) or a string like "5s", "2m", "500ms".`);
|
|
387
|
-
const n = parseFloat(match[1]);
|
|
388
|
-
switch (match[2]) {
|
|
389
|
-
case "h":
|
|
390
|
-
return n * 36e5;
|
|
391
|
-
case "m":
|
|
392
|
-
return n * 6e4;
|
|
393
|
-
case "s":
|
|
394
|
-
return n * 1e3;
|
|
395
|
-
case "ms":
|
|
396
|
-
default:
|
|
397
|
-
return n;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
var init_duration = __esm({
|
|
401
|
-
"src/utils/duration.ts"() {
|
|
402
|
-
"use strict";
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
// src/cli/dev.ts
|
|
407
|
-
var dev_exports = {};
|
|
408
|
-
import { createServer } from "node:http";
|
|
409
|
-
import { createServer as createViteServer } from "vite";
|
|
410
|
-
import { getRequestListener } from "@hono/node-server";
|
|
411
|
-
import { Hono } from "hono";
|
|
412
|
-
var VIRTUAL_RENDER2, VIRTUAL_API2, config, port, host, vite, renderModule, apiModule, app, honoHandler;
|
|
413
|
-
var init_dev = __esm({
|
|
414
|
-
async "src/cli/dev.ts"() {
|
|
415
|
-
"use strict";
|
|
416
|
-
init_vite();
|
|
417
|
-
init_routes();
|
|
418
|
-
init_banner();
|
|
419
|
-
init_collect_css();
|
|
420
|
-
init_duration();
|
|
421
|
-
VIRTUAL_RENDER2 = "virtual:devix/render";
|
|
422
|
-
VIRTUAL_API2 = "virtual:devix/api";
|
|
423
|
-
config = (await import(`${process.cwd()}/devix.config.ts`)).default;
|
|
424
|
-
port = Number(process.env.PORT) || config.port || 3e3;
|
|
425
|
-
host = typeof config.host === "string" ? config.host : config.host ? "0.0.0.0" : "localhost";
|
|
426
|
-
vite = await createViteServer({
|
|
427
|
-
...devix(config),
|
|
428
|
-
configFile: false,
|
|
429
|
-
appType: "custom",
|
|
430
|
-
server: { middlewareMode: true }
|
|
431
|
-
});
|
|
432
|
-
renderModule = {
|
|
433
|
-
render: async (...args) => (await vite.ssrLoadModule(VIRTUAL_RENDER2)).render(...args),
|
|
434
|
-
runLoader: async (...args) => (await vite.ssrLoadModule(VIRTUAL_RENDER2)).runLoader(...args)
|
|
435
|
-
};
|
|
436
|
-
apiModule = {
|
|
437
|
-
handleApiRequest: async (...args) => (await vite.ssrLoadModule(VIRTUAL_API2)).handleApiRequest(...args)
|
|
438
|
-
};
|
|
439
|
-
app = new Hono();
|
|
440
|
-
registerApiRoutes(app, { renderModule, apiModule });
|
|
441
|
-
app.get("*", async (c) => {
|
|
442
|
-
try {
|
|
443
|
-
const { html, statusCode, headers } = await renderModule.render(c.req.url, c.req.raw, { loaderTimeout: parseDuration(config.loaderTimeout ?? 1e4) });
|
|
444
|
-
const cssUrls = await collectCss(vite);
|
|
445
|
-
const cssLinks = cssUrls.map((url) => `<link rel="stylesheet" href="${url}">`).join("\n");
|
|
446
|
-
const htmlWithCss = cssLinks ? html.replace("</head>", `${cssLinks}
|
|
447
|
-
</head>`) : html;
|
|
448
|
-
const transformed = await vite.transformIndexHtml(c.req.url, `<!DOCTYPE html>${htmlWithCss}`);
|
|
449
|
-
const res = c.html(transformed, statusCode);
|
|
450
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
451
|
-
res.headers.set(key, value);
|
|
452
|
-
}
|
|
453
|
-
return res;
|
|
454
|
-
} catch (e) {
|
|
455
|
-
vite.ssrFixStacktrace(e);
|
|
456
|
-
console.error(e);
|
|
457
|
-
return c.text("Internal Server Error", 500);
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
honoHandler = getRequestListener(app.fetch);
|
|
461
|
-
createServer(async (req, res) => {
|
|
462
|
-
await new Promise((resolve5) => vite.middlewares(req, res, resolve5));
|
|
463
|
-
if (!res.writableEnded) await honoHandler(req, res);
|
|
464
|
-
}).listen(port, host, () => {
|
|
465
|
-
printDevBanner(port);
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
// src/cli/build.ts
|
|
471
|
-
var build_exports = {};
|
|
472
|
-
import { writeFileSync } from "node:fs";
|
|
473
|
-
import { resolve as resolve2 } from "node:path";
|
|
474
|
-
import { build } from "vite";
|
|
475
|
-
var config2, baseConfig, runtimeConfig;
|
|
476
|
-
var init_build = __esm({
|
|
477
|
-
async "src/cli/build.ts"() {
|
|
478
|
-
"use strict";
|
|
479
|
-
init_vite();
|
|
480
|
-
init_duration();
|
|
481
|
-
config2 = (await import(`${process.cwd()}/devix.config.ts`)).default;
|
|
482
|
-
baseConfig = devix(config2);
|
|
483
|
-
await build({
|
|
484
|
-
...baseConfig,
|
|
485
|
-
configFile: false,
|
|
486
|
-
build: {
|
|
487
|
-
outDir: "dist/client",
|
|
488
|
-
manifest: true,
|
|
489
|
-
rolldownOptions: {
|
|
490
|
-
input: "virtual:devix/entry-client"
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
await build({
|
|
495
|
-
...baseConfig,
|
|
496
|
-
configFile: false,
|
|
497
|
-
build: {
|
|
498
|
-
ssr: true,
|
|
499
|
-
outDir: "dist/server",
|
|
500
|
-
rolldownOptions: {
|
|
501
|
-
input: {
|
|
502
|
-
render: "virtual:devix/render",
|
|
503
|
-
api: "virtual:devix/api"
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
});
|
|
508
|
-
runtimeConfig = {
|
|
509
|
-
port: config2.port ?? 3e3,
|
|
510
|
-
host: config2.host ?? false,
|
|
511
|
-
loaderTimeout: parseDuration(config2.loaderTimeout ?? 1e4),
|
|
512
|
-
output: config2.output ?? "server"
|
|
513
|
-
};
|
|
514
|
-
writeFileSync(
|
|
515
|
-
resolve2(process.cwd(), "dist/devix.config.json"),
|
|
516
|
-
JSON.stringify(runtimeConfig, null, 2),
|
|
517
|
-
"utf-8"
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
// src/cli/generate.ts
|
|
523
|
-
var generate_exports = {};
|
|
524
|
-
import { readFileSync, mkdirSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
525
|
-
import { resolve as resolve3, join } from "node:path";
|
|
526
|
-
var userConfig, t, renderModule2, manifest, urls;
|
|
527
|
-
var init_generate = __esm({
|
|
528
|
-
async "src/cli/generate.ts"() {
|
|
529
|
-
"use strict";
|
|
530
|
-
userConfig = (await import(`${process.cwd()}/devix.config.ts`)).default;
|
|
531
|
-
if (userConfig.output !== "static") {
|
|
532
|
-
console.warn('[devix] Tip: set output: "static" in devix.config.ts to skip the SSR server at runtime.');
|
|
533
|
-
}
|
|
534
|
-
await init_build().then(() => build_exports);
|
|
535
|
-
t = Date.now();
|
|
536
|
-
renderModule2 = await import(resolve3(process.cwd(), "dist/server/render.js") + `?t=${t}`);
|
|
537
|
-
manifest = JSON.parse(
|
|
538
|
-
readFileSync(resolve3(process.cwd(), "dist/client/.vite/manifest.json"), "utf-8")
|
|
539
|
-
);
|
|
540
|
-
urls = await renderModule2.getStaticRoutes();
|
|
541
|
-
console.log(`[devix] Generating ${urls.length} static page${urls.length === 1 ? "" : "s"}...`);
|
|
542
|
-
for (const url of urls) {
|
|
543
|
-
const fullUrl = `http://localhost${url}`;
|
|
544
|
-
const { html, statusCode } = await renderModule2.render(fullUrl, new Request(fullUrl), { manifest });
|
|
545
|
-
if (statusCode !== 200) {
|
|
546
|
-
console.warn(`[devix] Skipping ${url} \u2014 status ${statusCode}`);
|
|
547
|
-
continue;
|
|
548
|
-
}
|
|
549
|
-
const outPath = url === "/" ? join(process.cwd(), "dist/client/index.html") : join(process.cwd(), "dist/client", url, "index.html");
|
|
550
|
-
mkdirSync(join(outPath, ".."), { recursive: true });
|
|
551
|
-
writeFileSync2(outPath, `<!DOCTYPE html>${html}`, "utf-8");
|
|
552
|
-
console.log(` \u2713 ${url}`);
|
|
553
|
-
}
|
|
554
|
-
console.log("[devix] Generation complete.");
|
|
555
|
-
}
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
// src/cli/start.ts
|
|
559
|
-
var start_exports = {};
|
|
560
|
-
import { readFileSync as readFileSync2 } from "node:fs";
|
|
561
|
-
import { serve } from "@hono/node-server";
|
|
562
|
-
import { serveStatic } from "@hono/node-server/serve-static";
|
|
563
|
-
import { Hono as Hono2 } from "hono";
|
|
564
|
-
import { resolve as resolve4 } from "node:path";
|
|
565
|
-
var renderModule3, apiModule2, manifest2, runtimeConfig2, port2, host2, app2;
|
|
566
|
-
var init_start = __esm({
|
|
567
|
-
async "src/cli/start.ts"() {
|
|
568
|
-
"use strict";
|
|
569
|
-
init_routes();
|
|
570
|
-
try {
|
|
571
|
-
runtimeConfig2 = JSON.parse(readFileSync2(resolve4(process.cwd(), "dist/devix.config.json"), "utf-8"));
|
|
572
|
-
if (runtimeConfig2.output !== "static") {
|
|
573
|
-
renderModule3 = await import(resolve4(process.cwd(), "dist/server/render.js"));
|
|
574
|
-
apiModule2 = await import(resolve4(process.cwd(), "dist/server/api.js"));
|
|
575
|
-
}
|
|
576
|
-
manifest2 = JSON.parse(readFileSync2(resolve4(process.cwd(), "dist/client/.vite/manifest.json"), "utf-8"));
|
|
577
|
-
} catch {
|
|
578
|
-
console.error('[devix] Build not found. Run "devix build" first.');
|
|
579
|
-
process.exit(1);
|
|
580
|
-
}
|
|
581
|
-
port2 = Number(process.env.PORT) || runtimeConfig2.port || 3e3;
|
|
582
|
-
host2 = typeof runtimeConfig2.host === "string" ? runtimeConfig2.host : runtimeConfig2.host ? "0.0.0.0" : process.env.HOST || "0.0.0.0";
|
|
583
|
-
app2 = new Hono2();
|
|
584
|
-
app2.use("/*", serveStatic({
|
|
585
|
-
root: "./dist/client",
|
|
586
|
-
onFound: (_path, c) => {
|
|
587
|
-
c.header("Cache-Control", _path.includes("/assets/") ? "public, immutable, max-age=31536000" : "no-cache");
|
|
588
|
-
}
|
|
589
|
-
}));
|
|
590
|
-
if (runtimeConfig2.output === "static") {
|
|
591
|
-
console.log("[devix] Static mode \u2014 serving pre-generated files from dist/client");
|
|
592
|
-
} else {
|
|
593
|
-
registerApiRoutes(app2, { renderModule: renderModule3, apiModule: apiModule2, manifest: manifest2 });
|
|
594
|
-
registerSsrRoute(app2, { renderModule: renderModule3, apiModule: apiModule2, manifest: manifest2, loaderTimeout: runtimeConfig2.loaderTimeout });
|
|
595
|
-
}
|
|
596
|
-
serve({ fetch: app2.fetch, port: port2, hostname: host2 }, (info) => console.log(`http://${info.address}:${info.port}`));
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
|
-
|
|
600
|
-
// src/cli/index.ts
|
|
601
|
-
import { readFileSync as readFileSync3 } from "node:fs";
|
|
602
|
-
import { join as join2, dirname as dirname2 } from "node:path";
|
|
603
|
-
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
604
|
-
var command = process.argv[2];
|
|
605
|
-
switch (command) {
|
|
606
|
-
case "dev":
|
|
607
|
-
await init_dev().then(() => dev_exports);
|
|
608
|
-
break;
|
|
609
|
-
case "build":
|
|
610
|
-
await init_build().then(() => build_exports);
|
|
611
|
-
break;
|
|
612
|
-
case "generate":
|
|
613
|
-
await init_generate().then(() => generate_exports);
|
|
614
|
-
break;
|
|
615
|
-
case "start":
|
|
616
|
-
await init_start().then(() => start_exports);
|
|
617
|
-
break;
|
|
618
|
-
case "--version":
|
|
619
|
-
case "-v": {
|
|
620
|
-
const pkg = JSON.parse(readFileSync3(join2(dirname2(fileURLToPath2(import.meta.url)), "../../package.json"), "utf-8"));
|
|
621
|
-
console.log(pkg.version);
|
|
622
|
-
break;
|
|
623
|
-
}
|
|
624
|
-
case "--help":
|
|
625
|
-
case "-h":
|
|
626
|
-
console.log(`
|
|
126
|
+
`}var ue=s(()=>{"use strict"});function He(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"")}function pe(e){let t=new Set;for(let r of He(e).matchAll(je))t.add(r[1]);return[...t]}var je,de=s(()=>{"use strict";je=/export\s+(?:const|async\s+function|function)\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g});function qe(e,t){return"_api_"+e.slice(`${t}/`.length).replace(/\.(ts|tsx)$/,"").replace(/[^a-zA-Z0-9]/g,"_")}function me(e,t,r){return{filePath:e,urlPattern:ce(e,t),identifier:qe(e,t),methods:r}}function A(e,t){if(e.length===0)return`// auto-generado por devix \u2014 no editar
|
|
127
|
+
declare module '@devlusoft/devix' {
|
|
128
|
+
interface ApiRoutes {}
|
|
129
|
+
}
|
|
130
|
+
`;let r=e.map(o=>{let a="../"+o.filePath.replace(/\.(ts|tsx)$/,"");return`import type * as ${o.identifier} from '${a}'`}).join(`
|
|
131
|
+
`),n=e.flatMap(o=>o.methods.map(a=>` '${a} ${o.urlPattern}': InferRoute<(typeof ${o.identifier})['${a}']>`)).join(`
|
|
132
|
+
`);return`// auto-generado por devix \u2014 no editar
|
|
133
|
+
${r}
|
|
134
|
+
|
|
135
|
+
type JsonResponse<T> = Response & { readonly __body: T }
|
|
136
|
+
type InferRoute<T> = T extends (...args: any[]) => any
|
|
137
|
+
? Awaited<ReturnType<T>> extends JsonResponse<infer U>
|
|
138
|
+
? U
|
|
139
|
+
: Exclude<Awaited<ReturnType<T>>, Response | null | void>
|
|
140
|
+
: never
|
|
141
|
+
|
|
142
|
+
declare module '@devlusoft/devix' {
|
|
143
|
+
interface ApiRoutes {
|
|
144
|
+
${n}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
`}var M=s(()=>{"use strict";C()});import{readFileSync as Fe,readdirSync as Ne,statSync as Ve}from"node:fs";import{join as O,relative as We}from"node:path";function fe(e,t){let r=[];for(let n of Ne(e)){let o=O(e,n);Ve(o).isDirectory()?r.push(...fe(o,t)):/\.(ts|tsx)$/.test(n)&&r.push(We(t,o).replace(/\\/g,"/"))}return r}function k(e,t){let r=O(t,e,"api"),n;try{n=fe(r,t)}catch{return[]}return n.filter(o=>!o.endsWith("middleware.ts")&&!o.endsWith("middleware.tsx")).flatMap(o=>{try{let a=Fe(O(t,o),"utf-8"),l=pe(a);return l.length===0?[]:[me(o,`${e}/api`,l)]}catch{return[]}})}var ge=s(()=>{"use strict";de();M()});import{mkdirSync as Ge,readFileSync as Je,writeFileSync as Be,existsSync as Ye}from"node:fs";import{join as he}from"node:path";function L(e,t){let r=he(t,".devix"),n=he(r,"routes.d.ts");return Ge(r,{recursive:!0}),Ye(n)&&Je(n,"utf-8")===e?!1:(Be(n,e,"utf-8"),!0)}var xe=s(()=>{"use strict"});import{mergeConfig as Xe}from"vite";import ze from"@vitejs/plugin-react";import{fileURLToPath as Ze}from"node:url";import{dirname as Ke,resolve as x}from"node:path";function y(e){let t=e.appDir??"app",r=`${t}/pages`,n=(e.css??[]).map(i=>i.startsWith("/")?i:`/${i.replace(/^\.\//,"")}`),o=x(I,"../server/render.js").replace(/\\/g,"/"),a=x(I,"../server/api.js").replace(/\\/g,"/"),l=x(I,"../runtime/client-router.js").replace(/\\/g,"/"),f={name:"devix",enforce:"pre",resolveId(i){if(i===U)return`\0${U}`;if(i===j)return`\0${j}`;if(i===H)return`\0${H}`;if(i===q)return`\0${q}`;if(i===F)return`\0${F}`},load(i){if(i===`\0${U}`)return Q({cssUrls:n});if(i===`\0${j}`)return te({pagesDir:r,matcherPath:l});if(i===`\0${H}`)return oe({pagesDir:r,renderPath:o});if(i===`\0${q}`)return ie({apiPath:a,appDir:t});if(i===`\0${F}`)return le()},buildStart(){let i=process.cwd(),u=k(t,i);L(A(u,`${t}/api`),i)},configureServer(i){let u=process.cwd(),S=()=>{let p=k(t,u);L(A(p,`${t}/api`),u)};i.watcher.on("add",p=>{p.startsWith(x(u,r))&&D(),p.includes(`${t}/api`)&&(b(),S())}),i.watcher.on("unlink",p=>{p.startsWith(x(u,r))&&D(),p.includes(`${t}/api`)&&(b(),S())}),i.watcher.on("change",p=>{p.includes(`${t}/api`)&&!p.endsWith("middleware.ts")&&S()})}},d={plugins:[ze(),f],ssr:{noExternal:["@devlusoft/devix"]},...e.envPrefix?{envPrefix:e.envPrefix}:{}};return Xe(d,e.vite??{})}var I,U,j,H,q,F,N=s(()=>{"use strict";ee();re();ne();se();ae();C();ue();ge();M();xe();I=Ke(Ze(import.meta.url)),U="virtual:devix/entry-client",j="virtual:devix/client-routes",H="virtual:devix/render",q="virtual:devix/api",F="virtual:devix/context"});function w(e,{apiModule:t,renderModule:r,loaderTimeout:n}){e.all("/api/*",async o=>{try{return await t.handleApiRequest(o.req.url,o.req.raw)}catch(a){return console.error(a),o.json({error:"internal error"},500)}}),e.get("/_data/*",async o=>{try{let{pathname:a,search:l}=new URL(o.req.url,"http://localhost"),f=a.replace(/^\/_data/,"")+l,d=await r.runLoader(f,o.req.raw,{loaderTimeout:n});return o.json(d)}catch(a){return console.error(a),o.json({error:"internal error"},500)}})}function ve(e,{renderModule:t,manifest:r,loaderTimeout:n}){e.get("*",async o=>{try{let{html:a,statusCode:l,headers:f}=await t.render(o.req.url,o.req.raw,{manifest:r,loaderTimeout:n}),d=o.html(`<!DOCTYPE html>${a}`,l);for(let[i,u]of Object.entries(f))d.headers.set(i,u);return d}catch(a){return console.error(a),o.text("Internal Server Error",500)}})}var V=s(()=>{"use strict"});import c from"picocolors";import{networkInterfaces as Qe}from"node:os";import{createRequire as et}from"node:module";function tt(e){let t=Qe();for(let r of Object.values(t))for(let n of r??[])if(n.family==="IPv4"&&!n.internal)return`http://${n.address}:${e}/`;return null}function ye(e){let r=et(import.meta.url)("../../package.json").version,n=tt(e);console.log(),console.log(` ${c.bold(c.yellow("devix"))} ${c.dim(`v${r}`)}`),console.log(),console.log(` ${c.green("\u279C")} ${c.bold("Local:")} ${c.cyan(`http://localhost:${e}/`)}`),console.log(n?` ${c.green("\u279C")} ${c.bold("Network:")} ${c.cyan(n)}`:` ${c.green("\u279C")} ${c.bold("Network:")} ${c.dim("use --host to expose")}`),console.log()}var we=s(()=>{"use strict"});async function Re(e){let t=new Set;for(let[,r]of e.moduleGraph.idToModuleMap)r.id&&(r.id.endsWith(".css")||r.id.includes(".css?"))&&t.add(r.url);return[...t]}var $e=s(()=>{"use strict"});function R(e){if(typeof e=="number")return e;let t=e.trim().match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h)?$/);if(!t)throw new Error(`[devix] Invalid duration: "${e}". Use a number (ms) or a string like "5s", "2m", "500ms".`);let r=parseFloat(t[1]);switch(t[2]){case"h":return r*36e5;case"m":return r*6e4;case"s":return r*1e3;default:return r}}var W=s(()=>{"use strict"});import{loadEnv as rt}from"vite";function $(e){let t=rt(e,process.cwd(),"");for(let[r,n]of Object.entries(t))process.env[r]===void 0&&(process.env[r]=n)}var G=s(()=>{"use strict"});var pt={};import{createServer as ot}from"node:http";import{createServer as nt}from"vite";import{getRequestListener as it}from"@hono/node-server";import{Hono as st}from"hono";var Ee,at,h,Pe,ct,g,Se,lt,J,ut,Te=s(async()=>{"use strict";N();V();we();$e();W();G();$("development");Ee="virtual:devix/render",at="virtual:devix/api",h=(await import(`${process.cwd()}/devix.config.ts`)).default,Pe=Number(process.env.PORT)||h.port||3e3,ct=typeof h.host=="string"?h.host:h.host?"0.0.0.0":"localhost",g=await nt({...y(h),configFile:!1,appType:"custom",server:{middlewareMode:!0}}),Se={render:async(...e)=>(await g.ssrLoadModule(Ee)).render(...e),runLoader:async(...e)=>(await g.ssrLoadModule(Ee)).runLoader(...e)},lt={handleApiRequest:async(...e)=>(await g.ssrLoadModule(at)).handleApiRequest(...e)},J=new st;w(J,{renderModule:Se,apiModule:lt});J.get("*",async e=>{try{let{html:t,statusCode:r,headers:n}=await Se.render(e.req.url,e.req.raw,{loaderTimeout:R(h.loaderTimeout??1e4)}),a=(await Re(g)).map(i=>`<link rel="stylesheet" href="${i}">`).join(`
|
|
148
|
+
`),l=a?t.replace("</head>",`${a}
|
|
149
|
+
</head>`):t,f=await g.transformIndexHtml(e.req.url,`<!DOCTYPE html>${l}`),d=e.html(f,r);for(let[i,u]of Object.entries(n))d.headers.set(i,u);return d}catch(t){return g.ssrFixStacktrace(t),console.error(t),e.text("Internal Server Error",500)}});ut=it(J.fetch);ot(async(e,t)=>{await new Promise(r=>g.middlewares(e,t,r)),t.writableEnded||await ut(e,t)}).listen(Pe,ct,()=>{ye(Pe)})});var be={};import{writeFileSync as dt}from"node:fs";import{resolve as mt}from"node:path";import{build as _e}from"vite";var v,De,ft,B=s(async()=>{"use strict";N();W();v=(await import(`${process.cwd()}/devix.config.ts`)).default,De=y(v);await _e({...De,configFile:!1,build:{outDir:"dist/client",manifest:!0,rolldownOptions:{input:"virtual:devix/entry-client"}}});await _e({...De,configFile:!1,build:{ssr:!0,outDir:"dist/server",rolldownOptions:{input:{render:"virtual:devix/render",api:"virtual:devix/api"}}}});ft={port:v.port??3e3,host:v.host??!1,loaderTimeout:R(v.loaderTimeout??1e4),output:v.output??"server"};dt(mt(process.cwd(),"dist/devix.config.json"),JSON.stringify(ft,null,2),"utf-8")});var Rt={};import{readFileSync as gt,mkdirSync as ht,writeFileSync as xt}from"node:fs";import{resolve as Ce,join as Y}from"node:path";var vt,yt,Ae,wt,X,Me=s(async()=>{"use strict";vt=(await import(`${process.cwd()}/devix.config.ts`)).default;vt.output!=="static"&&console.warn('[devix] Tip: set output: "static" in devix.config.ts to skip the SSR server at runtime.');await B().then(()=>be);yt=Date.now(),Ae=await import(Ce(process.cwd(),"dist/server/render.js")+`?t=${yt}`),wt=JSON.parse(gt(Ce(process.cwd(),"dist/client/.vite/manifest.json"),"utf-8")),X=await Ae.getStaticRoutes();console.log(`[devix] Generating ${X.length} static page${X.length===1?"":"s"}...`);for(let e of X){let t=`http://localhost${e}`,{html:r,statusCode:n}=await Ae.render(t,new Request(t),{manifest:wt});if(n!==200){console.warn(`[devix] Skipping ${e} \u2014 status ${n}`);continue}let o=e==="/"?Y(process.cwd(),"dist/client/index.html"):Y(process.cwd(),"dist/client",e,"index.html");ht(Y(o,".."),{recursive:!0}),xt(o,`<!DOCTYPE html>${r}`,"utf-8"),console.log(` \u2713 ${e}`)}console.log("[devix] Generation complete.")});var _t={};import{readFileSync as Oe}from"node:fs";import{serve as $t}from"@hono/node-server";import{serveStatic as Et}from"@hono/node-server/serve-static";import{Hono as Pt}from"hono";import{resolve as E}from"node:path";var z,Z,K,m,St,Tt,P,ke=s(async()=>{"use strict";V();G();$("production");try{m=JSON.parse(Oe(E(process.cwd(),"dist/devix.config.json"),"utf-8")),m.output!=="static"&&(z=await import(E(process.cwd(),"dist/server/render.js")),Z=await import(E(process.cwd(),"dist/server/api.js"))),K=JSON.parse(Oe(E(process.cwd(),"dist/client/.vite/manifest.json"),"utf-8"))}catch{console.error('[devix] Build not found. Run "devix build" first.'),process.exit(1)}St=Number(process.env.PORT)||m.port||3e3,Tt=typeof m.host=="string"?m.host:m.host?"0.0.0.0":process.env.HOST||"0.0.0.0",P=new Pt;P.use("/*",Et({root:"./dist/client",onFound:(e,t)=>{t.header("Cache-Control",e.includes("/assets/")?"public, immutable, max-age=31536000":"no-cache")}}));m.output==="static"?console.log("[devix] Static mode \u2014 serving pre-generated files from dist/client"):(w(P,{renderModule:z,apiModule:Z,manifest:K}),ve(P,{renderModule:z,apiModule:Z,manifest:K,loaderTimeout:m.loaderTimeout}));$t({fetch:P.fetch,port:St,hostname:Tt},e=>console.log(`http://${e.address}:${e.port}`))});import{readFileSync as Dt}from"node:fs";import{join as bt,dirname as Ct}from"node:path";import{fileURLToPath as At}from"node:url";var Le=process.argv[2];switch(Le){case"dev":await Te().then(()=>pt);break;case"build":await B().then(()=>be);break;case"generate":await Me().then(()=>Rt);break;case"start":await ke().then(()=>_t);break;case"--version":case"-v":{let e=JSON.parse(Dt(bt(Ct(At(import.meta.url)),"../../package.json"),"utf-8"));console.log(e.version);break}case"--help":case"-h":console.log(`
|
|
627
150
|
devix \u2014 a lightweight SSR framework
|
|
628
151
|
|
|
629
152
|
Usage:
|
|
@@ -639,11 +162,5 @@ Options:
|
|
|
639
162
|
Output modes (set in devix.config.ts):
|
|
640
163
|
output: "server" SSR mode \u2014 devix start handles requests dynamically (default)
|
|
641
164
|
output: "static" SSG mode \u2014 devix generate pre-renders all pages; devix start serves static files only
|
|
642
|
-
`.trim());
|
|
643
|
-
break;
|
|
644
|
-
default:
|
|
645
|
-
console.error(`Unknown command: ${command}`);
|
|
646
|
-
console.error("Usage: devix <dev|build|generate|start>");
|
|
647
|
-
process.exit(1);
|
|
648
|
-
}
|
|
165
|
+
`.trim());break;default:console.error(`Unknown command: ${Le}`),console.error("Usage: devix <dev|build|generate|start>"),process.exit(1)}
|
|
649
166
|
//# sourceMappingURL=index.js.map
|