@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 +221 -97
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +220 -97
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +211 -92
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +210 -92
- package/dist/index.mjs.map +1 -1
- package/dist/preview/preview-app.tsx +195 -37
- package/package.json +6 -3
- package/templates/default/.env.example +4 -0
- package/templates/default/package.json.ejs +2 -1
package/dist/cli.mjs
CHANGED
|
@@ -25,7 +25,6 @@ import { WebSocketServer, WebSocket } from 'ws';
|
|
|
25
25
|
|
|
26
26
|
var __defProp = Object.defineProperty;
|
|
27
27
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
28
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
|
|
29
28
|
var __esm = (fn, res) => function __init() {
|
|
30
29
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
31
30
|
};
|
|
@@ -33,7 +32,6 @@ var __export = (target, all) => {
|
|
|
33
32
|
for (var name in all)
|
|
34
33
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
35
34
|
};
|
|
36
|
-
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);
|
|
37
35
|
var Logger, logger;
|
|
38
36
|
var init_logger = __esm({
|
|
39
37
|
"src/utils/logger.ts"() {
|
|
@@ -106,7 +104,7 @@ async function resolveNodeModulesFile(startDir, relativePath) {
|
|
|
106
104
|
try {
|
|
107
105
|
await fs7.access(candidate);
|
|
108
106
|
return candidate;
|
|
109
|
-
} catch
|
|
107
|
+
} catch {
|
|
110
108
|
const parent = path.dirname(dir);
|
|
111
109
|
if (parent === dir) break;
|
|
112
110
|
dir = parent;
|
|
@@ -125,7 +123,7 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
125
123
|
}));
|
|
126
124
|
build2.onLoad({ filter: /.*/, namespace: "core-global" }, async (args) => {
|
|
127
125
|
const match = args.path.match(/^@onexapis\/core(\/(.+))?$/);
|
|
128
|
-
const subpath =
|
|
126
|
+
const subpath = match?.[2] || "";
|
|
129
127
|
const moduleAccess = subpath ? `['${subpath}']` : "";
|
|
130
128
|
let namedExports = [];
|
|
131
129
|
const cacheKey = subpath || "__root__";
|
|
@@ -149,7 +147,7 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
149
147
|
namedExports.push(...names);
|
|
150
148
|
}
|
|
151
149
|
namedExports = [...new Set(namedExports)];
|
|
152
|
-
} catch
|
|
150
|
+
} catch {
|
|
153
151
|
}
|
|
154
152
|
exportsBySubpath[cacheKey] = namedExports;
|
|
155
153
|
}
|
|
@@ -181,6 +179,73 @@ ${namedExportLines}
|
|
|
181
179
|
}
|
|
182
180
|
};
|
|
183
181
|
}
|
|
182
|
+
async function generateThemeData(themePath, outputDir, themeId) {
|
|
183
|
+
const { createJiti } = await import('jiti');
|
|
184
|
+
const jiti = createJiti(import.meta.url);
|
|
185
|
+
let themeConfig = null;
|
|
186
|
+
let layoutConfig = null;
|
|
187
|
+
const pages = {};
|
|
188
|
+
for (const ext of [".ts", ".js"]) {
|
|
189
|
+
try {
|
|
190
|
+
const mod = await jiti.import(path.join(themePath, `theme.config${ext}`));
|
|
191
|
+
themeConfig = mod.default || mod;
|
|
192
|
+
break;
|
|
193
|
+
} catch {
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
for (const ext of [".ts", ".js"]) {
|
|
197
|
+
try {
|
|
198
|
+
const mod = await jiti.import(path.join(themePath, `theme.layout${ext}`));
|
|
199
|
+
layoutConfig = mod.default || mod;
|
|
200
|
+
break;
|
|
201
|
+
} catch {
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const pagesDir = path.join(themePath, "pages");
|
|
205
|
+
try {
|
|
206
|
+
const files = await fs7.readdir(pagesDir);
|
|
207
|
+
for (const file of files) {
|
|
208
|
+
if (!file.match(/\.(ts|js)$/)) continue;
|
|
209
|
+
const name = file.replace(/\.(ts|js)$/, "");
|
|
210
|
+
try {
|
|
211
|
+
const mod = await jiti.import(path.join(pagesDir, file));
|
|
212
|
+
const config = mod.default || mod;
|
|
213
|
+
pages[name] = {
|
|
214
|
+
id: name,
|
|
215
|
+
name: config.title || name,
|
|
216
|
+
path: config.path || `/${name}`,
|
|
217
|
+
config: { id: name, ...config },
|
|
218
|
+
sections: config.sections || [],
|
|
219
|
+
seo: config.seo
|
|
220
|
+
};
|
|
221
|
+
} catch {
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
} catch {
|
|
225
|
+
}
|
|
226
|
+
await fs7.writeFile(
|
|
227
|
+
path.join(outputDir, "theme-data.json"),
|
|
228
|
+
JSON.stringify(
|
|
229
|
+
{
|
|
230
|
+
themeId,
|
|
231
|
+
theme: {
|
|
232
|
+
id: themeId,
|
|
233
|
+
name: themeConfig?.name || themeId,
|
|
234
|
+
config: themeConfig,
|
|
235
|
+
layout: {
|
|
236
|
+
header: layoutConfig?.headerSections || [],
|
|
237
|
+
footer: layoutConfig?.footerSections || []
|
|
238
|
+
},
|
|
239
|
+
pages: Object.keys(pages)
|
|
240
|
+
},
|
|
241
|
+
pages
|
|
242
|
+
},
|
|
243
|
+
null,
|
|
244
|
+
2
|
|
245
|
+
)
|
|
246
|
+
);
|
|
247
|
+
logger.info(`Generated theme-data.json (${Object.keys(pages).length} pages)`);
|
|
248
|
+
}
|
|
184
249
|
async function contentHashEntry(outputDir) {
|
|
185
250
|
const entryPath = path.join(outputDir, "bundle-entry.js");
|
|
186
251
|
const mapPath = path.join(outputDir, "bundle-entry.js.map");
|
|
@@ -191,11 +256,11 @@ async function contentHashEntry(outputDir) {
|
|
|
191
256
|
let entryContent;
|
|
192
257
|
try {
|
|
193
258
|
entryContent = await fs7.readFile(entryPath, "utf-8");
|
|
194
|
-
} catch
|
|
259
|
+
} catch {
|
|
195
260
|
const indexPath = path.join(outputDir, "index.js");
|
|
196
261
|
try {
|
|
197
262
|
entryContent = await fs7.readFile(indexPath, "utf-8");
|
|
198
|
-
} catch
|
|
263
|
+
} catch {
|
|
199
264
|
logger.warning("No entry file found in output, skipping content hash");
|
|
200
265
|
return;
|
|
201
266
|
}
|
|
@@ -212,7 +277,7 @@ async function contentHashEntry(outputDir) {
|
|
|
212
277
|
try {
|
|
213
278
|
await fs7.access(indexMapPath);
|
|
214
279
|
await fs7.rename(indexMapPath, path.join(outputDir, hashedMapName2));
|
|
215
|
-
} catch
|
|
280
|
+
} catch {
|
|
216
281
|
}
|
|
217
282
|
logger.info(`Entry hashed: ${hashedName2}`);
|
|
218
283
|
return;
|
|
@@ -229,10 +294,32 @@ async function contentHashEntry(outputDir) {
|
|
|
229
294
|
try {
|
|
230
295
|
await fs7.access(mapPath);
|
|
231
296
|
await fs7.rename(mapPath, path.join(outputDir, hashedMapName));
|
|
232
|
-
} catch
|
|
297
|
+
} catch {
|
|
233
298
|
}
|
|
234
299
|
logger.info(`Entry hashed: ${hashedName}`);
|
|
235
300
|
}
|
|
301
|
+
async function extractDataRequirements(themePath) {
|
|
302
|
+
const { createJiti } = await import('jiti');
|
|
303
|
+
const jiti = createJiti(import.meta.url);
|
|
304
|
+
const schemaFiles = await glob("sections/**/*.schema.ts", { cwd: themePath });
|
|
305
|
+
const requirements = {};
|
|
306
|
+
for (const file of schemaFiles) {
|
|
307
|
+
try {
|
|
308
|
+
const mod = await jiti.import(path.join(themePath, file));
|
|
309
|
+
const exports$1 = mod;
|
|
310
|
+
for (const value of Object.values(exports$1)) {
|
|
311
|
+
if (value && typeof value === "object" && typeof value.type === "string" && value.dataRequirements && typeof value.dataRequirements === "object") {
|
|
312
|
+
requirements[value.type] = value.dataRequirements;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
} catch (err) {
|
|
316
|
+
logger.warning(
|
|
317
|
+
`Could not load schema ${file}: ${err instanceof Error ? err.message : String(err)}`
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return requirements;
|
|
322
|
+
}
|
|
236
323
|
async function generateManifest2(themeName, themePath, outputDir) {
|
|
237
324
|
let version = "1.0.0";
|
|
238
325
|
let themeId = themeName;
|
|
@@ -246,18 +333,19 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
246
333
|
if (pkg.name) {
|
|
247
334
|
themeId = pkg.name.replace(/^@onex-themes\//, "");
|
|
248
335
|
}
|
|
249
|
-
} catch
|
|
336
|
+
} catch {
|
|
250
337
|
}
|
|
251
338
|
const [sectionFiles, blockFiles, schemaFiles] = await Promise.all([
|
|
252
339
|
glob("sections/**/index.ts", { cwd: themePath }),
|
|
253
340
|
glob("blocks/**/index.ts", { cwd: themePath }),
|
|
254
341
|
glob("**/*.schema.ts", { cwd: themePath })
|
|
255
342
|
]);
|
|
343
|
+
const dataRequirements = await extractDataRequirements(themePath);
|
|
256
344
|
let hasThemeConfig = false;
|
|
257
345
|
try {
|
|
258
346
|
await fs7.access(path.join(themePath, "theme.config.ts"));
|
|
259
347
|
hasThemeConfig = true;
|
|
260
|
-
} catch
|
|
348
|
+
} catch {
|
|
261
349
|
}
|
|
262
350
|
const allFiles = await glob("**/*", { cwd: outputDir, nodir: true });
|
|
263
351
|
const jsFiles = allFiles.filter((f) => f.endsWith(".js"));
|
|
@@ -292,7 +380,9 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
292
380
|
blocks: blockFiles,
|
|
293
381
|
schemas: schemaFiles,
|
|
294
382
|
hasThemeConfig
|
|
295
|
-
}
|
|
383
|
+
},
|
|
384
|
+
// Section data requirements for server-side prefetching (keyed by section type)
|
|
385
|
+
dataRequirements
|
|
296
386
|
};
|
|
297
387
|
await fs7.writeFile(
|
|
298
388
|
path.join(outputDir, "manifest.json"),
|
|
@@ -307,7 +397,7 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
307
397
|
try {
|
|
308
398
|
await fs7.access(bundleEntry);
|
|
309
399
|
entryPoint = bundleEntry;
|
|
310
|
-
} catch
|
|
400
|
+
} catch {
|
|
311
401
|
}
|
|
312
402
|
const shimPath = path.join(outputDir, ".process-shim.js");
|
|
313
403
|
await fs7.mkdir(outputDir, { recursive: true });
|
|
@@ -358,10 +448,11 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
358
448
|
const result = await esbuild.build(buildOptions);
|
|
359
449
|
try {
|
|
360
450
|
await fs7.unlink(shimPath);
|
|
361
|
-
} catch
|
|
451
|
+
} catch {
|
|
362
452
|
}
|
|
363
453
|
await contentHashEntry(outputDir);
|
|
364
454
|
await generateManifest2(themeName, themePath, outputDir);
|
|
455
|
+
await generateThemeData(themePath, outputDir, themeName);
|
|
365
456
|
if (result.metafile) {
|
|
366
457
|
const outputs = result.metafile.outputs;
|
|
367
458
|
let totalSize = 0;
|
|
@@ -375,7 +466,7 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
375
466
|
} catch (error) {
|
|
376
467
|
try {
|
|
377
468
|
await fs7.unlink(shimPath);
|
|
378
|
-
} catch
|
|
469
|
+
} catch {
|
|
379
470
|
}
|
|
380
471
|
logger.error(`esbuild compilation failed: ${error}`);
|
|
381
472
|
return false;
|
|
@@ -389,7 +480,7 @@ async function compileStandaloneThemeDev(themePath, themeName) {
|
|
|
389
480
|
try {
|
|
390
481
|
await fs7.access(bundleEntry);
|
|
391
482
|
entryPoint = bundleEntry;
|
|
392
|
-
} catch
|
|
483
|
+
} catch {
|
|
393
484
|
}
|
|
394
485
|
const shimPath = path.join(outputDir, ".process-shim.js");
|
|
395
486
|
await fs7.mkdir(outputDir, { recursive: true });
|
|
@@ -438,6 +529,7 @@ async function compileStandaloneThemeDev(themePath, themeName) {
|
|
|
438
529
|
const context2 = await esbuild.context(buildOptions);
|
|
439
530
|
await context2.rebuild();
|
|
440
531
|
await generateManifest2(themeName, themePath, outputDir);
|
|
532
|
+
await generateThemeData(themePath, outputDir, themeName);
|
|
441
533
|
return { context: context2, outputDir };
|
|
442
534
|
}
|
|
443
535
|
async function compilePreviewRuntime(themePath) {
|
|
@@ -455,7 +547,7 @@ async function compilePreviewRuntime(themePath) {
|
|
|
455
547
|
await fs7.access(loc);
|
|
456
548
|
previewEntryPath = loc;
|
|
457
549
|
break;
|
|
458
|
-
} catch
|
|
550
|
+
} catch {
|
|
459
551
|
}
|
|
460
552
|
}
|
|
461
553
|
if (!previewEntryPath) {
|
|
@@ -495,10 +587,13 @@ ${locations.join("\n")}`
|
|
|
495
587
|
"zlib"
|
|
496
588
|
];
|
|
497
589
|
for (const mod of nodeBuiltins) {
|
|
498
|
-
build2.onResolve(
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
590
|
+
build2.onResolve(
|
|
591
|
+
{ filter: new RegExp(`^${mod.replace("/", "\\/")}$`) },
|
|
592
|
+
() => ({
|
|
593
|
+
path: mod,
|
|
594
|
+
namespace: "node-stub"
|
|
595
|
+
})
|
|
596
|
+
);
|
|
502
597
|
}
|
|
503
598
|
build2.onLoad({ filter: /.*/, namespace: "node-stub" }, (args) => {
|
|
504
599
|
const stubs = {
|
|
@@ -512,8 +607,7 @@ ${locations.join("\n")}`
|
|
|
512
607
|
};
|
|
513
608
|
});
|
|
514
609
|
build2.onResolve({ filter: /^lucide-react/ }, async (args) => {
|
|
515
|
-
|
|
516
|
-
if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
|
|
610
|
+
if (args.pluginData?.skipStub) return void 0;
|
|
517
611
|
try {
|
|
518
612
|
const result = await build2.resolve(args.path, {
|
|
519
613
|
kind: args.kind,
|
|
@@ -523,7 +617,7 @@ ${locations.join("\n")}`
|
|
|
523
617
|
pluginData: { skipStub: true }
|
|
524
618
|
});
|
|
525
619
|
if (!result.errors.length) return result;
|
|
526
|
-
} catch
|
|
620
|
+
} catch {
|
|
527
621
|
}
|
|
528
622
|
return { path: args.path, namespace: "lucide-stub" };
|
|
529
623
|
});
|
|
@@ -545,8 +639,7 @@ export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true :
|
|
|
545
639
|
loader: "jsx"
|
|
546
640
|
}));
|
|
547
641
|
build2.onResolve({ filter: /^framer-motion/ }, async (args) => {
|
|
548
|
-
|
|
549
|
-
if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
|
|
642
|
+
if (args.pluginData?.skipStub) return void 0;
|
|
550
643
|
try {
|
|
551
644
|
const result = await build2.resolve(args.path, {
|
|
552
645
|
kind: args.kind,
|
|
@@ -556,7 +649,7 @@ export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true :
|
|
|
556
649
|
pluginData: { skipStub: true }
|
|
557
650
|
});
|
|
558
651
|
if (!result.errors.length) return result;
|
|
559
|
-
} catch
|
|
652
|
+
} catch {
|
|
560
653
|
}
|
|
561
654
|
return { path: args.path, namespace: "motion-stub" };
|
|
562
655
|
});
|
|
@@ -570,8 +663,59 @@ export default { motion, AnimatePresence };
|
|
|
570
663
|
`.trim(),
|
|
571
664
|
loader: "jsx"
|
|
572
665
|
}));
|
|
666
|
+
build2.onResolve({ filter: /^next\// }, async (args) => {
|
|
667
|
+
if (args.pluginData?.skipStub) return void 0;
|
|
668
|
+
try {
|
|
669
|
+
const result = await build2.resolve(args.path, {
|
|
670
|
+
kind: args.kind,
|
|
671
|
+
resolveDir: args.resolveDir,
|
|
672
|
+
importer: args.importer,
|
|
673
|
+
namespace: "file",
|
|
674
|
+
pluginData: { skipStub: true }
|
|
675
|
+
});
|
|
676
|
+
if (!result.errors.length) return result;
|
|
677
|
+
} catch {
|
|
678
|
+
}
|
|
679
|
+
return { path: args.path, namespace: "next-stub" };
|
|
680
|
+
});
|
|
681
|
+
build2.onLoad({ filter: /.*/, namespace: "next-stub" }, (args) => {
|
|
682
|
+
const stubs = {
|
|
683
|
+
"next/image": `
|
|
684
|
+
const Image = (props) => {
|
|
685
|
+
const { src, alt, width, height, fill, priority, ...rest } = props;
|
|
686
|
+
const imgSrc = typeof src === 'object' ? src.src : src;
|
|
687
|
+
return React.createElement('img', { src: imgSrc, alt, width: fill ? undefined : width, height: fill ? undefined : height, loading: priority ? 'eager' : 'lazy', ...rest });
|
|
688
|
+
};
|
|
689
|
+
import React from 'react';
|
|
690
|
+
export default Image;
|
|
691
|
+
`,
|
|
692
|
+
"next/link": `
|
|
693
|
+
const Link = ({ href, children, ...rest }) => React.createElement('a', { href, ...rest }, children);
|
|
694
|
+
import React from 'react';
|
|
695
|
+
export default Link;
|
|
696
|
+
`,
|
|
697
|
+
"next/navigation": `
|
|
698
|
+
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(){} }; }
|
|
699
|
+
export function usePathname() { return window.location.pathname; }
|
|
700
|
+
export function useSearchParams() { return new URLSearchParams(window.location.search); }
|
|
701
|
+
export function useParams() { return {}; }
|
|
702
|
+
export function redirect(url) { window.location.href = url; }
|
|
703
|
+
export function notFound() { throw new Error('Not Found'); }
|
|
704
|
+
`,
|
|
705
|
+
"next/headers": `
|
|
706
|
+
export function cookies() { return { get(){}, getAll(){ return []; }, set(){}, delete(){}, has(){ return false; } }; }
|
|
707
|
+
export function headers() { return new Headers(); }
|
|
708
|
+
`
|
|
709
|
+
};
|
|
710
|
+
return {
|
|
711
|
+
contents: stubs[args.path] || "export default {};",
|
|
712
|
+
loader: "jsx"
|
|
713
|
+
};
|
|
714
|
+
});
|
|
573
715
|
}
|
|
574
716
|
};
|
|
717
|
+
const shimPath = path.join(outputDir, ".process-shim-preview.js");
|
|
718
|
+
await fs7.writeFile(shimPath, PROCESS_SHIM);
|
|
575
719
|
await esbuild.build({
|
|
576
720
|
entryPoints: [previewEntryPath],
|
|
577
721
|
bundle: true,
|
|
@@ -581,6 +725,7 @@ export default { motion, AnimatePresence };
|
|
|
581
725
|
// Bundle React + core INTO the output (NOT externalized)
|
|
582
726
|
external: [],
|
|
583
727
|
plugins: [serverStubPlugin],
|
|
728
|
+
inject: [shimPath],
|
|
584
729
|
minify: false,
|
|
585
730
|
sourcemap: true,
|
|
586
731
|
target: "es2020",
|
|
@@ -588,6 +733,12 @@ export default { motion, AnimatePresence };
|
|
|
588
733
|
jsxImportSource: "react",
|
|
589
734
|
define: {
|
|
590
735
|
"process.env.NODE_ENV": JSON.stringify("development"),
|
|
736
|
+
"process.env.NEXT_PUBLIC_API_URL": JSON.stringify(
|
|
737
|
+
process.env.NEXT_PUBLIC_API_URL || ""
|
|
738
|
+
),
|
|
739
|
+
"process.env.NEXT_PUBLIC_COMPANY_ID": JSON.stringify(
|
|
740
|
+
process.env.NEXT_PUBLIC_COMPANY_ID || ""
|
|
741
|
+
),
|
|
591
742
|
global: "globalThis"
|
|
592
743
|
},
|
|
593
744
|
loader: { ".tsx": "tsx", ".ts": "ts" },
|
|
@@ -598,6 +749,10 @@ export default { motion, AnimatePresence };
|
|
|
598
749
|
"ignored-bare-import": "silent"
|
|
599
750
|
}
|
|
600
751
|
});
|
|
752
|
+
try {
|
|
753
|
+
await fs7.unlink(shimPath);
|
|
754
|
+
} catch {
|
|
755
|
+
}
|
|
601
756
|
return outputPath;
|
|
602
757
|
}
|
|
603
758
|
var PROCESS_SHIM, reactGlobalPlugin;
|
|
@@ -1034,7 +1189,7 @@ Add your theme-specific blocks here.
|
|
|
1034
1189
|
stdio: "ignore"
|
|
1035
1190
|
});
|
|
1036
1191
|
logger.stopSpinner(true, "Git repository initialized!");
|
|
1037
|
-
} catch
|
|
1192
|
+
} catch {
|
|
1038
1193
|
logger.stopSpinner(false, "Failed to initialize git");
|
|
1039
1194
|
}
|
|
1040
1195
|
}
|
|
@@ -1045,7 +1200,7 @@ Add your theme-specific blocks here.
|
|
|
1045
1200
|
try {
|
|
1046
1201
|
await installDependencies(projectPath, packageManager);
|
|
1047
1202
|
logger.stopSpinner(true, "Dependencies installed!");
|
|
1048
|
-
} catch
|
|
1203
|
+
} catch {
|
|
1049
1204
|
logger.stopSpinner(false, "Failed to install dependencies");
|
|
1050
1205
|
logger.info(
|
|
1051
1206
|
"You can install dependencies manually by running: cd " + name + " && npm install"
|
|
@@ -2309,7 +2464,6 @@ async function validateCommand(options) {
|
|
|
2309
2464
|
// src/commands/build.ts
|
|
2310
2465
|
init_logger();
|
|
2311
2466
|
async function buildCommand(options) {
|
|
2312
|
-
var _a;
|
|
2313
2467
|
logger.header("Build Theme");
|
|
2314
2468
|
let themePath;
|
|
2315
2469
|
let themeName;
|
|
@@ -2322,7 +2476,7 @@ async function buildCommand(options) {
|
|
|
2322
2476
|
} else {
|
|
2323
2477
|
themePath = path.join(process.cwd(), themeName);
|
|
2324
2478
|
}
|
|
2325
|
-
} catch
|
|
2479
|
+
} catch {
|
|
2326
2480
|
themePath = path.join(process.cwd(), themeName);
|
|
2327
2481
|
}
|
|
2328
2482
|
if (!fs.existsSync(themePath)) {
|
|
@@ -2379,7 +2533,7 @@ async function buildCommand(options) {
|
|
|
2379
2533
|
}
|
|
2380
2534
|
logger.stopSpinner(true, "Lint passed");
|
|
2381
2535
|
const pkgJson = fs.readJsonSync(packageJsonPath);
|
|
2382
|
-
const buildScript =
|
|
2536
|
+
const buildScript = pkgJson.scripts?.build || "";
|
|
2383
2537
|
const isRecursive = buildScript.includes("onex build") || buildScript.includes("onex-cli build");
|
|
2384
2538
|
logger.startSpinner(
|
|
2385
2539
|
options.watch ? "Building (watch mode)..." : "Building..."
|
|
@@ -2736,7 +2890,6 @@ async function findCompiledThemeDir(themeId, version) {
|
|
|
2736
2890
|
return null;
|
|
2737
2891
|
}
|
|
2738
2892
|
async function readManifest() {
|
|
2739
|
-
var _a;
|
|
2740
2893
|
const manifestTsPath = path.resolve(process.cwd(), "manifest.ts");
|
|
2741
2894
|
if (await fs.pathExists(manifestTsPath)) {
|
|
2742
2895
|
try {
|
|
@@ -2750,7 +2903,7 @@ async function readManifest() {
|
|
|
2750
2903
|
if (await fs.pathExists(packageJsonPath)) {
|
|
2751
2904
|
const pkg = await fs.readJson(packageJsonPath);
|
|
2752
2905
|
return {
|
|
2753
|
-
themeId:
|
|
2906
|
+
themeId: pkg.name?.replace("@onex-themes/", "") || "unknown",
|
|
2754
2907
|
version: pkg.version || "1.0.0"
|
|
2755
2908
|
};
|
|
2756
2909
|
}
|
|
@@ -2994,39 +3147,15 @@ function getBucketName2(env) {
|
|
|
2994
3147
|
}
|
|
2995
3148
|
async function streamToString(stream) {
|
|
2996
3149
|
const chunks = [];
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
const chunk = temp.value;
|
|
3000
|
-
chunks.push(Buffer.from(chunk));
|
|
3001
|
-
}
|
|
3002
|
-
} catch (temp) {
|
|
3003
|
-
error = [temp];
|
|
3004
|
-
} finally {
|
|
3005
|
-
try {
|
|
3006
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
3007
|
-
} finally {
|
|
3008
|
-
if (error)
|
|
3009
|
-
throw error[0];
|
|
3010
|
-
}
|
|
3150
|
+
for await (const chunk of stream) {
|
|
3151
|
+
chunks.push(Buffer.from(chunk));
|
|
3011
3152
|
}
|
|
3012
3153
|
return Buffer.concat(chunks).toString("utf-8");
|
|
3013
3154
|
}
|
|
3014
3155
|
async function streamToBuffer(stream) {
|
|
3015
3156
|
const chunks = [];
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
const chunk = temp.value;
|
|
3019
|
-
chunks.push(Buffer.from(chunk));
|
|
3020
|
-
}
|
|
3021
|
-
} catch (temp) {
|
|
3022
|
-
error = [temp];
|
|
3023
|
-
} finally {
|
|
3024
|
-
try {
|
|
3025
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
3026
|
-
} finally {
|
|
3027
|
-
if (error)
|
|
3028
|
-
throw error[0];
|
|
3029
|
-
}
|
|
3157
|
+
for await (const chunk of stream) {
|
|
3158
|
+
chunks.push(Buffer.from(chunk));
|
|
3030
3159
|
}
|
|
3031
3160
|
return Buffer.concat(chunks);
|
|
3032
3161
|
}
|
|
@@ -3048,8 +3177,7 @@ async function resolveLatestVersion(s3Client, bucket, themeId) {
|
|
|
3048
3177
|
}
|
|
3049
3178
|
}
|
|
3050
3179
|
async function createCompatibilityFiles(outputDir, manifest) {
|
|
3051
|
-
|
|
3052
|
-
const entryFile = ((_a = manifest.output) == null ? void 0 : _a.entry) || "bundle-entry.js";
|
|
3180
|
+
const entryFile = manifest.output?.entry || "bundle-entry.js";
|
|
3053
3181
|
if (entryFile !== "bundle-entry.js" && entryFile.startsWith("bundle-entry-")) {
|
|
3054
3182
|
const hashedPath = path.join(outputDir, entryFile);
|
|
3055
3183
|
const stablePath = path.join(outputDir, "bundle-entry.js");
|
|
@@ -3220,39 +3348,15 @@ function getBucketName3(env) {
|
|
|
3220
3348
|
}
|
|
3221
3349
|
async function streamToString2(stream) {
|
|
3222
3350
|
const chunks = [];
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
const chunk = temp.value;
|
|
3226
|
-
chunks.push(Buffer.from(chunk));
|
|
3227
|
-
}
|
|
3228
|
-
} catch (temp) {
|
|
3229
|
-
error = [temp];
|
|
3230
|
-
} finally {
|
|
3231
|
-
try {
|
|
3232
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
3233
|
-
} finally {
|
|
3234
|
-
if (error)
|
|
3235
|
-
throw error[0];
|
|
3236
|
-
}
|
|
3351
|
+
for await (const chunk of stream) {
|
|
3352
|
+
chunks.push(Buffer.from(chunk));
|
|
3237
3353
|
}
|
|
3238
3354
|
return Buffer.concat(chunks).toString("utf-8");
|
|
3239
3355
|
}
|
|
3240
3356
|
async function streamToBuffer2(stream) {
|
|
3241
3357
|
const chunks = [];
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
const chunk = temp.value;
|
|
3245
|
-
chunks.push(Buffer.from(chunk));
|
|
3246
|
-
}
|
|
3247
|
-
} catch (temp) {
|
|
3248
|
-
error = [temp];
|
|
3249
|
-
} finally {
|
|
3250
|
-
try {
|
|
3251
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
3252
|
-
} finally {
|
|
3253
|
-
if (error)
|
|
3254
|
-
throw error[0];
|
|
3255
|
-
}
|
|
3358
|
+
for await (const chunk of stream) {
|
|
3359
|
+
chunks.push(Buffer.from(chunk));
|
|
3256
3360
|
}
|
|
3257
3361
|
return Buffer.concat(chunks);
|
|
3258
3362
|
}
|
|
@@ -3428,6 +3532,19 @@ async function cloneCommand(themeName, options) {
|
|
|
3428
3532
|
spinner.succeed(
|
|
3429
3533
|
`Renamed theme: ${chalk4.gray(themeName)} \u2192 ${chalk4.cyan(newName)}`
|
|
3430
3534
|
);
|
|
3535
|
+
const envExamplePath = path.join(outputDir, ".env.example");
|
|
3536
|
+
if (!await fs.pathExists(envExamplePath)) {
|
|
3537
|
+
await fs.writeFile(
|
|
3538
|
+
envExamplePath,
|
|
3539
|
+
[
|
|
3540
|
+
"# API Configuration (enables real data in preview)",
|
|
3541
|
+
"# Get your Company ID from the OneX dashboard",
|
|
3542
|
+
"NEXT_PUBLIC_API_URL=https://api-dev.onexeos.com",
|
|
3543
|
+
"NEXT_PUBLIC_COMPANY_ID=",
|
|
3544
|
+
""
|
|
3545
|
+
].join("\n")
|
|
3546
|
+
);
|
|
3547
|
+
}
|
|
3431
3548
|
if (options.install !== false) {
|
|
3432
3549
|
const hasPkgJson = await fs.pathExists(
|
|
3433
3550
|
path.join(outputDir, "package.json")
|
|
@@ -3458,6 +3575,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3458
3575
|
console.log();
|
|
3459
3576
|
console.log(chalk4.cyan("Next steps:"));
|
|
3460
3577
|
console.log(chalk4.gray(` cd ${path.relative(process.cwd(), outputDir)}`));
|
|
3578
|
+
console.log(chalk4.gray(" cp .env.example .env # then add your Company ID"));
|
|
3461
3579
|
if (options.install === false) {
|
|
3462
3580
|
console.log(chalk4.gray(" pnpm install"));
|
|
3463
3581
|
}
|
|
@@ -3515,7 +3633,12 @@ function createDevServer(options) {
|
|
|
3515
3633
|
res.end("Forbidden");
|
|
3516
3634
|
return;
|
|
3517
3635
|
}
|
|
3518
|
-
|
|
3636
|
+
if (fs2.existsSync(filePath) && fs2.statSync(filePath).isFile()) {
|
|
3637
|
+
serveFile(res, filePath);
|
|
3638
|
+
} else {
|
|
3639
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
3640
|
+
res.end(generatePreviewHTML(options.themeName));
|
|
3641
|
+
}
|
|
3519
3642
|
});
|
|
3520
3643
|
const wss = new WebSocketServer({ server });
|
|
3521
3644
|
wss.on("connection", (ws) => {
|
|
@@ -3550,7 +3673,7 @@ function serveFile(res, filePath) {
|
|
|
3550
3673
|
const content = fs2.readFileSync(filePath);
|
|
3551
3674
|
res.writeHead(200, { "Content-Type": contentType });
|
|
3552
3675
|
res.end(content);
|
|
3553
|
-
} catch
|
|
3676
|
+
} catch {
|
|
3554
3677
|
res.writeHead(500);
|
|
3555
3678
|
res.end("Internal Server Error");
|
|
3556
3679
|
}
|
|
@@ -3611,7 +3734,7 @@ async function devCommand(options) {
|
|
|
3611
3734
|
} else {
|
|
3612
3735
|
themePath = path.join(process.cwd(), themeName);
|
|
3613
3736
|
}
|
|
3614
|
-
} catch
|
|
3737
|
+
} catch {
|
|
3615
3738
|
themePath = path.join(process.cwd(), themeName);
|
|
3616
3739
|
}
|
|
3617
3740
|
if (!fs.existsSync(themePath)) {
|
|
@@ -3697,7 +3820,7 @@ async function devCommand(options) {
|
|
|
3697
3820
|
const shimPath = path.join(outputDir, ".process-shim.js");
|
|
3698
3821
|
try {
|
|
3699
3822
|
await fs7.unlink(shimPath);
|
|
3700
|
-
} catch
|
|
3823
|
+
} catch {
|
|
3701
3824
|
}
|
|
3702
3825
|
process.exit(0);
|
|
3703
3826
|
});
|
|
@@ -3711,7 +3834,7 @@ try {
|
|
|
3711
3834
|
quiet: true
|
|
3712
3835
|
});
|
|
3713
3836
|
dotenv.config({ path: path.join(projectRoot, ".env"), quiet: true });
|
|
3714
|
-
} catch
|
|
3837
|
+
} catch {
|
|
3715
3838
|
}
|
|
3716
3839
|
dotenv.config({
|
|
3717
3840
|
path: path.join(os.homedir(), ".onex", ".env"),
|