@zenithbuild/cli 1.3.7 → 1.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/zen-build.js +399 -342
- package/dist/zen-dev.js +399 -342
- package/dist/zen-preview.js +399 -342
- package/dist/zenith.js +399 -342
- package/package.json +9 -9
- package/src/commands/dev.ts +79 -5
- package/src/serve.ts +43 -36
- package/src/ssg-build.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenithbuild/cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.18",
|
|
4
4
|
"description": "CLI for Zenith framework - dev server, build tools, and plugin management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
"zen-build": "./dist/zen-build.js",
|
|
10
10
|
"zen-preview": "./dist/zen-preview.js"
|
|
11
11
|
},
|
|
12
|
-
"main": "./
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
13
|
"types": "./src/index.ts",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
|
-
"types": "./
|
|
17
|
-
"import": "./
|
|
16
|
+
"types": "./dist/index.d.d.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
@@ -50,16 +50,16 @@
|
|
|
50
50
|
},
|
|
51
51
|
"private": false,
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@zenithbuild/core": "^1.3.
|
|
54
|
-
"@zenithbuild/compiler": "^1.3.
|
|
53
|
+
"@zenithbuild/core": "^1.3.17",
|
|
54
|
+
"@zenithbuild/compiler": "^1.3.17"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/bun": "latest",
|
|
58
|
-
"@zenithbuild/compiler": "^1.3.
|
|
58
|
+
"@zenithbuild/compiler": "^1.3.17"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@zenithbuild/bundler": "^1.3.
|
|
62
|
-
"@zenithbuild/router": "^1.3.
|
|
61
|
+
"@zenithbuild/bundler": "^1.3.17",
|
|
62
|
+
"@zenithbuild/router": "^1.3.17",
|
|
63
63
|
"glob": "^13.0.0",
|
|
64
64
|
"picocolors": "^1.0.0"
|
|
65
65
|
}
|
package/src/commands/dev.ts
CHANGED
|
@@ -208,11 +208,31 @@ export async function dev(options: DevOptions = {}): Promise<void> {
|
|
|
208
208
|
* Generate dev HTML
|
|
209
209
|
*/
|
|
210
210
|
async function generateDevHTML(page: CompiledPage): Promise<string> {
|
|
211
|
-
|
|
211
|
+
// Injection Block
|
|
212
|
+
const injection = `
|
|
213
|
+
<!-- Zenith Dev Injection -->
|
|
214
|
+
<link rel="stylesheet" href="/assets/styles.css">
|
|
215
|
+
<script>window.zenith = window.zenith || {};</script>
|
|
216
|
+
<script src="/runtime.js"></script>
|
|
217
|
+
<script type="importmap">
|
|
218
|
+
{
|
|
219
|
+
"imports": {
|
|
220
|
+
"zenith:core": "/zenith-core.js",
|
|
221
|
+
"@zenithbuild/core": "/zenith-core.js",
|
|
222
|
+
"@zenithbuild/runtime": "/zenith-core.js",
|
|
223
|
+
"@zenithbuild/router": "/zenith-router.js",
|
|
224
|
+
"gsap": "https://esm.sh/gsap"
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
</script>
|
|
228
|
+
<script type="module">
|
|
229
|
+
${page.script}
|
|
230
|
+
</script>
|
|
231
|
+
`;
|
|
212
232
|
|
|
213
233
|
let html = page.html.includes('</body>')
|
|
214
|
-
? page.html.replace('</body>', `${
|
|
215
|
-
: `${page.html}\n${
|
|
234
|
+
? page.html.replace('</body>', `${injection}\n</body>`)
|
|
235
|
+
: `${page.html}\n${injection}`
|
|
216
236
|
|
|
217
237
|
if (!html.trimStart().toLowerCase().startsWith('<!doctype')) {
|
|
218
238
|
html = `<!DOCTYPE html>\n${html}`
|
|
@@ -295,6 +315,27 @@ export async function dev(options: DevOptions = {}): Promise<void> {
|
|
|
295
315
|
}
|
|
296
316
|
|
|
297
317
|
// Handle Zenith assets
|
|
318
|
+
// 1. Intercept /assets/ requests and serve from disk (dist/assets or src/dist/assets)
|
|
319
|
+
if (pathname.startsWith('/assets/')) {
|
|
320
|
+
// Try standard dist/
|
|
321
|
+
let assetPath = path.join(rootDir, 'dist', pathname);
|
|
322
|
+
if (!fs.existsSync(assetPath)) {
|
|
323
|
+
// Try src/dist/ (current project structure)
|
|
324
|
+
assetPath = path.join(rootDir, 'src', 'dist', pathname);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (fs.existsSync(assetPath)) {
|
|
328
|
+
const content = fs.readFileSync(assetPath);
|
|
329
|
+
const contentType = ext === '.css' ? 'text/css' :
|
|
330
|
+
ext === '.js' ? 'application/javascript' :
|
|
331
|
+
'application/octet-stream';
|
|
332
|
+
|
|
333
|
+
return new Response(content, {
|
|
334
|
+
headers: { 'Content-Type': contentType }
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
298
339
|
if (pathname === '/runtime.js') {
|
|
299
340
|
// Collect runtime payloads from ALL plugins
|
|
300
341
|
const payloads = await collectHookReturns('cli:runtime:collect', hookCtx)
|
|
@@ -307,8 +348,41 @@ export async function dev(options: DevOptions = {}): Promise<void> {
|
|
|
307
348
|
return response
|
|
308
349
|
}
|
|
309
350
|
|
|
310
|
-
// Serve
|
|
311
|
-
if (pathname === '/
|
|
351
|
+
// DYNAMIC BUNDLING: Serve Core and Router directly from node_modules
|
|
352
|
+
if (pathname === '/zenith-core.js') {
|
|
353
|
+
try {
|
|
354
|
+
const entry = require.resolve('@zenithbuild/core'); // or runtime/index.ts
|
|
355
|
+
const build = await Bun.build({
|
|
356
|
+
entrypoints: [entry],
|
|
357
|
+
external: ['@zenithbuild/router'], // keep router external so it uses the map
|
|
358
|
+
target: "browser",
|
|
359
|
+
format: "esm"
|
|
360
|
+
});
|
|
361
|
+
if (build.success) {
|
|
362
|
+
return new Response(build.outputs[0]);
|
|
363
|
+
}
|
|
364
|
+
} catch (e) {
|
|
365
|
+
logger.error('Failed to bundle zenith-core: ' + e);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
if (pathname === '/zenith-router.js') {
|
|
369
|
+
try {
|
|
370
|
+
const entry = require.resolve('@zenithbuild/router');
|
|
371
|
+
const build = await Bun.build({
|
|
372
|
+
entrypoints: [entry],
|
|
373
|
+
target: "browser",
|
|
374
|
+
format: "esm"
|
|
375
|
+
});
|
|
376
|
+
if (build.success) {
|
|
377
|
+
return new Response(build.outputs[0]);
|
|
378
|
+
}
|
|
379
|
+
} catch (e) {
|
|
380
|
+
logger.error('Failed to bundle zenith-router: ' + e);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// Fallback: Serve compiler-owned CSS (Tailwind compiled) from memory if not on disk
|
|
385
|
+
if (pathname === '/assets/styles.css' && compiledCss) {
|
|
312
386
|
const response = new Response(compiledCss, {
|
|
313
387
|
headers: { 'Content-Type': 'text/css; charset=utf-8' }
|
|
314
388
|
})
|
package/src/serve.ts
CHANGED
|
@@ -15,6 +15,15 @@ import { serve } from "bun"
|
|
|
15
15
|
import path from "path"
|
|
16
16
|
|
|
17
17
|
const distDir = path.resolve(process.cwd(), "dist")
|
|
18
|
+
const srcDistDir = path.resolve(process.cwd(), "src/dist")
|
|
19
|
+
|
|
20
|
+
// Determine which dist to use
|
|
21
|
+
const finalDistDir = (await Bun.file(path.join(distDir, "index.html")).exists())
|
|
22
|
+
? distDir
|
|
23
|
+
: (await Bun.file(path.join(srcDistDir, "index.html")).exists())
|
|
24
|
+
? srcDistDir
|
|
25
|
+
: distDir // Fallback to root dist
|
|
26
|
+
|
|
18
27
|
|
|
19
28
|
// File extensions that should be served as static assets
|
|
20
29
|
const STATIC_EXTENSIONS = new Set([
|
|
@@ -42,49 +51,47 @@ serve({
|
|
|
42
51
|
const url = new URL(req.url)
|
|
43
52
|
const pathname = url.pathname
|
|
44
53
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (STATIC_EXTENSIONS.has(ext)) {
|
|
50
|
-
const filePath = path.join(distDir, pathname)
|
|
51
|
-
const file = Bun.file(filePath)
|
|
52
|
-
|
|
53
|
-
// Check if file exists
|
|
54
|
+
// 1. Root Route -> dist/index.html
|
|
55
|
+
if (pathname === "/" || pathname === "/index.html") {
|
|
56
|
+
const indexPath = path.join(finalDistDir, "index.html")
|
|
57
|
+
const file = Bun.file(indexPath)
|
|
54
58
|
if (await file.exists()) {
|
|
55
|
-
return new Response(file
|
|
59
|
+
return new Response(file, {
|
|
60
|
+
headers: { "Content-Type": "text/html; charset=utf-8" }
|
|
61
|
+
})
|
|
56
62
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
// No index.html found - likely need to run build first
|
|
64
|
+
return new Response(
|
|
65
|
+
`<html>
|
|
66
|
+
<head><title>Zenith - Build Required</title></head>
|
|
67
|
+
<body style="font-family: system-ui; padding: 2rem; text-align: center;">
|
|
68
|
+
<h1>Build Required</h1>
|
|
69
|
+
<p>Run <code>zenith build</code> first to compile the pages.</p>
|
|
70
|
+
<p>Checked: ${finalDistDir}</p>
|
|
71
|
+
</body>
|
|
72
|
+
</html>`,
|
|
73
|
+
{
|
|
74
|
+
status: 500,
|
|
75
|
+
headers: { "Content-Type": "text/html; charset=utf-8" }
|
|
76
|
+
}
|
|
77
|
+
)
|
|
60
78
|
}
|
|
61
79
|
|
|
62
|
-
//
|
|
63
|
-
const
|
|
64
|
-
const
|
|
80
|
+
// 2. Static Assets (js, css, etc.)
|
|
81
|
+
const filePath = path.join(finalDistDir, pathname)
|
|
82
|
+
const file = Bun.file(filePath)
|
|
65
83
|
|
|
66
|
-
if (await
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
if (await file.exists()) {
|
|
85
|
+
// Force correct MIME types for critical files
|
|
86
|
+
const headers = new Headers();
|
|
87
|
+
if (pathname.endsWith(".css")) headers.set("Content-Type", "text/css");
|
|
88
|
+
if (pathname.endsWith(".js")) headers.set("Content-Type", "application/javascript");
|
|
89
|
+
|
|
90
|
+
return new Response(file, { headers })
|
|
72
91
|
}
|
|
73
92
|
|
|
74
|
-
//
|
|
75
|
-
return new Response(
|
|
76
|
-
`<html>
|
|
77
|
-
<head><title>Zenith - Build Required</title></head>
|
|
78
|
-
<body style="font-family: system-ui; padding: 2rem; text-align: center;">
|
|
79
|
-
<h1>Build Required</h1>
|
|
80
|
-
<p>Run <code>zenith build</code> first to compile the pages.</p>
|
|
81
|
-
</body>
|
|
82
|
-
</html>`,
|
|
83
|
-
{
|
|
84
|
-
status: 500,
|
|
85
|
-
headers: { "Content-Type": "text/html; charset=utf-8" }
|
|
86
|
-
}
|
|
87
|
-
)
|
|
93
|
+
// 3. 404 - Not Found (Do not fallback to SPA yet to verify strict static serving)
|
|
94
|
+
return new Response("Not Found", { status: 404 })
|
|
88
95
|
}
|
|
89
96
|
})
|
|
90
97
|
|
package/src/ssg-build.ts
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import fs from "fs"
|
|
27
|
+
import path from 'path'
|
|
27
28
|
import { compile } from "@zenithbuild/compiler"
|
|
28
29
|
import { discoverComponents } from "./discovery/componentDiscovery"
|
|
29
30
|
import { discoverPages, generateRouteDefinition } from "@zenithbuild/router/manifest"
|