@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 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") {
@@ -1532,25 +1532,25 @@ function showServerPanel(options) {
1532
1532
  `);
1533
1533
  }
1534
1534
 
1535
- // ../zenith-bundler/src/bundle-generator.ts
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;
@@ -2338,7 +2338,7 @@ ${lifecycleJS ? ` // ============================================
2338
2338
  function transformExportsToGlobal(source) {
2339
2339
  return source.replace(/export\s+(const|function|class)\s+(\w+)/g, "var $2");
2340
2340
  }
2341
- // ../zenith-bundler/src/build-analyzer.ts
2341
+ // ../zenith-bundler/dist/build-analyzer.js
2342
2342
  function analyzePageSource(source) {
2343
2343
  const scriptMatch = source.match(/<script[^>]*>([\s\S]*?)<\/script>/i);
2344
2344
  const scriptContent = scriptMatch?.[1] || "";
@@ -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
  }
@@ -8978,7 +8978,7 @@ if (isMainThread) {
8978
8978
  }
8979
8979
  var BindingMagicString = import_binding6.BindingMagicString;
8980
8980
 
8981
- // ../zenith-bundler/src/bundler.ts
8981
+ // ../zenith-bundler/dist/bundler.js
8982
8982
  async function bundlePageScript(plan) {
8983
8983
  const VIRTUAL_ENTRY = "\x00zenith:entry.tsx";
8984
8984
  const virtualModules = new Map;
@@ -9022,9 +9022,9 @@ async function bundlePageScript(plan) {
9022
9022
  }
9023
9023
  return output[0].code;
9024
9024
  }
9025
- // ../zenith-bundler/src/css.ts
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,15 +9158,15 @@ 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;
9168
9168
  }
