@onexapis/cli 1.1.1 → 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.js CHANGED
@@ -66,7 +66,22 @@ var http__default = /*#__PURE__*/_interopDefault(http);
66
66
 
67
67
  var __defProp = Object.defineProperty;
68
68
  var __getOwnPropNames = Object.getOwnPropertyNames;
69
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
70
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
71
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
69
72
  var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
73
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
74
+ var __spreadValues = (a, b) => {
75
+ for (var prop in b || (b = {}))
76
+ if (__hasOwnProp.call(b, prop))
77
+ __defNormalProp(a, prop, b[prop]);
78
+ if (__getOwnPropSymbols)
79
+ for (var prop of __getOwnPropSymbols(b)) {
80
+ if (__propIsEnum.call(b, prop))
81
+ __defNormalProp(a, prop, b[prop]);
82
+ }
83
+ return a;
84
+ };
70
85
  var __esm = (fn, res) => function __init() {
71
86
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
72
87
  };
@@ -222,6 +237,75 @@ ${namedExportLines}
222
237
  }
223
238
  };
224
239
  }
240
+ async function generateThemeData(themePath, outputDir, themeId) {
241
+ const { createJiti } = await import('jiti');
242
+ const jiti = createJiti(import_meta.url);
243
+ let themeConfig = null;
244
+ let layoutConfig = null;
245
+ const pages = {};
246
+ for (const ext of [".ts", ".js"]) {
247
+ try {
248
+ const mod = await jiti.import(path__default.default.join(themePath, `theme.config${ext}`));
249
+ themeConfig = mod.default || mod;
250
+ break;
251
+ } catch (e) {
252
+ }
253
+ }
254
+ for (const ext of [".ts", ".js"]) {
255
+ try {
256
+ const mod = await jiti.import(path__default.default.join(themePath, `theme.layout${ext}`));
257
+ layoutConfig = mod.default || mod;
258
+ break;
259
+ } catch (e) {
260
+ }
261
+ }
262
+ const pagesDir = path__default.default.join(themePath, "pages");
263
+ try {
264
+ const files = await fs7__default.default.readdir(pagesDir);
265
+ for (const file of files) {
266
+ if (!file.match(/\.(ts|js)$/)) continue;
267
+ const name = file.replace(/\.(ts|js)$/, "");
268
+ try {
269
+ const mod = await jiti.import(path__default.default.join(pagesDir, file));
270
+ const config = mod.default || mod;
271
+ pages[name] = {
272
+ id: name,
273
+ name: config.title || name,
274
+ path: config.path || `/${name}`,
275
+ config: __spreadValues({ id: name }, config),
276
+ sections: config.sections || [],
277
+ seo: config.seo
278
+ };
279
+ } catch (e) {
280
+ }
281
+ }
282
+ } catch (e) {
283
+ }
284
+ await fs7__default.default.writeFile(
285
+ path__default.default.join(outputDir, "theme-data.json"),
286
+ JSON.stringify(
287
+ {
288
+ themeId,
289
+ theme: {
290
+ id: themeId,
291
+ name: (themeConfig == null ? void 0 : themeConfig.name) || themeId,
292
+ config: themeConfig,
293
+ layout: {
294
+ header: (layoutConfig == null ? void 0 : layoutConfig.headerSections) || [],
295
+ footer: (layoutConfig == null ? void 0 : layoutConfig.footerSections) || []
296
+ },
297
+ pages: Object.keys(pages)
298
+ },
299
+ pages
300
+ },
301
+ null,
302
+ 2
303
+ )
304
+ );
305
+ logger.info(
306
+ `Generated theme-data.json (${Object.keys(pages).length} pages)`
307
+ );
308
+ }
225
309
  async function contentHashEntry(outputDir) {
226
310
  const entryPath = path__default.default.join(outputDir, "bundle-entry.js");
227
311
  const mapPath = path__default.default.join(outputDir, "bundle-entry.js.map");
@@ -403,6 +487,7 @@ async function compileStandaloneTheme(themePath, themeName) {
403
487
  }
404
488
  await contentHashEntry(outputDir);
405
489
  await generateManifest2(themeName, themePath, outputDir);
490
+ await generateThemeData(themePath, outputDir, themeName);
406
491
  if (result.metafile) {
407
492
  const outputs = result.metafile.outputs;
408
493
  let totalSize = 0;
@@ -479,6 +564,7 @@ async function compileStandaloneThemeDev(themePath, themeName) {
479
564
  const context2 = await esbuild__namespace.context(buildOptions);
480
565
  await context2.rebuild();
481
566
  await generateManifest2(themeName, themePath, outputDir);
567
+ await generateThemeData(themePath, outputDir, themeName);
482
568
  return { context: context2, outputDir };
483
569
  }
484
570
  async function compilePreviewRuntime(themePath) {
@@ -641,10 +727,11 @@ export default { motion, AnimatePresence };
641
727
  });
642
728
  return outputPath;
643
729
  }
644
- var PROCESS_SHIM, reactGlobalPlugin;
730
+ var import_meta, PROCESS_SHIM, reactGlobalPlugin;
645
731
  var init_compile_theme = __esm({
646
732
  "src/utils/compile-theme.ts"() {
647
733
  init_logger();
734
+ import_meta = {};
648
735
  PROCESS_SHIM = `
649
736
  if (typeof process === "undefined") {
650
737
  globalThis.process = {
@@ -3556,7 +3643,12 @@ function createDevServer(options) {
3556
3643
  res.end("Forbidden");
3557
3644
  return;
3558
3645
  }
3559
- serveFile(res, filePath);
3646
+ if (fs2__default.default.existsSync(filePath) && fs2__default.default.statSync(filePath).isFile()) {
3647
+ serveFile(res, filePath);
3648
+ } else {
3649
+ res.writeHead(200, { "Content-Type": "text/html" });
3650
+ res.end(generatePreviewHTML(options.themeName));
3651
+ }
3560
3652
  });
3561
3653
  const wss = new ws.WebSocketServer({ server });
3562
3654
  wss.on("connection", (ws) => {