@onexapis/cli 1.1.2 → 1.1.4
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 +352 -314
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +350 -313
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +304 -266
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +302 -265
- package/dist/index.mjs.map +1 -1
- package/dist/preview/preview-app.tsx +112 -21
- package/package.json +3 -1
- package/templates/default/.env.example +4 -0
- package/templates/default/package.json.ejs +2 -1
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
var chalk4 = require('chalk');
|
|
5
5
|
var ora = require('ora');
|
|
6
6
|
var esbuild = require('esbuild');
|
|
7
|
-
var
|
|
7
|
+
var path8 = require('path');
|
|
8
8
|
var fs7 = require('fs/promises');
|
|
9
9
|
var crypto = require('crypto');
|
|
10
10
|
var glob = require('glob');
|
|
@@ -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) {
|
|
@@ -48,7 +49,7 @@ function _interopNamespace(e) {
|
|
|
48
49
|
var chalk4__default = /*#__PURE__*/_interopDefault(chalk4);
|
|
49
50
|
var ora__default = /*#__PURE__*/_interopDefault(ora);
|
|
50
51
|
var esbuild__namespace = /*#__PURE__*/_interopNamespace(esbuild);
|
|
51
|
-
var
|
|
52
|
+
var path8__default = /*#__PURE__*/_interopDefault(path8);
|
|
52
53
|
var fs7__default = /*#__PURE__*/_interopDefault(fs7);
|
|
53
54
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
54
55
|
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
@@ -66,22 +67,6 @@ var http__default = /*#__PURE__*/_interopDefault(http);
|
|
|
66
67
|
|
|
67
68
|
var __defProp = Object.defineProperty;
|
|
68
69
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
69
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
70
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
71
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
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
|
-
};
|
|
85
70
|
var __esm = (fn, res) => function __init() {
|
|
86
71
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
87
72
|
};
|
|
@@ -89,7 +74,6 @@ var __export = (target, all) => {
|
|
|
89
74
|
for (var name in all)
|
|
90
75
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
91
76
|
};
|
|
92
|
-
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);
|
|
93
77
|
var Logger, logger;
|
|
94
78
|
var init_logger = __esm({
|
|
95
79
|
"src/utils/logger.ts"() {
|
|
@@ -158,12 +142,12 @@ __export(compile_theme_exports, {
|
|
|
158
142
|
async function resolveNodeModulesFile(startDir, relativePath) {
|
|
159
143
|
let dir = startDir;
|
|
160
144
|
while (true) {
|
|
161
|
-
const candidate =
|
|
145
|
+
const candidate = path8__default.default.join(dir, "node_modules", relativePath);
|
|
162
146
|
try {
|
|
163
147
|
await fs7__default.default.access(candidate);
|
|
164
148
|
return candidate;
|
|
165
|
-
} catch
|
|
166
|
-
const parent =
|
|
149
|
+
} catch {
|
|
150
|
+
const parent = path8__default.default.dirname(dir);
|
|
167
151
|
if (parent === dir) break;
|
|
168
152
|
dir = parent;
|
|
169
153
|
}
|
|
@@ -181,7 +165,7 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
181
165
|
}));
|
|
182
166
|
build2.onLoad({ filter: /.*/, namespace: "core-global" }, async (args) => {
|
|
183
167
|
const match = args.path.match(/^@onexapis\/core(\/(.+))?$/);
|
|
184
|
-
const subpath =
|
|
168
|
+
const subpath = match?.[2] || "";
|
|
185
169
|
const moduleAccess = subpath ? `['${subpath}']` : "";
|
|
186
170
|
let namedExports = [];
|
|
187
171
|
const cacheKey = subpath || "__root__";
|
|
@@ -189,10 +173,16 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
189
173
|
namedExports = exportsBySubpath[cacheKey];
|
|
190
174
|
} else {
|
|
191
175
|
const distFileName = subpath ? `${subpath}.mjs` : "index.mjs";
|
|
192
|
-
|
|
176
|
+
let distPath = await resolveNodeModulesFile(
|
|
193
177
|
themePath,
|
|
194
|
-
|
|
178
|
+
path8__default.default.join("@onexapis", "core", "dist", distFileName)
|
|
195
179
|
);
|
|
180
|
+
if (!distPath) {
|
|
181
|
+
distPath = await resolveNodeModulesFile(
|
|
182
|
+
__dirname,
|
|
183
|
+
path8__default.default.join("@onexapis", "core", "dist", distFileName)
|
|
184
|
+
);
|
|
185
|
+
}
|
|
196
186
|
try {
|
|
197
187
|
if (!distPath) throw new Error("not found");
|
|
198
188
|
const distContent = await fs7__default.default.readFile(distPath, "utf-8");
|
|
@@ -205,7 +195,7 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
205
195
|
namedExports.push(...names);
|
|
206
196
|
}
|
|
207
197
|
namedExports = [...new Set(namedExports)];
|
|
208
|
-
} catch
|
|
198
|
+
} catch {
|
|
209
199
|
}
|
|
210
200
|
exportsBySubpath[cacheKey] = namedExports;
|
|
211
201
|
}
|
|
@@ -239,60 +229,60 @@ ${namedExportLines}
|
|
|
239
229
|
}
|
|
240
230
|
async function generateThemeData(themePath, outputDir, themeId) {
|
|
241
231
|
const { createJiti } = await import('jiti');
|
|
242
|
-
const jiti = createJiti(
|
|
232
|
+
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)));
|
|
243
233
|
let themeConfig = null;
|
|
244
234
|
let layoutConfig = null;
|
|
245
235
|
const pages = {};
|
|
246
236
|
for (const ext of [".ts", ".js"]) {
|
|
247
237
|
try {
|
|
248
|
-
const mod = await jiti.import(
|
|
238
|
+
const mod = await jiti.import(path8__default.default.join(themePath, `theme.config${ext}`));
|
|
249
239
|
themeConfig = mod.default || mod;
|
|
250
240
|
break;
|
|
251
|
-
} catch
|
|
241
|
+
} catch {
|
|
252
242
|
}
|
|
253
243
|
}
|
|
254
244
|
for (const ext of [".ts", ".js"]) {
|
|
255
245
|
try {
|
|
256
|
-
const mod = await jiti.import(
|
|
246
|
+
const mod = await jiti.import(path8__default.default.join(themePath, `theme.layout${ext}`));
|
|
257
247
|
layoutConfig = mod.default || mod;
|
|
258
248
|
break;
|
|
259
|
-
} catch
|
|
249
|
+
} catch {
|
|
260
250
|
}
|
|
261
251
|
}
|
|
262
|
-
const pagesDir =
|
|
252
|
+
const pagesDir = path8__default.default.join(themePath, "pages");
|
|
263
253
|
try {
|
|
264
254
|
const files = await fs7__default.default.readdir(pagesDir);
|
|
265
255
|
for (const file of files) {
|
|
266
256
|
if (!file.match(/\.(ts|js)$/)) continue;
|
|
267
257
|
const name = file.replace(/\.(ts|js)$/, "");
|
|
268
258
|
try {
|
|
269
|
-
const mod = await jiti.import(
|
|
259
|
+
const mod = await jiti.import(path8__default.default.join(pagesDir, file));
|
|
270
260
|
const config = mod.default || mod;
|
|
271
261
|
pages[name] = {
|
|
272
262
|
id: name,
|
|
273
263
|
name: config.title || name,
|
|
274
264
|
path: config.path || `/${name}`,
|
|
275
|
-
config:
|
|
265
|
+
config: { id: name, ...config },
|
|
276
266
|
sections: config.sections || [],
|
|
277
267
|
seo: config.seo
|
|
278
268
|
};
|
|
279
|
-
} catch
|
|
269
|
+
} catch {
|
|
280
270
|
}
|
|
281
271
|
}
|
|
282
|
-
} catch
|
|
272
|
+
} catch {
|
|
283
273
|
}
|
|
284
274
|
await fs7__default.default.writeFile(
|
|
285
|
-
|
|
275
|
+
path8__default.default.join(outputDir, "theme-data.json"),
|
|
286
276
|
JSON.stringify(
|
|
287
277
|
{
|
|
288
278
|
themeId,
|
|
289
279
|
theme: {
|
|
290
280
|
id: themeId,
|
|
291
|
-
name:
|
|
281
|
+
name: themeConfig?.name || themeId,
|
|
292
282
|
config: themeConfig,
|
|
293
283
|
layout: {
|
|
294
|
-
header:
|
|
295
|
-
footer:
|
|
284
|
+
header: layoutConfig?.headerSections || [],
|
|
285
|
+
footer: layoutConfig?.footerSections || []
|
|
296
286
|
},
|
|
297
287
|
pages: Object.keys(pages)
|
|
298
288
|
},
|
|
@@ -302,42 +292,40 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
302
292
|
2
|
|
303
293
|
)
|
|
304
294
|
);
|
|
305
|
-
logger.info(
|
|
306
|
-
`Generated theme-data.json (${Object.keys(pages).length} pages)`
|
|
307
|
-
);
|
|
295
|
+
logger.info(`Generated theme-data.json (${Object.keys(pages).length} pages)`);
|
|
308
296
|
}
|
|
309
297
|
async function contentHashEntry(outputDir) {
|
|
310
|
-
const entryPath =
|
|
311
|
-
const mapPath =
|
|
298
|
+
const entryPath = path8__default.default.join(outputDir, "bundle-entry.js");
|
|
299
|
+
const mapPath = path8__default.default.join(outputDir, "bundle-entry.js.map");
|
|
312
300
|
const oldFiles = await glob.glob("bundle-entry-*.js*", { cwd: outputDir });
|
|
313
301
|
for (const f of oldFiles) {
|
|
314
|
-
await fs7__default.default.unlink(
|
|
302
|
+
await fs7__default.default.unlink(path8__default.default.join(outputDir, f));
|
|
315
303
|
}
|
|
316
304
|
let entryContent;
|
|
317
305
|
try {
|
|
318
306
|
entryContent = await fs7__default.default.readFile(entryPath, "utf-8");
|
|
319
|
-
} catch
|
|
320
|
-
const indexPath =
|
|
307
|
+
} catch {
|
|
308
|
+
const indexPath = path8__default.default.join(outputDir, "index.js");
|
|
321
309
|
try {
|
|
322
310
|
entryContent = await fs7__default.default.readFile(indexPath, "utf-8");
|
|
323
|
-
} catch
|
|
311
|
+
} catch {
|
|
324
312
|
logger.warning("No entry file found in output, skipping content hash");
|
|
325
313
|
return;
|
|
326
314
|
}
|
|
327
315
|
const hash2 = crypto__default.default.createHash("sha256").update(entryContent).digest("hex").slice(0, 8);
|
|
328
316
|
const hashedName2 = `bundle-entry-${hash2}.js`;
|
|
329
|
-
const indexMapPath =
|
|
317
|
+
const indexMapPath = path8__default.default.join(outputDir, "index.js.map");
|
|
330
318
|
const hashedMapName2 = `bundle-entry-${hash2}.js.map`;
|
|
331
319
|
entryContent = entryContent.replace(
|
|
332
320
|
/\/\/# sourceMappingURL=index\.js\.map/,
|
|
333
321
|
`//# sourceMappingURL=${hashedMapName2}`
|
|
334
322
|
);
|
|
335
|
-
await fs7__default.default.writeFile(
|
|
323
|
+
await fs7__default.default.writeFile(path8__default.default.join(outputDir, hashedName2), entryContent);
|
|
336
324
|
await fs7__default.default.unlink(indexPath);
|
|
337
325
|
try {
|
|
338
326
|
await fs7__default.default.access(indexMapPath);
|
|
339
|
-
await fs7__default.default.rename(indexMapPath,
|
|
340
|
-
} catch
|
|
327
|
+
await fs7__default.default.rename(indexMapPath, path8__default.default.join(outputDir, hashedMapName2));
|
|
328
|
+
} catch {
|
|
341
329
|
}
|
|
342
330
|
logger.info(`Entry hashed: ${hashedName2}`);
|
|
343
331
|
return;
|
|
@@ -349,21 +337,43 @@ async function contentHashEntry(outputDir) {
|
|
|
349
337
|
/\/\/# sourceMappingURL=bundle-entry\.js\.map/,
|
|
350
338
|
`//# sourceMappingURL=${hashedMapName}`
|
|
351
339
|
);
|
|
352
|
-
await fs7__default.default.writeFile(
|
|
340
|
+
await fs7__default.default.writeFile(path8__default.default.join(outputDir, hashedName), entryContent);
|
|
353
341
|
await fs7__default.default.unlink(entryPath);
|
|
354
342
|
try {
|
|
355
343
|
await fs7__default.default.access(mapPath);
|
|
356
|
-
await fs7__default.default.rename(mapPath,
|
|
357
|
-
} catch
|
|
344
|
+
await fs7__default.default.rename(mapPath, path8__default.default.join(outputDir, hashedMapName));
|
|
345
|
+
} catch {
|
|
358
346
|
}
|
|
359
347
|
logger.info(`Entry hashed: ${hashedName}`);
|
|
360
348
|
}
|
|
349
|
+
async function extractDataRequirements(themePath) {
|
|
350
|
+
const { createJiti } = await import('jiti');
|
|
351
|
+
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)));
|
|
352
|
+
const schemaFiles = await glob.glob("sections/**/*.schema.ts", { cwd: themePath });
|
|
353
|
+
const requirements = {};
|
|
354
|
+
for (const file of schemaFiles) {
|
|
355
|
+
try {
|
|
356
|
+
const mod = await jiti.import(path8__default.default.join(themePath, file));
|
|
357
|
+
const exports$1 = mod;
|
|
358
|
+
for (const value of Object.values(exports$1)) {
|
|
359
|
+
if (value && typeof value === "object" && typeof value.type === "string" && value.dataRequirements && typeof value.dataRequirements === "object") {
|
|
360
|
+
requirements[value.type] = value.dataRequirements;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
} catch (err) {
|
|
364
|
+
logger.warning(
|
|
365
|
+
`Could not load schema ${file}: ${err instanceof Error ? err.message : String(err)}`
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return requirements;
|
|
370
|
+
}
|
|
361
371
|
async function generateManifest2(themeName, themePath, outputDir) {
|
|
362
372
|
let version = "1.0.0";
|
|
363
373
|
let themeId = themeName;
|
|
364
374
|
try {
|
|
365
375
|
const pkgContent = await fs7__default.default.readFile(
|
|
366
|
-
|
|
376
|
+
path8__default.default.join(themePath, "package.json"),
|
|
367
377
|
"utf-8"
|
|
368
378
|
);
|
|
369
379
|
const pkg = JSON.parse(pkgContent);
|
|
@@ -371,18 +381,19 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
371
381
|
if (pkg.name) {
|
|
372
382
|
themeId = pkg.name.replace(/^@onex-themes\//, "");
|
|
373
383
|
}
|
|
374
|
-
} catch
|
|
384
|
+
} catch {
|
|
375
385
|
}
|
|
376
386
|
const [sectionFiles, blockFiles, schemaFiles] = await Promise.all([
|
|
377
387
|
glob.glob("sections/**/index.ts", { cwd: themePath }),
|
|
378
388
|
glob.glob("blocks/**/index.ts", { cwd: themePath }),
|
|
379
389
|
glob.glob("**/*.schema.ts", { cwd: themePath })
|
|
380
390
|
]);
|
|
391
|
+
const dataRequirements = await extractDataRequirements(themePath);
|
|
381
392
|
let hasThemeConfig = false;
|
|
382
393
|
try {
|
|
383
|
-
await fs7__default.default.access(
|
|
394
|
+
await fs7__default.default.access(path8__default.default.join(themePath, "theme.config.ts"));
|
|
384
395
|
hasThemeConfig = true;
|
|
385
|
-
} catch
|
|
396
|
+
} catch {
|
|
386
397
|
}
|
|
387
398
|
const allFiles = await glob.glob("**/*", { cwd: outputDir, nodir: true });
|
|
388
399
|
const jsFiles = allFiles.filter((f) => f.endsWith(".js"));
|
|
@@ -417,24 +428,26 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
417
428
|
blocks: blockFiles,
|
|
418
429
|
schemas: schemaFiles,
|
|
419
430
|
hasThemeConfig
|
|
420
|
-
}
|
|
431
|
+
},
|
|
432
|
+
// Section data requirements for server-side prefetching (keyed by section type)
|
|
433
|
+
dataRequirements
|
|
421
434
|
};
|
|
422
435
|
await fs7__default.default.writeFile(
|
|
423
|
-
|
|
436
|
+
path8__default.default.join(outputDir, "manifest.json"),
|
|
424
437
|
JSON.stringify(manifest, null, 2)
|
|
425
438
|
);
|
|
426
439
|
}
|
|
427
440
|
async function compileStandaloneTheme(themePath, themeName) {
|
|
428
|
-
const outputDir =
|
|
429
|
-
const bundleEntry =
|
|
430
|
-
const indexEntry =
|
|
441
|
+
const outputDir = path8__default.default.join(themePath, "dist");
|
|
442
|
+
const bundleEntry = path8__default.default.join(themePath, "bundle-entry.ts");
|
|
443
|
+
const indexEntry = path8__default.default.join(themePath, "index.ts");
|
|
431
444
|
let entryPoint = indexEntry;
|
|
432
445
|
try {
|
|
433
446
|
await fs7__default.default.access(bundleEntry);
|
|
434
447
|
entryPoint = bundleEntry;
|
|
435
|
-
} catch
|
|
448
|
+
} catch {
|
|
436
449
|
}
|
|
437
|
-
const shimPath =
|
|
450
|
+
const shimPath = path8__default.default.join(outputDir, ".process-shim.js");
|
|
438
451
|
await fs7__default.default.mkdir(outputDir, { recursive: true });
|
|
439
452
|
await fs7__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
440
453
|
const buildOptions = {
|
|
@@ -483,7 +496,7 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
483
496
|
const result = await esbuild__namespace.build(buildOptions);
|
|
484
497
|
try {
|
|
485
498
|
await fs7__default.default.unlink(shimPath);
|
|
486
|
-
} catch
|
|
499
|
+
} catch {
|
|
487
500
|
}
|
|
488
501
|
await contentHashEntry(outputDir);
|
|
489
502
|
await generateManifest2(themeName, themePath, outputDir);
|
|
@@ -501,23 +514,23 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
501
514
|
} catch (error) {
|
|
502
515
|
try {
|
|
503
516
|
await fs7__default.default.unlink(shimPath);
|
|
504
|
-
} catch
|
|
517
|
+
} catch {
|
|
505
518
|
}
|
|
506
519
|
logger.error(`esbuild compilation failed: ${error}`);
|
|
507
520
|
return false;
|
|
508
521
|
}
|
|
509
522
|
}
|
|
510
523
|
async function compileStandaloneThemeDev(themePath, themeName) {
|
|
511
|
-
const outputDir =
|
|
512
|
-
const bundleEntry =
|
|
513
|
-
const indexEntry =
|
|
524
|
+
const outputDir = path8__default.default.join(themePath, "dist");
|
|
525
|
+
const bundleEntry = path8__default.default.join(themePath, "bundle-entry.ts");
|
|
526
|
+
const indexEntry = path8__default.default.join(themePath, "index.ts");
|
|
514
527
|
let entryPoint = indexEntry;
|
|
515
528
|
try {
|
|
516
529
|
await fs7__default.default.access(bundleEntry);
|
|
517
530
|
entryPoint = bundleEntry;
|
|
518
|
-
} catch
|
|
531
|
+
} catch {
|
|
519
532
|
}
|
|
520
|
-
const shimPath =
|
|
533
|
+
const shimPath = path8__default.default.join(outputDir, ".process-shim.js");
|
|
521
534
|
await fs7__default.default.mkdir(outputDir, { recursive: true });
|
|
522
535
|
await fs7__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
523
536
|
const buildOptions = {
|
|
@@ -568,13 +581,13 @@ async function compileStandaloneThemeDev(themePath, themeName) {
|
|
|
568
581
|
return { context: context2, outputDir };
|
|
569
582
|
}
|
|
570
583
|
async function compilePreviewRuntime(themePath) {
|
|
571
|
-
const outputDir =
|
|
584
|
+
const outputDir = path8__default.default.join(themePath, "dist");
|
|
572
585
|
await fs7__default.default.mkdir(outputDir, { recursive: true });
|
|
573
|
-
const outputPath =
|
|
586
|
+
const outputPath = path8__default.default.join(outputDir, "preview-runtime.js");
|
|
574
587
|
const locations = [
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
588
|
+
path8__default.default.join(__dirname, "..", "preview", "preview-app.tsx"),
|
|
589
|
+
path8__default.default.join(__dirname, "preview", "preview-app.tsx"),
|
|
590
|
+
path8__default.default.join(__dirname, "..", "..", "src", "preview", "preview-app.tsx")
|
|
578
591
|
];
|
|
579
592
|
let previewEntryPath = null;
|
|
580
593
|
for (const loc of locations) {
|
|
@@ -582,7 +595,7 @@ async function compilePreviewRuntime(themePath) {
|
|
|
582
595
|
await fs7__default.default.access(loc);
|
|
583
596
|
previewEntryPath = loc;
|
|
584
597
|
break;
|
|
585
|
-
} catch
|
|
598
|
+
} catch {
|
|
586
599
|
}
|
|
587
600
|
}
|
|
588
601
|
if (!previewEntryPath) {
|
|
@@ -622,10 +635,13 @@ ${locations.join("\n")}`
|
|
|
622
635
|
"zlib"
|
|
623
636
|
];
|
|
624
637
|
for (const mod of nodeBuiltins) {
|
|
625
|
-
build2.onResolve(
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
638
|
+
build2.onResolve(
|
|
639
|
+
{ filter: new RegExp(`^${mod.replace("/", "\\/")}$`) },
|
|
640
|
+
() => ({
|
|
641
|
+
path: mod,
|
|
642
|
+
namespace: "node-stub"
|
|
643
|
+
})
|
|
644
|
+
);
|
|
629
645
|
}
|
|
630
646
|
build2.onLoad({ filter: /.*/, namespace: "node-stub" }, (args) => {
|
|
631
647
|
const stubs = {
|
|
@@ -639,8 +655,7 @@ ${locations.join("\n")}`
|
|
|
639
655
|
};
|
|
640
656
|
});
|
|
641
657
|
build2.onResolve({ filter: /^lucide-react/ }, async (args) => {
|
|
642
|
-
|
|
643
|
-
if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
|
|
658
|
+
if (args.pluginData?.skipStub) return void 0;
|
|
644
659
|
try {
|
|
645
660
|
const result = await build2.resolve(args.path, {
|
|
646
661
|
kind: args.kind,
|
|
@@ -650,7 +665,7 @@ ${locations.join("\n")}`
|
|
|
650
665
|
pluginData: { skipStub: true }
|
|
651
666
|
});
|
|
652
667
|
if (!result.errors.length) return result;
|
|
653
|
-
} catch
|
|
668
|
+
} catch {
|
|
654
669
|
}
|
|
655
670
|
return { path: args.path, namespace: "lucide-stub" };
|
|
656
671
|
});
|
|
@@ -672,8 +687,7 @@ export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true :
|
|
|
672
687
|
loader: "jsx"
|
|
673
688
|
}));
|
|
674
689
|
build2.onResolve({ filter: /^framer-motion/ }, async (args) => {
|
|
675
|
-
|
|
676
|
-
if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
|
|
690
|
+
if (args.pluginData?.skipStub) return void 0;
|
|
677
691
|
try {
|
|
678
692
|
const result = await build2.resolve(args.path, {
|
|
679
693
|
kind: args.kind,
|
|
@@ -683,7 +697,7 @@ export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true :
|
|
|
683
697
|
pluginData: { skipStub: true }
|
|
684
698
|
});
|
|
685
699
|
if (!result.errors.length) return result;
|
|
686
|
-
} catch
|
|
700
|
+
} catch {
|
|
687
701
|
}
|
|
688
702
|
return { path: args.path, namespace: "motion-stub" };
|
|
689
703
|
});
|
|
@@ -697,8 +711,59 @@ export default { motion, AnimatePresence };
|
|
|
697
711
|
`.trim(),
|
|
698
712
|
loader: "jsx"
|
|
699
713
|
}));
|
|
714
|
+
build2.onResolve({ filter: /^next\// }, async (args) => {
|
|
715
|
+
if (args.pluginData?.skipStub) return void 0;
|
|
716
|
+
try {
|
|
717
|
+
const result = await build2.resolve(args.path, {
|
|
718
|
+
kind: args.kind,
|
|
719
|
+
resolveDir: args.resolveDir,
|
|
720
|
+
importer: args.importer,
|
|
721
|
+
namespace: "file",
|
|
722
|
+
pluginData: { skipStub: true }
|
|
723
|
+
});
|
|
724
|
+
if (!result.errors.length) return result;
|
|
725
|
+
} catch {
|
|
726
|
+
}
|
|
727
|
+
return { path: args.path, namespace: "next-stub" };
|
|
728
|
+
});
|
|
729
|
+
build2.onLoad({ filter: /.*/, namespace: "next-stub" }, (args) => {
|
|
730
|
+
const stubs = {
|
|
731
|
+
"next/image": `
|
|
732
|
+
const Image = (props) => {
|
|
733
|
+
const { src, alt, width, height, fill, priority, ...rest } = props;
|
|
734
|
+
const imgSrc = typeof src === 'object' ? src.src : src;
|
|
735
|
+
return React.createElement('img', { src: imgSrc, alt, width: fill ? undefined : width, height: fill ? undefined : height, loading: priority ? 'eager' : 'lazy', ...rest });
|
|
736
|
+
};
|
|
737
|
+
import React from 'react';
|
|
738
|
+
export default Image;
|
|
739
|
+
`,
|
|
740
|
+
"next/link": `
|
|
741
|
+
const Link = ({ href, children, ...rest }) => React.createElement('a', { href, ...rest }, children);
|
|
742
|
+
import React from 'react';
|
|
743
|
+
export default Link;
|
|
744
|
+
`,
|
|
745
|
+
"next/navigation": `
|
|
746
|
+
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(){} }; }
|
|
747
|
+
export function usePathname() { return window.location.pathname; }
|
|
748
|
+
export function useSearchParams() { return new URLSearchParams(window.location.search); }
|
|
749
|
+
export function useParams() { return {}; }
|
|
750
|
+
export function redirect(url) { window.location.href = url; }
|
|
751
|
+
export function notFound() { throw new Error('Not Found'); }
|
|
752
|
+
`,
|
|
753
|
+
"next/headers": `
|
|
754
|
+
export function cookies() { return { get(){}, getAll(){ return []; }, set(){}, delete(){}, has(){ return false; } }; }
|
|
755
|
+
export function headers() { return new Headers(); }
|
|
756
|
+
`
|
|
757
|
+
};
|
|
758
|
+
return {
|
|
759
|
+
contents: stubs[args.path] || "export default {};",
|
|
760
|
+
loader: "jsx"
|
|
761
|
+
};
|
|
762
|
+
});
|
|
700
763
|
}
|
|
701
764
|
};
|
|
765
|
+
const shimPath = path8__default.default.join(outputDir, ".process-shim-preview.js");
|
|
766
|
+
await fs7__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
702
767
|
await esbuild__namespace.build({
|
|
703
768
|
entryPoints: [previewEntryPath],
|
|
704
769
|
bundle: true,
|
|
@@ -708,6 +773,7 @@ export default { motion, AnimatePresence };
|
|
|
708
773
|
// Bundle React + core INTO the output (NOT externalized)
|
|
709
774
|
external: [],
|
|
710
775
|
plugins: [serverStubPlugin],
|
|
776
|
+
inject: [shimPath],
|
|
711
777
|
minify: false,
|
|
712
778
|
sourcemap: true,
|
|
713
779
|
target: "es2020",
|
|
@@ -715,6 +781,12 @@ export default { motion, AnimatePresence };
|
|
|
715
781
|
jsxImportSource: "react",
|
|
716
782
|
define: {
|
|
717
783
|
"process.env.NODE_ENV": JSON.stringify("development"),
|
|
784
|
+
"process.env.NEXT_PUBLIC_API_URL": JSON.stringify(
|
|
785
|
+
process.env.NEXT_PUBLIC_API_URL || ""
|
|
786
|
+
),
|
|
787
|
+
"process.env.NEXT_PUBLIC_COMPANY_ID": JSON.stringify(
|
|
788
|
+
process.env.NEXT_PUBLIC_COMPANY_ID || ""
|
|
789
|
+
),
|
|
718
790
|
global: "globalThis"
|
|
719
791
|
},
|
|
720
792
|
loader: { ".tsx": "tsx", ".ts": "ts" },
|
|
@@ -725,13 +797,16 @@ export default { motion, AnimatePresence };
|
|
|
725
797
|
"ignored-bare-import": "silent"
|
|
726
798
|
}
|
|
727
799
|
});
|
|
800
|
+
try {
|
|
801
|
+
await fs7__default.default.unlink(shimPath);
|
|
802
|
+
} catch {
|
|
803
|
+
}
|
|
728
804
|
return outputPath;
|
|
729
805
|
}
|
|
730
|
-
var
|
|
806
|
+
var PROCESS_SHIM, reactGlobalPlugin;
|
|
731
807
|
var init_compile_theme = __esm({
|
|
732
808
|
"src/utils/compile-theme.ts"() {
|
|
733
809
|
init_logger();
|
|
734
|
-
import_meta = {};
|
|
735
810
|
PROCESS_SHIM = `
|
|
736
811
|
if (typeof process === "undefined") {
|
|
737
812
|
globalThis.process = {
|
|
@@ -856,18 +931,18 @@ async function renderTemplate(templatePath, data) {
|
|
|
856
931
|
return ejs__default.default.render(template, data);
|
|
857
932
|
}
|
|
858
933
|
async function writeFile(filePath, content) {
|
|
859
|
-
await fs__default.default.ensureDir(
|
|
934
|
+
await fs__default.default.ensureDir(path8__default.default.dirname(filePath));
|
|
860
935
|
await fs__default.default.writeFile(filePath, content, "utf-8");
|
|
861
936
|
}
|
|
862
937
|
function getTemplatesDir() {
|
|
863
938
|
const locations = [
|
|
864
|
-
|
|
939
|
+
path8__default.default.join(__dirname, "../../templates"),
|
|
865
940
|
// Development
|
|
866
|
-
|
|
941
|
+
path8__default.default.join(__dirname, "../templates"),
|
|
867
942
|
// Production (dist/)
|
|
868
|
-
|
|
943
|
+
path8__default.default.join(process.cwd(), "templates"),
|
|
869
944
|
// Fallback
|
|
870
|
-
|
|
945
|
+
path8__default.default.join(process.cwd(), "packages/cli/templates")
|
|
871
946
|
// Monorepo
|
|
872
947
|
];
|
|
873
948
|
for (const location of locations) {
|
|
@@ -879,7 +954,7 @@ function getTemplatesDir() {
|
|
|
879
954
|
}
|
|
880
955
|
async function copyTemplate(templateName, targetDir, data) {
|
|
881
956
|
const templatesDir = getTemplatesDir();
|
|
882
|
-
const templateDir =
|
|
957
|
+
const templateDir = path8__default.default.join(templatesDir, templateName);
|
|
883
958
|
if (!fs__default.default.existsSync(templateDir)) {
|
|
884
959
|
throw new Error(
|
|
885
960
|
`Template "${templateName}" not found at ${templateDir}. Available templates: ${fs__default.default.readdirSync(templatesDir).join(", ")}`
|
|
@@ -888,8 +963,8 @@ async function copyTemplate(templateName, targetDir, data) {
|
|
|
888
963
|
await fs__default.default.ensureDir(targetDir);
|
|
889
964
|
const files = await fs__default.default.readdir(templateDir);
|
|
890
965
|
for (const file of files) {
|
|
891
|
-
const templatePath =
|
|
892
|
-
const targetPath =
|
|
966
|
+
const templatePath = path8__default.default.join(templateDir, file);
|
|
967
|
+
const targetPath = path8__default.default.join(targetDir, file);
|
|
893
968
|
const stat = await fs__default.default.stat(templatePath);
|
|
894
969
|
if (stat.isDirectory()) {
|
|
895
970
|
await copyTemplateDir(templatePath, targetPath, data);
|
|
@@ -906,8 +981,8 @@ async function copyTemplateDir(templateDir, targetDir, data) {
|
|
|
906
981
|
await fs__default.default.ensureDir(targetDir);
|
|
907
982
|
const files = await fs__default.default.readdir(templateDir);
|
|
908
983
|
for (const file of files) {
|
|
909
|
-
const templatePath =
|
|
910
|
-
const targetPath =
|
|
984
|
+
const templatePath = path8__default.default.join(templateDir, file);
|
|
985
|
+
const targetPath = path8__default.default.join(targetDir, file);
|
|
911
986
|
const stat = await fs__default.default.stat(templatePath);
|
|
912
987
|
if (stat.isDirectory()) {
|
|
913
988
|
await copyTemplateDir(templatePath, targetPath, data);
|
|
@@ -922,32 +997,32 @@ async function copyTemplateDir(templateDir, targetDir, data) {
|
|
|
922
997
|
}
|
|
923
998
|
function getProjectRoot() {
|
|
924
999
|
let currentDir = process.cwd();
|
|
925
|
-
while (currentDir !==
|
|
926
|
-
const packageJsonPath =
|
|
1000
|
+
while (currentDir !== path8__default.default.parse(currentDir).root) {
|
|
1001
|
+
const packageJsonPath = path8__default.default.join(currentDir, "package.json");
|
|
927
1002
|
if (fs__default.default.existsSync(packageJsonPath)) {
|
|
928
1003
|
const packageJson = fs__default.default.readJsonSync(packageJsonPath);
|
|
929
|
-
if (packageJson.workspaces || fs__default.default.existsSync(
|
|
1004
|
+
if (packageJson.workspaces || fs__default.default.existsSync(path8__default.default.join(currentDir, "src/themes")) || fs__default.default.existsSync(path8__default.default.join(currentDir, "themes"))) {
|
|
930
1005
|
return currentDir;
|
|
931
1006
|
}
|
|
932
1007
|
}
|
|
933
|
-
currentDir =
|
|
1008
|
+
currentDir = path8__default.default.dirname(currentDir);
|
|
934
1009
|
}
|
|
935
1010
|
return process.cwd();
|
|
936
1011
|
}
|
|
937
1012
|
function getThemesDir() {
|
|
938
1013
|
const root = getProjectRoot();
|
|
939
|
-
if (fs__default.default.existsSync(
|
|
940
|
-
return
|
|
941
|
-
if (fs__default.default.existsSync(
|
|
942
|
-
return
|
|
943
|
-
return
|
|
1014
|
+
if (fs__default.default.existsSync(path8__default.default.join(root, "themes")))
|
|
1015
|
+
return path8__default.default.join(root, "themes");
|
|
1016
|
+
if (fs__default.default.existsSync(path8__default.default.join(root, "src/themes")))
|
|
1017
|
+
return path8__default.default.join(root, "src/themes");
|
|
1018
|
+
return path8__default.default.dirname(root);
|
|
944
1019
|
}
|
|
945
1020
|
function getFeaturesDir() {
|
|
946
|
-
return
|
|
1021
|
+
return path8__default.default.join(getProjectRoot(), "src/features");
|
|
947
1022
|
}
|
|
948
1023
|
function isOneXProject() {
|
|
949
1024
|
const root = getProjectRoot();
|
|
950
|
-
return fs__default.default.existsSync(
|
|
1025
|
+
return fs__default.default.existsSync(path8__default.default.join(root, "themes")) || fs__default.default.existsSync(path8__default.default.join(root, "src/themes")) || fs__default.default.existsSync(path8__default.default.join(root, "theme.config.ts")) || fs__default.default.existsSync(path8__default.default.join(root, "bundle-entry.ts"));
|
|
951
1026
|
}
|
|
952
1027
|
function ensureOneXProject() {
|
|
953
1028
|
if (!isOneXProject()) {
|
|
@@ -963,13 +1038,13 @@ function listThemes() {
|
|
|
963
1038
|
return [];
|
|
964
1039
|
}
|
|
965
1040
|
return fs__default.default.readdirSync(themesDir).filter((name) => {
|
|
966
|
-
const themePath =
|
|
967
|
-
return fs__default.default.statSync(themePath).isDirectory() && (fs__default.default.existsSync(
|
|
1041
|
+
const themePath = path8__default.default.join(themesDir, name);
|
|
1042
|
+
return fs__default.default.statSync(themePath).isDirectory() && (fs__default.default.existsSync(path8__default.default.join(themePath, "theme.config.ts")) || fs__default.default.existsSync(path8__default.default.join(themePath, "bundle-entry.ts")) || fs__default.default.existsSync(path8__default.default.join(themePath, "manifest.ts")));
|
|
968
1043
|
});
|
|
969
1044
|
}
|
|
970
1045
|
function themeExists(themeName) {
|
|
971
|
-
const themePath =
|
|
972
|
-
return fs__default.default.existsSync(themePath) && (fs__default.default.existsSync(
|
|
1046
|
+
const themePath = path8__default.default.join(getThemesDir(), themeName);
|
|
1047
|
+
return fs__default.default.existsSync(themePath) && (fs__default.default.existsSync(path8__default.default.join(themePath, "theme.config.ts")) || fs__default.default.existsSync(path8__default.default.join(themePath, "bundle-entry.ts")) || fs__default.default.existsSync(path8__default.default.join(themePath, "manifest.ts")));
|
|
973
1048
|
}
|
|
974
1049
|
function detectPackageManager() {
|
|
975
1050
|
const userAgent = process.env.npm_config_user_agent || "";
|
|
@@ -977,9 +1052,9 @@ function detectPackageManager() {
|
|
|
977
1052
|
if (userAgent.includes("yarn")) return "yarn";
|
|
978
1053
|
if (userAgent.includes("bun")) return "bun";
|
|
979
1054
|
const cwd = process.cwd();
|
|
980
|
-
if (fs__default.default.existsSync(
|
|
981
|
-
if (fs__default.default.existsSync(
|
|
982
|
-
if (fs__default.default.existsSync(
|
|
1055
|
+
if (fs__default.default.existsSync(path8__default.default.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
1056
|
+
if (fs__default.default.existsSync(path8__default.default.join(cwd, "yarn.lock"))) return "yarn";
|
|
1057
|
+
if (fs__default.default.existsSync(path8__default.default.join(cwd, "bun.lockb"))) return "bun";
|
|
983
1058
|
return "npm";
|
|
984
1059
|
}
|
|
985
1060
|
async function installDependencies(projectPath, packageManager = "npm") {
|
|
@@ -1045,7 +1120,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
1045
1120
|
if (!validateThemeName(kebabName)) {
|
|
1046
1121
|
return "Invalid project name. Use lowercase letters, numbers, and hyphens only.";
|
|
1047
1122
|
}
|
|
1048
|
-
if (fs2__default.default.existsSync(
|
|
1123
|
+
if (fs2__default.default.existsSync(path8__default.default.join(process.cwd(), kebabName))) {
|
|
1049
1124
|
return `Directory "${kebabName}" already exists`;
|
|
1050
1125
|
}
|
|
1051
1126
|
return true;
|
|
@@ -1056,7 +1131,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
1056
1131
|
} else {
|
|
1057
1132
|
name = toKebabCase(projectName);
|
|
1058
1133
|
}
|
|
1059
|
-
const projectPath =
|
|
1134
|
+
const projectPath = path8__default.default.join(process.cwd(), name);
|
|
1060
1135
|
if (fs2__default.default.existsSync(projectPath)) {
|
|
1061
1136
|
logger.error(`Directory "${name}" already exists.`);
|
|
1062
1137
|
process.exit(1);
|
|
@@ -1119,38 +1194,38 @@ async function initCommand(projectName, options = {}) {
|
|
|
1119
1194
|
try {
|
|
1120
1195
|
fs2__default.default.mkdirSync(projectPath, { recursive: true });
|
|
1121
1196
|
await copyTemplate(template, projectPath, data);
|
|
1122
|
-
const srcPath =
|
|
1197
|
+
const srcPath = path8__default.default.join(projectPath, "src");
|
|
1123
1198
|
fs2__default.default.mkdirSync(srcPath, { recursive: true });
|
|
1124
1199
|
const manifestContent = generateManifest(data);
|
|
1125
|
-
await writeFile(
|
|
1200
|
+
await writeFile(path8__default.default.join(srcPath, "manifest.ts"), manifestContent);
|
|
1126
1201
|
const configContent = generateThemeConfig(data);
|
|
1127
|
-
await writeFile(
|
|
1202
|
+
await writeFile(path8__default.default.join(srcPath, "config.ts"), configContent);
|
|
1128
1203
|
const layoutContent = generateThemeLayout(data);
|
|
1129
|
-
await writeFile(
|
|
1204
|
+
await writeFile(path8__default.default.join(srcPath, "layout.ts"), layoutContent);
|
|
1130
1205
|
const indexContent = generateThemeIndex(data);
|
|
1131
|
-
await writeFile(
|
|
1132
|
-
const sectionsPath =
|
|
1206
|
+
await writeFile(path8__default.default.join(srcPath, "index.ts"), indexContent);
|
|
1207
|
+
const sectionsPath = path8__default.default.join(srcPath, "sections");
|
|
1133
1208
|
fs2__default.default.mkdirSync(sectionsPath, { recursive: true });
|
|
1134
1209
|
await writeFile(
|
|
1135
|
-
|
|
1210
|
+
path8__default.default.join(sectionsPath, "README.md"),
|
|
1136
1211
|
`# ${displayName} Sections
|
|
1137
1212
|
|
|
1138
1213
|
Add your theme-specific sections here.
|
|
1139
1214
|
`
|
|
1140
1215
|
);
|
|
1141
|
-
const blocksPath =
|
|
1216
|
+
const blocksPath = path8__default.default.join(srcPath, "blocks");
|
|
1142
1217
|
fs2__default.default.mkdirSync(blocksPath, { recursive: true });
|
|
1143
1218
|
await writeFile(
|
|
1144
|
-
|
|
1219
|
+
path8__default.default.join(blocksPath, "README.md"),
|
|
1145
1220
|
`# ${displayName} Blocks
|
|
1146
1221
|
|
|
1147
1222
|
Add your theme-specific blocks here.
|
|
1148
1223
|
`
|
|
1149
1224
|
);
|
|
1150
|
-
const pagesPath =
|
|
1225
|
+
const pagesPath = path8__default.default.join(srcPath, "pages");
|
|
1151
1226
|
fs2__default.default.mkdirSync(pagesPath, { recursive: true });
|
|
1152
1227
|
const homePageContent = generateHomePage(data);
|
|
1153
|
-
await writeFile(
|
|
1228
|
+
await writeFile(path8__default.default.join(pagesPath, "home.ts"), homePageContent);
|
|
1154
1229
|
logger.stopSpinner(true, "Project structure created!");
|
|
1155
1230
|
if (options.git) {
|
|
1156
1231
|
logger.startSpinner("Initializing git repository...");
|
|
@@ -1162,7 +1237,7 @@ Add your theme-specific blocks here.
|
|
|
1162
1237
|
stdio: "ignore"
|
|
1163
1238
|
});
|
|
1164
1239
|
logger.stopSpinner(true, "Git repository initialized!");
|
|
1165
|
-
} catch
|
|
1240
|
+
} catch {
|
|
1166
1241
|
logger.stopSpinner(false, "Failed to initialize git");
|
|
1167
1242
|
}
|
|
1168
1243
|
}
|
|
@@ -1173,7 +1248,7 @@ Add your theme-specific blocks here.
|
|
|
1173
1248
|
try {
|
|
1174
1249
|
await installDependencies(projectPath, packageManager);
|
|
1175
1250
|
logger.stopSpinner(true, "Dependencies installed!");
|
|
1176
|
-
} catch
|
|
1251
|
+
} catch {
|
|
1177
1252
|
logger.stopSpinner(false, "Failed to install dependencies");
|
|
1178
1253
|
logger.info(
|
|
1179
1254
|
"You can install dependencies manually by running: cd " + name + " && npm install"
|
|
@@ -1449,10 +1524,10 @@ async function createSectionCommand(name, options) {
|
|
|
1449
1524
|
ensureOneXProject();
|
|
1450
1525
|
if (!options.theme) {
|
|
1451
1526
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
1452
|
-
(f) => fs__default.default.existsSync(
|
|
1527
|
+
(f) => fs__default.default.existsSync(path8__default.default.join(process.cwd(), f))
|
|
1453
1528
|
);
|
|
1454
1529
|
if (isStandaloneTheme) {
|
|
1455
|
-
options.theme =
|
|
1530
|
+
options.theme = path8__default.default.basename(process.cwd());
|
|
1456
1531
|
}
|
|
1457
1532
|
}
|
|
1458
1533
|
const sectionName = toKebabCase(name);
|
|
@@ -1515,35 +1590,35 @@ async function createSectionCommand(name, options) {
|
|
|
1515
1590
|
};
|
|
1516
1591
|
logger.startSpinner("Creating section files...");
|
|
1517
1592
|
try {
|
|
1518
|
-
const themePath =
|
|
1519
|
-
const sectionPath =
|
|
1593
|
+
const themePath = path8__default.default.join(getThemesDir(), themeName);
|
|
1594
|
+
const sectionPath = path8__default.default.join(themePath, "sections", sectionName);
|
|
1520
1595
|
const schemaContent = generateSectionSchema(data);
|
|
1521
1596
|
await writeFile(
|
|
1522
|
-
|
|
1597
|
+
path8__default.default.join(sectionPath, `${sectionName}.schema.ts`),
|
|
1523
1598
|
schemaContent
|
|
1524
1599
|
);
|
|
1525
1600
|
if (createTemplate) {
|
|
1526
1601
|
const templateContent = generateSectionTemplate(data);
|
|
1527
1602
|
await writeFile(
|
|
1528
|
-
|
|
1603
|
+
path8__default.default.join(sectionPath, `${sectionName}-default.tsx`),
|
|
1529
1604
|
templateContent
|
|
1530
1605
|
);
|
|
1531
1606
|
}
|
|
1532
1607
|
const indexContent = generateSectionIndex(data, createTemplate);
|
|
1533
|
-
await writeFile(
|
|
1608
|
+
await writeFile(path8__default.default.join(sectionPath, "index.ts"), indexContent);
|
|
1534
1609
|
logger.stopSpinner(true, "Section files created successfully!");
|
|
1535
1610
|
logger.newLine();
|
|
1536
1611
|
logger.section("Next steps:");
|
|
1537
1612
|
logger.log(
|
|
1538
|
-
` 1. Edit schema: ${
|
|
1613
|
+
` 1. Edit schema: ${path8__default.default.relative(process.cwd(), path8__default.default.join(sectionPath, `${sectionName}.schema.ts`))}`
|
|
1539
1614
|
);
|
|
1540
1615
|
if (createTemplate) {
|
|
1541
1616
|
logger.log(
|
|
1542
|
-
` 2. Edit template: ${
|
|
1617
|
+
` 2. Edit template: ${path8__default.default.relative(process.cwd(), path8__default.default.join(sectionPath, `${sectionName}-default.tsx`))}`
|
|
1543
1618
|
);
|
|
1544
1619
|
}
|
|
1545
1620
|
logger.log(
|
|
1546
|
-
` 3. Add to theme manifest: ${
|
|
1621
|
+
` 3. Add to theme manifest: ${path8__default.default.relative(process.cwd(), path8__default.default.join(themePath, "manifest.ts"))}`
|
|
1547
1622
|
);
|
|
1548
1623
|
logger.newLine();
|
|
1549
1624
|
logger.success("Section created successfully!");
|
|
@@ -1691,10 +1766,10 @@ async function createBlockCommand(name, options) {
|
|
|
1691
1766
|
ensureOneXProject();
|
|
1692
1767
|
if (!options.theme) {
|
|
1693
1768
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
1694
|
-
(f) => fs__default.default.existsSync(
|
|
1769
|
+
(f) => fs__default.default.existsSync(path8__default.default.join(process.cwd(), f))
|
|
1695
1770
|
);
|
|
1696
1771
|
if (isStandaloneTheme) {
|
|
1697
|
-
options.theme =
|
|
1772
|
+
options.theme = path8__default.default.basename(process.cwd());
|
|
1698
1773
|
}
|
|
1699
1774
|
}
|
|
1700
1775
|
const blockName = toKebabCase(name);
|
|
@@ -1769,24 +1844,24 @@ async function createBlockCommand(name, options) {
|
|
|
1769
1844
|
};
|
|
1770
1845
|
logger.startSpinner("Creating block files...");
|
|
1771
1846
|
try {
|
|
1772
|
-
const blockPath = scope === "shared" ?
|
|
1847
|
+
const blockPath = scope === "shared" ? path8__default.default.join(getFeaturesDir(), "blocks", blockName) : path8__default.default.join(getThemesDir(), themeName, "blocks", blockName);
|
|
1773
1848
|
const schemaContent = generateBlockSchema(data);
|
|
1774
1849
|
await writeFile(
|
|
1775
|
-
|
|
1850
|
+
path8__default.default.join(blockPath, `${blockName}.schema.ts`),
|
|
1776
1851
|
schemaContent
|
|
1777
1852
|
);
|
|
1778
1853
|
const componentContent = generateBlockComponent(data);
|
|
1779
|
-
await writeFile(
|
|
1854
|
+
await writeFile(path8__default.default.join(blockPath, `${blockName}.tsx`), componentContent);
|
|
1780
1855
|
const indexContent = generateBlockIndex(data);
|
|
1781
|
-
await writeFile(
|
|
1856
|
+
await writeFile(path8__default.default.join(blockPath, "index.ts"), indexContent);
|
|
1782
1857
|
logger.stopSpinner(true, "Block files created successfully!");
|
|
1783
1858
|
logger.newLine();
|
|
1784
1859
|
logger.section("Next steps:");
|
|
1785
1860
|
logger.log(
|
|
1786
|
-
` 1. Edit schema: ${
|
|
1861
|
+
` 1. Edit schema: ${path8__default.default.relative(process.cwd(), path8__default.default.join(blockPath, `${blockName}.schema.ts`))}`
|
|
1787
1862
|
);
|
|
1788
1863
|
logger.log(
|
|
1789
|
-
` 2. Edit component: ${
|
|
1864
|
+
` 2. Edit component: ${path8__default.default.relative(process.cwd(), path8__default.default.join(blockPath, `${blockName}.tsx`))}`
|
|
1790
1865
|
);
|
|
1791
1866
|
logger.log(
|
|
1792
1867
|
` 3. Register in block registry: src/lib/registry/block-registry.ts`
|
|
@@ -1964,31 +2039,31 @@ async function createComponentCommand(name, options) {
|
|
|
1964
2039
|
};
|
|
1965
2040
|
logger.startSpinner("Creating component files...");
|
|
1966
2041
|
try {
|
|
1967
|
-
const componentPath =
|
|
2042
|
+
const componentPath = path8__default.default.join(
|
|
1968
2043
|
getFeaturesDir(),
|
|
1969
2044
|
"components",
|
|
1970
2045
|
componentName
|
|
1971
2046
|
);
|
|
1972
2047
|
const schemaContent = generateComponentSchema(data);
|
|
1973
2048
|
await writeFile(
|
|
1974
|
-
|
|
2049
|
+
path8__default.default.join(componentPath, `${componentName}.schema.ts`),
|
|
1975
2050
|
schemaContent
|
|
1976
2051
|
);
|
|
1977
2052
|
const componentContent = generateComponent(data);
|
|
1978
2053
|
await writeFile(
|
|
1979
|
-
|
|
2054
|
+
path8__default.default.join(componentPath, `${componentName}.tsx`),
|
|
1980
2055
|
componentContent
|
|
1981
2056
|
);
|
|
1982
2057
|
const indexContent = generateComponentIndex(data);
|
|
1983
|
-
await writeFile(
|
|
2058
|
+
await writeFile(path8__default.default.join(componentPath, "index.ts"), indexContent);
|
|
1984
2059
|
logger.stopSpinner(true, "Component files created successfully!");
|
|
1985
2060
|
logger.newLine();
|
|
1986
2061
|
logger.section("Next steps:");
|
|
1987
2062
|
logger.log(
|
|
1988
|
-
` 1. Edit schema: ${
|
|
2063
|
+
` 1. Edit schema: ${path8__default.default.relative(process.cwd(), path8__default.default.join(componentPath, `${componentName}.schema.ts`))}`
|
|
1989
2064
|
);
|
|
1990
2065
|
logger.log(
|
|
1991
|
-
` 2. Edit component: ${
|
|
2066
|
+
` 2. Edit component: ${path8__default.default.relative(process.cwd(), path8__default.default.join(componentPath, `${componentName}.tsx`))}`
|
|
1992
2067
|
);
|
|
1993
2068
|
logger.log(
|
|
1994
2069
|
` 3. Register in component registry: src/lib/registry/component-registry.ts`
|
|
@@ -2145,13 +2220,13 @@ async function listSections(themeFilter) {
|
|
|
2145
2220
|
return;
|
|
2146
2221
|
}
|
|
2147
2222
|
for (const theme of themes) {
|
|
2148
|
-
const sectionsDir =
|
|
2223
|
+
const sectionsDir = path8__default.default.join(getThemesDir(), theme, "sections");
|
|
2149
2224
|
if (!fs__default.default.existsSync(sectionsDir)) {
|
|
2150
2225
|
continue;
|
|
2151
2226
|
}
|
|
2152
2227
|
const sections = fs__default.default.readdirSync(sectionsDir).filter((name) => {
|
|
2153
|
-
const sectionPath =
|
|
2154
|
-
return fs__default.default.statSync(sectionPath).isDirectory() && fs__default.default.existsSync(
|
|
2228
|
+
const sectionPath = path8__default.default.join(sectionsDir, name);
|
|
2229
|
+
return fs__default.default.statSync(sectionPath).isDirectory() && fs__default.default.existsSync(path8__default.default.join(sectionPath, "index.ts"));
|
|
2155
2230
|
});
|
|
2156
2231
|
if (sections.length > 0) {
|
|
2157
2232
|
logger.log(chalk4__default.default.cyan(`
|
|
@@ -2165,11 +2240,11 @@ async function listSections(themeFilter) {
|
|
|
2165
2240
|
}
|
|
2166
2241
|
async function listBlocks(themeFilter) {
|
|
2167
2242
|
logger.section("\u{1F9F1} Blocks");
|
|
2168
|
-
const sharedBlocksDir =
|
|
2243
|
+
const sharedBlocksDir = path8__default.default.join(getFeaturesDir(), "blocks");
|
|
2169
2244
|
if (fs__default.default.existsSync(sharedBlocksDir)) {
|
|
2170
2245
|
const sharedBlocks = fs__default.default.readdirSync(sharedBlocksDir).filter((name) => {
|
|
2171
|
-
const blockPath =
|
|
2172
|
-
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(
|
|
2246
|
+
const blockPath = path8__default.default.join(sharedBlocksDir, name);
|
|
2247
|
+
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(path8__default.default.join(blockPath, "index.ts"));
|
|
2173
2248
|
});
|
|
2174
2249
|
if (sharedBlocks.length > 0) {
|
|
2175
2250
|
logger.log(chalk4__default.default.cyan("\n Shared:"));
|
|
@@ -2180,13 +2255,13 @@ async function listBlocks(themeFilter) {
|
|
|
2180
2255
|
}
|
|
2181
2256
|
const themes = themeFilter ? [themeFilter] : listThemes();
|
|
2182
2257
|
for (const theme of themes) {
|
|
2183
|
-
const blocksDir =
|
|
2258
|
+
const blocksDir = path8__default.default.join(getThemesDir(), theme, "blocks");
|
|
2184
2259
|
if (!fs__default.default.existsSync(blocksDir)) {
|
|
2185
2260
|
continue;
|
|
2186
2261
|
}
|
|
2187
2262
|
const blocks = fs__default.default.readdirSync(blocksDir).filter((name) => {
|
|
2188
|
-
const blockPath =
|
|
2189
|
-
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(
|
|
2263
|
+
const blockPath = path8__default.default.join(blocksDir, name);
|
|
2264
|
+
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(path8__default.default.join(blockPath, "index.ts"));
|
|
2190
2265
|
});
|
|
2191
2266
|
if (blocks.length > 0) {
|
|
2192
2267
|
logger.log(chalk4__default.default.cyan(`
|
|
@@ -2200,14 +2275,14 @@ async function listBlocks(themeFilter) {
|
|
|
2200
2275
|
}
|
|
2201
2276
|
async function listComponents() {
|
|
2202
2277
|
logger.section("\u2699\uFE0F Components");
|
|
2203
|
-
const componentsDir =
|
|
2278
|
+
const componentsDir = path8__default.default.join(getFeaturesDir(), "components");
|
|
2204
2279
|
if (!fs__default.default.existsSync(componentsDir)) {
|
|
2205
2280
|
logger.warning("No components directory found");
|
|
2206
2281
|
return;
|
|
2207
2282
|
}
|
|
2208
2283
|
const components = fs__default.default.readdirSync(componentsDir).filter((name) => {
|
|
2209
|
-
const componentPath =
|
|
2210
|
-
return fs__default.default.statSync(componentPath).isDirectory() && fs__default.default.existsSync(
|
|
2284
|
+
const componentPath = path8__default.default.join(componentsDir, name);
|
|
2285
|
+
return fs__default.default.statSync(componentPath).isDirectory() && fs__default.default.existsSync(path8__default.default.join(componentPath, "index.ts"));
|
|
2211
2286
|
});
|
|
2212
2287
|
if (components.length === 0) {
|
|
2213
2288
|
logger.warning("No components found");
|
|
@@ -2228,11 +2303,11 @@ async function listThemesInfo() {
|
|
|
2228
2303
|
}
|
|
2229
2304
|
logger.log("");
|
|
2230
2305
|
for (const theme of themes) {
|
|
2231
|
-
const themeDir =
|
|
2306
|
+
const themeDir = path8__default.default.join(getThemesDir(), theme);
|
|
2232
2307
|
const candidates = ["theme.config.ts", "bundle-entry.ts", "manifest.ts"];
|
|
2233
2308
|
let manifestContent = "";
|
|
2234
2309
|
for (const candidate of candidates) {
|
|
2235
|
-
const candidatePath =
|
|
2310
|
+
const candidatePath = path8__default.default.join(themeDir, candidate);
|
|
2236
2311
|
if (fs__default.default.existsSync(candidatePath)) {
|
|
2237
2312
|
manifestContent = fs__default.default.readFileSync(candidatePath, "utf-8");
|
|
2238
2313
|
break;
|
|
@@ -2270,9 +2345,9 @@ async function validateCommand(options) {
|
|
|
2270
2345
|
"theme.config.ts",
|
|
2271
2346
|
"bundle-entry.ts",
|
|
2272
2347
|
"manifest.ts"
|
|
2273
|
-
].some((f) => fs__default.default.existsSync(
|
|
2348
|
+
].some((f) => fs__default.default.existsSync(path8__default.default.join(process.cwd(), f)));
|
|
2274
2349
|
if (isThemeDir) {
|
|
2275
|
-
themeToValidate =
|
|
2350
|
+
themeToValidate = path8__default.default.basename(process.cwd());
|
|
2276
2351
|
logger.info(`Validating current theme: ${themeToValidate}`);
|
|
2277
2352
|
} else {
|
|
2278
2353
|
logger.error(
|
|
@@ -2281,11 +2356,11 @@ async function validateCommand(options) {
|
|
|
2281
2356
|
process.exit(1);
|
|
2282
2357
|
}
|
|
2283
2358
|
}
|
|
2284
|
-
const themePath =
|
|
2359
|
+
const themePath = path8__default.default.join(getThemesDir(), themeToValidate);
|
|
2285
2360
|
logger.startSpinner("Running validation checks...");
|
|
2286
2361
|
const entryFiles = ["manifest.ts", "theme.config.ts", "bundle-entry.ts"];
|
|
2287
2362
|
const foundEntry = entryFiles.find(
|
|
2288
|
-
(f) => fs__default.default.existsSync(
|
|
2363
|
+
(f) => fs__default.default.existsSync(path8__default.default.join(themePath, f))
|
|
2289
2364
|
);
|
|
2290
2365
|
if (!foundEntry) {
|
|
2291
2366
|
issues.push({
|
|
@@ -2295,7 +2370,7 @@ async function validateCommand(options) {
|
|
|
2295
2370
|
});
|
|
2296
2371
|
} else if (foundEntry === "manifest.ts") {
|
|
2297
2372
|
const manifestContent = fs__default.default.readFileSync(
|
|
2298
|
-
|
|
2373
|
+
path8__default.default.join(themePath, foundEntry),
|
|
2299
2374
|
"utf-8"
|
|
2300
2375
|
);
|
|
2301
2376
|
if (!manifestContent.includes("export const") && !manifestContent.includes("export default") && !manifestContent.includes("export interface")) {
|
|
@@ -2306,7 +2381,7 @@ async function validateCommand(options) {
|
|
|
2306
2381
|
});
|
|
2307
2382
|
}
|
|
2308
2383
|
}
|
|
2309
|
-
const configPath =
|
|
2384
|
+
const configPath = path8__default.default.join(themePath, "theme.config.ts");
|
|
2310
2385
|
if (!fs__default.default.existsSync(configPath)) {
|
|
2311
2386
|
issues.push({
|
|
2312
2387
|
type: "warning",
|
|
@@ -2314,7 +2389,7 @@ async function validateCommand(options) {
|
|
|
2314
2389
|
message: "Theme config file not found (recommended)"
|
|
2315
2390
|
});
|
|
2316
2391
|
}
|
|
2317
|
-
const indexPath =
|
|
2392
|
+
const indexPath = path8__default.default.join(themePath, "index.ts");
|
|
2318
2393
|
if (!fs__default.default.existsSync(indexPath)) {
|
|
2319
2394
|
issues.push({
|
|
2320
2395
|
type: "warning",
|
|
@@ -2322,7 +2397,7 @@ async function validateCommand(options) {
|
|
|
2322
2397
|
message: "Index file not found (recommended)"
|
|
2323
2398
|
});
|
|
2324
2399
|
}
|
|
2325
|
-
const sectionsDir =
|
|
2400
|
+
const sectionsDir = path8__default.default.join(themePath, "sections");
|
|
2326
2401
|
if (!fs__default.default.existsSync(sectionsDir)) {
|
|
2327
2402
|
issues.push({
|
|
2328
2403
|
type: "warning",
|
|
@@ -2331,16 +2406,16 @@ async function validateCommand(options) {
|
|
|
2331
2406
|
});
|
|
2332
2407
|
} else {
|
|
2333
2408
|
const sections = fs__default.default.readdirSync(sectionsDir).filter(
|
|
2334
|
-
(name) => fs__default.default.statSync(
|
|
2409
|
+
(name) => fs__default.default.statSync(path8__default.default.join(sectionsDir, name)).isDirectory()
|
|
2335
2410
|
);
|
|
2336
2411
|
for (const sectionName of sections) {
|
|
2337
|
-
const sectionPath =
|
|
2338
|
-
const schemaFile =
|
|
2339
|
-
const defaultTemplate =
|
|
2412
|
+
const sectionPath = path8__default.default.join(sectionsDir, sectionName);
|
|
2413
|
+
const schemaFile = path8__default.default.join(sectionPath, `${sectionName}.schema.ts`);
|
|
2414
|
+
const defaultTemplate = path8__default.default.join(
|
|
2340
2415
|
sectionPath,
|
|
2341
2416
|
`${sectionName}-default.tsx`
|
|
2342
2417
|
);
|
|
2343
|
-
const indexFile =
|
|
2418
|
+
const indexFile = path8__default.default.join(sectionPath, "index.ts");
|
|
2344
2419
|
if (!fs__default.default.existsSync(schemaFile)) {
|
|
2345
2420
|
issues.push({
|
|
2346
2421
|
type: "error",
|
|
@@ -2364,14 +2439,14 @@ async function validateCommand(options) {
|
|
|
2364
2439
|
}
|
|
2365
2440
|
}
|
|
2366
2441
|
}
|
|
2367
|
-
const blocksDir =
|
|
2442
|
+
const blocksDir = path8__default.default.join(themePath, "blocks");
|
|
2368
2443
|
if (fs__default.default.existsSync(blocksDir)) {
|
|
2369
|
-
const blocks = fs__default.default.readdirSync(blocksDir).filter((name) => fs__default.default.statSync(
|
|
2444
|
+
const blocks = fs__default.default.readdirSync(blocksDir).filter((name) => fs__default.default.statSync(path8__default.default.join(blocksDir, name)).isDirectory());
|
|
2370
2445
|
for (const blockName of blocks) {
|
|
2371
|
-
const blockPath =
|
|
2372
|
-
const schemaFile =
|
|
2373
|
-
const componentFile =
|
|
2374
|
-
const indexFile =
|
|
2446
|
+
const blockPath = path8__default.default.join(blocksDir, blockName);
|
|
2447
|
+
const schemaFile = path8__default.default.join(blockPath, `${blockName}.schema.ts`);
|
|
2448
|
+
const componentFile = path8__default.default.join(blockPath, `${blockName}.tsx`);
|
|
2449
|
+
const indexFile = path8__default.default.join(blockPath, "index.ts");
|
|
2375
2450
|
if (!fs__default.default.existsSync(schemaFile)) {
|
|
2376
2451
|
issues.push({
|
|
2377
2452
|
type: "error",
|
|
@@ -2437,21 +2512,20 @@ async function validateCommand(options) {
|
|
|
2437
2512
|
// src/commands/build.ts
|
|
2438
2513
|
init_logger();
|
|
2439
2514
|
async function buildCommand(options) {
|
|
2440
|
-
var _a;
|
|
2441
2515
|
logger.header("Build Theme");
|
|
2442
2516
|
let themePath;
|
|
2443
2517
|
let themeName;
|
|
2444
2518
|
if (options.theme) {
|
|
2445
2519
|
themeName = options.theme;
|
|
2446
2520
|
try {
|
|
2447
|
-
const workspaceThemePath =
|
|
2521
|
+
const workspaceThemePath = path8__default.default.join(getThemesDir(), themeName);
|
|
2448
2522
|
if (fs__default.default.existsSync(workspaceThemePath)) {
|
|
2449
2523
|
themePath = workspaceThemePath;
|
|
2450
2524
|
} else {
|
|
2451
|
-
themePath =
|
|
2525
|
+
themePath = path8__default.default.join(process.cwd(), themeName);
|
|
2452
2526
|
}
|
|
2453
|
-
} catch
|
|
2454
|
-
themePath =
|
|
2527
|
+
} catch {
|
|
2528
|
+
themePath = path8__default.default.join(process.cwd(), themeName);
|
|
2455
2529
|
}
|
|
2456
2530
|
if (!fs__default.default.existsSync(themePath)) {
|
|
2457
2531
|
logger.error(`Theme "${themeName}" not found.`);
|
|
@@ -2462,10 +2536,10 @@ async function buildCommand(options) {
|
|
|
2462
2536
|
"theme.config.ts",
|
|
2463
2537
|
"bundle-entry.ts",
|
|
2464
2538
|
"manifest.ts"
|
|
2465
|
-
].some((f) => fs__default.default.existsSync(
|
|
2539
|
+
].some((f) => fs__default.default.existsSync(path8__default.default.join(process.cwd(), f)));
|
|
2466
2540
|
if (isThemeDir) {
|
|
2467
2541
|
themePath = process.cwd();
|
|
2468
|
-
themeName =
|
|
2542
|
+
themeName = path8__default.default.basename(themePath);
|
|
2469
2543
|
logger.info(`Building current theme: ${themeName}`);
|
|
2470
2544
|
} else {
|
|
2471
2545
|
logger.error(
|
|
@@ -2474,7 +2548,7 @@ async function buildCommand(options) {
|
|
|
2474
2548
|
process.exit(1);
|
|
2475
2549
|
}
|
|
2476
2550
|
}
|
|
2477
|
-
const packageJsonPath =
|
|
2551
|
+
const packageJsonPath = path8__default.default.join(themePath, "package.json");
|
|
2478
2552
|
const hasPkgJson = fs__default.default.existsSync(packageJsonPath);
|
|
2479
2553
|
if (!hasPkgJson) {
|
|
2480
2554
|
logger.warning(
|
|
@@ -2507,7 +2581,7 @@ async function buildCommand(options) {
|
|
|
2507
2581
|
}
|
|
2508
2582
|
logger.stopSpinner(true, "Lint passed");
|
|
2509
2583
|
const pkgJson = fs__default.default.readJsonSync(packageJsonPath);
|
|
2510
|
-
const buildScript =
|
|
2584
|
+
const buildScript = pkgJson.scripts?.build || "";
|
|
2511
2585
|
const isRecursive = buildScript.includes("onex build") || buildScript.includes("onex-cli build");
|
|
2512
2586
|
logger.startSpinner(
|
|
2513
2587
|
options.watch ? "Building (watch mode)..." : "Building..."
|
|
@@ -2530,9 +2604,9 @@ async function buildCommand(options) {
|
|
|
2530
2604
|
logger.success("\u2713 Theme built successfully!");
|
|
2531
2605
|
logger.newLine();
|
|
2532
2606
|
logger.info(`Theme: ${themeName}`);
|
|
2533
|
-
const distPath =
|
|
2607
|
+
const distPath = path8__default.default.join(themePath, "dist");
|
|
2534
2608
|
if (fs__default.default.existsSync(distPath)) {
|
|
2535
|
-
logger.log(`Output: ${
|
|
2609
|
+
logger.log(`Output: ${path8__default.default.relative(process.cwd(), distPath)}`);
|
|
2536
2610
|
const files = fs__default.default.readdirSync(distPath);
|
|
2537
2611
|
logger.log(`Files: ${files.length}`);
|
|
2538
2612
|
}
|
|
@@ -2570,7 +2644,7 @@ async function packageCommand(options) {
|
|
|
2570
2644
|
let themeName;
|
|
2571
2645
|
if (options.theme) {
|
|
2572
2646
|
themeName = options.theme;
|
|
2573
|
-
themePath =
|
|
2647
|
+
themePath = path8__default.default.join(getThemesDir(), themeName);
|
|
2574
2648
|
if (!fs__default.default.existsSync(themePath)) {
|
|
2575
2649
|
logger.error(`Theme "${themeName}" not found.`);
|
|
2576
2650
|
process.exit(1);
|
|
@@ -2580,10 +2654,10 @@ async function packageCommand(options) {
|
|
|
2580
2654
|
"theme.config.ts",
|
|
2581
2655
|
"bundle-entry.ts",
|
|
2582
2656
|
"manifest.ts"
|
|
2583
|
-
].some((f) => fs__default.default.existsSync(
|
|
2657
|
+
].some((f) => fs__default.default.existsSync(path8__default.default.join(process.cwd(), f)));
|
|
2584
2658
|
if (isThemeDir) {
|
|
2585
2659
|
themePath = process.cwd();
|
|
2586
|
-
themeName =
|
|
2660
|
+
themeName = path8__default.default.basename(themePath);
|
|
2587
2661
|
logger.info(`Packaging current theme: ${themeName}`);
|
|
2588
2662
|
} else {
|
|
2589
2663
|
logger.error(
|
|
@@ -2592,7 +2666,7 @@ async function packageCommand(options) {
|
|
|
2592
2666
|
process.exit(1);
|
|
2593
2667
|
}
|
|
2594
2668
|
}
|
|
2595
|
-
const packageJsonPath =
|
|
2669
|
+
const packageJsonPath = path8__default.default.join(themePath, "package.json");
|
|
2596
2670
|
let version = "1.0.0";
|
|
2597
2671
|
if (fs__default.default.existsSync(packageJsonPath)) {
|
|
2598
2672
|
const packageJson = await fs__default.default.readJson(packageJsonPath);
|
|
@@ -2602,7 +2676,7 @@ async function packageCommand(options) {
|
|
|
2602
2676
|
logger.info(`Theme: ${themeName}`);
|
|
2603
2677
|
logger.info(`Version: ${version}`);
|
|
2604
2678
|
logger.newLine();
|
|
2605
|
-
const compiledThemePath =
|
|
2679
|
+
const compiledThemePath = path8__default.default.join(
|
|
2606
2680
|
process.cwd(),
|
|
2607
2681
|
"themes",
|
|
2608
2682
|
themeName,
|
|
@@ -2636,8 +2710,8 @@ async function packageCommand(options) {
|
|
|
2636
2710
|
logger.newLine();
|
|
2637
2711
|
logger.section("Step 2: Create Package");
|
|
2638
2712
|
const packageName = options.name || `${themeName}-${version}`;
|
|
2639
|
-
const outputDir = options.output ||
|
|
2640
|
-
const outputPath =
|
|
2713
|
+
const outputDir = options.output || path8__default.default.join(process.cwd(), "dist");
|
|
2714
|
+
const outputPath = path8__default.default.join(outputDir, `${packageName}.zip`);
|
|
2641
2715
|
await fs__default.default.ensureDir(outputDir);
|
|
2642
2716
|
logger.startSpinner("Creating zip archive...");
|
|
2643
2717
|
try {
|
|
@@ -2650,11 +2724,11 @@ async function packageCommand(options) {
|
|
|
2650
2724
|
logger.newLine();
|
|
2651
2725
|
logger.info(`Package: ${packageName}.zip`);
|
|
2652
2726
|
logger.log(`Size: ${sizeMB} MB`);
|
|
2653
|
-
logger.log(`Location: ${
|
|
2727
|
+
logger.log(`Location: ${path8__default.default.relative(process.cwd(), outputPath)}`);
|
|
2654
2728
|
logger.newLine();
|
|
2655
2729
|
logger.section("Next steps:");
|
|
2656
2730
|
logger.log(
|
|
2657
|
-
` onex deploy --package ${
|
|
2731
|
+
` onex deploy --package ${path8__default.default.relative(process.cwd(), outputPath)}`
|
|
2658
2732
|
);
|
|
2659
2733
|
} catch (error) {
|
|
2660
2734
|
logger.stopSpinner(false, "Failed to create package");
|
|
@@ -2712,9 +2786,9 @@ async function deployCommand(options) {
|
|
|
2712
2786
|
ensureOneXProject();
|
|
2713
2787
|
let packagePath;
|
|
2714
2788
|
if (options.package) {
|
|
2715
|
-
packagePath =
|
|
2789
|
+
packagePath = path8__default.default.resolve(options.package);
|
|
2716
2790
|
} else if (options.theme) {
|
|
2717
|
-
const distDir =
|
|
2791
|
+
const distDir = path8__default.default.join(process.cwd(), "dist");
|
|
2718
2792
|
if (!fs__default.default.existsSync(distDir)) {
|
|
2719
2793
|
logger.error("No dist/ directory found. Run 'onex package' first.");
|
|
2720
2794
|
process.exit(1);
|
|
@@ -2729,7 +2803,7 @@ async function deployCommand(options) {
|
|
|
2729
2803
|
process.exit(1);
|
|
2730
2804
|
}
|
|
2731
2805
|
packageFiles.sort().reverse();
|
|
2732
|
-
packagePath =
|
|
2806
|
+
packagePath = path8__default.default.join(distDir, packageFiles[0]);
|
|
2733
2807
|
} else {
|
|
2734
2808
|
logger.error("Either --package or --theme must be specified.");
|
|
2735
2809
|
logger.info("Examples:");
|
|
@@ -2743,11 +2817,11 @@ async function deployCommand(options) {
|
|
|
2743
2817
|
}
|
|
2744
2818
|
const stats = await fs__default.default.stat(packagePath);
|
|
2745
2819
|
const sizeMB = (stats.size / 1024 / 1024).toFixed(2);
|
|
2746
|
-
const fileName =
|
|
2820
|
+
const fileName = path8__default.default.basename(packagePath);
|
|
2747
2821
|
logger.newLine();
|
|
2748
2822
|
logger.info(`Package: ${fileName}`);
|
|
2749
2823
|
logger.log(`Size: ${sizeMB} MB`);
|
|
2750
|
-
logger.log(`Path: ${
|
|
2824
|
+
logger.log(`Path: ${path8__default.default.relative(process.cwd(), packagePath)}`);
|
|
2751
2825
|
logger.newLine();
|
|
2752
2826
|
const apiUrl = options.apiUrl || process.env.ONEX_API_URL || "http://localhost:3001";
|
|
2753
2827
|
const uploadEndpoint = `${apiUrl}/api/themes/upload`;
|
|
@@ -2851,11 +2925,11 @@ function getBucketName(env) {
|
|
|
2851
2925
|
return environment === "production" ? "onex-themes-prod" : "onex-themes-staging";
|
|
2852
2926
|
}
|
|
2853
2927
|
async function findCompiledThemeDir(themeId, version) {
|
|
2854
|
-
const searchPaths = [
|
|
2928
|
+
const searchPaths = [path8__default.default.resolve(process.cwd(), "dist")];
|
|
2855
2929
|
for (const dir of searchPaths) {
|
|
2856
2930
|
if (await fs__default.default.pathExists(dir)) {
|
|
2857
|
-
const hasManifest = await fs__default.default.pathExists(
|
|
2858
|
-
const hasThemeEntry = await fs__default.default.pathExists(
|
|
2931
|
+
const hasManifest = await fs__default.default.pathExists(path8__default.default.join(dir, "manifest.json"));
|
|
2932
|
+
const hasThemeEntry = await fs__default.default.pathExists(path8__default.default.join(dir, "bundle-entry.js")) || await fs__default.default.pathExists(path8__default.default.join(dir, "theme.config.js")) || await fs__default.default.pathExists(path8__default.default.join(dir, "index.js"));
|
|
2859
2933
|
if (hasManifest || hasThemeEntry) {
|
|
2860
2934
|
return dir;
|
|
2861
2935
|
}
|
|
@@ -2864,8 +2938,7 @@ async function findCompiledThemeDir(themeId, version) {
|
|
|
2864
2938
|
return null;
|
|
2865
2939
|
}
|
|
2866
2940
|
async function readManifest() {
|
|
2867
|
-
|
|
2868
|
-
const manifestTsPath = path__default.default.resolve(process.cwd(), "manifest.ts");
|
|
2941
|
+
const manifestTsPath = path8__default.default.resolve(process.cwd(), "manifest.ts");
|
|
2869
2942
|
if (await fs__default.default.pathExists(manifestTsPath)) {
|
|
2870
2943
|
try {
|
|
2871
2944
|
const module = await import(manifestTsPath);
|
|
@@ -2874,11 +2947,11 @@ async function readManifest() {
|
|
|
2874
2947
|
logger.warning("Failed to import manifest.ts, trying package.json");
|
|
2875
2948
|
}
|
|
2876
2949
|
}
|
|
2877
|
-
const packageJsonPath =
|
|
2950
|
+
const packageJsonPath = path8__default.default.resolve(process.cwd(), "package.json");
|
|
2878
2951
|
if (await fs__default.default.pathExists(packageJsonPath)) {
|
|
2879
2952
|
const pkg = await fs__default.default.readJson(packageJsonPath);
|
|
2880
2953
|
return {
|
|
2881
|
-
themeId:
|
|
2954
|
+
themeId: pkg.name?.replace("@onex-themes/", "") || "unknown",
|
|
2882
2955
|
version: pkg.version || "1.0.0"
|
|
2883
2956
|
};
|
|
2884
2957
|
}
|
|
@@ -2908,13 +2981,13 @@ async function findSourceDir(themeId, explicitDir) {
|
|
|
2908
2981
|
}
|
|
2909
2982
|
const searchPaths = [
|
|
2910
2983
|
process.cwd(),
|
|
2911
|
-
|
|
2912
|
-
|
|
2984
|
+
path8__default.default.resolve(process.cwd(), `../../themes/${themeId}`),
|
|
2985
|
+
path8__default.default.resolve(process.cwd(), `../themes/${themeId}`)
|
|
2913
2986
|
];
|
|
2914
2987
|
const markers = ["theme.config.ts", "bundle-entry.ts"];
|
|
2915
2988
|
for (const dir of searchPaths) {
|
|
2916
2989
|
for (const marker of markers) {
|
|
2917
|
-
if (await fs__default.default.pathExists(
|
|
2990
|
+
if (await fs__default.default.pathExists(path8__default.default.join(dir, marker))) {
|
|
2918
2991
|
return dir;
|
|
2919
2992
|
}
|
|
2920
2993
|
}
|
|
@@ -2966,7 +3039,7 @@ async function uploadCommand(options) {
|
|
|
2966
3039
|
spinner.succeed(`Found compiled theme at: ${compiledDir}`);
|
|
2967
3040
|
spinner.start("Creating bundle.zip...");
|
|
2968
3041
|
const tmpDir = os__default.default.tmpdir();
|
|
2969
|
-
const bundleZipPath =
|
|
3042
|
+
const bundleZipPath = path8__default.default.join(tmpDir, `${themeId}-${version}-bundle.zip`);
|
|
2970
3043
|
await createZipFromDir(compiledDir, bundleZipPath);
|
|
2971
3044
|
const bundleZipBuffer = await fs__default.default.readFile(bundleZipPath);
|
|
2972
3045
|
const bundleSizeMB = (bundleZipBuffer.length / 1024 / 1024).toFixed(2);
|
|
@@ -3020,7 +3093,7 @@ async function uploadCommand(options) {
|
|
|
3020
3093
|
if (sourceDir) {
|
|
3021
3094
|
spinner.succeed(`Found source at: ${sourceDir}`);
|
|
3022
3095
|
spinner.start("Creating source.zip...");
|
|
3023
|
-
const sourceZipPath =
|
|
3096
|
+
const sourceZipPath = path8__default.default.join(
|
|
3024
3097
|
tmpDir,
|
|
3025
3098
|
`${themeId}-${version}-source.zip`
|
|
3026
3099
|
);
|
|
@@ -3122,39 +3195,15 @@ function getBucketName2(env) {
|
|
|
3122
3195
|
}
|
|
3123
3196
|
async function streamToString(stream) {
|
|
3124
3197
|
const chunks = [];
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
const chunk = temp.value;
|
|
3128
|
-
chunks.push(Buffer.from(chunk));
|
|
3129
|
-
}
|
|
3130
|
-
} catch (temp) {
|
|
3131
|
-
error = [temp];
|
|
3132
|
-
} finally {
|
|
3133
|
-
try {
|
|
3134
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
3135
|
-
} finally {
|
|
3136
|
-
if (error)
|
|
3137
|
-
throw error[0];
|
|
3138
|
-
}
|
|
3198
|
+
for await (const chunk of stream) {
|
|
3199
|
+
chunks.push(Buffer.from(chunk));
|
|
3139
3200
|
}
|
|
3140
3201
|
return Buffer.concat(chunks).toString("utf-8");
|
|
3141
3202
|
}
|
|
3142
3203
|
async function streamToBuffer(stream) {
|
|
3143
3204
|
const chunks = [];
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
const chunk = temp.value;
|
|
3147
|
-
chunks.push(Buffer.from(chunk));
|
|
3148
|
-
}
|
|
3149
|
-
} catch (temp) {
|
|
3150
|
-
error = [temp];
|
|
3151
|
-
} finally {
|
|
3152
|
-
try {
|
|
3153
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
3154
|
-
} finally {
|
|
3155
|
-
if (error)
|
|
3156
|
-
throw error[0];
|
|
3157
|
-
}
|
|
3205
|
+
for await (const chunk of stream) {
|
|
3206
|
+
chunks.push(Buffer.from(chunk));
|
|
3158
3207
|
}
|
|
3159
3208
|
return Buffer.concat(chunks);
|
|
3160
3209
|
}
|
|
@@ -3176,11 +3225,10 @@ async function resolveLatestVersion(s3Client, bucket, themeId) {
|
|
|
3176
3225
|
}
|
|
3177
3226
|
}
|
|
3178
3227
|
async function createCompatibilityFiles(outputDir, manifest) {
|
|
3179
|
-
|
|
3180
|
-
const entryFile = ((_a = manifest.output) == null ? void 0 : _a.entry) || "bundle-entry.js";
|
|
3228
|
+
const entryFile = manifest.output?.entry || "bundle-entry.js";
|
|
3181
3229
|
if (entryFile !== "bundle-entry.js" && entryFile.startsWith("bundle-entry-")) {
|
|
3182
|
-
const hashedPath =
|
|
3183
|
-
const stablePath =
|
|
3230
|
+
const hashedPath = path8__default.default.join(outputDir, entryFile);
|
|
3231
|
+
const stablePath = path8__default.default.join(outputDir, "bundle-entry.js");
|
|
3184
3232
|
if (await fs__default.default.pathExists(hashedPath)) {
|
|
3185
3233
|
await fs__default.default.copy(hashedPath, stablePath);
|
|
3186
3234
|
const mapPath = hashedPath + ".map";
|
|
@@ -3189,13 +3237,13 @@ async function createCompatibilityFiles(outputDir, manifest) {
|
|
|
3189
3237
|
}
|
|
3190
3238
|
}
|
|
3191
3239
|
}
|
|
3192
|
-
const sectionsRegistryPath =
|
|
3240
|
+
const sectionsRegistryPath = path8__default.default.join(outputDir, "sections-registry.js");
|
|
3193
3241
|
const content = `// Re-export all sections from bundle-entry
|
|
3194
3242
|
// This file exists to maintain compatibility with the import path
|
|
3195
3243
|
export * from './bundle-entry.js';
|
|
3196
3244
|
`;
|
|
3197
3245
|
await fs__default.default.writeFile(sectionsRegistryPath, content, "utf-8");
|
|
3198
|
-
const pkgJsonPath =
|
|
3246
|
+
const pkgJsonPath = path8__default.default.join(outputDir, "package.json");
|
|
3199
3247
|
await fs__default.default.writeFile(pkgJsonPath, '{\n "type": "module"\n}\n', "utf-8");
|
|
3200
3248
|
}
|
|
3201
3249
|
function showDownloadFailureHelp(themeId, bucket) {
|
|
@@ -3278,7 +3326,7 @@ async function downloadCommand(options) {
|
|
|
3278
3326
|
zip.extractAllTo(outputDir, true);
|
|
3279
3327
|
const entries = zip.getEntries().filter((e) => !e.isDirectory);
|
|
3280
3328
|
spinner.succeed(`Extracted ${entries.length} files to ${outputDir}`);
|
|
3281
|
-
const manifestPath =
|
|
3329
|
+
const manifestPath = path8__default.default.join(outputDir, "manifest.json");
|
|
3282
3330
|
const manifest = await fs__default.default.readJson(manifestPath);
|
|
3283
3331
|
await createCompatibilityFiles(outputDir, manifest);
|
|
3284
3332
|
console.log();
|
|
@@ -3348,39 +3396,15 @@ function getBucketName3(env) {
|
|
|
3348
3396
|
}
|
|
3349
3397
|
async function streamToString2(stream) {
|
|
3350
3398
|
const chunks = [];
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
const chunk = temp.value;
|
|
3354
|
-
chunks.push(Buffer.from(chunk));
|
|
3355
|
-
}
|
|
3356
|
-
} catch (temp) {
|
|
3357
|
-
error = [temp];
|
|
3358
|
-
} finally {
|
|
3359
|
-
try {
|
|
3360
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
3361
|
-
} finally {
|
|
3362
|
-
if (error)
|
|
3363
|
-
throw error[0];
|
|
3364
|
-
}
|
|
3399
|
+
for await (const chunk of stream) {
|
|
3400
|
+
chunks.push(Buffer.from(chunk));
|
|
3365
3401
|
}
|
|
3366
3402
|
return Buffer.concat(chunks).toString("utf-8");
|
|
3367
3403
|
}
|
|
3368
3404
|
async function streamToBuffer2(stream) {
|
|
3369
3405
|
const chunks = [];
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
const chunk = temp.value;
|
|
3373
|
-
chunks.push(Buffer.from(chunk));
|
|
3374
|
-
}
|
|
3375
|
-
} catch (temp) {
|
|
3376
|
-
error = [temp];
|
|
3377
|
-
} finally {
|
|
3378
|
-
try {
|
|
3379
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
3380
|
-
} finally {
|
|
3381
|
-
if (error)
|
|
3382
|
-
throw error[0];
|
|
3383
|
-
}
|
|
3406
|
+
for await (const chunk of stream) {
|
|
3407
|
+
chunks.push(Buffer.from(chunk));
|
|
3384
3408
|
}
|
|
3385
3409
|
return Buffer.concat(chunks);
|
|
3386
3410
|
}
|
|
@@ -3436,7 +3460,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3436
3460
|
const oldPrefix = `${oldName}-`;
|
|
3437
3461
|
const newPrefix = `${newName}-`;
|
|
3438
3462
|
const newDisplayName = newName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3439
|
-
const pkgPath =
|
|
3463
|
+
const pkgPath = path8__default.default.join(themeDir, "package.json");
|
|
3440
3464
|
if (await fs__default.default.pathExists(pkgPath)) {
|
|
3441
3465
|
const pkg = await fs__default.default.readJson(pkgPath);
|
|
3442
3466
|
pkg.name = `@onex-themes/${newName}`;
|
|
@@ -3449,7 +3473,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3449
3473
|
pkg.version = "1.0.0";
|
|
3450
3474
|
await fs__default.default.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3451
3475
|
}
|
|
3452
|
-
const configPath =
|
|
3476
|
+
const configPath = path8__default.default.join(themeDir, "theme.config.ts");
|
|
3453
3477
|
if (await fs__default.default.pathExists(configPath)) {
|
|
3454
3478
|
let content = await fs__default.default.readFile(configPath, "utf-8");
|
|
3455
3479
|
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
@@ -3459,7 +3483,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3459
3483
|
);
|
|
3460
3484
|
await fs__default.default.writeFile(configPath, content);
|
|
3461
3485
|
}
|
|
3462
|
-
const layoutPath =
|
|
3486
|
+
const layoutPath = path8__default.default.join(themeDir, "theme.layout.ts");
|
|
3463
3487
|
if (await fs__default.default.pathExists(layoutPath)) {
|
|
3464
3488
|
let content = await fs__default.default.readFile(layoutPath, "utf-8");
|
|
3465
3489
|
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
@@ -3472,7 +3496,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3472
3496
|
const oldDisplayName = oldName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3473
3497
|
const tsFiles = await glob.glob("**/*.ts", { cwd: themeDir, nodir: true });
|
|
3474
3498
|
for (const file of tsFiles) {
|
|
3475
|
-
const filePath =
|
|
3499
|
+
const filePath = path8__default.default.join(themeDir, file);
|
|
3476
3500
|
let content = await fs__default.default.readFile(filePath, "utf-8");
|
|
3477
3501
|
const original = content;
|
|
3478
3502
|
content = content.replace(
|
|
@@ -3501,7 +3525,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3501
3525
|
const spinner = ora__default.default("Initializing clone...").start();
|
|
3502
3526
|
try {
|
|
3503
3527
|
const bucket = options.bucket || getBucketName3(options.environment);
|
|
3504
|
-
const outputDir = options.output ||
|
|
3528
|
+
const outputDir = options.output || path8__default.default.resolve(process.cwd(), newName);
|
|
3505
3529
|
const s3Client = getS3Client3();
|
|
3506
3530
|
if (await fs__default.default.pathExists(outputDir)) {
|
|
3507
3531
|
spinner.fail(chalk4__default.default.red(`Directory already exists: ${outputDir}`));
|
|
@@ -3556,9 +3580,22 @@ async function cloneCommand(themeName, options) {
|
|
|
3556
3580
|
spinner.succeed(
|
|
3557
3581
|
`Renamed theme: ${chalk4__default.default.gray(themeName)} \u2192 ${chalk4__default.default.cyan(newName)}`
|
|
3558
3582
|
);
|
|
3583
|
+
const envExamplePath = path8__default.default.join(outputDir, ".env.example");
|
|
3584
|
+
if (!await fs__default.default.pathExists(envExamplePath)) {
|
|
3585
|
+
await fs__default.default.writeFile(
|
|
3586
|
+
envExamplePath,
|
|
3587
|
+
[
|
|
3588
|
+
"# API Configuration (enables real data in preview)",
|
|
3589
|
+
"# Get your Company ID from the OneX dashboard",
|
|
3590
|
+
"NEXT_PUBLIC_API_URL=https://api-dev.onexeos.com",
|
|
3591
|
+
"NEXT_PUBLIC_COMPANY_ID=",
|
|
3592
|
+
""
|
|
3593
|
+
].join("\n")
|
|
3594
|
+
);
|
|
3595
|
+
}
|
|
3559
3596
|
if (options.install !== false) {
|
|
3560
3597
|
const hasPkgJson = await fs__default.default.pathExists(
|
|
3561
|
-
|
|
3598
|
+
path8__default.default.join(outputDir, "package.json")
|
|
3562
3599
|
);
|
|
3563
3600
|
if (hasPkgJson) {
|
|
3564
3601
|
spinner.start("Installing dependencies...");
|
|
@@ -3585,7 +3622,8 @@ async function cloneCommand(themeName, options) {
|
|
|
3585
3622
|
console.log(chalk4__default.default.cyan(" Files: ") + chalk4__default.default.white(entries.length));
|
|
3586
3623
|
console.log();
|
|
3587
3624
|
console.log(chalk4__default.default.cyan("Next steps:"));
|
|
3588
|
-
console.log(chalk4__default.default.gray(` cd ${
|
|
3625
|
+
console.log(chalk4__default.default.gray(` cd ${path8__default.default.relative(process.cwd(), outputDir)}`));
|
|
3626
|
+
console.log(chalk4__default.default.gray(" cp .env.example .env # then add your Company ID"));
|
|
3589
3627
|
if (options.install === false) {
|
|
3590
3628
|
console.log(chalk4__default.default.gray(" pnpm install"));
|
|
3591
3629
|
}
|
|
@@ -3637,7 +3675,7 @@ function createDevServer(options) {
|
|
|
3637
3675
|
serveFile(res, options.previewRuntimePath);
|
|
3638
3676
|
return;
|
|
3639
3677
|
}
|
|
3640
|
-
const filePath =
|
|
3678
|
+
const filePath = path8__default.default.join(options.distDir, pathname);
|
|
3641
3679
|
if (!filePath.startsWith(options.distDir)) {
|
|
3642
3680
|
res.writeHead(403);
|
|
3643
3681
|
res.end("Forbidden");
|
|
@@ -3678,12 +3716,12 @@ function serveFile(res, filePath) {
|
|
|
3678
3716
|
res.end("Not Found");
|
|
3679
3717
|
return;
|
|
3680
3718
|
}
|
|
3681
|
-
const ext =
|
|
3719
|
+
const ext = path8__default.default.extname(filePath);
|
|
3682
3720
|
const contentType = MIME_TYPES[ext] || "application/octet-stream";
|
|
3683
3721
|
const content = fs2__default.default.readFileSync(filePath);
|
|
3684
3722
|
res.writeHead(200, { "Content-Type": contentType });
|
|
3685
3723
|
res.end(content);
|
|
3686
|
-
} catch
|
|
3724
|
+
} catch {
|
|
3687
3725
|
res.writeHead(500);
|
|
3688
3726
|
res.end("Internal Server Error");
|
|
3689
3727
|
}
|
|
@@ -3738,14 +3776,14 @@ async function devCommand(options) {
|
|
|
3738
3776
|
if (options.theme) {
|
|
3739
3777
|
themeName = options.theme;
|
|
3740
3778
|
try {
|
|
3741
|
-
const workspaceThemePath =
|
|
3779
|
+
const workspaceThemePath = path8__default.default.join(getThemesDir(), themeName);
|
|
3742
3780
|
if (fs__default.default.existsSync(workspaceThemePath)) {
|
|
3743
3781
|
themePath = workspaceThemePath;
|
|
3744
3782
|
} else {
|
|
3745
|
-
themePath =
|
|
3783
|
+
themePath = path8__default.default.join(process.cwd(), themeName);
|
|
3746
3784
|
}
|
|
3747
|
-
} catch
|
|
3748
|
-
themePath =
|
|
3785
|
+
} catch {
|
|
3786
|
+
themePath = path8__default.default.join(process.cwd(), themeName);
|
|
3749
3787
|
}
|
|
3750
3788
|
if (!fs__default.default.existsSync(themePath)) {
|
|
3751
3789
|
logger.error(`Theme "${themeName}" not found.`);
|
|
@@ -3756,10 +3794,10 @@ async function devCommand(options) {
|
|
|
3756
3794
|
"theme.config.ts",
|
|
3757
3795
|
"bundle-entry.ts",
|
|
3758
3796
|
"manifest.ts"
|
|
3759
|
-
].some((f) => fs__default.default.existsSync(
|
|
3797
|
+
].some((f) => fs__default.default.existsSync(path8__default.default.join(process.cwd(), f)));
|
|
3760
3798
|
if (isThemeDir) {
|
|
3761
3799
|
themePath = process.cwd();
|
|
3762
|
-
themeName =
|
|
3800
|
+
themeName = path8__default.default.basename(themePath);
|
|
3763
3801
|
} else {
|
|
3764
3802
|
logger.error(
|
|
3765
3803
|
"Not in a theme directory and no --theme specified. Run from theme root or use --theme flag."
|
|
@@ -3827,10 +3865,10 @@ async function devCommand(options) {
|
|
|
3827
3865
|
watcher.close();
|
|
3828
3866
|
await context2.dispose();
|
|
3829
3867
|
server.close();
|
|
3830
|
-
const shimPath =
|
|
3868
|
+
const shimPath = path8__default.default.join(outputDir, ".process-shim.js");
|
|
3831
3869
|
try {
|
|
3832
3870
|
await fs7__default.default.unlink(shimPath);
|
|
3833
|
-
} catch
|
|
3871
|
+
} catch {
|
|
3834
3872
|
}
|
|
3835
3873
|
process.exit(0);
|
|
3836
3874
|
});
|
|
@@ -3840,14 +3878,14 @@ async function devCommand(options) {
|
|
|
3840
3878
|
try {
|
|
3841
3879
|
const projectRoot = getProjectRoot();
|
|
3842
3880
|
dotenv__default.default.config({
|
|
3843
|
-
path:
|
|
3881
|
+
path: path8__default.default.join(projectRoot, ".env.local"),
|
|
3844
3882
|
quiet: true
|
|
3845
3883
|
});
|
|
3846
|
-
dotenv__default.default.config({ path:
|
|
3847
|
-
} catch
|
|
3884
|
+
dotenv__default.default.config({ path: path8__default.default.join(projectRoot, ".env"), quiet: true });
|
|
3885
|
+
} catch {
|
|
3848
3886
|
}
|
|
3849
3887
|
dotenv__default.default.config({
|
|
3850
|
-
path:
|
|
3888
|
+
path: path8__default.default.join(os__default.default.homedir(), ".onex", ".env"),
|
|
3851
3889
|
quiet: true
|
|
3852
3890
|
});
|
|
3853
3891
|
var program = new commander.Command();
|