@onexapis/cli 1.1.0 → 1.1.2

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.mjs CHANGED
@@ -25,7 +25,22 @@ import { WebSocketServer, WebSocket } from 'ws';
25
25
 
26
26
  var __defProp = Object.defineProperty;
27
27
  var __getOwnPropNames = Object.getOwnPropertyNames;
28
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
29
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
30
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
28
31
  var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
32
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
33
+ var __spreadValues = (a, b) => {
34
+ for (var prop in b || (b = {}))
35
+ if (__hasOwnProp.call(b, prop))
36
+ __defNormalProp(a, prop, b[prop]);
37
+ if (__getOwnPropSymbols)
38
+ for (var prop of __getOwnPropSymbols(b)) {
39
+ if (__propIsEnum.call(b, prop))
40
+ __defNormalProp(a, prop, b[prop]);
41
+ }
42
+ return a;
43
+ };
29
44
  var __esm = (fn, res) => function __init() {
30
45
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
31
46
  };
@@ -181,6 +196,75 @@ ${namedExportLines}
181
196
  }
182
197
  };
183
198
  }
199
+ async function generateThemeData(themePath, outputDir, themeId) {
200
+ const { createJiti } = await import('jiti');
201
+ const jiti = createJiti(import_meta.url);
202
+ let themeConfig = null;
203
+ let layoutConfig = null;
204
+ const pages = {};
205
+ for (const ext of [".ts", ".js"]) {
206
+ try {
207
+ const mod = await jiti.import(path.join(themePath, `theme.config${ext}`));
208
+ themeConfig = mod.default || mod;
209
+ break;
210
+ } catch (e) {
211
+ }
212
+ }
213
+ for (const ext of [".ts", ".js"]) {
214
+ try {
215
+ const mod = await jiti.import(path.join(themePath, `theme.layout${ext}`));
216
+ layoutConfig = mod.default || mod;
217
+ break;
218
+ } catch (e) {
219
+ }
220
+ }
221
+ const pagesDir = path.join(themePath, "pages");
222
+ try {
223
+ const files = await fs7.readdir(pagesDir);
224
+ for (const file of files) {
225
+ if (!file.match(/\.(ts|js)$/)) continue;
226
+ const name = file.replace(/\.(ts|js)$/, "");
227
+ try {
228
+ const mod = await jiti.import(path.join(pagesDir, file));
229
+ const config = mod.default || mod;
230
+ pages[name] = {
231
+ id: name,
232
+ name: config.title || name,
233
+ path: config.path || `/${name}`,
234
+ config: __spreadValues({ id: name }, config),
235
+ sections: config.sections || [],
236
+ seo: config.seo
237
+ };
238
+ } catch (e) {
239
+ }
240
+ }
241
+ } catch (e) {
242
+ }
243
+ await fs7.writeFile(
244
+ path.join(outputDir, "theme-data.json"),
245
+ JSON.stringify(
246
+ {
247
+ themeId,
248
+ theme: {
249
+ id: themeId,
250
+ name: (themeConfig == null ? void 0 : themeConfig.name) || themeId,
251
+ config: themeConfig,
252
+ layout: {
253
+ header: (layoutConfig == null ? void 0 : layoutConfig.headerSections) || [],
254
+ footer: (layoutConfig == null ? void 0 : layoutConfig.footerSections) || []
255
+ },
256
+ pages: Object.keys(pages)
257
+ },
258
+ pages
259
+ },
260
+ null,
261
+ 2
262
+ )
263
+ );
264
+ logger.info(
265
+ `Generated theme-data.json (${Object.keys(pages).length} pages)`
266
+ );
267
+ }
184
268
  async function contentHashEntry(outputDir) {
185
269
  const entryPath = path.join(outputDir, "bundle-entry.js");
186
270
  const mapPath = path.join(outputDir, "bundle-entry.js.map");
@@ -362,6 +446,7 @@ async function compileStandaloneTheme(themePath, themeName) {
362
446
  }
363
447
  await contentHashEntry(outputDir);
364
448
  await generateManifest2(themeName, themePath, outputDir);
449
+ await generateThemeData(themePath, outputDir, themeName);
365
450
  if (result.metafile) {
366
451
  const outputs = result.metafile.outputs;
367
452
  let totalSize = 0;
@@ -438,6 +523,7 @@ async function compileStandaloneThemeDev(themePath, themeName) {
438
523
  const context2 = await esbuild.context(buildOptions);
439
524
  await context2.rebuild();
440
525
  await generateManifest2(themeName, themePath, outputDir);
526
+ await generateThemeData(themePath, outputDir, themeName);
441
527
  return { context: context2, outputDir };
442
528
  }
443
529
  async function compilePreviewRuntime(themePath) {
@@ -511,6 +597,65 @@ ${locations.join("\n")}`
511
597
  loader: "js"
512
598
  };
513
599
  });
600
+ build2.onResolve({ filter: /^lucide-react/ }, async (args) => {
601
+ var _a;
602
+ if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
603
+ try {
604
+ const result = await build2.resolve(args.path, {
605
+ kind: args.kind,
606
+ resolveDir: args.resolveDir,
607
+ importer: args.importer,
608
+ namespace: "file",
609
+ pluginData: { skipStub: true }
610
+ });
611
+ if (!result.errors.length) return result;
612
+ } catch (e) {
613
+ }
614
+ return { path: args.path, namespace: "lucide-stub" };
615
+ });
616
+ build2.onLoad({ filter: /.*/, namespace: "lucide-stub" }, () => ({
617
+ // Provide all icon names used by @onexapis/core as no-op SVG stub components
618
+ contents: `
619
+ const icon = (props) => null;
620
+ export { icon as Check, icon as ChevronDown, icon as XCircle, icon as AlertTriangle };
621
+ export { icon as CheckCircle, icon as Info, icon as X, icon as XIcon };
622
+ export { icon as CircleIcon, icon as Star, icon as ShoppingCart };
623
+ export { icon as ChevronRight, icon as ChevronLeft, icon as ChevronUp };
624
+ export { icon as Search, icon as Menu, icon as Heart, icon as User };
625
+ export { icon as Trash2, icon as Plus, icon as Minus, icon as Eye, icon as EyeOff };
626
+ export { icon as ArrowRight, icon as ArrowLeft, icon as ExternalLink, icon as Mail };
627
+ export { icon as Phone, icon as MapPin, icon as Calendar, icon as Clock };
628
+ export { icon as Facebook, icon as Twitter, icon as Instagram, icon as Linkedin, icon as Github };
629
+ export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true : icon });
630
+ `.trim(),
631
+ loader: "jsx"
632
+ }));
633
+ build2.onResolve({ filter: /^framer-motion/ }, async (args) => {
634
+ var _a;
635
+ if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
636
+ try {
637
+ const result = await build2.resolve(args.path, {
638
+ kind: args.kind,
639
+ resolveDir: args.resolveDir,
640
+ importer: args.importer,
641
+ namespace: "file",
642
+ pluginData: { skipStub: true }
643
+ });
644
+ if (!result.errors.length) return result;
645
+ } catch (e) {
646
+ }
647
+ return { path: args.path, namespace: "motion-stub" };
648
+ });
649
+ build2.onLoad({ filter: /.*/, namespace: "motion-stub" }, () => ({
650
+ contents: `
651
+ const stub = (props) => props.children || null;
652
+ const handler = { get: (_, name) => name === '__esModule' ? true : stub };
653
+ export const motion = new Proxy({}, handler);
654
+ export const AnimatePresence = stub;
655
+ export default { motion, AnimatePresence };
656
+ `.trim(),
657
+ loader: "jsx"
658
+ }));
514
659
  }
515
660
  };
516
661
  await esbuild.build({
@@ -541,10 +686,11 @@ ${locations.join("\n")}`
541
686
  });
542
687
  return outputPath;
543
688
  }
544
- var PROCESS_SHIM, reactGlobalPlugin;
689
+ var import_meta, PROCESS_SHIM, reactGlobalPlugin;
545
690
  var init_compile_theme = __esm({
546
691
  "src/utils/compile-theme.ts"() {
547
692
  init_logger();
693
+ import_meta = {};
548
694
  PROCESS_SHIM = `
549
695
  if (typeof process === "undefined") {
550
696
  globalThis.process = {
@@ -3456,7 +3602,12 @@ function createDevServer(options) {
3456
3602
  res.end("Forbidden");
3457
3603
  return;
3458
3604
  }
3459
- serveFile(res, filePath);
3605
+ if (fs2.existsSync(filePath) && fs2.statSync(filePath).isFile()) {
3606
+ serveFile(res, filePath);
3607
+ } else {
3608
+ res.writeHead(200, { "Content-Type": "text/html" });
3609
+ res.end(generatePreviewHTML(options.themeName));
3610
+ }
3460
3611
  });
3461
3612
  const wss = new WebSocketServer({ server });
3462
3613
  wss.on("connection", (ws) => {