@zenithbuild/cli 1.3.17 → 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 CHANGED
@@ -1320,17 +1320,17 @@ var require_compiler_native = __commonJS((exports, module) => {
1320
1320
  import process2 from "process";
1321
1321
 
1322
1322
  // src/commands/dev.ts
1323
- import path11 from "path";
1323
+ import path10 from "path";
1324
1324
  import fs7 from "fs";
1325
1325
  var {serve } = globalThis.Bun;
1326
1326
 
1327
1327
  // src/utils/project.ts
1328
1328
  import fs from "fs";
1329
- import path2 from "path";
1329
+ import path from "path";
1330
1330
  function findProjectRoot(startDir = process.cwd()) {
1331
1331
  let current = startDir;
1332
- while (current !== path2.dirname(current)) {
1333
- const pkgPath = path2.join(current, "package.json");
1332
+ while (current !== path.dirname(current)) {
1333
+ const pkgPath = path.join(current, "package.json");
1334
1334
  if (fs.existsSync(pkgPath)) {
1335
1335
  try {
1336
1336
  const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
@@ -1341,7 +1341,7 @@ function findProjectRoot(startDir = process.cwd()) {
1341
1341
  }
1342
1342
  } catch {}
1343
1343
  }
1344
- current = path2.dirname(current);
1344
+ current = path.dirname(current);
1345
1345
  }
1346
1346
  return null;
1347
1347
  }
@@ -1349,14 +1349,14 @@ function getProject(cwd = process.cwd()) {
1349
1349
  const root = findProjectRoot(cwd);
1350
1350
  if (!root)
1351
1351
  return null;
1352
- let appDir = path2.join(root, "app");
1352
+ let appDir = path.join(root, "app");
1353
1353
  if (!fs.existsSync(appDir)) {
1354
- appDir = path2.join(root, "src");
1354
+ appDir = path.join(root, "src");
1355
1355
  }
1356
1356
  return {
1357
1357
  root,
1358
- pagesDir: path2.join(appDir, "pages"),
1359
- distDir: path2.join(appDir, "dist"),
1358
+ pagesDir: path.join(appDir, "pages"),
1359
+ distDir: path.join(appDir, "dist"),
1360
1360
  hasZenithDeps: true
1361
1361
  };
1362
1362
  }
@@ -1390,13 +1390,13 @@ function header(title) {
1390
1390
  ${import_picocolors.default.bold(import_picocolors.default.cyan(title))}
1391
1391
  `);
1392
1392
  }
1393
- function hmr(type, path3) {
1394
- console.log(`${import_picocolors.default.magenta("[HMR]")} ${import_picocolors.default.bold(type)} updated: ${import_picocolors.default.dim(path3)}`);
1393
+ function hmr(type, path2) {
1394
+ console.log(`${import_picocolors.default.magenta("[HMR]")} ${import_picocolors.default.bold(type)} updated: ${import_picocolors.default.dim(path2)}`);
1395
1395
  }
1396
- function route(method, path3, status, totalMs, compileMs, renderMs) {
1396
+ function route(method, path2, status, totalMs, compileMs, renderMs) {
1397
1397
  const statusColor = status < 400 ? import_picocolors.default.green : import_picocolors.default.red;
1398
1398
  const timeColor = totalMs > 1000 ? import_picocolors.default.yellow : import_picocolors.default.gray;
1399
- console.log(`${import_picocolors.default.bold(method)} ${import_picocolors.default.cyan(path3.padEnd(15))} ` + `${statusColor(status)} ${import_picocolors.default.dim("in")} ${timeColor(`${totalMs}ms`)} ` + `${import_picocolors.default.dim(`(compile: ${compileMs}ms, render: ${renderMs}ms)`)}`);
1399
+ console.log(`${import_picocolors.default.bold(method)} ${import_picocolors.default.cyan(path2.padEnd(15))} ` + `${statusColor(status)} ${import_picocolors.default.dim("in")} ${timeColor(`${totalMs}ms`)} ` + `${import_picocolors.default.dim(`(compile: ${compileMs}ms, render: ${renderMs}ms)`)}`);
1400
1400
  }
1401
1401
  function debug(message) {
1402
1402
  if (process.env.ZENITH_DEBUG === "true") {
@@ -1534,23 +1534,23 @@ function showServerPanel(options) {
1534
1534
 
1535
1535
  // ../zenith-bundler/dist/bundle-generator.js
1536
1536
  import { readFileSync, existsSync } from "fs";
1537
- import path3 from "path";
1537
+ import path2 from "path";
1538
1538
  function generateBundleJS(pluginData) {
1539
1539
  const serializedData = pluginData ? JSON.stringify(pluginData).replace(/<\/script/g, "<\\/script") : "{}";
1540
1540
  const rootDir = process.cwd();
1541
- let coreRuntimePath = path3.join(rootDir, "../zenith-core/dist/runtime");
1541
+ let coreRuntimePath = path2.join(rootDir, "../zenith-core/dist/runtime");
1542
1542
  if (!existsSync(coreRuntimePath)) {
1543
- coreRuntimePath = path3.join(rootDir, "../zenith-core/core");
1543
+ coreRuntimePath = path2.join(rootDir, "../zenith-core/core");
1544
1544
  }
1545
1545
  let reactivityJS = "";
1546
1546
  let lifecycleJS = "";
1547
1547
  try {
1548
- let reactivityFile = path3.join(coreRuntimePath, "reactivity/index.js");
1548
+ let reactivityFile = path2.join(coreRuntimePath, "reactivity/index.js");
1549
1549
  if (!existsSync(reactivityFile))
1550
- reactivityFile = path3.join(coreRuntimePath, "reactivity/index.ts");
1551
- let lifecycleFile = path3.join(coreRuntimePath, "lifecycle/index.js");
1550
+ reactivityFile = path2.join(coreRuntimePath, "reactivity/index.ts");
1551
+ let lifecycleFile = path2.join(coreRuntimePath, "lifecycle/index.js");
1552
1552
  if (!existsSync(lifecycleFile))
1553
- lifecycleFile = path3.join(coreRuntimePath, "lifecycle/index.ts");
1553
+ lifecycleFile = path2.join(coreRuntimePath, "lifecycle/index.ts");
1554
1554
  if (existsSync(reactivityFile) && reactivityFile.endsWith(".js")) {
1555
1555
  reactivityJS = transformExportsToGlobal(readFileSync(reactivityFile, "utf-8"));
1556
1556
  }
@@ -1563,8 +1563,8 @@ function generateBundleJS(pluginData) {
1563
1563
  }
1564
1564
  }
1565
1565
  if (!reactivityJS || !lifecycleJS) {
1566
- const compilerRoot = path3.resolve(path3.dirname(import.meta.url.replace("file://", "")), "../../zenith-compiler");
1567
- const nativeRuntimePath = path3.join(compilerRoot, "native/compiler-native/src/hydration_runtime.js");
1566
+ const compilerRoot = path2.resolve(path2.dirname(import.meta.url.replace("file://", "")), "../../zenith-compiler");
1567
+ const nativeRuntimePath = path2.join(compilerRoot, "native/compiler-native/src/hydration_runtime.js");
1568
1568
  if (existsSync(nativeRuntimePath)) {
1569
1569
  const nativeJS = readFileSync(nativeRuntimePath, "utf-8");
1570
1570
  reactivityJS = nativeJS;
@@ -3344,7 +3344,7 @@ function parseAst(sourceText, options, filename) {
3344
3344
  }
3345
3345
 
3346
3346
  // ../node_modules/.bun/rolldown@1.0.0-rc.3/node_modules/rolldown/dist/shared/bindingify-input-options-CorDub0q.mjs
3347
- import path4 from "path";
3347
+ import path3 from "path";
3348
3348
 
3349
3349
  // ../node_modules/.bun/@rolldown+pluginutils@1.0.0-rc.3/node_modules/@rolldown/pluginutils/dist/filter/composable-filters.js
3350
3350
  class And {
@@ -4629,9 +4629,9 @@ function preProcessSourceMap(ret, id2) {
4629
4629
  return;
4630
4630
  let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
4631
4631
  if (!isEmptySourcemapFiled(map.sources)) {
4632
- const directory = path4.dirname(id2) || ".";
4632
+ const directory = path3.dirname(id2) || ".";
4633
4633
  const sourceRoot = map.sourceRoot || ".";
4634
- map.sources = map.sources.map((source) => path4.resolve(directory, sourceRoot, source));
4634
+ map.sources = map.sources.map((source) => path3.resolve(directory, sourceRoot, source));
4635
4635
  }
4636
4636
  return map;
4637
4637
  }
@@ -5675,7 +5675,7 @@ function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
5675
5675
 
5676
5676
  // ../node_modules/.bun/rolldown@1.0.0-rc.3/node_modules/rolldown/dist/shared/rolldown-build-CGNuOAoF.mjs
5677
5677
  import { Worker } from "worker_threads";
5678
- import path5, { sep } from "path";
5678
+ import path4, { sep } from "path";
5679
5679
  import { formatWithOptions, styleText } from "util";
5680
5680
  import process$12 from "process";
5681
5681
  import * as tty from "tty";
@@ -5761,9 +5761,9 @@ var getExtendedLogMessage = (log2) => {
5761
5761
  return prefix + log2.message;
5762
5762
  };
5763
5763
  function relativeId(id2) {
5764
- if (!path5.isAbsolute(id2))
5764
+ if (!path4.isAbsolute(id2))
5765
5765
  return id2;
5766
- return path5.relative(path5.resolve(), id2);
5766
+ return path4.relative(path4.resolve(), id2);
5767
5767
  }
5768
5768
  var ENUMERATED_INPUT_PLUGIN_HOOK_NAMES = [
5769
5769
  "options",
@@ -7421,12 +7421,12 @@ function validateOption(key, options) {
7421
7421
  if (!parsed.success) {
7422
7422
  const errors = parsed.issues.map((issue) => {
7423
7423
  let issueMsg = issue.message;
7424
- const issuePaths = issue.path.map((path6) => path6.key);
7424
+ const issuePaths = issue.path.map((path5) => path5.key);
7425
7425
  if (issue.type === "union") {
7426
7426
  const subIssue = issue.issues?.find((i) => !(i.type !== issue.received && i.input === issue.input));
7427
7427
  if (subIssue) {
7428
7428
  if (subIssue.path)
7429
- issuePaths.push(subIssue.path.map((path6) => path6.key));
7429
+ issuePaths.push(subIssue.path.map((path5) => path5.key));
7430
7430
  issueMsg = subIssue.message;
7431
7431
  }
7432
7432
  }
@@ -9024,7 +9024,7 @@ async function bundlePageScript(plan) {
9024
9024
  }
9025
9025
  // ../zenith-bundler/dist/css.js
9026
9026
  import { spawn, spawnSync } from "child_process";
9027
- import path6 from "path";
9027
+ import path5 from "path";
9028
9028
  import fs2 from "fs";
9029
9029
  function compileCss(options) {
9030
9030
  const startTime = performance.now();
@@ -9051,7 +9051,7 @@ function compileCss(options) {
9051
9051
  args2.push("--minify");
9052
9052
  }
9053
9053
  const result = spawnSync("bunx", args2, {
9054
- cwd: path6.dirname(input),
9054
+ cwd: path5.dirname(input),
9055
9055
  encoding: "utf-8",
9056
9056
  stdio: useStdout ? ["pipe", "pipe", "pipe"] : ["pipe", "inherit", "pipe"],
9057
9057
  env: { ...process.env }
@@ -9108,7 +9108,7 @@ async function compileCssAsync(options) {
9108
9108
  args2.push("--minify");
9109
9109
  }
9110
9110
  const child = spawn("bunx", args2, {
9111
- cwd: path6.dirname(input),
9111
+ cwd: path5.dirname(input),
9112
9112
  stdio: useStdout ? ["pipe", "pipe", "pipe"] : ["pipe", "inherit", "pipe"],
9113
9113
  env: { ...process.env }
9114
9114
  });
@@ -9158,10 +9158,10 @@ async function compileCssAsync(options) {
9158
9158
  });
9159
9159
  }
9160
9160
  function resolveGlobalsCss(projectRoot) {
9161
- const globalsPath = path6.join(projectRoot, "src", "styles", "globals.css");
9161
+ const globalsPath = path5.join(projectRoot, "src", "styles", "globals.css");
9162
9162
  if (fs2.existsSync(globalsPath))
9163
9163
  return globalsPath;
9164
- const globalPath = path6.join(projectRoot, "src", "styles", "global.css");
9164
+ const globalPath = path5.join(projectRoot, "src", "styles", "global.css");
9165
9165
  if (fs2.existsSync(globalPath))
9166
9166
  return globalPath;
9167
9167
  return null;
@@ -9271,12 +9271,12 @@ class InvariantError extends CompilerError {
9271
9271
 
9272
9272
  // ../zenith-compiler/dist/core/config/loader.js
9273
9273
  import fs3 from "fs";
9274
- import path7 from "path";
9274
+ import path6 from "path";
9275
9275
  async function loadZenithConfig(projectRoot) {
9276
9276
  const configPaths = [
9277
- path7.join(projectRoot, "zenith.config.ts"),
9278
- path7.join(projectRoot, "zenith.config.js"),
9279
- path7.join(projectRoot, "zenith.config.mjs")
9277
+ path6.join(projectRoot, "zenith.config.ts"),
9278
+ path6.join(projectRoot, "zenith.config.js"),
9279
+ path6.join(projectRoot, "zenith.config.mjs")
9280
9280
  ];
9281
9281
  let configPath = null;
9282
9282
  for (const p of configPaths) {
@@ -9432,7 +9432,7 @@ async function compile(source, filePath, options) {
9432
9432
 
9433
9433
  // ../zenith-router/dist/manifest.js
9434
9434
  import fs4 from "fs";
9435
- import path8 from "path";
9435
+ import path7 from "path";
9436
9436
 
9437
9437
  // ../zenith-router/index.js
9438
9438
  import { createRequire as createRequire2 } from "module";
@@ -9453,7 +9453,7 @@ function discoverPages(pagesDir) {
9453
9453
  return;
9454
9454
  const entries = fs4.readdirSync(dir, { withFileTypes: true });
9455
9455
  for (const entry of entries) {
9456
- const fullPath = path8.join(dir, entry.name);
9456
+ const fullPath = path7.join(dir, entry.name);
9457
9457
  if (entry.isDirectory()) {
9458
9458
  walk(fullPath);
9459
9459
  } else if (entry.isFile() && entry.name.endsWith(".zen")) {
@@ -9465,9 +9465,9 @@ function discoverPages(pagesDir) {
9465
9465
  return pages;
9466
9466
  }
9467
9467
  function filePathToRoutePath(filePath, pagesDir) {
9468
- const relativePath = path8.relative(pagesDir, filePath);
9468
+ const relativePath = path7.relative(pagesDir, filePath);
9469
9469
  const withoutExt = relativePath.replace(/\.zen$/, "");
9470
- const segmentsList = withoutExt.split(path8.sep);
9470
+ const segmentsList = withoutExt.split(path7.sep);
9471
9471
  const routeSegments = [];
9472
9472
  for (const segment of segmentsList) {
9473
9473
  if (segment === "index")
@@ -9569,7 +9569,7 @@ function generateRouteDefinition(filePath, pagesDir) {
9569
9569
  }
9570
9570
  // src/discovery/layouts.ts
9571
9571
  import * as fs5 from "fs";
9572
- import * as path9 from "path";
9572
+ import * as path8 from "path";
9573
9573
  function discoverLayouts2(layoutsDir) {
9574
9574
  const layouts2 = new Map;
9575
9575
  if (!fs5.existsSync(layoutsDir))
@@ -9577,8 +9577,8 @@ function discoverLayouts2(layoutsDir) {
9577
9577
  const files = fs5.readdirSync(layoutsDir);
9578
9578
  for (const file of files) {
9579
9579
  if (file.endsWith(".zen")) {
9580
- const fullPath = path9.join(layoutsDir, file);
9581
- const name = path9.basename(file, ".zen");
9580
+ const fullPath = path8.join(layoutsDir, file);
9581
+ const name = path8.basename(file, ".zen");
9582
9582
  try {
9583
9583
  const ir = parseZenFile(fullPath, undefined, { mode: "metadata" });
9584
9584
  layouts2.set(name, {
@@ -9600,7 +9600,7 @@ function discoverLayouts2(layoutsDir) {
9600
9600
 
9601
9601
  // src/discovery/componentDiscovery.ts
9602
9602
  import * as fs6 from "fs";
9603
- import * as path10 from "path";
9603
+ import * as path9 from "path";
9604
9604
  function discoverComponents2(baseDir) {
9605
9605
  const components = new Map;
9606
9606
  if (!fs6.existsSync(baseDir))
@@ -9608,11 +9608,11 @@ function discoverComponents2(baseDir) {
9608
9608
  const walk = (dir) => {
9609
9609
  const files = fs6.readdirSync(dir);
9610
9610
  for (const file of files) {
9611
- const fullPath = path10.join(dir, file);
9611
+ const fullPath = path9.join(dir, file);
9612
9612
  if (fs6.statSync(fullPath).isDirectory()) {
9613
9613
  walk(fullPath);
9614
9614
  } else if (file.endsWith(".zen")) {
9615
- const name = path10.basename(file, ".zen");
9615
+ const name = path9.basename(file, ".zen");
9616
9616
  try {
9617
9617
  const ir = parseZenFile(fullPath, undefined, { mode: "metadata" });
9618
9618
  components.set(name, {
@@ -9666,7 +9666,7 @@ async function dev(options = {}) {
9666
9666
  const globalsCssPath = resolveGlobalsCss(rootDir);
9667
9667
  let compiledCss = "";
9668
9668
  if (globalsCssPath) {
9669
- debug(`Compiling CSS: ${path11.relative(rootDir, globalsCssPath)}`);
9669
+ debug(`Compiling CSS: ${path10.relative(rootDir, globalsCssPath)}`);
9670
9670
  const cssResult = await compileCssAsync({ input: globalsCssPath, output: ":memory:" });
9671
9671
  if (cssResult.success) {
9672
9672
  compiledCss = cssResult.css;
@@ -9702,8 +9702,8 @@ async function dev(options = {}) {
9702
9702
  ]);
9703
9703
  async function compilePageInMemory(pagePath) {
9704
9704
  try {
9705
- const layoutsDir = path11.join(pagesDir, "../layouts");
9706
- const componentsDir = path11.join(pagesDir, "../components");
9705
+ const layoutsDir = path10.join(pagesDir, "../layouts");
9706
+ const componentsDir = path10.join(pagesDir, "../components");
9707
9707
  const layouts2 = discoverLayouts2(layoutsDir);
9708
9708
  const components = new Map([...layouts2]);
9709
9709
  if (fs7.existsSync(componentsDir)) {
@@ -9738,19 +9738,36 @@ async function dev(options = {}) {
9738
9738
  }
9739
9739
  }
9740
9740
  async function generateDevHTML(page) {
9741
- const scriptTag = `<script type="module">
9741
+ const injection = `
9742
+ <!-- Zenith Dev Injection -->
9743
+ <link rel="stylesheet" href="/assets/styles.css">
9744
+ <script>window.zenith = window.zenith || {};</script>
9745
+ <script src="/runtime.js"></script>
9746
+ <script type="importmap">
9747
+ {
9748
+ "imports": {
9749
+ "zenith:core": "/zenith-core.js",
9750
+ "@zenithbuild/core": "/zenith-core.js",
9751
+ "@zenithbuild/runtime": "/zenith-core.js",
9752
+ "@zenithbuild/router": "/zenith-router.js",
9753
+ "gsap": "https://esm.sh/gsap"
9754
+ }
9755
+ }
9756
+ </script>
9757
+ <script type="module">
9742
9758
  ${page.script}
9743
- </script>`;
9744
- let html = page.html.includes("</body>") ? page.html.replace("</body>", `${scriptTag}
9759
+ </script>
9760
+ `;
9761
+ let html = page.html.includes("</body>") ? page.html.replace("</body>", `${injection}
9745
9762
  </body>`) : `${page.html}
9746
- ${scriptTag}`;
9763
+ ${injection}`;
9747
9764
  if (!html.trimStart().toLowerCase().startsWith("<!doctype")) {
9748
9765
  html = `<!DOCTYPE html>
9749
9766
  ${html}`;
9750
9767
  }
9751
9768
  return html;
9752
9769
  }
9753
- const watcher = fs7.watch(path11.join(pagesDir, ".."), { recursive: true }, async (event, filename) => {
9770
+ const watcher = fs7.watch(path10.join(pagesDir, ".."), { recursive: true }, async (event, filename) => {
9754
9771
  if (!filename)
9755
9772
  return;
9756
9773
  await runPluginHooks("cli:dev:file-change", {
@@ -9794,12 +9811,25 @@ ${html}`;
9794
9811
  const startTime = performance.now();
9795
9812
  const url = new URL(req.url);
9796
9813
  const pathname = url.pathname;
9797
- const ext = path11.extname(pathname).toLowerCase();
9814
+ const ext = path10.extname(pathname).toLowerCase();
9798
9815
  if (pathname === "/hmr") {
9799
9816
  const upgraded = server2.upgrade(req, { data: { timestamp: Date.now() } });
9800
9817
  if (upgraded)
9801
9818
  return;
9802
9819
  }
9820
+ if (pathname.startsWith("/assets/")) {
9821
+ let assetPath = path10.join(rootDir, "dist", pathname);
9822
+ if (!fs7.existsSync(assetPath)) {
9823
+ assetPath = path10.join(rootDir, "src", "dist", pathname);
9824
+ }
9825
+ if (fs7.existsSync(assetPath)) {
9826
+ const content = fs7.readFileSync(assetPath);
9827
+ const contentType = ext === ".css" ? "text/css" : ext === ".js" ? "application/javascript" : "application/octet-stream";
9828
+ return new Response(content, {
9829
+ headers: { "Content-Type": contentType }
9830
+ });
9831
+ }
9832
+ }
9803
9833
  if (pathname === "/runtime.js") {
9804
9834
  const payloads = await collectHookReturns("cli:runtime:collect", hookCtx);
9805
9835
  const envelope = buildRuntimeEnvelope(payloads);
@@ -9809,7 +9839,38 @@ ${html}`;
9809
9839
  route("GET", pathname, 200, Math.round(performance.now() - startTime), 0, Math.round(performance.now() - startTime));
9810
9840
  return response;
9811
9841
  }
9812
- if (pathname === "/assets/styles.css") {
9842
+ if (pathname === "/zenith-core.js") {
9843
+ try {
9844
+ const entry = __require.resolve("@zenithbuild/core");
9845
+ const build = await Bun.build({
9846
+ entrypoints: [entry],
9847
+ external: ["@zenithbuild/router"],
9848
+ target: "browser",
9849
+ format: "esm"
9850
+ });
9851
+ if (build.success) {
9852
+ return new Response(build.outputs[0]);
9853
+ }
9854
+ } catch (e3) {
9855
+ error("Failed to bundle zenith-core: " + e3);
9856
+ }
9857
+ }
9858
+ if (pathname === "/zenith-router.js") {
9859
+ try {
9860
+ const entry = __require.resolve("/Users/judahsullivan/Personal/zenith/zenith-router/dist/index.js");
9861
+ const build = await Bun.build({
9862
+ entrypoints: [entry],
9863
+ target: "browser",
9864
+ format: "esm"
9865
+ });
9866
+ if (build.success) {
9867
+ return new Response(build.outputs[0]);
9868
+ }
9869
+ } catch (e3) {
9870
+ error("Failed to bundle zenith-router: " + e3);
9871
+ }
9872
+ }
9873
+ if (pathname === "/assets/styles.css" && compiledCss) {
9813
9874
  const response = new Response(compiledCss, {
9814
9875
  headers: { "Content-Type": "text/css; charset=utf-8" }
9815
9876
  });
@@ -9824,7 +9885,7 @@ ${html}`;
9824
9885
  return response;
9825
9886
  }
9826
9887
  if (STATIC_EXTENSIONS.has(ext)) {
9827
- const publicPath = path11.join(pagesDir, "../public", pathname);
9888
+ const publicPath = path10.join(pagesDir, "../public", pathname);
9828
9889
  if (fs7.existsSync(publicPath)) {
9829
9890
  const response = new Response(Bun.file(publicPath));
9830
9891
  route("GET", pathname, 200, Math.round(performance.now() - startTime), 0, Math.round(performance.now() - startTime));
@@ -9874,32 +9935,32 @@ ${html}`;
9874
9935
  await new Promise(() => {});
9875
9936
  }
9876
9937
  function findPageForRoute(route2, pagesDir) {
9877
- const exactPath = path11.join(pagesDir, route2 === "/" ? "index.zen" : `${route2.slice(1)}.zen`);
9938
+ const exactPath = path10.join(pagesDir, route2 === "/" ? "index.zen" : `${route2.slice(1)}.zen`);
9878
9939
  if (fs7.existsSync(exactPath))
9879
9940
  return exactPath;
9880
- const indexPath = path11.join(pagesDir, route2 === "/" ? "index.zen" : `${route2.slice(1)}/index.zen`);
9941
+ const indexPath = path10.join(pagesDir, route2 === "/" ? "index.zen" : `${route2.slice(1)}/index.zen`);
9881
9942
  if (fs7.existsSync(indexPath))
9882
9943
  return indexPath;
9883
9944
  const segments = route2 === "/" ? [] : route2.slice(1).split("/").filter(Boolean);
9884
9945
  for (let i2 = segments.length - 1;i2 >= 0; i2--) {
9885
9946
  const staticPart = segments.slice(0, i2).join("/");
9886
- const baseDir = staticPart ? path11.join(pagesDir, staticPart) : pagesDir;
9887
- const singleDynamicPath = path11.join(baseDir, "[slug].zen");
9947
+ const baseDir = staticPart ? path10.join(pagesDir, staticPart) : pagesDir;
9948
+ const singleDynamicPath = path10.join(baseDir, "[slug].zen");
9888
9949
  if (fs7.existsSync(singleDynamicPath))
9889
9950
  return singleDynamicPath;
9890
- const catchAllPath = path11.join(baseDir, "[...slug].zen");
9951
+ const catchAllPath = path10.join(baseDir, "[...slug].zen");
9891
9952
  if (fs7.existsSync(catchAllPath)) {
9892
9953
  return catchAllPath;
9893
9954
  }
9894
9955
  }
9895
- const rootCatchAll = path11.join(pagesDir, "[...slug].zen");
9956
+ const rootCatchAll = path10.join(pagesDir, "[...slug].zen");
9896
9957
  if (fs7.existsSync(rootCatchAll))
9897
9958
  return rootCatchAll;
9898
9959
  return null;
9899
9960
  }
9900
9961
 
9901
9962
  // src/commands/preview.ts
9902
- import path12 from "path";
9963
+ import path11 from "path";
9903
9964
  var {serve: serve2 } = globalThis.Bun;
9904
9965
  async function preview(options = {}) {
9905
9966
  const project = requireProject();
@@ -9929,16 +9990,16 @@ async function preview(options = {}) {
9929
9990
  async fetch(req) {
9930
9991
  const url = new URL(req.url);
9931
9992
  const pathname = url.pathname;
9932
- const ext = path12.extname(pathname).toLowerCase();
9993
+ const ext = path11.extname(pathname).toLowerCase();
9933
9994
  if (STATIC_EXTENSIONS.has(ext)) {
9934
- const filePath = path12.join(distDir, pathname);
9995
+ const filePath = path11.join(distDir, pathname);
9935
9996
  const file = Bun.file(filePath);
9936
9997
  if (await file.exists()) {
9937
9998
  return new Response(file);
9938
9999
  }
9939
10000
  return new Response("Not found", { status: 404 });
9940
10001
  }
9941
- const indexPath = path12.join(distDir, "index.html");
10002
+ const indexPath = path11.join(distDir, "index.html");
9942
10003
  const indexFile = Bun.file(indexPath);
9943
10004
  if (await indexFile.exists()) {
9944
10005
  return new Response(indexFile, {
@@ -9955,12 +10016,13 @@ async function preview(options = {}) {
9955
10016
 
9956
10017
  // src/ssg-build.ts
9957
10018
  import fs8 from "fs";
10019
+ import path12 from "path";
9958
10020
  async function compilePage(pagePath, pagesDir, baseDir = process.cwd()) {
9959
10021
  const source = fs8.readFileSync(pagePath, "utf-8");
9960
10022
  const analysis = analyzePageSource(source);
9961
- const srcDir = path.dirname(pagesDir);
9962
- const componentsDir = path.join(srcDir, "components");
9963
- const layoutsDir = path.join(srcDir, "layouts");
10023
+ const srcDir = path12.dirname(pagesDir);
10024
+ const componentsDir = path12.join(srcDir, "components");
10025
+ const layoutsDir = path12.join(srcDir, "layouts");
9964
10026
  const components = new Map;
9965
10027
  if (fs8.existsSync(componentsDir)) {
9966
10028
  const comps = discoverComponents2(componentsDir);
@@ -10077,7 +10139,7 @@ ${page.pageScript}
10077
10139
  `;
10078
10140
  }
10079
10141
  async function buildSSG(options) {
10080
- const { pagesDir, outDir, baseDir = path.dirname(pagesDir) } = options;
10142
+ const { pagesDir, outDir, baseDir = path12.dirname(pagesDir) } = options;
10081
10143
  console.log("\uD83D\uDD28 Zenith SSG Build");
10082
10144
  console.log(` Pages: ${pagesDir}`);
10083
10145
  console.log(` Output: ${outDir}`);
@@ -10105,7 +10167,7 @@ async function buildSSG(options) {
10105
10167
  fs8.rmSync(outDir, { recursive: true, force: true });
10106
10168
  }
10107
10169
  fs8.mkdirSync(outDir, { recursive: true });
10108
- fs8.mkdirSync(path.join(outDir, "assets"), { recursive: true });
10170
+ fs8.mkdirSync(path12.join(outDir, "assets"), { recursive: true });
10109
10171
  const pageFiles = discoverPages(pagesDir);
10110
10172
  if (pageFiles.length === 0) {
10111
10173
  console.warn("\u26A0\uFE0F No pages found in", pagesDir);
@@ -10115,7 +10177,7 @@ async function buildSSG(options) {
10115
10177
  const compiledPages = [];
10116
10178
  let hasHydratedPages = false;
10117
10179
  for (const pageFile of pageFiles) {
10118
- const relativePath = path.relative(pagesDir, pageFile);
10180
+ const relativePath = path12.relative(pagesDir, pageFile);
10119
10181
  console.log(` Compiling: ${relativePath}`);
10120
10182
  try {
10121
10183
  const compiled = await compilePage(pageFile, pagesDir, baseDir);
@@ -10136,8 +10198,8 @@ async function buildSSG(options) {
10136
10198
  let globalStyles = "";
10137
10199
  const globalsCssPath = resolveGlobalsCss(baseDir);
10138
10200
  if (globalsCssPath) {
10139
- console.log("\uD83D\uDCE6 Compiling CSS:", path.relative(baseDir, globalsCssPath));
10140
- const cssOutputPath = path.join(outDir, "assets", "styles.css");
10201
+ console.log("\uD83D\uDCE6 Compiling CSS:", path12.relative(baseDir, globalsCssPath));
10202
+ const cssOutputPath = path12.join(outDir, "assets", "styles.css");
10141
10203
  const result = compileCss({
10142
10204
  input: globalsCssPath,
10143
10205
  output: cssOutputPath,
@@ -10152,14 +10214,14 @@ async function buildSSG(options) {
10152
10214
  }
10153
10215
  if (hasHydratedPages) {
10154
10216
  const bundleJS = generateBundleJS(pluginEnvelope);
10155
- fs8.writeFileSync(path.join(outDir, "assets", "bundle.js"), bundleJS);
10217
+ fs8.writeFileSync(path12.join(outDir, "assets", "bundle.js"), bundleJS);
10156
10218
  console.log("\uD83D\uDCE6 Generated assets/bundle.js (with plugin data)");
10157
10219
  }
10158
10220
  for (const page of compiledPages) {
10159
- const pageOutDir = path.join(outDir, page.outputDir);
10221
+ const pageOutDir = path12.join(outDir, page.outputDir);
10160
10222
  fs8.mkdirSync(pageOutDir, { recursive: true });
10161
10223
  const html = generatePageHTML(page, globalStyles, pluginEnvelope);
10162
- fs8.writeFileSync(path.join(pageOutDir, "index.html"), html);
10224
+ fs8.writeFileSync(path12.join(pageOutDir, "index.html"), html);
10163
10225
  if (page.pageScript) {
10164
10226
  const pageJsName = page.routePath === "/" ? "page_index.js" : `page_${page.routePath.replace(/^\//, "").replace(/\//g, "_")}.js`;
10165
10227
  const pageJS = generatePageJS(page);
@@ -10178,28 +10240,28 @@ async function buildSSG(options) {
10178
10240
  const plan = {
10179
10241
  ...page.bundlePlan,
10180
10242
  entry: pageJS,
10181
- resolveRoots: [path.join(baseDir, "node_modules"), "node_modules"]
10243
+ resolveRoots: [path12.join(baseDir, "node_modules"), "node_modules"]
10182
10244
  };
10183
10245
  bundledJS = await bundlePageScript(plan);
10184
10246
  }
10185
- fs8.writeFileSync(path.join(outDir, "assets", pageJsName), bundledJS);
10247
+ fs8.writeFileSync(path12.join(outDir, "assets", pageJsName), bundledJS);
10186
10248
  }
10187
10249
  console.log(`\u2705 ${page.outputDir}/index.html`);
10188
10250
  }
10189
- const faviconPath = path.join(baseDir, "favicon.ico");
10251
+ const faviconPath = path12.join(baseDir, "favicon.ico");
10190
10252
  if (fs8.existsSync(faviconPath)) {
10191
- fs8.copyFileSync(faviconPath, path.join(outDir, "favicon.ico"));
10253
+ fs8.copyFileSync(faviconPath, path12.join(outDir, "favicon.ico"));
10192
10254
  console.log("\uD83D\uDCE6 Copied favicon.ico");
10193
10255
  }
10194
10256
  const custom404Candidates = ["404.zen", "+404.zen", "not-found.zen"];
10195
10257
  let has404 = false;
10196
10258
  for (const candidate of custom404Candidates) {
10197
- const custom404Path = path.join(pagesDir, candidate);
10259
+ const custom404Path = path12.join(pagesDir, candidate);
10198
10260
  if (fs8.existsSync(custom404Path)) {
10199
10261
  try {
10200
10262
  const compiled = await compilePage(custom404Path, pagesDir, baseDir);
10201
10263
  const html = generatePageHTML(compiled, globalStyles, pluginEnvelope);
10202
- fs8.writeFileSync(path.join(outDir, "404.html"), html);
10264
+ fs8.writeFileSync(path12.join(outDir, "404.html"), html);
10203
10265
  console.log("\uD83D\uDCE6 Generated 404.html (custom)");
10204
10266
  has404 = true;
10205
10267
  if (compiled.pageScript) {
@@ -10209,11 +10271,11 @@ async function buildSSG(options) {
10209
10271
  const plan = {
10210
10272
  ...compiled.bundlePlan,
10211
10273
  entry: pageJS,
10212
- resolveRoots: [path.join(baseDir, "node_modules"), "node_modules"]
10274
+ resolveRoots: [path12.join(baseDir, "node_modules"), "node_modules"]
10213
10275
  };
10214
10276
  bundledJS = await bundlePageScript(plan);
10215
10277
  }
10216
- fs8.writeFileSync(path.join(outDir, "assets", "page_404.js"), bundledJS);
10278
+ fs8.writeFileSync(path12.join(outDir, "assets", "page_404.js"), bundledJS);
10217
10279
  }
10218
10280
  } catch (error4) {
10219
10281
  console.warn(` \u26A0\uFE0F Could not compile ${candidate}: ${error4.message}`);
@@ -10247,7 +10309,7 @@ async function buildSSG(options) {
10247
10309
  </div>
10248
10310
  </body>
10249
10311
  </html>`;
10250
- fs8.writeFileSync(path.join(outDir, "404.html"), default404HTML);
10312
+ fs8.writeFileSync(path12.join(outDir, "404.html"), default404HTML);
10251
10313
  console.log("\uD83D\uDCE6 Generated 404.html (default)");
10252
10314
  }
10253
10315
  console.log("");