@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/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var chalk4 = require('chalk');
|
|
4
4
|
var ora = require('ora');
|
|
5
5
|
var esbuild = require('esbuild');
|
|
6
|
-
var
|
|
6
|
+
var path7 = require('path');
|
|
7
7
|
var fs6 = require('fs/promises');
|
|
8
8
|
var crypto = require('crypto');
|
|
9
9
|
var glob = require('glob');
|
|
@@ -17,6 +17,7 @@ var os = require('os');
|
|
|
17
17
|
var archiver = require('archiver');
|
|
18
18
|
var AdmZip = require('adm-zip');
|
|
19
19
|
|
|
20
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
20
21
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
22
|
|
|
22
23
|
function _interopNamespace(e) {
|
|
@@ -40,7 +41,7 @@ function _interopNamespace(e) {
|
|
|
40
41
|
var chalk4__default = /*#__PURE__*/_interopDefault(chalk4);
|
|
41
42
|
var ora__default = /*#__PURE__*/_interopDefault(ora);
|
|
42
43
|
var esbuild__namespace = /*#__PURE__*/_interopNamespace(esbuild);
|
|
43
|
-
var
|
|
44
|
+
var path7__default = /*#__PURE__*/_interopDefault(path7);
|
|
44
45
|
var fs6__default = /*#__PURE__*/_interopDefault(fs6);
|
|
45
46
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
46
47
|
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
@@ -53,22 +54,6 @@ var AdmZip__default = /*#__PURE__*/_interopDefault(AdmZip);
|
|
|
53
54
|
|
|
54
55
|
var __defProp = Object.defineProperty;
|
|
55
56
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
56
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
57
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
58
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
59
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
|
|
60
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
61
|
-
var __spreadValues = (a, b) => {
|
|
62
|
-
for (var prop in b || (b = {}))
|
|
63
|
-
if (__hasOwnProp.call(b, prop))
|
|
64
|
-
__defNormalProp(a, prop, b[prop]);
|
|
65
|
-
if (__getOwnPropSymbols)
|
|
66
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
67
|
-
if (__propIsEnum.call(b, prop))
|
|
68
|
-
__defNormalProp(a, prop, b[prop]);
|
|
69
|
-
}
|
|
70
|
-
return a;
|
|
71
|
-
};
|
|
72
57
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
73
58
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
74
59
|
}) : x)(function(x) {
|
|
@@ -82,7 +67,6 @@ var __export = (target, all) => {
|
|
|
82
67
|
for (var name in all)
|
|
83
68
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
84
69
|
};
|
|
85
|
-
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);
|
|
86
70
|
exports.Logger = void 0; exports.logger = void 0;
|
|
87
71
|
var init_logger = __esm({
|
|
88
72
|
"src/utils/logger.ts"() {
|
|
@@ -151,12 +135,12 @@ __export(compile_theme_exports, {
|
|
|
151
135
|
async function resolveNodeModulesFile(startDir, relativePath) {
|
|
152
136
|
let dir = startDir;
|
|
153
137
|
while (true) {
|
|
154
|
-
const candidate =
|
|
138
|
+
const candidate = path7__default.default.join(dir, "node_modules", relativePath);
|
|
155
139
|
try {
|
|
156
140
|
await fs6__default.default.access(candidate);
|
|
157
141
|
return candidate;
|
|
158
|
-
} catch
|
|
159
|
-
const parent =
|
|
142
|
+
} catch {
|
|
143
|
+
const parent = path7__default.default.dirname(dir);
|
|
160
144
|
if (parent === dir) break;
|
|
161
145
|
dir = parent;
|
|
162
146
|
}
|
|
@@ -174,7 +158,7 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
174
158
|
}));
|
|
175
159
|
build2.onLoad({ filter: /.*/, namespace: "core-global" }, async (args) => {
|
|
176
160
|
const match = args.path.match(/^@onexapis\/core(\/(.+))?$/);
|
|
177
|
-
const subpath =
|
|
161
|
+
const subpath = match?.[2] || "";
|
|
178
162
|
const moduleAccess = subpath ? `['${subpath}']` : "";
|
|
179
163
|
let namedExports = [];
|
|
180
164
|
const cacheKey = subpath || "__root__";
|
|
@@ -182,10 +166,16 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
182
166
|
namedExports = exportsBySubpath[cacheKey];
|
|
183
167
|
} else {
|
|
184
168
|
const distFileName = subpath ? `${subpath}.mjs` : "index.mjs";
|
|
185
|
-
|
|
169
|
+
let distPath = await resolveNodeModulesFile(
|
|
186
170
|
themePath,
|
|
187
|
-
|
|
171
|
+
path7__default.default.join("@onexapis", "core", "dist", distFileName)
|
|
188
172
|
);
|
|
173
|
+
if (!distPath) {
|
|
174
|
+
distPath = await resolveNodeModulesFile(
|
|
175
|
+
__dirname,
|
|
176
|
+
path7__default.default.join("@onexapis", "core", "dist", distFileName)
|
|
177
|
+
);
|
|
178
|
+
}
|
|
189
179
|
try {
|
|
190
180
|
if (!distPath) throw new Error("not found");
|
|
191
181
|
const distContent = await fs6__default.default.readFile(distPath, "utf-8");
|
|
@@ -198,7 +188,7 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
198
188
|
namedExports.push(...names);
|
|
199
189
|
}
|
|
200
190
|
namedExports = [...new Set(namedExports)];
|
|
201
|
-
} catch
|
|
191
|
+
} catch {
|
|
202
192
|
}
|
|
203
193
|
exportsBySubpath[cacheKey] = namedExports;
|
|
204
194
|
}
|
|
@@ -232,60 +222,60 @@ ${namedExportLines}
|
|
|
232
222
|
}
|
|
233
223
|
async function generateThemeData(themePath, outputDir, themeId) {
|
|
234
224
|
const { createJiti } = await import('jiti');
|
|
235
|
-
const jiti = createJiti(
|
|
225
|
+
const jiti = createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
|
|
236
226
|
let themeConfig = null;
|
|
237
227
|
let layoutConfig = null;
|
|
238
228
|
const pages = {};
|
|
239
229
|
for (const ext of [".ts", ".js"]) {
|
|
240
230
|
try {
|
|
241
|
-
const mod = await jiti.import(
|
|
231
|
+
const mod = await jiti.import(path7__default.default.join(themePath, `theme.config${ext}`));
|
|
242
232
|
themeConfig = mod.default || mod;
|
|
243
233
|
break;
|
|
244
|
-
} catch
|
|
234
|
+
} catch {
|
|
245
235
|
}
|
|
246
236
|
}
|
|
247
237
|
for (const ext of [".ts", ".js"]) {
|
|
248
238
|
try {
|
|
249
|
-
const mod = await jiti.import(
|
|
239
|
+
const mod = await jiti.import(path7__default.default.join(themePath, `theme.layout${ext}`));
|
|
250
240
|
layoutConfig = mod.default || mod;
|
|
251
241
|
break;
|
|
252
|
-
} catch
|
|
242
|
+
} catch {
|
|
253
243
|
}
|
|
254
244
|
}
|
|
255
|
-
const pagesDir =
|
|
245
|
+
const pagesDir = path7__default.default.join(themePath, "pages");
|
|
256
246
|
try {
|
|
257
247
|
const files = await fs6__default.default.readdir(pagesDir);
|
|
258
248
|
for (const file of files) {
|
|
259
249
|
if (!file.match(/\.(ts|js)$/)) continue;
|
|
260
250
|
const name = file.replace(/\.(ts|js)$/, "");
|
|
261
251
|
try {
|
|
262
|
-
const mod = await jiti.import(
|
|
252
|
+
const mod = await jiti.import(path7__default.default.join(pagesDir, file));
|
|
263
253
|
const config = mod.default || mod;
|
|
264
254
|
pages[name] = {
|
|
265
255
|
id: name,
|
|
266
256
|
name: config.title || name,
|
|
267
257
|
path: config.path || `/${name}`,
|
|
268
|
-
config:
|
|
258
|
+
config: { id: name, ...config },
|
|
269
259
|
sections: config.sections || [],
|
|
270
260
|
seo: config.seo
|
|
271
261
|
};
|
|
272
|
-
} catch
|
|
262
|
+
} catch {
|
|
273
263
|
}
|
|
274
264
|
}
|
|
275
|
-
} catch
|
|
265
|
+
} catch {
|
|
276
266
|
}
|
|
277
267
|
await fs6__default.default.writeFile(
|
|
278
|
-
|
|
268
|
+
path7__default.default.join(outputDir, "theme-data.json"),
|
|
279
269
|
JSON.stringify(
|
|
280
270
|
{
|
|
281
271
|
themeId,
|
|
282
272
|
theme: {
|
|
283
273
|
id: themeId,
|
|
284
|
-
name:
|
|
274
|
+
name: themeConfig?.name || themeId,
|
|
285
275
|
config: themeConfig,
|
|
286
276
|
layout: {
|
|
287
|
-
header:
|
|
288
|
-
footer:
|
|
277
|
+
header: layoutConfig?.headerSections || [],
|
|
278
|
+
footer: layoutConfig?.footerSections || []
|
|
289
279
|
},
|
|
290
280
|
pages: Object.keys(pages)
|
|
291
281
|
},
|
|
@@ -295,42 +285,40 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
295
285
|
2
|
|
296
286
|
)
|
|
297
287
|
);
|
|
298
|
-
exports.logger.info(
|
|
299
|
-
`Generated theme-data.json (${Object.keys(pages).length} pages)`
|
|
300
|
-
);
|
|
288
|
+
exports.logger.info(`Generated theme-data.json (${Object.keys(pages).length} pages)`);
|
|
301
289
|
}
|
|
302
290
|
async function contentHashEntry(outputDir) {
|
|
303
|
-
const entryPath =
|
|
304
|
-
const mapPath =
|
|
291
|
+
const entryPath = path7__default.default.join(outputDir, "bundle-entry.js");
|
|
292
|
+
const mapPath = path7__default.default.join(outputDir, "bundle-entry.js.map");
|
|
305
293
|
const oldFiles = await glob.glob("bundle-entry-*.js*", { cwd: outputDir });
|
|
306
294
|
for (const f of oldFiles) {
|
|
307
|
-
await fs6__default.default.unlink(
|
|
295
|
+
await fs6__default.default.unlink(path7__default.default.join(outputDir, f));
|
|
308
296
|
}
|
|
309
297
|
let entryContent;
|
|
310
298
|
try {
|
|
311
299
|
entryContent = await fs6__default.default.readFile(entryPath, "utf-8");
|
|
312
|
-
} catch
|
|
313
|
-
const indexPath =
|
|
300
|
+
} catch {
|
|
301
|
+
const indexPath = path7__default.default.join(outputDir, "index.js");
|
|
314
302
|
try {
|
|
315
303
|
entryContent = await fs6__default.default.readFile(indexPath, "utf-8");
|
|
316
|
-
} catch
|
|
304
|
+
} catch {
|
|
317
305
|
exports.logger.warning("No entry file found in output, skipping content hash");
|
|
318
306
|
return;
|
|
319
307
|
}
|
|
320
308
|
const hash2 = crypto__default.default.createHash("sha256").update(entryContent).digest("hex").slice(0, 8);
|
|
321
309
|
const hashedName2 = `bundle-entry-${hash2}.js`;
|
|
322
|
-
const indexMapPath =
|
|
310
|
+
const indexMapPath = path7__default.default.join(outputDir, "index.js.map");
|
|
323
311
|
const hashedMapName2 = `bundle-entry-${hash2}.js.map`;
|
|
324
312
|
entryContent = entryContent.replace(
|
|
325
313
|
/\/\/# sourceMappingURL=index\.js\.map/,
|
|
326
314
|
`//# sourceMappingURL=${hashedMapName2}`
|
|
327
315
|
);
|
|
328
|
-
await fs6__default.default.writeFile(
|
|
316
|
+
await fs6__default.default.writeFile(path7__default.default.join(outputDir, hashedName2), entryContent);
|
|
329
317
|
await fs6__default.default.unlink(indexPath);
|
|
330
318
|
try {
|
|
331
319
|
await fs6__default.default.access(indexMapPath);
|
|
332
|
-
await fs6__default.default.rename(indexMapPath,
|
|
333
|
-
} catch
|
|
320
|
+
await fs6__default.default.rename(indexMapPath, path7__default.default.join(outputDir, hashedMapName2));
|
|
321
|
+
} catch {
|
|
334
322
|
}
|
|
335
323
|
exports.logger.info(`Entry hashed: ${hashedName2}`);
|
|
336
324
|
return;
|
|
@@ -342,21 +330,43 @@ async function contentHashEntry(outputDir) {
|
|
|
342
330
|
/\/\/# sourceMappingURL=bundle-entry\.js\.map/,
|
|
343
331
|
`//# sourceMappingURL=${hashedMapName}`
|
|
344
332
|
);
|
|
345
|
-
await fs6__default.default.writeFile(
|
|
333
|
+
await fs6__default.default.writeFile(path7__default.default.join(outputDir, hashedName), entryContent);
|
|
346
334
|
await fs6__default.default.unlink(entryPath);
|
|
347
335
|
try {
|
|
348
336
|
await fs6__default.default.access(mapPath);
|
|
349
|
-
await fs6__default.default.rename(mapPath,
|
|
350
|
-
} catch
|
|
337
|
+
await fs6__default.default.rename(mapPath, path7__default.default.join(outputDir, hashedMapName));
|
|
338
|
+
} catch {
|
|
351
339
|
}
|
|
352
340
|
exports.logger.info(`Entry hashed: ${hashedName}`);
|
|
353
341
|
}
|
|
342
|
+
async function extractDataRequirements(themePath) {
|
|
343
|
+
const { createJiti } = await import('jiti');
|
|
344
|
+
const jiti = createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
|
|
345
|
+
const schemaFiles = await glob.glob("sections/**/*.schema.ts", { cwd: themePath });
|
|
346
|
+
const requirements = {};
|
|
347
|
+
for (const file of schemaFiles) {
|
|
348
|
+
try {
|
|
349
|
+
const mod = await jiti.import(path7__default.default.join(themePath, file));
|
|
350
|
+
const exports$1 = mod;
|
|
351
|
+
for (const value of Object.values(exports$1)) {
|
|
352
|
+
if (value && typeof value === "object" && typeof value.type === "string" && value.dataRequirements && typeof value.dataRequirements === "object") {
|
|
353
|
+
requirements[value.type] = value.dataRequirements;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
} catch (err) {
|
|
357
|
+
exports.logger.warning(
|
|
358
|
+
`Could not load schema ${file}: ${err instanceof Error ? err.message : String(err)}`
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return requirements;
|
|
363
|
+
}
|
|
354
364
|
async function generateManifest2(themeName, themePath, outputDir) {
|
|
355
365
|
let version = "1.0.0";
|
|
356
366
|
let themeId = themeName;
|
|
357
367
|
try {
|
|
358
368
|
const pkgContent = await fs6__default.default.readFile(
|
|
359
|
-
|
|
369
|
+
path7__default.default.join(themePath, "package.json"),
|
|
360
370
|
"utf-8"
|
|
361
371
|
);
|
|
362
372
|
const pkg = JSON.parse(pkgContent);
|
|
@@ -364,18 +374,19 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
364
374
|
if (pkg.name) {
|
|
365
375
|
themeId = pkg.name.replace(/^@onex-themes\//, "");
|
|
366
376
|
}
|
|
367
|
-
} catch
|
|
377
|
+
} catch {
|
|
368
378
|
}
|
|
369
379
|
const [sectionFiles, blockFiles, schemaFiles] = await Promise.all([
|
|
370
380
|
glob.glob("sections/**/index.ts", { cwd: themePath }),
|
|
371
381
|
glob.glob("blocks/**/index.ts", { cwd: themePath }),
|
|
372
382
|
glob.glob("**/*.schema.ts", { cwd: themePath })
|
|
373
383
|
]);
|
|
384
|
+
const dataRequirements = await extractDataRequirements(themePath);
|
|
374
385
|
let hasThemeConfig = false;
|
|
375
386
|
try {
|
|
376
|
-
await fs6__default.default.access(
|
|
387
|
+
await fs6__default.default.access(path7__default.default.join(themePath, "theme.config.ts"));
|
|
377
388
|
hasThemeConfig = true;
|
|
378
|
-
} catch
|
|
389
|
+
} catch {
|
|
379
390
|
}
|
|
380
391
|
const allFiles = await glob.glob("**/*", { cwd: outputDir, nodir: true });
|
|
381
392
|
const jsFiles = allFiles.filter((f) => f.endsWith(".js"));
|
|
@@ -410,24 +421,26 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
410
421
|
blocks: blockFiles,
|
|
411
422
|
schemas: schemaFiles,
|
|
412
423
|
hasThemeConfig
|
|
413
|
-
}
|
|
424
|
+
},
|
|
425
|
+
// Section data requirements for server-side prefetching (keyed by section type)
|
|
426
|
+
dataRequirements
|
|
414
427
|
};
|
|
415
428
|
await fs6__default.default.writeFile(
|
|
416
|
-
|
|
429
|
+
path7__default.default.join(outputDir, "manifest.json"),
|
|
417
430
|
JSON.stringify(manifest, null, 2)
|
|
418
431
|
);
|
|
419
432
|
}
|
|
420
433
|
async function compileStandaloneTheme(themePath, themeName) {
|
|
421
|
-
const outputDir =
|
|
422
|
-
const bundleEntry =
|
|
423
|
-
const indexEntry =
|
|
434
|
+
const outputDir = path7__default.default.join(themePath, "dist");
|
|
435
|
+
const bundleEntry = path7__default.default.join(themePath, "bundle-entry.ts");
|
|
436
|
+
const indexEntry = path7__default.default.join(themePath, "index.ts");
|
|
424
437
|
let entryPoint = indexEntry;
|
|
425
438
|
try {
|
|
426
439
|
await fs6__default.default.access(bundleEntry);
|
|
427
440
|
entryPoint = bundleEntry;
|
|
428
|
-
} catch
|
|
441
|
+
} catch {
|
|
429
442
|
}
|
|
430
|
-
const shimPath =
|
|
443
|
+
const shimPath = path7__default.default.join(outputDir, ".process-shim.js");
|
|
431
444
|
await fs6__default.default.mkdir(outputDir, { recursive: true });
|
|
432
445
|
await fs6__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
433
446
|
const buildOptions = {
|
|
@@ -476,7 +489,7 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
476
489
|
const result = await esbuild__namespace.build(buildOptions);
|
|
477
490
|
try {
|
|
478
491
|
await fs6__default.default.unlink(shimPath);
|
|
479
|
-
} catch
|
|
492
|
+
} catch {
|
|
480
493
|
}
|
|
481
494
|
await contentHashEntry(outputDir);
|
|
482
495
|
await generateManifest2(themeName, themePath, outputDir);
|
|
@@ -494,23 +507,23 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
494
507
|
} catch (error) {
|
|
495
508
|
try {
|
|
496
509
|
await fs6__default.default.unlink(shimPath);
|
|
497
|
-
} catch
|
|
510
|
+
} catch {
|
|
498
511
|
}
|
|
499
512
|
exports.logger.error(`esbuild compilation failed: ${error}`);
|
|
500
513
|
return false;
|
|
501
514
|
}
|
|
502
515
|
}
|
|
503
516
|
async function compileStandaloneThemeDev(themePath, themeName) {
|
|
504
|
-
const outputDir =
|
|
505
|
-
const bundleEntry =
|
|
506
|
-
const indexEntry =
|
|
517
|
+
const outputDir = path7__default.default.join(themePath, "dist");
|
|
518
|
+
const bundleEntry = path7__default.default.join(themePath, "bundle-entry.ts");
|
|
519
|
+
const indexEntry = path7__default.default.join(themePath, "index.ts");
|
|
507
520
|
let entryPoint = indexEntry;
|
|
508
521
|
try {
|
|
509
522
|
await fs6__default.default.access(bundleEntry);
|
|
510
523
|
entryPoint = bundleEntry;
|
|
511
|
-
} catch
|
|
524
|
+
} catch {
|
|
512
525
|
}
|
|
513
|
-
const shimPath =
|
|
526
|
+
const shimPath = path7__default.default.join(outputDir, ".process-shim.js");
|
|
514
527
|
await fs6__default.default.mkdir(outputDir, { recursive: true });
|
|
515
528
|
await fs6__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
516
529
|
const buildOptions = {
|
|
@@ -561,13 +574,13 @@ async function compileStandaloneThemeDev(themePath, themeName) {
|
|
|
561
574
|
return { context: context2, outputDir };
|
|
562
575
|
}
|
|
563
576
|
async function compilePreviewRuntime(themePath) {
|
|
564
|
-
const outputDir =
|
|
577
|
+
const outputDir = path7__default.default.join(themePath, "dist");
|
|
565
578
|
await fs6__default.default.mkdir(outputDir, { recursive: true });
|
|
566
|
-
const outputPath =
|
|
579
|
+
const outputPath = path7__default.default.join(outputDir, "preview-runtime.js");
|
|
567
580
|
const locations = [
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
581
|
+
path7__default.default.join(__dirname, "..", "preview", "preview-app.tsx"),
|
|
582
|
+
path7__default.default.join(__dirname, "preview", "preview-app.tsx"),
|
|
583
|
+
path7__default.default.join(__dirname, "..", "..", "src", "preview", "preview-app.tsx")
|
|
571
584
|
];
|
|
572
585
|
let previewEntryPath = null;
|
|
573
586
|
for (const loc of locations) {
|
|
@@ -575,7 +588,7 @@ async function compilePreviewRuntime(themePath) {
|
|
|
575
588
|
await fs6__default.default.access(loc);
|
|
576
589
|
previewEntryPath = loc;
|
|
577
590
|
break;
|
|
578
|
-
} catch
|
|
591
|
+
} catch {
|
|
579
592
|
}
|
|
580
593
|
}
|
|
581
594
|
if (!previewEntryPath) {
|
|
@@ -615,10 +628,13 @@ ${locations.join("\n")}`
|
|
|
615
628
|
"zlib"
|
|
616
629
|
];
|
|
617
630
|
for (const mod of nodeBuiltins) {
|
|
618
|
-
build2.onResolve(
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
631
|
+
build2.onResolve(
|
|
632
|
+
{ filter: new RegExp(`^${mod.replace("/", "\\/")}$`) },
|
|
633
|
+
() => ({
|
|
634
|
+
path: mod,
|
|
635
|
+
namespace: "node-stub"
|
|
636
|
+
})
|
|
637
|
+
);
|
|
622
638
|
}
|
|
623
639
|
build2.onLoad({ filter: /.*/, namespace: "node-stub" }, (args) => {
|
|
624
640
|
const stubs = {
|
|
@@ -632,8 +648,7 @@ ${locations.join("\n")}`
|
|
|
632
648
|
};
|
|
633
649
|
});
|
|
634
650
|
build2.onResolve({ filter: /^lucide-react/ }, async (args) => {
|
|
635
|
-
|
|
636
|
-
if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
|
|
651
|
+
if (args.pluginData?.skipStub) return void 0;
|
|
637
652
|
try {
|
|
638
653
|
const result = await build2.resolve(args.path, {
|
|
639
654
|
kind: args.kind,
|
|
@@ -643,7 +658,7 @@ ${locations.join("\n")}`
|
|
|
643
658
|
pluginData: { skipStub: true }
|
|
644
659
|
});
|
|
645
660
|
if (!result.errors.length) return result;
|
|
646
|
-
} catch
|
|
661
|
+
} catch {
|
|
647
662
|
}
|
|
648
663
|
return { path: args.path, namespace: "lucide-stub" };
|
|
649
664
|
});
|
|
@@ -665,8 +680,7 @@ export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true :
|
|
|
665
680
|
loader: "jsx"
|
|
666
681
|
}));
|
|
667
682
|
build2.onResolve({ filter: /^framer-motion/ }, async (args) => {
|
|
668
|
-
|
|
669
|
-
if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
|
|
683
|
+
if (args.pluginData?.skipStub) return void 0;
|
|
670
684
|
try {
|
|
671
685
|
const result = await build2.resolve(args.path, {
|
|
672
686
|
kind: args.kind,
|
|
@@ -676,7 +690,7 @@ export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true :
|
|
|
676
690
|
pluginData: { skipStub: true }
|
|
677
691
|
});
|
|
678
692
|
if (!result.errors.length) return result;
|
|
679
|
-
} catch
|
|
693
|
+
} catch {
|
|
680
694
|
}
|
|
681
695
|
return { path: args.path, namespace: "motion-stub" };
|
|
682
696
|
});
|
|
@@ -690,8 +704,59 @@ export default { motion, AnimatePresence };
|
|
|
690
704
|
`.trim(),
|
|
691
705
|
loader: "jsx"
|
|
692
706
|
}));
|
|
707
|
+
build2.onResolve({ filter: /^next\// }, async (args) => {
|
|
708
|
+
if (args.pluginData?.skipStub) return void 0;
|
|
709
|
+
try {
|
|
710
|
+
const result = await build2.resolve(args.path, {
|
|
711
|
+
kind: args.kind,
|
|
712
|
+
resolveDir: args.resolveDir,
|
|
713
|
+
importer: args.importer,
|
|
714
|
+
namespace: "file",
|
|
715
|
+
pluginData: { skipStub: true }
|
|
716
|
+
});
|
|
717
|
+
if (!result.errors.length) return result;
|
|
718
|
+
} catch {
|
|
719
|
+
}
|
|
720
|
+
return { path: args.path, namespace: "next-stub" };
|
|
721
|
+
});
|
|
722
|
+
build2.onLoad({ filter: /.*/, namespace: "next-stub" }, (args) => {
|
|
723
|
+
const stubs = {
|
|
724
|
+
"next/image": `
|
|
725
|
+
const Image = (props) => {
|
|
726
|
+
const { src, alt, width, height, fill, priority, ...rest } = props;
|
|
727
|
+
const imgSrc = typeof src === 'object' ? src.src : src;
|
|
728
|
+
return React.createElement('img', { src: imgSrc, alt, width: fill ? undefined : width, height: fill ? undefined : height, loading: priority ? 'eager' : 'lazy', ...rest });
|
|
729
|
+
};
|
|
730
|
+
import React from 'react';
|
|
731
|
+
export default Image;
|
|
732
|
+
`,
|
|
733
|
+
"next/link": `
|
|
734
|
+
const Link = ({ href, children, ...rest }) => React.createElement('a', { href, ...rest }, children);
|
|
735
|
+
import React from 'react';
|
|
736
|
+
export default Link;
|
|
737
|
+
`,
|
|
738
|
+
"next/navigation": `
|
|
739
|
+
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(){} }; }
|
|
740
|
+
export function usePathname() { return window.location.pathname; }
|
|
741
|
+
export function useSearchParams() { return new URLSearchParams(window.location.search); }
|
|
742
|
+
export function useParams() { return {}; }
|
|
743
|
+
export function redirect(url) { window.location.href = url; }
|
|
744
|
+
export function notFound() { throw new Error('Not Found'); }
|
|
745
|
+
`,
|
|
746
|
+
"next/headers": `
|
|
747
|
+
export function cookies() { return { get(){}, getAll(){ return []; }, set(){}, delete(){}, has(){ return false; } }; }
|
|
748
|
+
export function headers() { return new Headers(); }
|
|
749
|
+
`
|
|
750
|
+
};
|
|
751
|
+
return {
|
|
752
|
+
contents: stubs[args.path] || "export default {};",
|
|
753
|
+
loader: "jsx"
|
|
754
|
+
};
|
|
755
|
+
});
|
|
693
756
|
}
|
|
694
757
|
};
|
|
758
|
+
const shimPath = path7__default.default.join(outputDir, ".process-shim-preview.js");
|
|
759
|
+
await fs6__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
695
760
|
await esbuild__namespace.build({
|
|
696
761
|
entryPoints: [previewEntryPath],
|
|
697
762
|
bundle: true,
|
|
@@ -701,6 +766,7 @@ export default { motion, AnimatePresence };
|
|
|
701
766
|
// Bundle React + core INTO the output (NOT externalized)
|
|
702
767
|
external: [],
|
|
703
768
|
plugins: [serverStubPlugin],
|
|
769
|
+
inject: [shimPath],
|
|
704
770
|
minify: false,
|
|
705
771
|
sourcemap: true,
|
|
706
772
|
target: "es2020",
|
|
@@ -708,6 +774,12 @@ export default { motion, AnimatePresence };
|
|
|
708
774
|
jsxImportSource: "react",
|
|
709
775
|
define: {
|
|
710
776
|
"process.env.NODE_ENV": JSON.stringify("development"),
|
|
777
|
+
"process.env.NEXT_PUBLIC_API_URL": JSON.stringify(
|
|
778
|
+
process.env.NEXT_PUBLIC_API_URL || ""
|
|
779
|
+
),
|
|
780
|
+
"process.env.NEXT_PUBLIC_COMPANY_ID": JSON.stringify(
|
|
781
|
+
process.env.NEXT_PUBLIC_COMPANY_ID || ""
|
|
782
|
+
),
|
|
711
783
|
global: "globalThis"
|
|
712
784
|
},
|
|
713
785
|
loader: { ".tsx": "tsx", ".ts": "ts" },
|
|
@@ -718,13 +790,16 @@ export default { motion, AnimatePresence };
|
|
|
718
790
|
"ignored-bare-import": "silent"
|
|
719
791
|
}
|
|
720
792
|
});
|
|
793
|
+
try {
|
|
794
|
+
await fs6__default.default.unlink(shimPath);
|
|
795
|
+
} catch {
|
|
796
|
+
}
|
|
721
797
|
return outputPath;
|
|
722
798
|
}
|
|
723
|
-
var
|
|
799
|
+
var PROCESS_SHIM, reactGlobalPlugin;
|
|
724
800
|
var init_compile_theme = __esm({
|
|
725
801
|
"src/utils/compile-theme.ts"() {
|
|
726
802
|
init_logger();
|
|
727
|
-
import_meta = {};
|
|
728
803
|
PROCESS_SHIM = `
|
|
729
804
|
if (typeof process === "undefined") {
|
|
730
805
|
globalThis.process = {
|
|
@@ -905,18 +980,18 @@ async function renderTemplate(templatePath, data) {
|
|
|
905
980
|
return ejs__default.default.render(template, data);
|
|
906
981
|
}
|
|
907
982
|
async function writeFile(filePath, content) {
|
|
908
|
-
await fs__default.default.ensureDir(
|
|
983
|
+
await fs__default.default.ensureDir(path7__default.default.dirname(filePath));
|
|
909
984
|
await fs__default.default.writeFile(filePath, content, "utf-8");
|
|
910
985
|
}
|
|
911
986
|
function getTemplatesDir() {
|
|
912
987
|
const locations = [
|
|
913
|
-
|
|
988
|
+
path7__default.default.join(__dirname, "../../templates"),
|
|
914
989
|
// Development
|
|
915
|
-
|
|
990
|
+
path7__default.default.join(__dirname, "../templates"),
|
|
916
991
|
// Production (dist/)
|
|
917
|
-
|
|
992
|
+
path7__default.default.join(process.cwd(), "templates"),
|
|
918
993
|
// Fallback
|
|
919
|
-
|
|
994
|
+
path7__default.default.join(process.cwd(), "packages/cli/templates")
|
|
920
995
|
// Monorepo
|
|
921
996
|
];
|
|
922
997
|
for (const location of locations) {
|
|
@@ -928,7 +1003,7 @@ function getTemplatesDir() {
|
|
|
928
1003
|
}
|
|
929
1004
|
async function copyTemplate(templateName, targetDir, data) {
|
|
930
1005
|
const templatesDir = getTemplatesDir();
|
|
931
|
-
const templateDir =
|
|
1006
|
+
const templateDir = path7__default.default.join(templatesDir, templateName);
|
|
932
1007
|
if (!fs__default.default.existsSync(templateDir)) {
|
|
933
1008
|
throw new Error(
|
|
934
1009
|
`Template "${templateName}" not found at ${templateDir}. Available templates: ${fs__default.default.readdirSync(templatesDir).join(", ")}`
|
|
@@ -937,8 +1012,8 @@ async function copyTemplate(templateName, targetDir, data) {
|
|
|
937
1012
|
await fs__default.default.ensureDir(targetDir);
|
|
938
1013
|
const files = await fs__default.default.readdir(templateDir);
|
|
939
1014
|
for (const file of files) {
|
|
940
|
-
const templatePath =
|
|
941
|
-
const targetPath =
|
|
1015
|
+
const templatePath = path7__default.default.join(templateDir, file);
|
|
1016
|
+
const targetPath = path7__default.default.join(targetDir, file);
|
|
942
1017
|
const stat = await fs__default.default.stat(templatePath);
|
|
943
1018
|
if (stat.isDirectory()) {
|
|
944
1019
|
await copyTemplateDir(templatePath, targetPath, data);
|
|
@@ -955,8 +1030,8 @@ async function copyTemplateDir(templateDir, targetDir, data) {
|
|
|
955
1030
|
await fs__default.default.ensureDir(targetDir);
|
|
956
1031
|
const files = await fs__default.default.readdir(templateDir);
|
|
957
1032
|
for (const file of files) {
|
|
958
|
-
const templatePath =
|
|
959
|
-
const targetPath =
|
|
1033
|
+
const templatePath = path7__default.default.join(templateDir, file);
|
|
1034
|
+
const targetPath = path7__default.default.join(targetDir, file);
|
|
960
1035
|
const stat = await fs__default.default.stat(templatePath);
|
|
961
1036
|
if (stat.isDirectory()) {
|
|
962
1037
|
await copyTemplateDir(templatePath, targetPath, data);
|
|
@@ -971,32 +1046,32 @@ async function copyTemplateDir(templateDir, targetDir, data) {
|
|
|
971
1046
|
}
|
|
972
1047
|
function getProjectRoot() {
|
|
973
1048
|
let currentDir = process.cwd();
|
|
974
|
-
while (currentDir !==
|
|
975
|
-
const packageJsonPath =
|
|
1049
|
+
while (currentDir !== path7__default.default.parse(currentDir).root) {
|
|
1050
|
+
const packageJsonPath = path7__default.default.join(currentDir, "package.json");
|
|
976
1051
|
if (fs__default.default.existsSync(packageJsonPath)) {
|
|
977
1052
|
const packageJson = fs__default.default.readJsonSync(packageJsonPath);
|
|
978
|
-
if (packageJson.workspaces || fs__default.default.existsSync(
|
|
1053
|
+
if (packageJson.workspaces || fs__default.default.existsSync(path7__default.default.join(currentDir, "src/themes")) || fs__default.default.existsSync(path7__default.default.join(currentDir, "themes"))) {
|
|
979
1054
|
return currentDir;
|
|
980
1055
|
}
|
|
981
1056
|
}
|
|
982
|
-
currentDir =
|
|
1057
|
+
currentDir = path7__default.default.dirname(currentDir);
|
|
983
1058
|
}
|
|
984
1059
|
return process.cwd();
|
|
985
1060
|
}
|
|
986
1061
|
function getThemesDir() {
|
|
987
1062
|
const root = getProjectRoot();
|
|
988
|
-
if (fs__default.default.existsSync(
|
|
989
|
-
return
|
|
990
|
-
if (fs__default.default.existsSync(
|
|
991
|
-
return
|
|
992
|
-
return
|
|
1063
|
+
if (fs__default.default.existsSync(path7__default.default.join(root, "themes")))
|
|
1064
|
+
return path7__default.default.join(root, "themes");
|
|
1065
|
+
if (fs__default.default.existsSync(path7__default.default.join(root, "src/themes")))
|
|
1066
|
+
return path7__default.default.join(root, "src/themes");
|
|
1067
|
+
return path7__default.default.dirname(root);
|
|
993
1068
|
}
|
|
994
1069
|
function getFeaturesDir() {
|
|
995
|
-
return
|
|
1070
|
+
return path7__default.default.join(getProjectRoot(), "src/features");
|
|
996
1071
|
}
|
|
997
1072
|
function isOneXProject() {
|
|
998
1073
|
const root = getProjectRoot();
|
|
999
|
-
return fs__default.default.existsSync(
|
|
1074
|
+
return fs__default.default.existsSync(path7__default.default.join(root, "themes")) || fs__default.default.existsSync(path7__default.default.join(root, "src/themes")) || fs__default.default.existsSync(path7__default.default.join(root, "theme.config.ts")) || fs__default.default.existsSync(path7__default.default.join(root, "bundle-entry.ts"));
|
|
1000
1075
|
}
|
|
1001
1076
|
function ensureOneXProject() {
|
|
1002
1077
|
if (!isOneXProject()) {
|
|
@@ -1012,13 +1087,13 @@ function listThemes() {
|
|
|
1012
1087
|
return [];
|
|
1013
1088
|
}
|
|
1014
1089
|
return fs__default.default.readdirSync(themesDir).filter((name) => {
|
|
1015
|
-
const themePath =
|
|
1016
|
-
return fs__default.default.statSync(themePath).isDirectory() && (fs__default.default.existsSync(
|
|
1090
|
+
const themePath = path7__default.default.join(themesDir, name);
|
|
1091
|
+
return fs__default.default.statSync(themePath).isDirectory() && (fs__default.default.existsSync(path7__default.default.join(themePath, "theme.config.ts")) || fs__default.default.existsSync(path7__default.default.join(themePath, "bundle-entry.ts")) || fs__default.default.existsSync(path7__default.default.join(themePath, "manifest.ts")));
|
|
1017
1092
|
});
|
|
1018
1093
|
}
|
|
1019
1094
|
function themeExists(themeName) {
|
|
1020
|
-
const themePath =
|
|
1021
|
-
return fs__default.default.existsSync(themePath) && (fs__default.default.existsSync(
|
|
1095
|
+
const themePath = path7__default.default.join(getThemesDir(), themeName);
|
|
1096
|
+
return fs__default.default.existsSync(themePath) && (fs__default.default.existsSync(path7__default.default.join(themePath, "theme.config.ts")) || fs__default.default.existsSync(path7__default.default.join(themePath, "bundle-entry.ts")) || fs__default.default.existsSync(path7__default.default.join(themePath, "manifest.ts")));
|
|
1022
1097
|
}
|
|
1023
1098
|
function detectPackageManager() {
|
|
1024
1099
|
const userAgent = process.env.npm_config_user_agent || "";
|
|
@@ -1026,9 +1101,9 @@ function detectPackageManager() {
|
|
|
1026
1101
|
if (userAgent.includes("yarn")) return "yarn";
|
|
1027
1102
|
if (userAgent.includes("bun")) return "bun";
|
|
1028
1103
|
const cwd = process.cwd();
|
|
1029
|
-
if (fs__default.default.existsSync(
|
|
1030
|
-
if (fs__default.default.existsSync(
|
|
1031
|
-
if (fs__default.default.existsSync(
|
|
1104
|
+
if (fs__default.default.existsSync(path7__default.default.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
1105
|
+
if (fs__default.default.existsSync(path7__default.default.join(cwd, "yarn.lock"))) return "yarn";
|
|
1106
|
+
if (fs__default.default.existsSync(path7__default.default.join(cwd, "bun.lockb"))) return "bun";
|
|
1032
1107
|
return "npm";
|
|
1033
1108
|
}
|
|
1034
1109
|
async function installDependencies(projectPath, packageManager = "npm") {
|
|
@@ -1062,7 +1137,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
1062
1137
|
if (!validateThemeName(kebabName)) {
|
|
1063
1138
|
return "Invalid project name. Use lowercase letters, numbers, and hyphens only.";
|
|
1064
1139
|
}
|
|
1065
|
-
if (fs2__default.default.existsSync(
|
|
1140
|
+
if (fs2__default.default.existsSync(path7__default.default.join(process.cwd(), kebabName))) {
|
|
1066
1141
|
return `Directory "${kebabName}" already exists`;
|
|
1067
1142
|
}
|
|
1068
1143
|
return true;
|
|
@@ -1073,7 +1148,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
1073
1148
|
} else {
|
|
1074
1149
|
name = toKebabCase(projectName);
|
|
1075
1150
|
}
|
|
1076
|
-
const projectPath =
|
|
1151
|
+
const projectPath = path7__default.default.join(process.cwd(), name);
|
|
1077
1152
|
if (fs2__default.default.existsSync(projectPath)) {
|
|
1078
1153
|
exports.logger.error(`Directory "${name}" already exists.`);
|
|
1079
1154
|
process.exit(1);
|
|
@@ -1136,38 +1211,38 @@ async function initCommand(projectName, options = {}) {
|
|
|
1136
1211
|
try {
|
|
1137
1212
|
fs2__default.default.mkdirSync(projectPath, { recursive: true });
|
|
1138
1213
|
await copyTemplate(template, projectPath, data);
|
|
1139
|
-
const srcPath =
|
|
1214
|
+
const srcPath = path7__default.default.join(projectPath, "src");
|
|
1140
1215
|
fs2__default.default.mkdirSync(srcPath, { recursive: true });
|
|
1141
1216
|
const manifestContent = generateManifest(data);
|
|
1142
|
-
await writeFile(
|
|
1217
|
+
await writeFile(path7__default.default.join(srcPath, "manifest.ts"), manifestContent);
|
|
1143
1218
|
const configContent = generateThemeConfig(data);
|
|
1144
|
-
await writeFile(
|
|
1219
|
+
await writeFile(path7__default.default.join(srcPath, "config.ts"), configContent);
|
|
1145
1220
|
const layoutContent = generateThemeLayout(data);
|
|
1146
|
-
await writeFile(
|
|
1221
|
+
await writeFile(path7__default.default.join(srcPath, "layout.ts"), layoutContent);
|
|
1147
1222
|
const indexContent = generateThemeIndex(data);
|
|
1148
|
-
await writeFile(
|
|
1149
|
-
const sectionsPath =
|
|
1223
|
+
await writeFile(path7__default.default.join(srcPath, "index.ts"), indexContent);
|
|
1224
|
+
const sectionsPath = path7__default.default.join(srcPath, "sections");
|
|
1150
1225
|
fs2__default.default.mkdirSync(sectionsPath, { recursive: true });
|
|
1151
1226
|
await writeFile(
|
|
1152
|
-
|
|
1227
|
+
path7__default.default.join(sectionsPath, "README.md"),
|
|
1153
1228
|
`# ${displayName} Sections
|
|
1154
1229
|
|
|
1155
1230
|
Add your theme-specific sections here.
|
|
1156
1231
|
`
|
|
1157
1232
|
);
|
|
1158
|
-
const blocksPath =
|
|
1233
|
+
const blocksPath = path7__default.default.join(srcPath, "blocks");
|
|
1159
1234
|
fs2__default.default.mkdirSync(blocksPath, { recursive: true });
|
|
1160
1235
|
await writeFile(
|
|
1161
|
-
|
|
1236
|
+
path7__default.default.join(blocksPath, "README.md"),
|
|
1162
1237
|
`# ${displayName} Blocks
|
|
1163
1238
|
|
|
1164
1239
|
Add your theme-specific blocks here.
|
|
1165
1240
|
`
|
|
1166
1241
|
);
|
|
1167
|
-
const pagesPath =
|
|
1242
|
+
const pagesPath = path7__default.default.join(srcPath, "pages");
|
|
1168
1243
|
fs2__default.default.mkdirSync(pagesPath, { recursive: true });
|
|
1169
1244
|
const homePageContent = generateHomePage(data);
|
|
1170
|
-
await writeFile(
|
|
1245
|
+
await writeFile(path7__default.default.join(pagesPath, "home.ts"), homePageContent);
|
|
1171
1246
|
exports.logger.stopSpinner(true, "Project structure created!");
|
|
1172
1247
|
if (options.git) {
|
|
1173
1248
|
exports.logger.startSpinner("Initializing git repository...");
|
|
@@ -1179,7 +1254,7 @@ Add your theme-specific blocks here.
|
|
|
1179
1254
|
stdio: "ignore"
|
|
1180
1255
|
});
|
|
1181
1256
|
exports.logger.stopSpinner(true, "Git repository initialized!");
|
|
1182
|
-
} catch
|
|
1257
|
+
} catch {
|
|
1183
1258
|
exports.logger.stopSpinner(false, "Failed to initialize git");
|
|
1184
1259
|
}
|
|
1185
1260
|
}
|
|
@@ -1190,7 +1265,7 @@ Add your theme-specific blocks here.
|
|
|
1190
1265
|
try {
|
|
1191
1266
|
await installDependencies(projectPath, packageManager);
|
|
1192
1267
|
exports.logger.stopSpinner(true, "Dependencies installed!");
|
|
1193
|
-
} catch
|
|
1268
|
+
} catch {
|
|
1194
1269
|
exports.logger.stopSpinner(false, "Failed to install dependencies");
|
|
1195
1270
|
exports.logger.info(
|
|
1196
1271
|
"You can install dependencies manually by running: cd " + name + " && npm install"
|
|
@@ -1466,10 +1541,10 @@ async function createSectionCommand(name, options) {
|
|
|
1466
1541
|
ensureOneXProject();
|
|
1467
1542
|
if (!options.theme) {
|
|
1468
1543
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
1469
|
-
(f) => fs__default.default.existsSync(
|
|
1544
|
+
(f) => fs__default.default.existsSync(path7__default.default.join(process.cwd(), f))
|
|
1470
1545
|
);
|
|
1471
1546
|
if (isStandaloneTheme) {
|
|
1472
|
-
options.theme =
|
|
1547
|
+
options.theme = path7__default.default.basename(process.cwd());
|
|
1473
1548
|
}
|
|
1474
1549
|
}
|
|
1475
1550
|
const sectionName = toKebabCase(name);
|
|
@@ -1532,35 +1607,35 @@ async function createSectionCommand(name, options) {
|
|
|
1532
1607
|
};
|
|
1533
1608
|
exports.logger.startSpinner("Creating section files...");
|
|
1534
1609
|
try {
|
|
1535
|
-
const themePath =
|
|
1536
|
-
const sectionPath =
|
|
1610
|
+
const themePath = path7__default.default.join(getThemesDir(), themeName);
|
|
1611
|
+
const sectionPath = path7__default.default.join(themePath, "sections", sectionName);
|
|
1537
1612
|
const schemaContent = generateSectionSchema(data);
|
|
1538
1613
|
await writeFile(
|
|
1539
|
-
|
|
1614
|
+
path7__default.default.join(sectionPath, `${sectionName}.schema.ts`),
|
|
1540
1615
|
schemaContent
|
|
1541
1616
|
);
|
|
1542
1617
|
if (createTemplate) {
|
|
1543
1618
|
const templateContent = generateSectionTemplate(data);
|
|
1544
1619
|
await writeFile(
|
|
1545
|
-
|
|
1620
|
+
path7__default.default.join(sectionPath, `${sectionName}-default.tsx`),
|
|
1546
1621
|
templateContent
|
|
1547
1622
|
);
|
|
1548
1623
|
}
|
|
1549
1624
|
const indexContent = generateSectionIndex(data, createTemplate);
|
|
1550
|
-
await writeFile(
|
|
1625
|
+
await writeFile(path7__default.default.join(sectionPath, "index.ts"), indexContent);
|
|
1551
1626
|
exports.logger.stopSpinner(true, "Section files created successfully!");
|
|
1552
1627
|
exports.logger.newLine();
|
|
1553
1628
|
exports.logger.section("Next steps:");
|
|
1554
1629
|
exports.logger.log(
|
|
1555
|
-
` 1. Edit schema: ${
|
|
1630
|
+
` 1. Edit schema: ${path7__default.default.relative(process.cwd(), path7__default.default.join(sectionPath, `${sectionName}.schema.ts`))}`
|
|
1556
1631
|
);
|
|
1557
1632
|
if (createTemplate) {
|
|
1558
1633
|
exports.logger.log(
|
|
1559
|
-
` 2. Edit template: ${
|
|
1634
|
+
` 2. Edit template: ${path7__default.default.relative(process.cwd(), path7__default.default.join(sectionPath, `${sectionName}-default.tsx`))}`
|
|
1560
1635
|
);
|
|
1561
1636
|
}
|
|
1562
1637
|
exports.logger.log(
|
|
1563
|
-
` 3. Add to theme manifest: ${
|
|
1638
|
+
` 3. Add to theme manifest: ${path7__default.default.relative(process.cwd(), path7__default.default.join(themePath, "manifest.ts"))}`
|
|
1564
1639
|
);
|
|
1565
1640
|
exports.logger.newLine();
|
|
1566
1641
|
exports.logger.success("Section created successfully!");
|
|
@@ -1708,10 +1783,10 @@ async function createBlockCommand(name, options) {
|
|
|
1708
1783
|
ensureOneXProject();
|
|
1709
1784
|
if (!options.theme) {
|
|
1710
1785
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
1711
|
-
(f) => fs__default.default.existsSync(
|
|
1786
|
+
(f) => fs__default.default.existsSync(path7__default.default.join(process.cwd(), f))
|
|
1712
1787
|
);
|
|
1713
1788
|
if (isStandaloneTheme) {
|
|
1714
|
-
options.theme =
|
|
1789
|
+
options.theme = path7__default.default.basename(process.cwd());
|
|
1715
1790
|
}
|
|
1716
1791
|
}
|
|
1717
1792
|
const blockName = toKebabCase(name);
|
|
@@ -1786,24 +1861,24 @@ async function createBlockCommand(name, options) {
|
|
|
1786
1861
|
};
|
|
1787
1862
|
exports.logger.startSpinner("Creating block files...");
|
|
1788
1863
|
try {
|
|
1789
|
-
const blockPath = scope === "shared" ?
|
|
1864
|
+
const blockPath = scope === "shared" ? path7__default.default.join(getFeaturesDir(), "blocks", blockName) : path7__default.default.join(getThemesDir(), themeName, "blocks", blockName);
|
|
1790
1865
|
const schemaContent = generateBlockSchema(data);
|
|
1791
1866
|
await writeFile(
|
|
1792
|
-
|
|
1867
|
+
path7__default.default.join(blockPath, `${blockName}.schema.ts`),
|
|
1793
1868
|
schemaContent
|
|
1794
1869
|
);
|
|
1795
1870
|
const componentContent = generateBlockComponent(data);
|
|
1796
|
-
await writeFile(
|
|
1871
|
+
await writeFile(path7__default.default.join(blockPath, `${blockName}.tsx`), componentContent);
|
|
1797
1872
|
const indexContent = generateBlockIndex(data);
|
|
1798
|
-
await writeFile(
|
|
1873
|
+
await writeFile(path7__default.default.join(blockPath, "index.ts"), indexContent);
|
|
1799
1874
|
exports.logger.stopSpinner(true, "Block files created successfully!");
|
|
1800
1875
|
exports.logger.newLine();
|
|
1801
1876
|
exports.logger.section("Next steps:");
|
|
1802
1877
|
exports.logger.log(
|
|
1803
|
-
` 1. Edit schema: ${
|
|
1878
|
+
` 1. Edit schema: ${path7__default.default.relative(process.cwd(), path7__default.default.join(blockPath, `${blockName}.schema.ts`))}`
|
|
1804
1879
|
);
|
|
1805
1880
|
exports.logger.log(
|
|
1806
|
-
` 2. Edit component: ${
|
|
1881
|
+
` 2. Edit component: ${path7__default.default.relative(process.cwd(), path7__default.default.join(blockPath, `${blockName}.tsx`))}`
|
|
1807
1882
|
);
|
|
1808
1883
|
exports.logger.log(
|
|
1809
1884
|
` 3. Register in block registry: src/lib/registry/block-registry.ts`
|
|
@@ -1981,31 +2056,31 @@ async function createComponentCommand(name, options) {
|
|
|
1981
2056
|
};
|
|
1982
2057
|
exports.logger.startSpinner("Creating component files...");
|
|
1983
2058
|
try {
|
|
1984
|
-
const componentPath =
|
|
2059
|
+
const componentPath = path7__default.default.join(
|
|
1985
2060
|
getFeaturesDir(),
|
|
1986
2061
|
"components",
|
|
1987
2062
|
componentName
|
|
1988
2063
|
);
|
|
1989
2064
|
const schemaContent = generateComponentSchema(data);
|
|
1990
2065
|
await writeFile(
|
|
1991
|
-
|
|
2066
|
+
path7__default.default.join(componentPath, `${componentName}.schema.ts`),
|
|
1992
2067
|
schemaContent
|
|
1993
2068
|
);
|
|
1994
2069
|
const componentContent = generateComponent(data);
|
|
1995
2070
|
await writeFile(
|
|
1996
|
-
|
|
2071
|
+
path7__default.default.join(componentPath, `${componentName}.tsx`),
|
|
1997
2072
|
componentContent
|
|
1998
2073
|
);
|
|
1999
2074
|
const indexContent = generateComponentIndex(data);
|
|
2000
|
-
await writeFile(
|
|
2075
|
+
await writeFile(path7__default.default.join(componentPath, "index.ts"), indexContent);
|
|
2001
2076
|
exports.logger.stopSpinner(true, "Component files created successfully!");
|
|
2002
2077
|
exports.logger.newLine();
|
|
2003
2078
|
exports.logger.section("Next steps:");
|
|
2004
2079
|
exports.logger.log(
|
|
2005
|
-
` 1. Edit schema: ${
|
|
2080
|
+
` 1. Edit schema: ${path7__default.default.relative(process.cwd(), path7__default.default.join(componentPath, `${componentName}.schema.ts`))}`
|
|
2006
2081
|
);
|
|
2007
2082
|
exports.logger.log(
|
|
2008
|
-
` 2. Edit component: ${
|
|
2083
|
+
` 2. Edit component: ${path7__default.default.relative(process.cwd(), path7__default.default.join(componentPath, `${componentName}.tsx`))}`
|
|
2009
2084
|
);
|
|
2010
2085
|
exports.logger.log(
|
|
2011
2086
|
` 3. Register in component registry: src/lib/registry/component-registry.ts`
|
|
@@ -2162,13 +2237,13 @@ async function listSections(themeFilter) {
|
|
|
2162
2237
|
return;
|
|
2163
2238
|
}
|
|
2164
2239
|
for (const theme of themes) {
|
|
2165
|
-
const sectionsDir =
|
|
2240
|
+
const sectionsDir = path7__default.default.join(getThemesDir(), theme, "sections");
|
|
2166
2241
|
if (!fs__default.default.existsSync(sectionsDir)) {
|
|
2167
2242
|
continue;
|
|
2168
2243
|
}
|
|
2169
2244
|
const sections = fs__default.default.readdirSync(sectionsDir).filter((name) => {
|
|
2170
|
-
const sectionPath =
|
|
2171
|
-
return fs__default.default.statSync(sectionPath).isDirectory() && fs__default.default.existsSync(
|
|
2245
|
+
const sectionPath = path7__default.default.join(sectionsDir, name);
|
|
2246
|
+
return fs__default.default.statSync(sectionPath).isDirectory() && fs__default.default.existsSync(path7__default.default.join(sectionPath, "index.ts"));
|
|
2172
2247
|
});
|
|
2173
2248
|
if (sections.length > 0) {
|
|
2174
2249
|
exports.logger.log(chalk4__default.default.cyan(`
|
|
@@ -2182,11 +2257,11 @@ async function listSections(themeFilter) {
|
|
|
2182
2257
|
}
|
|
2183
2258
|
async function listBlocks(themeFilter) {
|
|
2184
2259
|
exports.logger.section("\u{1F9F1} Blocks");
|
|
2185
|
-
const sharedBlocksDir =
|
|
2260
|
+
const sharedBlocksDir = path7__default.default.join(getFeaturesDir(), "blocks");
|
|
2186
2261
|
if (fs__default.default.existsSync(sharedBlocksDir)) {
|
|
2187
2262
|
const sharedBlocks = fs__default.default.readdirSync(sharedBlocksDir).filter((name) => {
|
|
2188
|
-
const blockPath =
|
|
2189
|
-
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(
|
|
2263
|
+
const blockPath = path7__default.default.join(sharedBlocksDir, name);
|
|
2264
|
+
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(path7__default.default.join(blockPath, "index.ts"));
|
|
2190
2265
|
});
|
|
2191
2266
|
if (sharedBlocks.length > 0) {
|
|
2192
2267
|
exports.logger.log(chalk4__default.default.cyan("\n Shared:"));
|
|
@@ -2197,13 +2272,13 @@ async function listBlocks(themeFilter) {
|
|
|
2197
2272
|
}
|
|
2198
2273
|
const themes = themeFilter ? [themeFilter] : listThemes();
|
|
2199
2274
|
for (const theme of themes) {
|
|
2200
|
-
const blocksDir =
|
|
2275
|
+
const blocksDir = path7__default.default.join(getThemesDir(), theme, "blocks");
|
|
2201
2276
|
if (!fs__default.default.existsSync(blocksDir)) {
|
|
2202
2277
|
continue;
|
|
2203
2278
|
}
|
|
2204
2279
|
const blocks = fs__default.default.readdirSync(blocksDir).filter((name) => {
|
|
2205
|
-
const blockPath =
|
|
2206
|
-
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(
|
|
2280
|
+
const blockPath = path7__default.default.join(blocksDir, name);
|
|
2281
|
+
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(path7__default.default.join(blockPath, "index.ts"));
|
|
2207
2282
|
});
|
|
2208
2283
|
if (blocks.length > 0) {
|
|
2209
2284
|
exports.logger.log(chalk4__default.default.cyan(`
|
|
@@ -2217,14 +2292,14 @@ async function listBlocks(themeFilter) {
|
|
|
2217
2292
|
}
|
|
2218
2293
|
async function listComponents() {
|
|
2219
2294
|
exports.logger.section("\u2699\uFE0F Components");
|
|
2220
|
-
const componentsDir =
|
|
2295
|
+
const componentsDir = path7__default.default.join(getFeaturesDir(), "components");
|
|
2221
2296
|
if (!fs__default.default.existsSync(componentsDir)) {
|
|
2222
2297
|
exports.logger.warning("No components directory found");
|
|
2223
2298
|
return;
|
|
2224
2299
|
}
|
|
2225
2300
|
const components = fs__default.default.readdirSync(componentsDir).filter((name) => {
|
|
2226
|
-
const componentPath =
|
|
2227
|
-
return fs__default.default.statSync(componentPath).isDirectory() && fs__default.default.existsSync(
|
|
2301
|
+
const componentPath = path7__default.default.join(componentsDir, name);
|
|
2302
|
+
return fs__default.default.statSync(componentPath).isDirectory() && fs__default.default.existsSync(path7__default.default.join(componentPath, "index.ts"));
|
|
2228
2303
|
});
|
|
2229
2304
|
if (components.length === 0) {
|
|
2230
2305
|
exports.logger.warning("No components found");
|
|
@@ -2245,11 +2320,11 @@ async function listThemesInfo() {
|
|
|
2245
2320
|
}
|
|
2246
2321
|
exports.logger.log("");
|
|
2247
2322
|
for (const theme of themes) {
|
|
2248
|
-
const themeDir =
|
|
2323
|
+
const themeDir = path7__default.default.join(getThemesDir(), theme);
|
|
2249
2324
|
const candidates = ["theme.config.ts", "bundle-entry.ts", "manifest.ts"];
|
|
2250
2325
|
let manifestContent = "";
|
|
2251
2326
|
for (const candidate of candidates) {
|
|
2252
|
-
const candidatePath =
|
|
2327
|
+
const candidatePath = path7__default.default.join(themeDir, candidate);
|
|
2253
2328
|
if (fs__default.default.existsSync(candidatePath)) {
|
|
2254
2329
|
manifestContent = fs__default.default.readFileSync(candidatePath, "utf-8");
|
|
2255
2330
|
break;
|
|
@@ -2272,21 +2347,20 @@ async function listThemesInfo() {
|
|
|
2272
2347
|
// src/commands/build.ts
|
|
2273
2348
|
init_logger();
|
|
2274
2349
|
async function buildCommand(options) {
|
|
2275
|
-
var _a;
|
|
2276
2350
|
exports.logger.header("Build Theme");
|
|
2277
2351
|
let themePath;
|
|
2278
2352
|
let themeName;
|
|
2279
2353
|
if (options.theme) {
|
|
2280
2354
|
themeName = options.theme;
|
|
2281
2355
|
try {
|
|
2282
|
-
const workspaceThemePath =
|
|
2356
|
+
const workspaceThemePath = path7__default.default.join(getThemesDir(), themeName);
|
|
2283
2357
|
if (fs__default.default.existsSync(workspaceThemePath)) {
|
|
2284
2358
|
themePath = workspaceThemePath;
|
|
2285
2359
|
} else {
|
|
2286
|
-
themePath =
|
|
2360
|
+
themePath = path7__default.default.join(process.cwd(), themeName);
|
|
2287
2361
|
}
|
|
2288
|
-
} catch
|
|
2289
|
-
themePath =
|
|
2362
|
+
} catch {
|
|
2363
|
+
themePath = path7__default.default.join(process.cwd(), themeName);
|
|
2290
2364
|
}
|
|
2291
2365
|
if (!fs__default.default.existsSync(themePath)) {
|
|
2292
2366
|
exports.logger.error(`Theme "${themeName}" not found.`);
|
|
@@ -2297,10 +2371,10 @@ async function buildCommand(options) {
|
|
|
2297
2371
|
"theme.config.ts",
|
|
2298
2372
|
"bundle-entry.ts",
|
|
2299
2373
|
"manifest.ts"
|
|
2300
|
-
].some((f) => fs__default.default.existsSync(
|
|
2374
|
+
].some((f) => fs__default.default.existsSync(path7__default.default.join(process.cwd(), f)));
|
|
2301
2375
|
if (isThemeDir) {
|
|
2302
2376
|
themePath = process.cwd();
|
|
2303
|
-
themeName =
|
|
2377
|
+
themeName = path7__default.default.basename(themePath);
|
|
2304
2378
|
exports.logger.info(`Building current theme: ${themeName}`);
|
|
2305
2379
|
} else {
|
|
2306
2380
|
exports.logger.error(
|
|
@@ -2309,7 +2383,7 @@ async function buildCommand(options) {
|
|
|
2309
2383
|
process.exit(1);
|
|
2310
2384
|
}
|
|
2311
2385
|
}
|
|
2312
|
-
const packageJsonPath =
|
|
2386
|
+
const packageJsonPath = path7__default.default.join(themePath, "package.json");
|
|
2313
2387
|
const hasPkgJson = fs__default.default.existsSync(packageJsonPath);
|
|
2314
2388
|
if (!hasPkgJson) {
|
|
2315
2389
|
exports.logger.warning(
|
|
@@ -2342,7 +2416,7 @@ async function buildCommand(options) {
|
|
|
2342
2416
|
}
|
|
2343
2417
|
exports.logger.stopSpinner(true, "Lint passed");
|
|
2344
2418
|
const pkgJson = fs__default.default.readJsonSync(packageJsonPath);
|
|
2345
|
-
const buildScript =
|
|
2419
|
+
const buildScript = pkgJson.scripts?.build || "";
|
|
2346
2420
|
const isRecursive = buildScript.includes("onex build") || buildScript.includes("onex-cli build");
|
|
2347
2421
|
exports.logger.startSpinner(
|
|
2348
2422
|
options.watch ? "Building (watch mode)..." : "Building..."
|
|
@@ -2365,9 +2439,9 @@ async function buildCommand(options) {
|
|
|
2365
2439
|
exports.logger.success("\u2713 Theme built successfully!");
|
|
2366
2440
|
exports.logger.newLine();
|
|
2367
2441
|
exports.logger.info(`Theme: ${themeName}`);
|
|
2368
|
-
const distPath =
|
|
2442
|
+
const distPath = path7__default.default.join(themePath, "dist");
|
|
2369
2443
|
if (fs__default.default.existsSync(distPath)) {
|
|
2370
|
-
exports.logger.log(`Output: ${
|
|
2444
|
+
exports.logger.log(`Output: ${path7__default.default.relative(process.cwd(), distPath)}`);
|
|
2371
2445
|
const files = fs__default.default.readdirSync(distPath);
|
|
2372
2446
|
exports.logger.log(`Files: ${files.length}`);
|
|
2373
2447
|
}
|
|
@@ -2437,11 +2511,11 @@ function getBucketName(env) {
|
|
|
2437
2511
|
return environment === "production" ? "onex-themes-prod" : "onex-themes-staging";
|
|
2438
2512
|
}
|
|
2439
2513
|
async function findCompiledThemeDir(themeId, version) {
|
|
2440
|
-
const searchPaths = [
|
|
2514
|
+
const searchPaths = [path7__default.default.resolve(process.cwd(), "dist")];
|
|
2441
2515
|
for (const dir of searchPaths) {
|
|
2442
2516
|
if (await fs__default.default.pathExists(dir)) {
|
|
2443
|
-
const hasManifest = await fs__default.default.pathExists(
|
|
2444
|
-
const hasThemeEntry = await fs__default.default.pathExists(
|
|
2517
|
+
const hasManifest = await fs__default.default.pathExists(path7__default.default.join(dir, "manifest.json"));
|
|
2518
|
+
const hasThemeEntry = await fs__default.default.pathExists(path7__default.default.join(dir, "bundle-entry.js")) || await fs__default.default.pathExists(path7__default.default.join(dir, "theme.config.js")) || await fs__default.default.pathExists(path7__default.default.join(dir, "index.js"));
|
|
2445
2519
|
if (hasManifest || hasThemeEntry) {
|
|
2446
2520
|
return dir;
|
|
2447
2521
|
}
|
|
@@ -2450,8 +2524,7 @@ async function findCompiledThemeDir(themeId, version) {
|
|
|
2450
2524
|
return null;
|
|
2451
2525
|
}
|
|
2452
2526
|
async function readManifest() {
|
|
2453
|
-
|
|
2454
|
-
const manifestTsPath = path__default.default.resolve(process.cwd(), "manifest.ts");
|
|
2527
|
+
const manifestTsPath = path7__default.default.resolve(process.cwd(), "manifest.ts");
|
|
2455
2528
|
if (await fs__default.default.pathExists(manifestTsPath)) {
|
|
2456
2529
|
try {
|
|
2457
2530
|
const module = await import(manifestTsPath);
|
|
@@ -2460,11 +2533,11 @@ async function readManifest() {
|
|
|
2460
2533
|
exports.logger.warning("Failed to import manifest.ts, trying package.json");
|
|
2461
2534
|
}
|
|
2462
2535
|
}
|
|
2463
|
-
const packageJsonPath =
|
|
2536
|
+
const packageJsonPath = path7__default.default.resolve(process.cwd(), "package.json");
|
|
2464
2537
|
if (await fs__default.default.pathExists(packageJsonPath)) {
|
|
2465
2538
|
const pkg = await fs__default.default.readJson(packageJsonPath);
|
|
2466
2539
|
return {
|
|
2467
|
-
themeId:
|
|
2540
|
+
themeId: pkg.name?.replace("@onex-themes/", "") || "unknown",
|
|
2468
2541
|
version: pkg.version || "1.0.0"
|
|
2469
2542
|
};
|
|
2470
2543
|
}
|
|
@@ -2494,13 +2567,13 @@ async function findSourceDir(themeId, explicitDir) {
|
|
|
2494
2567
|
}
|
|
2495
2568
|
const searchPaths = [
|
|
2496
2569
|
process.cwd(),
|
|
2497
|
-
|
|
2498
|
-
|
|
2570
|
+
path7__default.default.resolve(process.cwd(), `../../themes/${themeId}`),
|
|
2571
|
+
path7__default.default.resolve(process.cwd(), `../themes/${themeId}`)
|
|
2499
2572
|
];
|
|
2500
2573
|
const markers = ["theme.config.ts", "bundle-entry.ts"];
|
|
2501
2574
|
for (const dir of searchPaths) {
|
|
2502
2575
|
for (const marker of markers) {
|
|
2503
|
-
if (await fs__default.default.pathExists(
|
|
2576
|
+
if (await fs__default.default.pathExists(path7__default.default.join(dir, marker))) {
|
|
2504
2577
|
return dir;
|
|
2505
2578
|
}
|
|
2506
2579
|
}
|
|
@@ -2552,7 +2625,7 @@ async function uploadCommand(options) {
|
|
|
2552
2625
|
spinner.succeed(`Found compiled theme at: ${compiledDir}`);
|
|
2553
2626
|
spinner.start("Creating bundle.zip...");
|
|
2554
2627
|
const tmpDir = os__default.default.tmpdir();
|
|
2555
|
-
const bundleZipPath =
|
|
2628
|
+
const bundleZipPath = path7__default.default.join(tmpDir, `${themeId}-${version}-bundle.zip`);
|
|
2556
2629
|
await createZipFromDir(compiledDir, bundleZipPath);
|
|
2557
2630
|
const bundleZipBuffer = await fs__default.default.readFile(bundleZipPath);
|
|
2558
2631
|
const bundleSizeMB = (bundleZipBuffer.length / 1024 / 1024).toFixed(2);
|
|
@@ -2606,7 +2679,7 @@ async function uploadCommand(options) {
|
|
|
2606
2679
|
if (sourceDir) {
|
|
2607
2680
|
spinner.succeed(`Found source at: ${sourceDir}`);
|
|
2608
2681
|
spinner.start("Creating source.zip...");
|
|
2609
|
-
const sourceZipPath =
|
|
2682
|
+
const sourceZipPath = path7__default.default.join(
|
|
2610
2683
|
tmpDir,
|
|
2611
2684
|
`${themeId}-${version}-source.zip`
|
|
2612
2685
|
);
|
|
@@ -2708,39 +2781,15 @@ function getBucketName2(env) {
|
|
|
2708
2781
|
}
|
|
2709
2782
|
async function streamToString(stream) {
|
|
2710
2783
|
const chunks = [];
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
const chunk = temp.value;
|
|
2714
|
-
chunks.push(Buffer.from(chunk));
|
|
2715
|
-
}
|
|
2716
|
-
} catch (temp) {
|
|
2717
|
-
error = [temp];
|
|
2718
|
-
} finally {
|
|
2719
|
-
try {
|
|
2720
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
2721
|
-
} finally {
|
|
2722
|
-
if (error)
|
|
2723
|
-
throw error[0];
|
|
2724
|
-
}
|
|
2784
|
+
for await (const chunk of stream) {
|
|
2785
|
+
chunks.push(Buffer.from(chunk));
|
|
2725
2786
|
}
|
|
2726
2787
|
return Buffer.concat(chunks).toString("utf-8");
|
|
2727
2788
|
}
|
|
2728
2789
|
async function streamToBuffer(stream) {
|
|
2729
2790
|
const chunks = [];
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
const chunk = temp.value;
|
|
2733
|
-
chunks.push(Buffer.from(chunk));
|
|
2734
|
-
}
|
|
2735
|
-
} catch (temp) {
|
|
2736
|
-
error = [temp];
|
|
2737
|
-
} finally {
|
|
2738
|
-
try {
|
|
2739
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
2740
|
-
} finally {
|
|
2741
|
-
if (error)
|
|
2742
|
-
throw error[0];
|
|
2743
|
-
}
|
|
2791
|
+
for await (const chunk of stream) {
|
|
2792
|
+
chunks.push(Buffer.from(chunk));
|
|
2744
2793
|
}
|
|
2745
2794
|
return Buffer.concat(chunks);
|
|
2746
2795
|
}
|
|
@@ -2762,11 +2811,10 @@ async function resolveLatestVersion(s3Client, bucket, themeId) {
|
|
|
2762
2811
|
}
|
|
2763
2812
|
}
|
|
2764
2813
|
async function createCompatibilityFiles(outputDir, manifest) {
|
|
2765
|
-
|
|
2766
|
-
const entryFile = ((_a = manifest.output) == null ? void 0 : _a.entry) || "bundle-entry.js";
|
|
2814
|
+
const entryFile = manifest.output?.entry || "bundle-entry.js";
|
|
2767
2815
|
if (entryFile !== "bundle-entry.js" && entryFile.startsWith("bundle-entry-")) {
|
|
2768
|
-
const hashedPath =
|
|
2769
|
-
const stablePath =
|
|
2816
|
+
const hashedPath = path7__default.default.join(outputDir, entryFile);
|
|
2817
|
+
const stablePath = path7__default.default.join(outputDir, "bundle-entry.js");
|
|
2770
2818
|
if (await fs__default.default.pathExists(hashedPath)) {
|
|
2771
2819
|
await fs__default.default.copy(hashedPath, stablePath);
|
|
2772
2820
|
const mapPath = hashedPath + ".map";
|
|
@@ -2775,13 +2823,13 @@ async function createCompatibilityFiles(outputDir, manifest) {
|
|
|
2775
2823
|
}
|
|
2776
2824
|
}
|
|
2777
2825
|
}
|
|
2778
|
-
const sectionsRegistryPath =
|
|
2826
|
+
const sectionsRegistryPath = path7__default.default.join(outputDir, "sections-registry.js");
|
|
2779
2827
|
const content = `// Re-export all sections from bundle-entry
|
|
2780
2828
|
// This file exists to maintain compatibility with the import path
|
|
2781
2829
|
export * from './bundle-entry.js';
|
|
2782
2830
|
`;
|
|
2783
2831
|
await fs__default.default.writeFile(sectionsRegistryPath, content, "utf-8");
|
|
2784
|
-
const pkgJsonPath =
|
|
2832
|
+
const pkgJsonPath = path7__default.default.join(outputDir, "package.json");
|
|
2785
2833
|
await fs__default.default.writeFile(pkgJsonPath, '{\n "type": "module"\n}\n', "utf-8");
|
|
2786
2834
|
}
|
|
2787
2835
|
function showDownloadFailureHelp(themeId, bucket) {
|
|
@@ -2864,7 +2912,7 @@ async function downloadCommand(options) {
|
|
|
2864
2912
|
zip.extractAllTo(outputDir, true);
|
|
2865
2913
|
const entries = zip.getEntries().filter((e) => !e.isDirectory);
|
|
2866
2914
|
spinner.succeed(`Extracted ${entries.length} files to ${outputDir}`);
|
|
2867
|
-
const manifestPath =
|
|
2915
|
+
const manifestPath = path7__default.default.join(outputDir, "manifest.json");
|
|
2868
2916
|
const manifest = await fs__default.default.readJson(manifestPath);
|
|
2869
2917
|
await createCompatibilityFiles(outputDir, manifest);
|
|
2870
2918
|
console.log();
|
|
@@ -2934,39 +2982,15 @@ function getBucketName3(env) {
|
|
|
2934
2982
|
}
|
|
2935
2983
|
async function streamToString2(stream) {
|
|
2936
2984
|
const chunks = [];
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
const chunk = temp.value;
|
|
2940
|
-
chunks.push(Buffer.from(chunk));
|
|
2941
|
-
}
|
|
2942
|
-
} catch (temp) {
|
|
2943
|
-
error = [temp];
|
|
2944
|
-
} finally {
|
|
2945
|
-
try {
|
|
2946
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
2947
|
-
} finally {
|
|
2948
|
-
if (error)
|
|
2949
|
-
throw error[0];
|
|
2950
|
-
}
|
|
2985
|
+
for await (const chunk of stream) {
|
|
2986
|
+
chunks.push(Buffer.from(chunk));
|
|
2951
2987
|
}
|
|
2952
2988
|
return Buffer.concat(chunks).toString("utf-8");
|
|
2953
2989
|
}
|
|
2954
2990
|
async function streamToBuffer2(stream) {
|
|
2955
2991
|
const chunks = [];
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
const chunk = temp.value;
|
|
2959
|
-
chunks.push(Buffer.from(chunk));
|
|
2960
|
-
}
|
|
2961
|
-
} catch (temp) {
|
|
2962
|
-
error = [temp];
|
|
2963
|
-
} finally {
|
|
2964
|
-
try {
|
|
2965
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
2966
|
-
} finally {
|
|
2967
|
-
if (error)
|
|
2968
|
-
throw error[0];
|
|
2969
|
-
}
|
|
2992
|
+
for await (const chunk of stream) {
|
|
2993
|
+
chunks.push(Buffer.from(chunk));
|
|
2970
2994
|
}
|
|
2971
2995
|
return Buffer.concat(chunks);
|
|
2972
2996
|
}
|
|
@@ -3022,7 +3046,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3022
3046
|
const oldPrefix = `${oldName}-`;
|
|
3023
3047
|
const newPrefix = `${newName}-`;
|
|
3024
3048
|
const newDisplayName = newName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3025
|
-
const pkgPath =
|
|
3049
|
+
const pkgPath = path7__default.default.join(themeDir, "package.json");
|
|
3026
3050
|
if (await fs__default.default.pathExists(pkgPath)) {
|
|
3027
3051
|
const pkg = await fs__default.default.readJson(pkgPath);
|
|
3028
3052
|
pkg.name = `@onex-themes/${newName}`;
|
|
@@ -3035,7 +3059,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3035
3059
|
pkg.version = "1.0.0";
|
|
3036
3060
|
await fs__default.default.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3037
3061
|
}
|
|
3038
|
-
const configPath =
|
|
3062
|
+
const configPath = path7__default.default.join(themeDir, "theme.config.ts");
|
|
3039
3063
|
if (await fs__default.default.pathExists(configPath)) {
|
|
3040
3064
|
let content = await fs__default.default.readFile(configPath, "utf-8");
|
|
3041
3065
|
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
@@ -3045,7 +3069,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3045
3069
|
);
|
|
3046
3070
|
await fs__default.default.writeFile(configPath, content);
|
|
3047
3071
|
}
|
|
3048
|
-
const layoutPath =
|
|
3072
|
+
const layoutPath = path7__default.default.join(themeDir, "theme.layout.ts");
|
|
3049
3073
|
if (await fs__default.default.pathExists(layoutPath)) {
|
|
3050
3074
|
let content = await fs__default.default.readFile(layoutPath, "utf-8");
|
|
3051
3075
|
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
@@ -3058,7 +3082,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3058
3082
|
const oldDisplayName = oldName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3059
3083
|
const tsFiles = await glob.glob("**/*.ts", { cwd: themeDir, nodir: true });
|
|
3060
3084
|
for (const file of tsFiles) {
|
|
3061
|
-
const filePath =
|
|
3085
|
+
const filePath = path7__default.default.join(themeDir, file);
|
|
3062
3086
|
let content = await fs__default.default.readFile(filePath, "utf-8");
|
|
3063
3087
|
const original = content;
|
|
3064
3088
|
content = content.replace(
|
|
@@ -3087,7 +3111,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3087
3111
|
const spinner = ora__default.default("Initializing clone...").start();
|
|
3088
3112
|
try {
|
|
3089
3113
|
const bucket = options.bucket || getBucketName3(options.environment);
|
|
3090
|
-
const outputDir = options.output ||
|
|
3114
|
+
const outputDir = options.output || path7__default.default.resolve(process.cwd(), newName);
|
|
3091
3115
|
const s3Client = getS3Client3();
|
|
3092
3116
|
if (await fs__default.default.pathExists(outputDir)) {
|
|
3093
3117
|
spinner.fail(chalk4__default.default.red(`Directory already exists: ${outputDir}`));
|
|
@@ -3142,9 +3166,22 @@ async function cloneCommand(themeName, options) {
|
|
|
3142
3166
|
spinner.succeed(
|
|
3143
3167
|
`Renamed theme: ${chalk4__default.default.gray(themeName)} \u2192 ${chalk4__default.default.cyan(newName)}`
|
|
3144
3168
|
);
|
|
3169
|
+
const envExamplePath = path7__default.default.join(outputDir, ".env.example");
|
|
3170
|
+
if (!await fs__default.default.pathExists(envExamplePath)) {
|
|
3171
|
+
await fs__default.default.writeFile(
|
|
3172
|
+
envExamplePath,
|
|
3173
|
+
[
|
|
3174
|
+
"# API Configuration (enables real data in preview)",
|
|
3175
|
+
"# Get your Company ID from the OneX dashboard",
|
|
3176
|
+
"NEXT_PUBLIC_API_URL=https://api-dev.onexeos.com",
|
|
3177
|
+
"NEXT_PUBLIC_COMPANY_ID=",
|
|
3178
|
+
""
|
|
3179
|
+
].join("\n")
|
|
3180
|
+
);
|
|
3181
|
+
}
|
|
3145
3182
|
if (options.install !== false) {
|
|
3146
3183
|
const hasPkgJson = await fs__default.default.pathExists(
|
|
3147
|
-
|
|
3184
|
+
path7__default.default.join(outputDir, "package.json")
|
|
3148
3185
|
);
|
|
3149
3186
|
if (hasPkgJson) {
|
|
3150
3187
|
spinner.start("Installing dependencies...");
|
|
@@ -3171,7 +3208,8 @@ async function cloneCommand(themeName, options) {
|
|
|
3171
3208
|
console.log(chalk4__default.default.cyan(" Files: ") + chalk4__default.default.white(entries.length));
|
|
3172
3209
|
console.log();
|
|
3173
3210
|
console.log(chalk4__default.default.cyan("Next steps:"));
|
|
3174
|
-
console.log(chalk4__default.default.gray(` cd ${
|
|
3211
|
+
console.log(chalk4__default.default.gray(` cd ${path7__default.default.relative(process.cwd(), outputDir)}`));
|
|
3212
|
+
console.log(chalk4__default.default.gray(" cp .env.example .env # then add your Company ID"));
|
|
3175
3213
|
if (options.install === false) {
|
|
3176
3214
|
console.log(chalk4__default.default.gray(" pnpm install"));
|
|
3177
3215
|
}
|