@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 +94 -2
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +94 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +88 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -1
- package/dist/index.mjs.map +1 -1
- package/dist/preview/preview-app.tsx +91 -24
- package/package.json +4 -3
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) {
|
|
@@ -600,10 +686,11 @@ export default { motion, AnimatePresence };
|
|
|
600
686
|
});
|
|
601
687
|
return outputPath;
|
|
602
688
|
}
|
|
603
|
-
var PROCESS_SHIM, reactGlobalPlugin;
|
|
689
|
+
var import_meta, PROCESS_SHIM, reactGlobalPlugin;
|
|
604
690
|
var init_compile_theme = __esm({
|
|
605
691
|
"src/utils/compile-theme.ts"() {
|
|
606
692
|
init_logger();
|
|
693
|
+
import_meta = {};
|
|
607
694
|
PROCESS_SHIM = `
|
|
608
695
|
if (typeof process === "undefined") {
|
|
609
696
|
globalThis.process = {
|
|
@@ -3515,7 +3602,12 @@ function createDevServer(options) {
|
|
|
3515
3602
|
res.end("Forbidden");
|
|
3516
3603
|
return;
|
|
3517
3604
|
}
|
|
3518
|
-
|
|
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
|
+
}
|
|
3519
3611
|
});
|
|
3520
3612
|
const wss = new WebSocketServer({ server });
|
|
3521
3613
|
wss.on("connection", (ws) => {
|