9169
- // ../zenith-bundler/src/runtime-generator.ts
9169
+ // ../zenith-bundler/dist/runtime-generator.js
9170
9170
  function generateRuntime(manifest, isDev = false) {
9171
9171
  const routes = JSON.stringify(manifest.routes);
9172
9172
  return {
@@ -9187,153 +9187,14 @@ if (window.zenith) {
9187
9187
  `
9188
9188
  };
9189
9189
  }
9190
- // ../zenith-router/src/manifest.ts
9191
- import fs3 from "fs";
9192
- import path7 from "path";
9193
-
9194
- // ../zenith-router/index.js
9195
- import { createRequire as createRequire2 } from "module";
9196
- var require2 = createRequire2(import.meta.url);
9197
- var native = require2("./zenith-router.node");
9198
- var { generateRouteManifestNative, renderRouteNative, resolveRouteNative, generateRuntimeRouterNative, SegmentType, routerBridge } = native;
9199
-
9200
- // ../zenith-router/src/manifest.ts
9201
- var SEGMENT_SCORES = {
9202
- [SegmentType.Static]: 10,
9203
- [SegmentType.Dynamic]: 5,
9204
- [SegmentType.CatchAll]: 1,
9205
- [SegmentType.OptionalCatchAll]: 0
9206
- };
9207
- function discoverPages(pagesDir) {
9208
- const pages = [];
9209
- function walk(dir) {
9210
- if (!fs3.existsSync(dir))
9211
- return;
9212
- const entries = fs3.readdirSync(dir, { withFileTypes: true });
9213
- for (const entry of entries) {
9214
- const fullPath = path7.join(dir, entry.name);
9215
- if (entry.isDirectory()) {
9216
- walk(fullPath);
9217
- } else if (entry.isFile() && entry.name.endsWith(".zen")) {
9218
- pages.push(fullPath);
9219
- }
9220
- }
9221
- }
9222
- walk(pagesDir);
9223
- return pages;
9224
- }
9225
- function filePathToRoutePath(filePath, pagesDir) {
9226
- const relativePath = path7.relative(pagesDir, filePath);
9227
- const withoutExt = relativePath.replace(/\.zen$/, "");
9228
- const segmentsList = withoutExt.split(path7.sep);
9229
- const routeSegments = [];
9230
- for (const segment of segmentsList) {
9231
- if (segment === "index")
9232
- continue;
9233
- const optionalCatchAllMatch = segment.match(/^\[\[\.\.\.(\w+)\]\]$/);
9234
- if (optionalCatchAllMatch) {
9235
- routeSegments.push(`*${optionalCatchAllMatch[1]}?`);
9236
- continue;
9237
- }
9238
- const catchAllMatch = segment.match(/^\[\.\.\.(\w+)\]$/);
9239
- if (catchAllMatch) {
9240
- routeSegments.push(`*${catchAllMatch[1]}`);
9241
- continue;
9242
- }
9243
- const dynamicMatch = segment.match(/^\[(\w+)\]$/);
9244
- if (dynamicMatch) {
9245
- routeSegments.push(`:${dynamicMatch[1]}`);
9246
- continue;
9247
- }
9248
- routeSegments.push(segment);
9249
- }
9250
- const routePath = "/" + routeSegments.join("/");
9251
- return routePath === "/" ? "/" : routePath.replace(/\/$/, "");
9252
- }
9253
- function parseRouteSegments(routePath) {
9254
- if (routePath === "/")
9255
- return [];
9256
- const segmentsList = routePath.slice(1).split("/");
9257
- const parsed = [];
9258
- for (const segment of segmentsList) {
9259
- if (segment.startsWith("*") && segment.endsWith("?")) {
9260
- parsed.push({ segmentType: SegmentType.OptionalCatchAll, paramName: segment.slice(1, -1), raw: segment });
9261
- continue;
9262
- }
9263
- if (segment.startsWith("*")) {
9264
- parsed.push({ segmentType: SegmentType.CatchAll, paramName: segment.slice(1), raw: segment });
9265
- continue;
9266
- }
9267
- if (segment.startsWith(":")) {
9268
- parsed.push({ segmentType: SegmentType.Dynamic, paramName: segment.slice(1), raw: segment });
9269
- continue;
9270
- }
9271
- parsed.push({ segmentType: SegmentType.Static, raw: segment });
9272
- }
9273
- return parsed;
9274
- }
9275
- function calculateRouteScore(segments) {
9276
- if (segments.length === 0)
9277
- return 100;
9278
- let score = 0;
9279
- for (const segment of segments) {
9280
- score += SEGMENT_SCORES[segment.segmentType];
9281
- }
9282
- const staticCount = segments.filter((s2) => s2.segmentType === SegmentType.Static).length;
9283
- score += staticCount * 2;
9284
- return score;
9285
- }
9286
- function extractParamNames(segments) {
9287
- return segments.filter((s2) => s2.paramName !== undefined).map((s2) => s2.paramName);
9288
- }
9289
- function routePathToRegex(routePath) {
9290
- if (routePath === "/")
9291
- return /^\/$/;
9292
- const segmentsList = routePath.slice(1).split("/");
9293
- const regexParts = [];
9294
- for (let i2 = 0;i2 < segmentsList.length; i2++) {
9295
- const segment = segmentsList[i2];
9296
- if (!segment)
9297
- continue;
9298
- if (segment.startsWith("*") && segment.endsWith("?")) {
9299
- regexParts.push("(?:\\/(.*))?");
9300
- continue;
9301
- }
9302
- if (segment.startsWith("*")) {
9303
- regexParts.push("\\/(.+)");
9304
- continue;
9305
- }
9306
- if (segment.startsWith(":")) {
9307
- regexParts.push("\\/([^/]+)");
9308
- continue;
9309
- }
9310
- const escaped = segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9311
- regexParts.push(`\\/${escaped}`);
9312
- }
9313
- return new RegExp(`^${regexParts.join("")}\\/?$`);
9314
- }
9315
- function generateRouteDefinition(filePath, pagesDir) {
9316
- const routePath = filePathToRoutePath(filePath, pagesDir);
9317
- const segments = parseRouteSegments(routePath);
9318
- const paramNames = extractParamNames(segments);
9319
- const score = calculateRouteScore(segments);
9320
- return {
9321
- path: routePath,
9322
- paramNames,
9323
- score,
9324
- filePath,
9325
- regex: routePathToRegex(routePath)
9326
- };
9327
- }
9328
-
9329
9190
  // ../zenith-compiler/dist/parseZenFile.js
9330
9191
  import { readFileSync as readFileSync2 } from "fs";
9331
- var native2;
9192
+ var native;
9332
9193
  try {
9333
- native2 = require_compiler_native();
9194
+ native = require_compiler_native();
9334
9195
  } catch (e3) {
9335
9196
  try {
9336
- native2 = require_compiler_native();
9197
+ native = require_compiler_native();
9337
9198
  } catch {
9338
9199
  console.error(`
9339
9200
  \x1B[31m[Zenith Critical] Native bridge unavailable.\x1B[0m`);
@@ -9347,7 +9208,7 @@ function parseZenFile(filePath, sourceInput, options = {}) {
9347
9208
  const source = sourceInput ?? readFileSync2(filePath, "utf-8");
9348
9209
  const mode = options.mode ?? "full";
9349
9210
  const useCache = options.useCache ?? process.env.ZENITH_CACHE !== "0";
9350
- if (!native2.parseFullZenNative) {
9211
+ if (!native.parseFullZenNative) {
9351
9212
  throw new Error("[Zenith Critical] Broken native bridge: parseFullZenNative symbol missing. Rebuild required.");
9352
9213
  }
9353
9214
  try {
@@ -9358,7 +9219,7 @@ function parseZenFile(filePath, sourceInput, options = {}) {
9358
9219
  layout: options.layout ?? null,
9359
9220
  props: options.props ?? null
9360
9221
  };
9361
- const result = native2.parseFullZenNative(source, filePath, JSON.stringify(nativeOptions));
9222
+ const result = native.parseFullZenNative(source, filePath, JSON.stringify(nativeOptions));
9362
9223
  return result;
9363
9224
  } catch (error4) {
9364
9225
  throw new Error(`[Zenith Native Fatal] ${error4.message}
@@ -9408,122 +9269,18 @@ class InvariantError extends CompilerError {
9408
9269
  }
9409
9270
  }
9410
9271
 
9411
- // ../zenith-compiler/dist/index.js
9412
- async function compile(source, filePath, options) {
9413
- const opts = options || {};
9414
- const components = opts.components || new Map;
9415
- const finalized = parseZenFile(filePath, source, {
9416
- mode: "full",
9417
- components: components ? Object.fromEntries(components) : {},
9418
- layout: opts.layout,
9419
- props: opts.props,
9420
- useCache: true
9421
- });
9422
- if (finalized.code && (finalized.errorType || finalized.error_type)) {
9423
- throw new InvariantError(finalized.code, finalized.message, finalized.guarantee || "Zenith Invariant Violation", filePath, finalized.line || 1, finalized.column || 1, finalized.context, finalized.hints);
9424
- }
9425
- return {
9426
- ir: finalized.ir,
9427
- compiled: {
9428
- html: finalized.html,
9429
- bindings: finalized.bindings || [],
9430
- scripts: finalized.js || null,
9431
- styles: finalized.styles || []
9432
- },
9433
- finalized: {
9434
- ...finalized,
9435
- js: finalized.js,
9436
- npmImports: finalized.npmImports,
9437
- bundlePlan: finalized.bundlePlan
9438
- }
9439
- };
9440
- }
9441
-
9442
- // src/discovery/layouts.ts
9443
- import * as fs4 from "fs";
9444
- import * as path8 from "path";
9445
- function discoverLayouts(layoutsDir) {
9446
- const layouts = new Map;
9447
- if (!fs4.existsSync(layoutsDir))
9448
- return layouts;
9449
- const files = fs4.readdirSync(layoutsDir);
9450
- for (const file of files) {
9451
- if (file.endsWith(".zen")) {
9452
- const fullPath = path8.join(layoutsDir, file);
9453
- const name = path8.basename(file, ".zen");
9454
- try {
9455
- const ir = parseZenFile(fullPath, undefined, { mode: "metadata" });
9456
- layouts.set(name, {
9457
- name,
9458
- filePath: fullPath,
9459
- props: ir.props || [],
9460
- states: new Map,
9461
- html: ir.template.raw,
9462
- scripts: ir.script ? [ir.script.content] : [],
9463
- styles: ir.styles?.map((s2) => s2.raw) || []
9464
- });
9465
- } catch (e3) {
9466
- console.error(`[Zenith Layout Discovery] Failed to parse layout ${file}:`, e3);
9467
- }
9468
- }
9469
- }
9470
- return layouts;
9471
- }
9472
-
9473
- // src/discovery/componentDiscovery.ts
9474
- import * as fs5 from "fs";
9475
- import * as path9 from "path";
9476
- function discoverComponents(baseDir) {
9477
- const components = new Map;
9478
- if (!fs5.existsSync(baseDir))
9479
- return components;
9480
- const walk = (dir) => {
9481
- const files = fs5.readdirSync(dir);
9482
- for (const file of files) {
9483
- const fullPath = path9.join(dir, file);
9484
- if (fs5.statSync(fullPath).isDirectory()) {
9485
- walk(fullPath);
9486
- } else if (file.endsWith(".zen")) {
9487
- const name = path9.basename(file, ".zen");
9488
- try {
9489
- const ir = parseZenFile(fullPath, undefined, { mode: "metadata" });
9490
- components.set(name, {
9491
- name,
9492
- path: fullPath,
9493
- template: ir.template.raw,
9494
- nodes: ir.template.nodes,
9495
- expressions: ir.template.expressions,
9496
- slots: [],
9497
- props: ir.props || [],
9498
- states: ir.script?.states || {},
9499
- styles: ir.styles?.map((s2) => s2.raw) || [],
9500
- script: ir.script?.raw || null,
9501
- scriptAttributes: ir.script?.attributes || null,
9502
- hasScript: !!ir.script,
9503
- hasStyles: ir.styles?.length > 0
9504
- });
9505
- } catch (e3) {
9506
- console.error(`[Zenith Discovery] Failed to parse component ${file}:`, e3);
9507
- }
9508
- }
9509
- }
9510
- };
9511
- walk(baseDir);
9512
- return components;
9513
- }
9514
-
9515
9272
  // ../zenith-compiler/dist/core/config/loader.js
9516
- import fs6 from "fs";
9517
- import path10 from "path";
9273
+ import fs3 from "fs";
9274
+ import path6 from "path";
9518
9275
  async function loadZenithConfig(projectRoot) {
9519
9276
  const configPaths = [
9520
- path10.join(projectRoot, "zenith.config.ts"),
9521
- path10.join(projectRoot, "zenith.config.js"),
9522
- path10.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")
9523
9280
  ];
9524
9281
  let configPath = null;
9525
9282
  for (const p of configPaths) {
9526
- if (fs6.existsSync(p)) {
9283
+ if (fs3.existsSync(p)) {
9527
9284
  configPath = p;
9528
9285
  break;
9529
9286
  }
@@ -9545,7 +9302,6 @@ async function loadZenithConfig(projectRoot) {
9545
9302
  return { plugins: [] };
9546
9303
  }
9547
9304
  }
9548
-
9549
9305
  // ../zenith-compiler/dist/core/plugins/registry.js
9550
9306
  var pluginDataStore = {};
9551
9307
  function getPluginDataByNamespace(namespace) {
@@ -9595,7 +9351,6 @@ function createPluginContext(projectRoot) {
9595
9351
  options: {}
9596
9352
  };
9597
9353
  }
9598
-
9599
9354
  // ../zenith-compiler/dist/core/plugins/bridge.js
9600
9355
  var hookRegistry = new Map;
9601
9356
  function registerHook(hook, handler) {
@@ -9644,6 +9399,246 @@ function createBridgeAPI() {
9644
9399
  on: registerHook
9645
9400
  };
9646
9401
  }
9402
+ // ../zenith-compiler/dist/index.js
9403
+ async function compile(source, filePath, options) {
9404
+ const opts = options || {};
9405
+ const components = opts.components || new Map;
9406
+ const finalized = parseZenFile(filePath, source, {
9407
+ mode: "full",
9408
+ components: components ? Object.fromEntries(components) : {},
9409
+ layout: opts.layout,
9410
+ props: opts.props,
9411
+ useCache: true
9412
+ });
9413
+ if (finalized.code && (finalized.errorType || finalized.error_type)) {
9414
+ throw new InvariantError(finalized.code, finalized.message, finalized.guarantee || "Zenith Invariant Violation", filePath, finalized.line || 1, finalized.column || 1, finalized.context, finalized.hints);
9415
+ }
9416
+ return {
9417
+ ir: finalized.ir,
9418
+ compiled: {
9419
+ html: finalized.html,
9420
+ bindings: finalized.bindings || [],
9421
+ scripts: finalized.js || null,
9422
+ styles: finalized.styles || []
9423
+ },
9424
+ finalized: {
9425
+ ...finalized,
9426
+ js: finalized.js,
9427
+ npmImports: finalized.npmImports,
9428
+ bundlePlan: finalized.bundlePlan
9429
+ }
9430
+ };
9431
+ }
9432
+
9433
+ // ../zenith-router/dist/manifest.js
9434
+ import fs4 from "fs";
9435
+ import path7 from "path";
9436
+
9437
+ // ../zenith-router/index.js
9438
+ import { createRequire as createRequire2 } from "module";
9439
+ var require2 = createRequire2(import.meta.url);
9440
+ var native2 = require2("./zenith-router.node");
9441
+
9442
+ // ../zenith-router/dist/manifest.js
9443
+ var SEGMENT_SCORES = {
9444
+ [0]: 10,
9445
+ [1]: 5,
9446
+ [2]: 1,
9447
+ [3]: 0
9448
+ };
9449
+ function discoverPages(pagesDir) {
9450
+ const pages = [];
9451
+ function walk(dir) {
9452
+ if (!fs4.existsSync(dir))
9453
+ return;
9454
+ const entries = fs4.readdirSync(dir, { withFileTypes: true });
9455
+ for (const entry of entries) {
9456
+ const fullPath = path7.join(dir, entry.name);
9457
+ if (entry.isDirectory()) {
9458
+ walk(fullPath);
9459
+ } else if (entry.isFile() && entry.name.endsWith(".zen")) {
9460
+ pages.push(fullPath);
9461
+ }
9462
+ }
9463
+ }
9464
+ walk(pagesDir);
9465
+ return pages;
9466
+ }
9467
+ function filePathToRoutePath(filePath, pagesDir) {
9468
+ const relativePath = path7.relative(pagesDir, filePath);
9469
+ const withoutExt = relativePath.replace(/\.zen$/, "");
9470
+ const segmentsList = withoutExt.split(path7.sep);
9471
+ const routeSegments = [];
9472
+ for (const segment of segmentsList) {
9473
+ if (segment === "index")
9474
+ continue;
9475
+ const optionalCatchAllMatch = segment.match(/^\[\[\.\.\.(\w+)\]\]$/);
9476
+ if (optionalCatchAllMatch) {
9477
+ routeSegments.push(`*${optionalCatchAllMatch[1]}?`);
9478
+ continue;
9479
+ }
9480
+ const catchAllMatch = segment.match(/^\[\.\.\.(\w+)\]$/);
9481
+ if (catchAllMatch) {
9482
+ routeSegments.push(`*${catchAllMatch[1]}`);
9483
+ continue;
9484
+ }
9485
+ const dynamicMatch = segment.match(/^\[(\w+)\]$/);
9486
+ if (dynamicMatch) {
9487
+ routeSegments.push(`:${dynamicMatch[1]}`);
9488
+ continue;
9489
+ }
9490
+ routeSegments.push(segment);
9491
+ }
9492
+ const routePath = "/" + routeSegments.join("/");
9493
+ return routePath === "/" ? "/" : routePath.replace(/\/$/, "");
9494
+ }
9495
+ function parseRouteSegments(routePath) {
9496
+ if (routePath === "/")
9497
+ return [];
9498
+ const segmentsList = routePath.slice(1).split("/");
9499
+ const parsed = [];
9500
+ for (const segment of segmentsList) {
9501
+ if (segment.startsWith("*") && segment.endsWith("?")) {
9502
+ parsed.push({ segmentType: 3, paramName: segment.slice(1, -1), raw: segment });
9503
+ continue;
9504
+ }
9505
+ if (segment.startsWith("*")) {
9506
+ parsed.push({ segmentType: 2, paramName: segment.slice(1), raw: segment });
9507
+ continue;
9508
+ }
9509
+ if (segment.startsWith(":")) {
9510
+ parsed.push({ segmentType: 1, paramName: segment.slice(1), raw: segment });
9511
+ continue;
9512
+ }
9513
+ parsed.push({ segmentType: 0, raw: segment });
9514
+ }
9515
+ return parsed;
9516
+ }
9517
+ function calculateRouteScore(segments) {
9518
+ if (segments.length === 0)
9519
+ return 100;
9520
+ let score = 0;
9521
+ for (const segment of segments) {
9522
+ score += SEGMENT_SCORES[segment.segmentType];
9523
+ }
9524
+ const staticCount = segments.filter((s2) => s2.segmentType === 0).length;
9525
+ score += staticCount * 2;
9526
+ return score;
9527
+ }
9528
+ function extractParamNames(segments) {
9529
+ return segments.filter((s2) => s2.paramName !== undefined).map((s2) => s2.paramName);
9530
+ }
9531
+ function routePathToRegex(routePath) {
9532
+ if (routePath === "/")
9533
+ return /^\/$/;
9534
+ const segmentsList = routePath.slice(1).split("/");
9535
+ const regexParts = [];
9536
+ for (let i2 = 0;i2 < segmentsList.length; i2++) {
9537
+ const segment = segmentsList[i2];
9538
+ if (!segment)
9539
+ continue;
9540
+ if (segment.startsWith("*") && segment.endsWith("?")) {
9541
+ regexParts.push("(?:\\/(.*))?");
9542
+ continue;
9543
+ }
9544
+ if (segment.startsWith("*")) {
9545
+ regexParts.push("\\/(.+)");
9546
+ continue;
9547
+ }
9548
+ if (segment.startsWith(":")) {
9549
+ regexParts.push("\\/([^/]+)");
9550
+ continue;
9551
+ }
9552
+ const escaped = segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9553
+ regexParts.push(`\\/${escaped}`);
9554
+ }
9555
+ return new RegExp(`^${regexParts.join("")}\\/?$`);
9556
+ }
9557
+ function generateRouteDefinition(filePath, pagesDir) {
9558
+ const routePath = filePathToRoutePath(filePath, pagesDir);
9559
+ const segments = parseRouteSegments(routePath);
9560
+ const paramNames = extractParamNames(segments);
9561
+ const score = calculateRouteScore(segments);
9562
+ return {
9563
+ path: routePath,
9564
+ paramNames,
9565
+ score,
9566
+ filePath,
9567
+ regex: routePathToRegex(routePath)
9568
+ };
9569
+ }
9570
+ // src/discovery/layouts.ts
9571
+ import * as fs5 from "fs";
9572
+ import * as path8 from "path";
9573
+ function discoverLayouts2(layoutsDir) {
9574
+ const layouts2 = new Map;
9575
+ if (!fs5.existsSync(layoutsDir))
9576
+ return layouts2;
9577
+ const files = fs5.readdirSync(layoutsDir);
9578
+ for (const file of files) {
9579
+ if (file.endsWith(".zen")) {
9580
+ const fullPath = path8.join(layoutsDir, file);
9581
+ const name = path8.basename(file, ".zen");
9582
+ try {
9583
+ const ir = parseZenFile(fullPath, undefined, { mode: "metadata" });
9584
+ layouts2.set(name, {
9585
+ name,
9586
+ filePath: fullPath,
9587
+ props: ir.props || [],
9588
+ states: new Map,
9589
+ html: ir.template.raw,
9590
+ scripts: ir.script ? [ir.script.content] : [],
9591
+ styles: ir.styles?.map((s2) => s2.raw) || []
9592
+ });
9593
+ } catch (e3) {
9594
+ console.error(`[Zenith Layout Discovery] Failed to parse layout ${file}:`, e3);
9595
+ }
9596
+ }
9597
+ }
9598
+ return layouts2;
9599
+ }
9600
+
9601
+ // src/discovery/componentDiscovery.ts
9602
+ import * as fs6 from "fs";
9603
+ import * as path9 from "path";
9604
+ function discoverComponents2(baseDir) {
9605
+ const components = new Map;
9606
+ if (!fs6.existsSync(baseDir))
9607
+ return components;
9608
+ const walk = (dir) => {
9609
+ const files = fs6.readdirSync(dir);
9610
+ for (const file of files) {
9611
+ const fullPath = path9.join(dir, file);
9612
+ if (fs6.statSync(fullPath).isDirectory()) {
9613
+ walk(fullPath);
9614
+ } else if (file.endsWith(".zen")) {
9615
+ const name = path9.basename(file, ".zen");
9616
+ try {
9617
+ const ir = parseZenFile(fullPath, undefined, { mode: "metadata" });
9618
+ components.set(name, {
9619
+ name,
9620
+ path: fullPath,
9621
+ template: ir.template.raw,
9622
+ nodes: ir.template.nodes,
9623
+ expressions: ir.template.expressions,
9624
+ slots: [],
9625
+ props: ir.props || [],
9626
+ states: ir.script?.states || {},
9627
+ styles: ir.styles?.map((s2) => s2.raw) || [],
9628
+ script: ir.script?.raw || null,
9629
+ scriptAttributes: ir.script?.attributes || null,
9630
+ hasScript: !!ir.script,
9631
+ hasStyles: ir.styles?.length > 0
9632
+ });
9633
+ } catch (e3) {
9634
+ console.error(`[Zenith Discovery] Failed to parse component ${file}:`, e3);
9635
+ }
9636
+ }
9637
+ }
9638
+ };
9639
+ walk(baseDir);
9640
+ return components;
9641
+ }
9647
9642
 
9648
9643
  // src/commands/dev.ts
9649
9644
  var pageCache = new Map;
@@ -9671,7 +9666,7 @@ async function dev(options = {}) {
9671
9666
  const globalsCssPath = resolveGlobalsCss(rootDir);
9672
9667
  let compiledCss = "";
9673
9668
  if (globalsCssPath) {
9674
- debug(`Compiling CSS: ${path11.relative(rootDir, globalsCssPath)}`);
9669
+ debug(`Compiling CSS: ${path10.relative(rootDir, globalsCssPath)}`);
9675
9670
  const cssResult = await compileCssAsync({ input: globalsCssPath, output: ":memory:" });
9676
9671
  if (cssResult.success) {
9677
9672
  compiledCss = cssResult.css;
@@ -9707,12 +9702,12 @@ async function dev(options = {}) {
9707
9702
  ]);
9708
9703
  async function compilePageInMemory(pagePath) {
9709
9704
  try {
9710
- const layoutsDir = path11.join(pagesDir, "../layouts");
9711
- const componentsDir = path11.join(pagesDir, "../components");
9712
- const layouts = discoverLayouts(layoutsDir);
9713
- const components = new Map([...layouts]);
9705
+ const layoutsDir = path10.join(pagesDir, "../layouts");
9706
+ const componentsDir = path10.join(pagesDir, "../components");
9707
+ const layouts2 = discoverLayouts2(layoutsDir);
9708
+ const components = new Map([...layouts2]);
9714
9709
  if (fs7.existsSync(componentsDir)) {
9715
- const discovered = discoverComponents(componentsDir);
9710
+ const discovered = discoverComponents2(componentsDir);
9716
9711
  for (const [k2, v2] of discovered) {
9717
9712
  components.set(k2, v2);
9718
9713
  }
@@ -9743,19 +9738,36 @@ async function dev(options = {}) {
9743
9738
  }
9744
9739
  }
9745
9740
  async function generateDevHTML(page) {
9746
- 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">
9747
9758
  ${page.script}
9748
- </script>`;
9749
- 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}
9750
9762
  </body>`) : `${page.html}
9751
- ${scriptTag}`;
9763
+ ${injection}`;
9752
9764
  if (!html.trimStart().toLowerCase().startsWith("<!doctype")) {
9753
9765
  html = `<!DOCTYPE html>
9754
9766
  ${html}`;
9755
9767
  }
9756
9768
  return html;
9757
9769
  }
9758
- 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) => {
9759
9771
  if (!filename)
9760
9772
  return;
9761
9773
  await runPluginHooks("cli:dev:file-change", {
@@ -9799,12 +9811,25 @@ ${html}`;
9799
9811
  const startTime = performance.now();
9800
9812
  const url = new URL(req.url);
9801
9813
  const pathname = url.pathname;
9802
- const ext = path11.extname(pathname).toLowerCase();
9814
+ const ext = path10.extname(pathname).toLowerCase();
9803
9815
  if (pathname === "/hmr") {
9804
9816
  const upgraded = server2.upgrade(req, { data: { timestamp: Date.now() } });
9805
9817
  if (upgraded)
9806
9818
  return;
9807
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
+ }
9808
9833
  if (pathname === "/runtime.js") {
9809
9834
  const payloads = await collectHookReturns("cli:runtime:collect", hookCtx);
9810
9835
  const envelope = buildRuntimeEnvelope(payloads);
@@ -9814,7 +9839,38 @@ ${html}`;
9814
9839
  route("GET", pathname, 200, Math.round(performance.now() - startTime), 0, Math.round(performance.now() - startTime));
9815
9840
  return response;
9816
9841
  }
9817
- 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) {
9818
9874
  const response = new Response(compiledCss, {
9819
9875
  headers: { "Content-Type": "text/css; charset=utf-8" }
9820
9876
  });
@@ -9829,7 +9885,7 @@ ${html}`;
9829
9885
  return response;
9830
9886
  }
9831
9887
  if (STATIC_EXTENSIONS.has(ext)) {
9832
- const publicPath = path11.join(pagesDir, "../public", pathname);
9888
+ const publicPath = path10.join(pagesDir, "../public", pathname);
9833
9889
  if (fs7.existsSync(publicPath)) {
9834
9890
  const response = new Response(Bun.file(publicPath));
9835
9891
  route("GET", pathname, 200, Math.round(performance.now() - startTime), 0, Math.round(performance.now() - startTime));
@@ -9879,32 +9935,32 @@ ${html}`;
9879
9935
  await new Promise(() => {});
9880
9936
  }
9881
9937
  function findPageForRoute(route2, pagesDir) {
9882
- 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`);
9883
9939
  if (fs7.existsSync(exactPath))
9884
9940
  return exactPath;
9885
- 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`);
9886
9942
  if (fs7.existsSync(indexPath))
9887
9943
  return indexPath;
9888
9944
  const segments = route2 === "/" ? [] : route2.slice(1).split("/").filter(Boolean);
9889
9945
  for (let i2 = segments.length - 1;i2 >= 0; i2--) {
9890
9946
  const staticPart = segments.slice(0, i2).join("/");
9891
- const baseDir = staticPart ? path11.join(pagesDir, staticPart) : pagesDir;
9892
- const singleDynamicPath = path11.join(baseDir, "[slug].zen");
9947
+ const baseDir = staticPart ? path10.join(pagesDir, staticPart) : pagesDir;
9948
+ const singleDynamicPath = path10.join(baseDir, "[slug].zen");
9893
9949
  if (fs7.existsSync(singleDynamicPath))
9894
9950
  return singleDynamicPath;
9895
- const catchAllPath = path11.join(baseDir, "[...slug].zen");
9951
+ const catchAllPath = path10.join(baseDir, "[...slug].zen");
9896
9952
  if (fs7.existsSync(catchAllPath)) {
9897
9953
  return catchAllPath;
9898
9954
  }
9899
9955
  }
9900
- const rootCatchAll = path11.join(pagesDir, "[...slug].zen");
9956
+ const rootCatchAll = path10.join(pagesDir, "[...slug].zen");
9901
9957
  if (fs7.existsSync(rootCatchAll))
9902
9958
  return rootCatchAll;
9903
9959
  return null;
9904
9960
  }
9905
9961
 
9906
9962
  // src/commands/preview.ts
9907
- import path12 from "path";
9963
+ import path11 from "path";
9908
9964
  var {serve: serve2 } = globalThis.Bun;
9909
9965
  async function preview(options = {}) {
9910
9966
  const project = requireProject();
@@ -9934,16 +9990,16 @@ async function preview(options = {}) {
9934
9990
  async fetch(req) {
9935
9991
  const url = new URL(req.url);
9936
9992
  const pathname = url.pathname;
9937
- const ext = path12.extname(pathname).toLowerCase();
9993
+ const ext = path11.extname(pathname).toLowerCase();
9938
9994
  if (STATIC_EXTENSIONS.has(ext)) {
9939
- const filePath = path12.join(distDir, pathname);
9995
+ const filePath = path11.join(distDir, pathname);
9940
9996
  const file = Bun.file(filePath);
9941
9997
  if (await file.exists()) {
9942
9998
  return new Response(file);
9943
9999
  }
9944
10000
  return new Response("Not found", { status: 404 });
9945
10001
  }
9946
- const indexPath = path12.join(distDir, "index.html");
10002
+ const indexPath = path11.join(distDir, "index.html");
9947
10003
  const indexFile = Bun.file(indexPath);
9948
10004
  if (await indexFile.exists()) {
9949
10005
  return new Response(indexFile, {
@@ -9960,20 +10016,21 @@ async function preview(options = {}) {
9960
10016
 
9961
10017
  // src/ssg-build.ts
9962
10018
  import fs8 from "fs";
10019
+ import path12 from "path";
9963
10020
  async function compilePage(pagePath, pagesDir, baseDir = process.cwd()) {
9964
10021
  const source = fs8.readFileSync(pagePath, "utf-8");
9965
10022
  const analysis = analyzePageSource(source);
9966
- const srcDir = path.dirname(pagesDir);
9967
- const componentsDir = path.join(srcDir, "components");
9968
- 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");
9969
10026
  const components = new Map;
9970
10027
  if (fs8.existsSync(componentsDir)) {
9971
- const comps = discoverComponents(componentsDir);
10028
+ const comps = discoverComponents2(componentsDir);
9972
10029
  for (const [k2, v2] of comps)
9973
10030
  components.set(k2, v2);
9974
10031
  }
9975
10032
  if (fs8.existsSync(layoutsDir)) {
9976
- const layoutComps = discoverComponents(layoutsDir);
10033
+ const layoutComps = discoverComponents2(layoutsDir);
9977
10034
  for (const [k2, v2] of layoutComps) {
9978
10035
  if (k2[0] === k2[0]?.toUpperCase()) {
9979
10036
  components.set(k2, v2);
@@ -10082,7 +10139,7 @@ ${page.pageScript}
10082
10139
  `;
10083
10140
  }
10084
10141
  async function buildSSG(options) {
10085
- const { pagesDir, outDir, baseDir = path.dirname(pagesDir) } = options;
10142
+ const { pagesDir, outDir, baseDir = path12.dirname(pagesDir) } = options;
10086
10143
  console.log("\uD83D\uDD28 Zenith SSG Build");
10087
10144
  console.log(` Pages: ${pagesDir}`);
10088
10145
  console.log(` Output: ${outDir}`);
@@ -10110,7 +10167,7 @@ async function buildSSG(options) {
10110
10167
  fs8.rmSync(outDir, { recursive: true, force: true });
10111
10168
  }
10112
10169
  fs8.mkdirSync(outDir, { recursive: true });
10113
- fs8.mkdirSync(path.join(outDir, "assets"), { recursive: true });
10170
+ fs8.mkdirSync(path12.join(outDir, "assets"), { recursive: true });
10114
10171
  const pageFiles = discoverPages(pagesDir);
10115
10172
  if (pageFiles.length === 0) {
10116
10173
  console.warn("\u26A0\uFE0F No pages found in", pagesDir);
@@ -10120,7 +10177,7 @@ async function buildSSG(options) {
10120
10177
  const compiledPages = [];
10121
10178
  let hasHydratedPages = false;
10122
10179
  for (const pageFile of pageFiles) {
10123
- const relativePath = path.relative(pagesDir, pageFile);
10180
+ const relativePath = path12.relative(pagesDir, pageFile);
10124
10181
  console.log(` Compiling: ${relativePath}`);
10125
10182
  try {
10126
10183
  const compiled = await compilePage(pageFile, pagesDir, baseDir);
@@ -10141,8 +10198,8 @@ async function buildSSG(options) {
10141
10198
  let globalStyles = "";
10142
10199
  const globalsCssPath = resolveGlobalsCss(baseDir);
10143
10200
  if (globalsCssPath) {
10144
- console.log("\uD83D\uDCE6 Compiling CSS:", path.relative(baseDir, globalsCssPath));
10145
- 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");
10146
10203
  const result = compileCss({
10147
10204
  input: globalsCssPath,
10148
10205
  output: cssOutputPath,
@@ -10157,14 +10214,14 @@ async function buildSSG(options) {
10157
10214
  }
10158
10215
  if (hasHydratedPages) {
10159
10216
  const bundleJS = generateBundleJS(pluginEnvelope);
10160
- fs8.writeFileSync(path.join(outDir, "assets", "bundle.js"), bundleJS);
10217
+ fs8.writeFileSync(path12.join(outDir, "assets", "bundle.js"), bundleJS);
10161
10218
  console.log("\uD83D\uDCE6 Generated assets/bundle.js (with plugin data)");
10162
10219
  }
10163
10220
  for (const page of compiledPages) {
10164
- const pageOutDir = path.join(outDir, page.outputDir);
10221
+ const pageOutDir = path12.join(outDir, page.outputDir);
10165
10222
  fs8.mkdirSync(pageOutDir, { recursive: true });
10166
10223
  const html = generatePageHTML(page, globalStyles, pluginEnvelope);
10167
- fs8.writeFileSync(path.join(pageOutDir, "index.html"), html);
10224
+ fs8.writeFileSync(path12.join(pageOutDir, "index.html"), html);
10168
10225
  if (page.pageScript) {
10169
10226
  const pageJsName = page.routePath === "/" ? "page_index.js" : `page_${page.routePath.replace(/^\//, "").replace(/\//g, "_")}.js`;
10170
10227
  const pageJS = generatePageJS(page);
@@ -10183,28 +10240,28 @@ async function buildSSG(options) {
10183
10240
  const plan = {
10184
10241
  ...page.bundlePlan,
10185
10242
  entry: pageJS,
10186
- resolveRoots: [path.join(baseDir, "node_modules"), "node_modules"]
10243
+ resolveRoots: [path12.join(baseDir, "node_modules"), "node_modules"]
10187
10244
  };
10188
10245
  bundledJS = await bundlePageScript(plan);
10189
10246
  }
10190
- fs8.writeFileSync(path.join(outDir, "assets", pageJsName), bundledJS);
10247
+ fs8.writeFileSync(path12.join(outDir, "assets", pageJsName), bundledJS);
10191
10248
  }
10192
10249
  console.log(`\u2705 ${page.outputDir}/index.html`);
10193
10250
  }
10194
- const faviconPath = path.join(baseDir, "favicon.ico");
10251
+ const faviconPath = path12.join(baseDir, "favicon.ico");
10195
10252
  if (fs8.existsSync(faviconPath)) {
10196
- fs8.copyFileSync(faviconPath, path.join(outDir, "favicon.ico"));
10253
+ fs8.copyFileSync(faviconPath, path12.join(outDir, "favicon.ico"));
10197
10254
  console.log("\uD83D\uDCE6 Copied favicon.ico");
10198
10255
  }
10199
10256
  const custom404Candidates = ["404.zen", "+404.zen", "not-found.zen"];
10200
10257
  let has404 = false;
10201
10258
  for (const candidate of custom404Candidates) {
10202
- const custom404Path = path.join(pagesDir, candidate);
10259
+ const custom404Path = path12.join(pagesDir, candidate);
10203
10260
  if (fs8.existsSync(custom404Path)) {
10204
10261
  try {
10205
10262
  const compiled = await compilePage(custom404Path, pagesDir, baseDir);
10206
10263
  const html = generatePageHTML(compiled, globalStyles, pluginEnvelope);
10207
- fs8.writeFileSync(path.join(outDir, "404.html"), html);
10264
+ fs8.writeFileSync(path12.join(outDir, "404.html"), html);
10208
10265
  console.log("\uD83D\uDCE6 Generated 404.html (custom)");
10209
10266
  has404 = true;
10210
10267
  if (compiled.pageScript) {
@@ -10214,11 +10271,11 @@ async function buildSSG(options) {
10214
10271
  const plan = {
10215
10272
  ...compiled.bundlePlan,
10216
10273
  entry: pageJS,
10217
- resolveRoots: [path.join(baseDir, "node_modules"), "node_modules"]
10274
+ resolveRoots: [path12.join(baseDir, "node_modules"), "node_modules"]
10218
10275
  };
10219
10276
  bundledJS = await bundlePageScript(plan);
10220
10277
  }
10221
- fs8.writeFileSync(path.join(outDir, "assets", "page_404.js"), bundledJS);
10278
+ fs8.writeFileSync(path12.join(outDir, "assets", "page_404.js"), bundledJS);
10222
10279
  }
10223
10280
  } catch (error4) {
10224
10281
  console.warn(` \u26A0\uFE0F Could not compile ${candidate}: ${error4.message}`);
@@ -10252,7 +10309,7 @@ async function buildSSG(options) {
10252
10309
  </div>
10253
10310
  </body>
10254
10311
  </html>`;
10255
- fs8.writeFileSync(path.join(outDir, "404.html"), default404HTML);
10312
+ fs8.writeFileSync(path12.join(outDir, "404.html"), default404HTML);
10256
10313
  console.log("\uD83D\uDCE6 Generated 404.html (default)");
10257
10314
  }
10258
10315
  console.log("");