@onexapis/cli 1.1.1 → 1.1.3

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/cli.js CHANGED
@@ -25,6 +25,7 @@ var chokidar = require('chokidar');
25
25
  var http = require('http');
26
26
  var ws = require('ws');
27
27
 
28
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
28
29
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
29
30
 
30
31
  function _interopNamespace(e) {
@@ -66,7 +67,6 @@ var http__default = /*#__PURE__*/_interopDefault(http);
66
67
 
67
68
  var __defProp = Object.defineProperty;
68
69
  var __getOwnPropNames = Object.getOwnPropertyNames;
69
- var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
70
70
  var __esm = (fn, res) => function __init() {
71
71
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
72
72
  };
@@ -74,7 +74,6 @@ var __export = (target, all) => {
74
74
  for (var name in all)
75
75
  __defProp(target, name, { get: all[name], enumerable: true });
76
76
  };
77
- var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
78
77
  var Logger, logger;
79
78
  var init_logger = __esm({
80
79
  "src/utils/logger.ts"() {
@@ -147,7 +146,7 @@ async function resolveNodeModulesFile(startDir, relativePath) {
147
146
  try {
148
147
  await fs7__default.default.access(candidate);
149
148
  return candidate;
150
- } catch (e) {
149
+ } catch {
151
150
  const parent = path__default.default.dirname(dir);
152
151
  if (parent === dir) break;
153
152
  dir = parent;
@@ -166,7 +165,7 @@ function createCoreGlobalPlugin(themePath) {
166
165
  }));
167
166
  build2.onLoad({ filter: /.*/, namespace: "core-global" }, async (args) => {
168
167
  const match = args.path.match(/^@onexapis\/core(\/(.+))?$/);
169
- const subpath = (match == null ? void 0 : match[2]) || "";
168
+ const subpath = match?.[2] || "";
170
169
  const moduleAccess = subpath ? `['${subpath}']` : "";
171
170
  let namedExports = [];
172
171
  const cacheKey = subpath || "__root__";
@@ -190,7 +189,7 @@ function createCoreGlobalPlugin(themePath) {
190
189
  namedExports.push(...names);
191
190
  }
192
191
  namedExports = [...new Set(namedExports)];
193
- } catch (e) {
192
+ } catch {
194
193
  }
195
194
  exportsBySubpath[cacheKey] = namedExports;
196
195
  }
@@ -222,6 +221,73 @@ ${namedExportLines}
222
221
  }
223
222
  };
224
223
  }
224
+ async function generateThemeData(themePath, outputDir, themeId) {
225
+ const { createJiti } = await import('jiti');
226
+ const jiti = createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.js', document.baseURI).href)));
227
+ let themeConfig = null;
228
+ let layoutConfig = null;
229
+ const pages = {};
230
+ for (const ext of [".ts", ".js"]) {
231
+ try {
232
+ const mod = await jiti.import(path__default.default.join(themePath, `theme.config${ext}`));
233
+ themeConfig = mod.default || mod;
234
+ break;
235
+ } catch {
236
+ }
237
+ }
238
+ for (const ext of [".ts", ".js"]) {
239
+ try {
240
+ const mod = await jiti.import(path__default.default.join(themePath, `theme.layout${ext}`));
241
+ layoutConfig = mod.default || mod;
242
+ break;
243
+ } catch {
244
+ }
245
+ }
246
+ const pagesDir = path__default.default.join(themePath, "pages");
247
+ try {
248
+ const files = await fs7__default.default.readdir(pagesDir);
249
+ for (const file of files) {
250
+ if (!file.match(/\.(ts|js)$/)) continue;
251
+ const name = file.replace(/\.(ts|js)$/, "");
252
+ try {
253
+ const mod = await jiti.import(path__default.default.join(pagesDir, file));
254
+ const config = mod.default || mod;
255
+ pages[name] = {
256
+ id: name,
257
+ name: config.title || name,
258
+ path: config.path || `/${name}`,
259
+ config: { id: name, ...config },
260
+ sections: config.sections || [],
261
+ seo: config.seo
262
+ };
263
+ } catch {
264
+ }
265
+ }
266
+ } catch {
267
+ }
268
+ await fs7__default.default.writeFile(
269
+ path__default.default.join(outputDir, "theme-data.json"),
270
+ JSON.stringify(
271
+ {
272
+ themeId,
273
+ theme: {
274
+ id: themeId,
275
+ name: themeConfig?.name || themeId,
276
+ config: themeConfig,
277
+ layout: {
278
+ header: layoutConfig?.headerSections || [],
279
+ footer: layoutConfig?.footerSections || []
280
+ },
281
+ pages: Object.keys(pages)
282
+ },
283
+ pages
284
+ },
285
+ null,
286
+ 2
287
+ )
288
+ );
289
+ logger.info(`Generated theme-data.json (${Object.keys(pages).length} pages)`);
290
+ }
225
291
  async function contentHashEntry(outputDir) {
226
292
  const entryPath = path__default.default.join(outputDir, "bundle-entry.js");
227
293
  const mapPath = path__default.default.join(outputDir, "bundle-entry.js.map");
@@ -232,11 +298,11 @@ async function contentHashEntry(outputDir) {
232
298
  let entryContent;
233
299
  try {
234
300
  entryContent = await fs7__default.default.readFile(entryPath, "utf-8");
235
- } catch (e) {
301
+ } catch {
236
302
  const indexPath = path__default.default.join(outputDir, "index.js");
237
303
  try {
238
304
  entryContent = await fs7__default.default.readFile(indexPath, "utf-8");
239
- } catch (e2) {
305
+ } catch {
240
306
  logger.warning("No entry file found in output, skipping content hash");
241
307
  return;
242
308
  }
@@ -253,7 +319,7 @@ async function contentHashEntry(outputDir) {
253
319
  try {
254
320
  await fs7__default.default.access(indexMapPath);
255
321
  await fs7__default.default.rename(indexMapPath, path__default.default.join(outputDir, hashedMapName2));
256
- } catch (e2) {
322
+ } catch {
257
323
  }
258
324
  logger.info(`Entry hashed: ${hashedName2}`);
259
325
  return;
@@ -270,10 +336,32 @@ async function contentHashEntry(outputDir) {
270
336
  try {
271
337
  await fs7__default.default.access(mapPath);
272
338
  await fs7__default.default.rename(mapPath, path__default.default.join(outputDir, hashedMapName));
273
- } catch (e) {
339
+ } catch {
274
340
  }
275
341
  logger.info(`Entry hashed: ${hashedName}`);
276
342
  }
343
+ async function extractDataRequirements(themePath) {
344
+ const { createJiti } = await import('jiti');
345
+ const jiti = createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.js', document.baseURI).href)));
346
+ const schemaFiles = await glob.glob("sections/**/*.schema.ts", { cwd: themePath });
347
+ const requirements = {};
348
+ for (const file of schemaFiles) {
349
+ try {
350
+ const mod = await jiti.import(path__default.default.join(themePath, file));
351
+ const exports$1 = mod;
352
+ for (const value of Object.values(exports$1)) {
353
+ if (value && typeof value === "object" && typeof value.type === "string" && value.dataRequirements && typeof value.dataRequirements === "object") {
354
+ requirements[value.type] = value.dataRequirements;
355
+ }
356
+ }
357
+ } catch (err) {
358
+ logger.warning(
359
+ `Could not load schema ${file}: ${err instanceof Error ? err.message : String(err)}`
360
+ );
361
+ }
362
+ }
363
+ return requirements;
364
+ }
277
365
  async function generateManifest2(themeName, themePath, outputDir) {
278
366
  let version = "1.0.0";
279
367
  let themeId = themeName;
@@ -287,18 +375,19 @@ async function generateManifest2(themeName, themePath, outputDir) {
287
375
  if (pkg.name) {
288
376
  themeId = pkg.name.replace(/^@onex-themes\//, "");
289
377
  }
290
- } catch (e) {
378
+ } catch {
291
379
  }
292
380
  const [sectionFiles, blockFiles, schemaFiles] = await Promise.all([
293
381
  glob.glob("sections/**/index.ts", { cwd: themePath }),
294
382
  glob.glob("blocks/**/index.ts", { cwd: themePath }),
295
383
  glob.glob("**/*.schema.ts", { cwd: themePath })
296
384
  ]);
385
+ const dataRequirements = await extractDataRequirements(themePath);
297
386
  let hasThemeConfig = false;
298
387
  try {
299
388
  await fs7__default.default.access(path__default.default.join(themePath, "theme.config.ts"));
300
389
  hasThemeConfig = true;
301
- } catch (e) {
390
+ } catch {
302
391
  }
303
392
  const allFiles = await glob.glob("**/*", { cwd: outputDir, nodir: true });
304
393
  const jsFiles = allFiles.filter((f) => f.endsWith(".js"));
@@ -333,7 +422,9 @@ async function generateManifest2(themeName, themePath, outputDir) {
333
422
  blocks: blockFiles,
334
423
  schemas: schemaFiles,
335
424
  hasThemeConfig
336
- }
425
+ },
426
+ // Section data requirements for server-side prefetching (keyed by section type)
427
+ dataRequirements
337
428
  };
338
429
  await fs7__default.default.writeFile(
339
430
  path__default.default.join(outputDir, "manifest.json"),
@@ -348,7 +439,7 @@ async function compileStandaloneTheme(themePath, themeName) {
348
439
  try {
349
440
  await fs7__default.default.access(bundleEntry);
350
441
  entryPoint = bundleEntry;
351
- } catch (e) {
442
+ } catch {
352
443
  }
353
444
  const shimPath = path__default.default.join(outputDir, ".process-shim.js");
354
445
  await fs7__default.default.mkdir(outputDir, { recursive: true });
@@ -399,10 +490,11 @@ async function compileStandaloneTheme(themePath, themeName) {
399
490
  const result = await esbuild__namespace.build(buildOptions);
400
491
  try {
401
492
  await fs7__default.default.unlink(shimPath);
402
- } catch (e) {
493
+ } catch {
403
494
  }
404
495
  await contentHashEntry(outputDir);
405
496
  await generateManifest2(themeName, themePath, outputDir);
497
+ await generateThemeData(themePath, outputDir, themeName);
406
498
  if (result.metafile) {
407
499
  const outputs = result.metafile.outputs;
408
500
  let totalSize = 0;
@@ -416,7 +508,7 @@ async function compileStandaloneTheme(themePath, themeName) {
416
508
  } catch (error) {
417
509
  try {
418
510
  await fs7__default.default.unlink(shimPath);
419
- } catch (e) {
511
+ } catch {
420
512
  }
421
513
  logger.error(`esbuild compilation failed: ${error}`);
422
514
  return false;
@@ -430,7 +522,7 @@ async function compileStandaloneThemeDev(themePath, themeName) {
430
522
  try {
431
523
  await fs7__default.default.access(bundleEntry);
432
524
  entryPoint = bundleEntry;
433
- } catch (e) {
525
+ } catch {
434
526
  }
435
527
  const shimPath = path__default.default.join(outputDir, ".process-shim.js");
436
528
  await fs7__default.default.mkdir(outputDir, { recursive: true });
@@ -479,6 +571,7 @@ async function compileStandaloneThemeDev(themePath, themeName) {
479
571
  const context2 = await esbuild__namespace.context(buildOptions);
480
572
  await context2.rebuild();
481
573
  await generateManifest2(themeName, themePath, outputDir);
574
+ await generateThemeData(themePath, outputDir, themeName);
482
575
  return { context: context2, outputDir };
483
576
  }
484
577
  async function compilePreviewRuntime(themePath) {
@@ -496,7 +589,7 @@ async function compilePreviewRuntime(themePath) {
496
589
  await fs7__default.default.access(loc);
497
590
  previewEntryPath = loc;
498
591
  break;
499
- } catch (e) {
592
+ } catch {
500
593
  }
501
594
  }
502
595
  if (!previewEntryPath) {
@@ -536,10 +629,13 @@ ${locations.join("\n")}`
536
629
  "zlib"
537
630
  ];
538
631
  for (const mod of nodeBuiltins) {
539
- build2.onResolve({ filter: new RegExp(`^${mod.replace("/", "\\/")}$`) }, () => ({
540
- path: mod,
541
- namespace: "node-stub"
542
- }));
632
+ build2.onResolve(
633
+ { filter: new RegExp(`^${mod.replace("/", "\\/")}$`) },
634
+ () => ({
635
+ path: mod,
636
+ namespace: "node-stub"
637
+ })
638
+ );
543
639
  }
544
640
  build2.onLoad({ filter: /.*/, namespace: "node-stub" }, (args) => {
545
641
  const stubs = {
@@ -553,8 +649,7 @@ ${locations.join("\n")}`
553
649
  };
554
650
  });
555
651
  build2.onResolve({ filter: /^lucide-react/ }, async (args) => {
556
- var _a;
557
- if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
652
+ if (args.pluginData?.skipStub) return void 0;
558
653
  try {
559
654
  const result = await build2.resolve(args.path, {
560
655
  kind: args.kind,
@@ -564,7 +659,7 @@ ${locations.join("\n")}`
564
659
  pluginData: { skipStub: true }
565
660
  });
566
661
  if (!result.errors.length) return result;
567
- } catch (e) {
662
+ } catch {
568
663
  }
569
664
  return { path: args.path, namespace: "lucide-stub" };
570
665
  });
@@ -586,8 +681,7 @@ export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true :
586
681
  loader: "jsx"
587
682
  }));
588
683
  build2.onResolve({ filter: /^framer-motion/ }, async (args) => {
589
- var _a;
590
- if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
684
+ if (args.pluginData?.skipStub) return void 0;
591
685
  try {
592
686
  const result = await build2.resolve(args.path, {
593
687
  kind: args.kind,
@@ -597,7 +691,7 @@ export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true :
597
691
  pluginData: { skipStub: true }
598
692
  });
599
693
  if (!result.errors.length) return result;
600
- } catch (e) {
694
+ } catch {
601
695
  }
602
696
  return { path: args.path, namespace: "motion-stub" };
603
697
  });
@@ -611,8 +705,59 @@ export default { motion, AnimatePresence };
611
705
  `.trim(),
612
706
  loader: "jsx"
613
707
  }));
708
+ build2.onResolve({ filter: /^next\// }, async (args) => {
709
+ if (args.pluginData?.skipStub) return void 0;
710
+ try {
711
+ const result = await build2.resolve(args.path, {
712
+ kind: args.kind,
713
+ resolveDir: args.resolveDir,
714
+ importer: args.importer,
715
+ namespace: "file",
716
+ pluginData: { skipStub: true }
717
+ });
718
+ if (!result.errors.length) return result;
719
+ } catch {
720
+ }
721
+ return { path: args.path, namespace: "next-stub" };
722
+ });
723
+ build2.onLoad({ filter: /.*/, namespace: "next-stub" }, (args) => {
724
+ const stubs = {
725
+ "next/image": `
726
+ const Image = (props) => {
727
+ const { src, alt, width, height, fill, priority, ...rest } = props;
728
+ const imgSrc = typeof src === 'object' ? src.src : src;
729
+ return React.createElement('img', { src: imgSrc, alt, width: fill ? undefined : width, height: fill ? undefined : height, loading: priority ? 'eager' : 'lazy', ...rest });
730
+ };
731
+ import React from 'react';
732
+ export default Image;
733
+ `,
734
+ "next/link": `
735
+ const Link = ({ href, children, ...rest }) => React.createElement('a', { href, ...rest }, children);
736
+ import React from 'react';
737
+ export default Link;
738
+ `,
739
+ "next/navigation": `
740
+ export function useRouter() { return { push(u){window.location.href=u}, replace(u){window.location.href=u}, back(){window.history.back()}, forward(){window.history.forward()}, refresh(){window.location.reload()}, prefetch(){} }; }
741
+ export function usePathname() { return window.location.pathname; }
742
+ export function useSearchParams() { return new URLSearchParams(window.location.search); }
743
+ export function useParams() { return {}; }
744
+ export function redirect(url) { window.location.href = url; }
745
+ export function notFound() { throw new Error('Not Found'); }
746
+ `,
747
+ "next/headers": `
748
+ export function cookies() { return { get(){}, getAll(){ return []; }, set(){}, delete(){}, has(){ return false; } }; }
749
+ export function headers() { return new Headers(); }
750
+ `
751
+ };
752
+ return {
753
+ contents: stubs[args.path] || "export default {};",
754
+ loader: "jsx"
755
+ };
756
+ });
614
757
  }
615
758
  };
759
+ const shimPath = path__default.default.join(outputDir, ".process-shim-preview.js");
760
+ await fs7__default.default.writeFile(shimPath, PROCESS_SHIM);
616
761
  await esbuild__namespace.build({
617
762
  entryPoints: [previewEntryPath],
618
763
  bundle: true,
@@ -622,6 +767,7 @@ export default { motion, AnimatePresence };
622
767
  // Bundle React + core INTO the output (NOT externalized)
623
768
  external: [],
624
769
  plugins: [serverStubPlugin],
770
+ inject: [shimPath],
625
771
  minify: false,
626
772
  sourcemap: true,
627
773
  target: "es2020",
@@ -629,6 +775,12 @@ export default { motion, AnimatePresence };
629
775
  jsxImportSource: "react",
630
776
  define: {
631
777
  "process.env.NODE_ENV": JSON.stringify("development"),
778
+ "process.env.NEXT_PUBLIC_API_URL": JSON.stringify(
779
+ process.env.NEXT_PUBLIC_API_URL || ""
780
+ ),
781
+ "process.env.NEXT_PUBLIC_COMPANY_ID": JSON.stringify(
782
+ process.env.NEXT_PUBLIC_COMPANY_ID || ""
783
+ ),
632
784
  global: "globalThis"
633
785
  },
634
786
  loader: { ".tsx": "tsx", ".ts": "ts" },
@@ -639,6 +791,10 @@ export default { motion, AnimatePresence };
639
791
  "ignored-bare-import": "silent"
640
792
  }
641
793
  });
794
+ try {
795
+ await fs7__default.default.unlink(shimPath);
796
+ } catch {
797
+ }
642
798
  return outputPath;
643
799
  }
644
800
  var PROCESS_SHIM, reactGlobalPlugin;
@@ -1075,7 +1231,7 @@ Add your theme-specific blocks here.
1075
1231
  stdio: "ignore"
1076
1232
  });
1077
1233
  logger.stopSpinner(true, "Git repository initialized!");
1078
- } catch (e) {
1234
+ } catch {
1079
1235
  logger.stopSpinner(false, "Failed to initialize git");
1080
1236
  }
1081
1237
  }
@@ -1086,7 +1242,7 @@ Add your theme-specific blocks here.
1086
1242
  try {
1087
1243
  await installDependencies(projectPath, packageManager);
1088
1244
  logger.stopSpinner(true, "Dependencies installed!");
1089
- } catch (e) {
1245
+ } catch {
1090
1246
  logger.stopSpinner(false, "Failed to install dependencies");
1091
1247
  logger.info(
1092
1248
  "You can install dependencies manually by running: cd " + name + " && npm install"
@@ -2350,7 +2506,6 @@ async function validateCommand(options) {
2350
2506
  // src/commands/build.ts
2351
2507
  init_logger();
2352
2508
  async function buildCommand(options) {
2353
- var _a;
2354
2509
  logger.header("Build Theme");
2355
2510
  let themePath;
2356
2511
  let themeName;
@@ -2363,7 +2518,7 @@ async function buildCommand(options) {
2363
2518
  } else {
2364
2519
  themePath = path__default.default.join(process.cwd(), themeName);
2365
2520
  }
2366
- } catch (e) {
2521
+ } catch {
2367
2522
  themePath = path__default.default.join(process.cwd(), themeName);
2368
2523
  }
2369
2524
  if (!fs__default.default.existsSync(themePath)) {
@@ -2420,7 +2575,7 @@ async function buildCommand(options) {
2420
2575
  }
2421
2576
  logger.stopSpinner(true, "Lint passed");
2422
2577
  const pkgJson = fs__default.default.readJsonSync(packageJsonPath);
2423
- const buildScript = ((_a = pkgJson.scripts) == null ? void 0 : _a.build) || "";
2578
+ const buildScript = pkgJson.scripts?.build || "";
2424
2579
  const isRecursive = buildScript.includes("onex build") || buildScript.includes("onex-cli build");
2425
2580
  logger.startSpinner(
2426
2581
  options.watch ? "Building (watch mode)..." : "Building..."
@@ -2777,7 +2932,6 @@ async function findCompiledThemeDir(themeId, version) {
2777
2932
  return null;
2778
2933
  }
2779
2934
  async function readManifest() {
2780
- var _a;
2781
2935
  const manifestTsPath = path__default.default.resolve(process.cwd(), "manifest.ts");
2782
2936
  if (await fs__default.default.pathExists(manifestTsPath)) {
2783
2937
  try {
@@ -2791,7 +2945,7 @@ async function readManifest() {
2791
2945
  if (await fs__default.default.pathExists(packageJsonPath)) {
2792
2946
  const pkg = await fs__default.default.readJson(packageJsonPath);
2793
2947
  return {
2794
- themeId: ((_a = pkg.name) == null ? void 0 : _a.replace("@onex-themes/", "")) || "unknown",
2948
+ themeId: pkg.name?.replace("@onex-themes/", "") || "unknown",
2795
2949
  version: pkg.version || "1.0.0"
2796
2950
  };
2797
2951
  }
@@ -3035,39 +3189,15 @@ function getBucketName2(env) {
3035
3189
  }
3036
3190
  async function streamToString(stream) {
3037
3191
  const chunks = [];
3038
- try {
3039
- for (var iter = __forAwait(stream), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
3040
- const chunk = temp.value;
3041
- chunks.push(Buffer.from(chunk));
3042
- }
3043
- } catch (temp) {
3044
- error = [temp];
3045
- } finally {
3046
- try {
3047
- more && (temp = iter.return) && await temp.call(iter);
3048
- } finally {
3049
- if (error)
3050
- throw error[0];
3051
- }
3192
+ for await (const chunk of stream) {
3193
+ chunks.push(Buffer.from(chunk));
3052
3194
  }
3053
3195
  return Buffer.concat(chunks).toString("utf-8");
3054
3196
  }
3055
3197
  async function streamToBuffer(stream) {
3056
3198
  const chunks = [];
3057
- try {
3058
- for (var iter = __forAwait(stream), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
3059
- const chunk = temp.value;
3060
- chunks.push(Buffer.from(chunk));
3061
- }
3062
- } catch (temp) {
3063
- error = [temp];
3064
- } finally {
3065
- try {
3066
- more && (temp = iter.return) && await temp.call(iter);
3067
- } finally {
3068
- if (error)
3069
- throw error[0];
3070
- }
3199
+ for await (const chunk of stream) {
3200
+ chunks.push(Buffer.from(chunk));
3071
3201
  }
3072
3202
  return Buffer.concat(chunks);
3073
3203
  }
@@ -3089,8 +3219,7 @@ async function resolveLatestVersion(s3Client, bucket, themeId) {
3089
3219
  }
3090
3220
  }
3091
3221
  async function createCompatibilityFiles(outputDir, manifest) {
3092
- var _a;
3093
- const entryFile = ((_a = manifest.output) == null ? void 0 : _a.entry) || "bundle-entry.js";
3222
+ const entryFile = manifest.output?.entry || "bundle-entry.js";
3094
3223
  if (entryFile !== "bundle-entry.js" && entryFile.startsWith("bundle-entry-")) {
3095
3224
  const hashedPath = path__default.default.join(outputDir, entryFile);
3096
3225
  const stablePath = path__default.default.join(outputDir, "bundle-entry.js");
@@ -3261,39 +3390,15 @@ function getBucketName3(env) {
3261
3390
  }
3262
3391
  async function streamToString2(stream) {
3263
3392
  const chunks = [];
3264
- try {
3265
- for (var iter = __forAwait(stream), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
3266
- const chunk = temp.value;
3267
- chunks.push(Buffer.from(chunk));
3268
- }
3269
- } catch (temp) {
3270
- error = [temp];
3271
- } finally {
3272
- try {
3273
- more && (temp = iter.return) && await temp.call(iter);
3274
- } finally {
3275
- if (error)
3276
- throw error[0];
3277
- }
3393
+ for await (const chunk of stream) {
3394
+ chunks.push(Buffer.from(chunk));
3278
3395
  }
3279
3396
  return Buffer.concat(chunks).toString("utf-8");
3280
3397
  }
3281
3398
  async function streamToBuffer2(stream) {
3282
3399
  const chunks = [];
3283
- try {
3284
- for (var iter = __forAwait(stream), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
3285
- const chunk = temp.value;
3286
- chunks.push(Buffer.from(chunk));
3287
- }
3288
- } catch (temp) {
3289
- error = [temp];
3290
- } finally {
3291
- try {
3292
- more && (temp = iter.return) && await temp.call(iter);
3293
- } finally {
3294
- if (error)
3295
- throw error[0];
3296
- }
3400
+ for await (const chunk of stream) {
3401
+ chunks.push(Buffer.from(chunk));
3297
3402
  }
3298
3403
  return Buffer.concat(chunks);
3299
3404
  }
@@ -3469,6 +3574,19 @@ async function cloneCommand(themeName, options) {
3469
3574
  spinner.succeed(
3470
3575
  `Renamed theme: ${chalk4__default.default.gray(themeName)} \u2192 ${chalk4__default.default.cyan(newName)}`
3471
3576
  );
3577
+ const envExamplePath = path__default.default.join(outputDir, ".env.example");
3578
+ if (!await fs__default.default.pathExists(envExamplePath)) {
3579
+ await fs__default.default.writeFile(
3580
+ envExamplePath,
3581
+ [
3582
+ "# API Configuration (enables real data in preview)",
3583
+ "# Get your Company ID from the OneX dashboard",
3584
+ "NEXT_PUBLIC_API_URL=https://api-dev.onexeos.com",
3585
+ "NEXT_PUBLIC_COMPANY_ID=",
3586
+ ""
3587
+ ].join("\n")
3588
+ );
3589
+ }
3472
3590
  if (options.install !== false) {
3473
3591
  const hasPkgJson = await fs__default.default.pathExists(
3474
3592
  path__default.default.join(outputDir, "package.json")
@@ -3499,6 +3617,7 @@ async function cloneCommand(themeName, options) {
3499
3617
  console.log();
3500
3618
  console.log(chalk4__default.default.cyan("Next steps:"));
3501
3619
  console.log(chalk4__default.default.gray(` cd ${path__default.default.relative(process.cwd(), outputDir)}`));
3620
+ console.log(chalk4__default.default.gray(" cp .env.example .env # then add your Company ID"));
3502
3621
  if (options.install === false) {
3503
3622
  console.log(chalk4__default.default.gray(" pnpm install"));
3504
3623
  }
@@ -3556,7 +3675,12 @@ function createDevServer(options) {
3556
3675
  res.end("Forbidden");
3557
3676
  return;
3558
3677
  }
3559
- serveFile(res, filePath);
3678
+ if (fs2__default.default.existsSync(filePath) && fs2__default.default.statSync(filePath).isFile()) {
3679
+ serveFile(res, filePath);
3680
+ } else {
3681
+ res.writeHead(200, { "Content-Type": "text/html" });
3682
+ res.end(generatePreviewHTML(options.themeName));
3683
+ }
3560
3684
  });
3561
3685
  const wss = new ws.WebSocketServer({ server });
3562
3686
  wss.on("connection", (ws) => {
@@ -3591,7 +3715,7 @@ function serveFile(res, filePath) {
3591
3715
  const content = fs2__default.default.readFileSync(filePath);
3592
3716
  res.writeHead(200, { "Content-Type": contentType });
3593
3717
  res.end(content);
3594
- } catch (e) {
3718
+ } catch {
3595
3719
  res.writeHead(500);
3596
3720
  res.end("Internal Server Error");
3597
3721
  }
@@ -3652,7 +3776,7 @@ async function devCommand(options) {
3652
3776
  } else {
3653
3777
  themePath = path__default.default.join(process.cwd(), themeName);
3654
3778
  }
3655
- } catch (e) {
3779
+ } catch {
3656
3780
  themePath = path__default.default.join(process.cwd(), themeName);
3657
3781
  }
3658
3782
  if (!fs__default.default.existsSync(themePath)) {
@@ -3738,7 +3862,7 @@ async function devCommand(options) {
3738
3862
  const shimPath = path__default.default.join(outputDir, ".process-shim.js");
3739
3863
  try {
3740
3864
  await fs7__default.default.unlink(shimPath);
3741
- } catch (e) {
3865
+ } catch {
3742
3866
  }
3743
3867
  process.exit(0);
3744
3868
  });
@@ -3752,7 +3876,7 @@ try {
3752
3876
  quiet: true
3753
3877
  });
3754
3878
  dotenv__default.default.config({ path: path__default.default.join(projectRoot, ".env"), quiet: true });
3755
- } catch (e) {
3879
+ } catch {
3756
3880
  }
3757
3881
  dotenv__default.default.config({
3758
3882
  path: path__default.default.join(os__default.default.homedir(), ".onex", ".env"),