@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.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import chalk4 from 'chalk';
|
|
2
2
|
import ora from 'ora';
|
|
3
3
|
import * as esbuild from 'esbuild';
|
|
4
|
-
import
|
|
4
|
+
import path7 from 'path';
|
|
5
5
|
import fs6 from 'fs/promises';
|
|
6
6
|
import crypto from 'crypto';
|
|
7
7
|
import { glob } from 'glob';
|
|
@@ -17,22 +17,6 @@ import AdmZip from 'adm-zip';
|
|
|
17
17
|
|
|
18
18
|
var __defProp = Object.defineProperty;
|
|
19
19
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
20
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
21
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
22
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
23
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
|
|
24
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
25
|
-
var __spreadValues = (a, b) => {
|
|
26
|
-
for (var prop in b || (b = {}))
|
|
27
|
-
if (__hasOwnProp.call(b, prop))
|
|
28
|
-
__defNormalProp(a, prop, b[prop]);
|
|
29
|
-
if (__getOwnPropSymbols)
|
|
30
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
31
|
-
if (__propIsEnum.call(b, prop))
|
|
32
|
-
__defNormalProp(a, prop, b[prop]);
|
|
33
|
-
}
|
|
34
|
-
return a;
|
|
35
|
-
};
|
|
36
20
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
37
21
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
38
22
|
}) : x)(function(x) {
|
|
@@ -46,7 +30,6 @@ var __export = (target, all) => {
|
|
|
46
30
|
for (var name in all)
|
|
47
31
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
48
32
|
};
|
|
49
|
-
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);
|
|
50
33
|
var Logger, logger;
|
|
51
34
|
var init_logger = __esm({
|
|
52
35
|
"src/utils/logger.ts"() {
|
|
@@ -115,12 +98,12 @@ __export(compile_theme_exports, {
|
|
|
115
98
|
async function resolveNodeModulesFile(startDir, relativePath) {
|
|
116
99
|
let dir = startDir;
|
|
117
100
|
while (true) {
|
|
118
|
-
const candidate =
|
|
101
|
+
const candidate = path7.join(dir, "node_modules", relativePath);
|
|
119
102
|
try {
|
|
120
103
|
await fs6.access(candidate);
|
|
121
104
|
return candidate;
|
|
122
|
-
} catch
|
|
123
|
-
const parent =
|
|
105
|
+
} catch {
|
|
106
|
+
const parent = path7.dirname(dir);
|
|
124
107
|
if (parent === dir) break;
|
|
125
108
|
dir = parent;
|
|
126
109
|
}
|
|
@@ -138,7 +121,7 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
138
121
|
}));
|
|
139
122
|
build2.onLoad({ filter: /.*/, namespace: "core-global" }, async (args) => {
|
|
140
123
|
const match = args.path.match(/^@onexapis\/core(\/(.+))?$/);
|
|
141
|
-
const subpath =
|
|
124
|
+
const subpath = match?.[2] || "";
|
|
142
125
|
const moduleAccess = subpath ? `['${subpath}']` : "";
|
|
143
126
|
let namedExports = [];
|
|
144
127
|
const cacheKey = subpath || "__root__";
|
|
@@ -146,10 +129,16 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
146
129
|
namedExports = exportsBySubpath[cacheKey];
|
|
147
130
|
} else {
|
|
148
131
|
const distFileName = subpath ? `${subpath}.mjs` : "index.mjs";
|
|
149
|
-
|
|
132
|
+
let distPath = await resolveNodeModulesFile(
|
|
150
133
|
themePath,
|
|
151
|
-
|
|
134
|
+
path7.join("@onexapis", "core", "dist", distFileName)
|
|
152
135
|
);
|
|
136
|
+
if (!distPath) {
|
|
137
|
+
distPath = await resolveNodeModulesFile(
|
|
138
|
+
__dirname,
|
|
139
|
+
path7.join("@onexapis", "core", "dist", distFileName)
|
|
140
|
+
);
|
|
141
|
+
}
|
|
153
142
|
try {
|
|
154
143
|
if (!distPath) throw new Error("not found");
|
|
155
144
|
const distContent = await fs6.readFile(distPath, "utf-8");
|
|
@@ -162,7 +151,7 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
162
151
|
namedExports.push(...names);
|
|
163
152
|
}
|
|
164
153
|
namedExports = [...new Set(namedExports)];
|
|
165
|
-
} catch
|
|
154
|
+
} catch {
|
|
166
155
|
}
|
|
167
156
|
exportsBySubpath[cacheKey] = namedExports;
|
|
168
157
|
}
|
|
@@ -196,60 +185,60 @@ ${namedExportLines}
|
|
|
196
185
|
}
|
|
197
186
|
async function generateThemeData(themePath, outputDir, themeId) {
|
|
198
187
|
const { createJiti } = await import('jiti');
|
|
199
|
-
const jiti = createJiti(
|
|
188
|
+
const jiti = createJiti(import.meta.url);
|
|
200
189
|
let themeConfig = null;
|
|
201
190
|
let layoutConfig = null;
|
|
202
191
|
const pages = {};
|
|
203
192
|
for (const ext of [".ts", ".js"]) {
|
|
204
193
|
try {
|
|
205
|
-
const mod = await jiti.import(
|
|
194
|
+
const mod = await jiti.import(path7.join(themePath, `theme.config${ext}`));
|
|
206
195
|
themeConfig = mod.default || mod;
|
|
207
196
|
break;
|
|
208
|
-
} catch
|
|
197
|
+
} catch {
|
|
209
198
|
}
|
|
210
199
|
}
|
|
211
200
|
for (const ext of [".ts", ".js"]) {
|
|
212
201
|
try {
|
|
213
|
-
const mod = await jiti.import(
|
|
202
|
+
const mod = await jiti.import(path7.join(themePath, `theme.layout${ext}`));
|
|
214
203
|
layoutConfig = mod.default || mod;
|
|
215
204
|
break;
|
|
216
|
-
} catch
|
|
205
|
+
} catch {
|
|
217
206
|
}
|
|
218
207
|
}
|
|
219
|
-
const pagesDir =
|
|
208
|
+
const pagesDir = path7.join(themePath, "pages");
|
|
220
209
|
try {
|
|
221
210
|
const files = await fs6.readdir(pagesDir);
|
|
222
211
|
for (const file of files) {
|
|
223
212
|
if (!file.match(/\.(ts|js)$/)) continue;
|
|
224
213
|
const name = file.replace(/\.(ts|js)$/, "");
|
|
225
214
|
try {
|
|
226
|
-
const mod = await jiti.import(
|
|
215
|
+
const mod = await jiti.import(path7.join(pagesDir, file));
|
|
227
216
|
const config = mod.default || mod;
|
|
228
217
|
pages[name] = {
|
|
229
218
|
id: name,
|
|
230
219
|
name: config.title || name,
|
|
231
220
|
path: config.path || `/${name}`,
|
|
232
|
-
config:
|
|
221
|
+
config: { id: name, ...config },
|
|
233
222
|
sections: config.sections || [],
|
|
234
223
|
seo: config.seo
|
|
235
224
|
};
|
|
236
|
-
} catch
|
|
225
|
+
} catch {
|
|
237
226
|
}
|
|
238
227
|
}
|
|
239
|
-
} catch
|
|
228
|
+
} catch {
|
|
240
229
|
}
|
|
241
230
|
await fs6.writeFile(
|
|
242
|
-
|
|
231
|
+
path7.join(outputDir, "theme-data.json"),
|
|
243
232
|
JSON.stringify(
|
|
244
233
|
{
|
|
245
234
|
themeId,
|
|
246
235
|
theme: {
|
|
247
236
|
id: themeId,
|
|
248
|
-
name:
|
|
237
|
+
name: themeConfig?.name || themeId,
|
|
249
238
|
config: themeConfig,
|
|
250
239
|
layout: {
|
|
251
|
-
header:
|
|
252
|
-
footer:
|
|
240
|
+
header: layoutConfig?.headerSections || [],
|
|
241
|
+
footer: layoutConfig?.footerSections || []
|
|
253
242
|
},
|
|
254
243
|
pages: Object.keys(pages)
|
|
255
244
|
},
|
|
@@ -259,42 +248,40 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
259
248
|
2
|
|
260
249
|
)
|
|
261
250
|
);
|
|
262
|
-
logger.info(
|
|
263
|
-
`Generated theme-data.json (${Object.keys(pages).length} pages)`
|
|
264
|
-
);
|
|
251
|
+
logger.info(`Generated theme-data.json (${Object.keys(pages).length} pages)`);
|
|
265
252
|
}
|
|
266
253
|
async function contentHashEntry(outputDir) {
|
|
267
|
-
const entryPath =
|
|
268
|
-
const mapPath =
|
|
254
|
+
const entryPath = path7.join(outputDir, "bundle-entry.js");
|
|
255
|
+
const mapPath = path7.join(outputDir, "bundle-entry.js.map");
|
|
269
256
|
const oldFiles = await glob("bundle-entry-*.js*", { cwd: outputDir });
|
|
270
257
|
for (const f of oldFiles) {
|
|
271
|
-
await fs6.unlink(
|
|
258
|
+
await fs6.unlink(path7.join(outputDir, f));
|
|
272
259
|
}
|
|
273
260
|
let entryContent;
|
|
274
261
|
try {
|
|
275
262
|
entryContent = await fs6.readFile(entryPath, "utf-8");
|
|
276
|
-
} catch
|
|
277
|
-
const indexPath =
|
|
263
|
+
} catch {
|
|
264
|
+
const indexPath = path7.join(outputDir, "index.js");
|
|
278
265
|
try {
|
|
279
266
|
entryContent = await fs6.readFile(indexPath, "utf-8");
|
|
280
|
-
} catch
|
|
267
|
+
} catch {
|
|
281
268
|
logger.warning("No entry file found in output, skipping content hash");
|
|
282
269
|
return;
|
|
283
270
|
}
|
|
284
271
|
const hash2 = crypto.createHash("sha256").update(entryContent).digest("hex").slice(0, 8);
|
|
285
272
|
const hashedName2 = `bundle-entry-${hash2}.js`;
|
|
286
|
-
const indexMapPath =
|
|
273
|
+
const indexMapPath = path7.join(outputDir, "index.js.map");
|
|
287
274
|
const hashedMapName2 = `bundle-entry-${hash2}.js.map`;
|
|
288
275
|
entryContent = entryContent.replace(
|
|
289
276
|
/\/\/# sourceMappingURL=index\.js\.map/,
|
|
290
277
|
`//# sourceMappingURL=${hashedMapName2}`
|
|
291
278
|
);
|
|
292
|
-
await fs6.writeFile(
|
|
279
|
+
await fs6.writeFile(path7.join(outputDir, hashedName2), entryContent);
|
|
293
280
|
await fs6.unlink(indexPath);
|
|
294
281
|
try {
|
|
295
282
|
await fs6.access(indexMapPath);
|
|
296
|
-
await fs6.rename(indexMapPath,
|
|
297
|
-
} catch
|
|
283
|
+
await fs6.rename(indexMapPath, path7.join(outputDir, hashedMapName2));
|
|
284
|
+
} catch {
|
|
298
285
|
}
|
|
299
286
|
logger.info(`Entry hashed: ${hashedName2}`);
|
|
300
287
|
return;
|
|
@@ -306,21 +293,43 @@ async function contentHashEntry(outputDir) {
|
|
|
306
293
|
/\/\/# sourceMappingURL=bundle-entry\.js\.map/,
|
|
307
294
|
`//# sourceMappingURL=${hashedMapName}`
|
|
308
295
|
);
|
|
309
|
-
await fs6.writeFile(
|
|
296
|
+
await fs6.writeFile(path7.join(outputDir, hashedName), entryContent);
|
|
310
297
|
await fs6.unlink(entryPath);
|
|
311
298
|
try {
|
|
312
299
|
await fs6.access(mapPath);
|
|
313
|
-
await fs6.rename(mapPath,
|
|
314
|
-
} catch
|
|
300
|
+
await fs6.rename(mapPath, path7.join(outputDir, hashedMapName));
|
|
301
|
+
} catch {
|
|
315
302
|
}
|
|
316
303
|
logger.info(`Entry hashed: ${hashedName}`);
|
|
317
304
|
}
|
|
305
|
+
async function extractDataRequirements(themePath) {
|
|
306
|
+
const { createJiti } = await import('jiti');
|
|
307
|
+
const jiti = createJiti(import.meta.url);
|
|
308
|
+
const schemaFiles = await glob("sections/**/*.schema.ts", { cwd: themePath });
|
|
309
|
+
const requirements = {};
|
|
310
|
+
for (const file of schemaFiles) {
|
|
311
|
+
try {
|
|
312
|
+
const mod = await jiti.import(path7.join(themePath, file));
|
|
313
|
+
const exports$1 = mod;
|
|
314
|
+
for (const value of Object.values(exports$1)) {
|
|
315
|
+
if (value && typeof value === "object" && typeof value.type === "string" && value.dataRequirements && typeof value.dataRequirements === "object") {
|
|
316
|
+
requirements[value.type] = value.dataRequirements;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
} catch (err) {
|
|
320
|
+
logger.warning(
|
|
321
|
+
`Could not load schema ${file}: ${err instanceof Error ? err.message : String(err)}`
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return requirements;
|
|
326
|
+
}
|
|
318
327
|
async function generateManifest2(themeName, themePath, outputDir) {
|
|
319
328
|
let version = "1.0.0";
|
|
320
329
|
let themeId = themeName;
|
|
321
330
|
try {
|
|
322
331
|
const pkgContent = await fs6.readFile(
|
|
323
|
-
|
|
332
|
+
path7.join(themePath, "package.json"),
|
|
324
333
|
"utf-8"
|
|
325
334
|
);
|
|
326
335
|
const pkg = JSON.parse(pkgContent);
|
|
@@ -328,18 +337,19 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
328
337
|
if (pkg.name) {
|
|
329
338
|
themeId = pkg.name.replace(/^@onex-themes\//, "");
|
|
330
339
|
}
|
|
331
|
-
} catch
|
|
340
|
+
} catch {
|
|
332
341
|
}
|
|
333
342
|
const [sectionFiles, blockFiles, schemaFiles] = await Promise.all([
|
|
334
343
|
glob("sections/**/index.ts", { cwd: themePath }),
|
|
335
344
|
glob("blocks/**/index.ts", { cwd: themePath }),
|
|
336
345
|
glob("**/*.schema.ts", { cwd: themePath })
|
|
337
346
|
]);
|
|
347
|
+
const dataRequirements = await extractDataRequirements(themePath);
|
|
338
348
|
let hasThemeConfig = false;
|
|
339
349
|
try {
|
|
340
|
-
await fs6.access(
|
|
350
|
+
await fs6.access(path7.join(themePath, "theme.config.ts"));
|
|
341
351
|
hasThemeConfig = true;
|
|
342
|
-
} catch
|
|
352
|
+
} catch {
|
|
343
353
|
}
|
|
344
354
|
const allFiles = await glob("**/*", { cwd: outputDir, nodir: true });
|
|
345
355
|
const jsFiles = allFiles.filter((f) => f.endsWith(".js"));
|
|
@@ -374,24 +384,26 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
374
384
|
blocks: blockFiles,
|
|
375
385
|
schemas: schemaFiles,
|
|
376
386
|
hasThemeConfig
|
|
377
|
-
}
|
|
387
|
+
},
|
|
388
|
+
// Section data requirements for server-side prefetching (keyed by section type)
|
|
389
|
+
dataRequirements
|
|
378
390
|
};
|
|
379
391
|
await fs6.writeFile(
|
|
380
|
-
|
|
392
|
+
path7.join(outputDir, "manifest.json"),
|
|
381
393
|
JSON.stringify(manifest, null, 2)
|
|
382
394
|
);
|
|
383
395
|
}
|
|
384
396
|
async function compileStandaloneTheme(themePath, themeName) {
|
|
385
|
-
const outputDir =
|
|
386
|
-
const bundleEntry =
|
|
387
|
-
const indexEntry =
|
|
397
|
+
const outputDir = path7.join(themePath, "dist");
|
|
398
|
+
const bundleEntry = path7.join(themePath, "bundle-entry.ts");
|
|
399
|
+
const indexEntry = path7.join(themePath, "index.ts");
|
|
388
400
|
let entryPoint = indexEntry;
|
|
389
401
|
try {
|
|
390
402
|
await fs6.access(bundleEntry);
|
|
391
403
|
entryPoint = bundleEntry;
|
|
392
|
-
} catch
|
|
404
|
+
} catch {
|
|
393
405
|
}
|
|
394
|
-
const shimPath =
|
|
406
|
+
const shimPath = path7.join(outputDir, ".process-shim.js");
|
|
395
407
|
await fs6.mkdir(outputDir, { recursive: true });
|
|
396
408
|
await fs6.writeFile(shimPath, PROCESS_SHIM);
|
|
397
409
|
const buildOptions = {
|
|
@@ -440,7 +452,7 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
440
452
|
const result = await esbuild.build(buildOptions);
|
|
441
453
|
try {
|
|
442
454
|
await fs6.unlink(shimPath);
|
|
443
|
-
} catch
|
|
455
|
+
} catch {
|
|
444
456
|
}
|
|
445
457
|
await contentHashEntry(outputDir);
|
|
446
458
|
await generateManifest2(themeName, themePath, outputDir);
|
|
@@ -458,23 +470,23 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
458
470
|
} catch (error) {
|
|
459
471
|
try {
|
|
460
472
|
await fs6.unlink(shimPath);
|
|
461
|
-
} catch
|
|
473
|
+
} catch {
|
|
462
474
|
}
|
|
463
475
|
logger.error(`esbuild compilation failed: ${error}`);
|
|
464
476
|
return false;
|
|
465
477
|
}
|
|
466
478
|
}
|
|
467
479
|
async function compileStandaloneThemeDev(themePath, themeName) {
|
|
468
|
-
const outputDir =
|
|
469
|
-
const bundleEntry =
|
|
470
|
-
const indexEntry =
|
|
480
|
+
const outputDir = path7.join(themePath, "dist");
|
|
481
|
+
const bundleEntry = path7.join(themePath, "bundle-entry.ts");
|
|
482
|
+
const indexEntry = path7.join(themePath, "index.ts");
|
|
471
483
|
let entryPoint = indexEntry;
|
|
472
484
|
try {
|
|
473
485
|
await fs6.access(bundleEntry);
|
|
474
486
|
entryPoint = bundleEntry;
|
|
475
|
-
} catch
|
|
487
|
+
} catch {
|
|
476
488
|
}
|
|
477
|
-
const shimPath =
|
|
489
|
+
const shimPath = path7.join(outputDir, ".process-shim.js");
|
|
478
490
|
await fs6.mkdir(outputDir, { recursive: true });
|
|
479
491
|
await fs6.writeFile(shimPath, PROCESS_SHIM);
|
|
480
492
|
const buildOptions = {
|
|
@@ -525,13 +537,13 @@ async function compileStandaloneThemeDev(themePath, themeName) {
|
|
|
525
537
|
return { context: context2, outputDir };
|
|
526
538
|
}
|
|
527
539
|
async function compilePreviewRuntime(themePath) {
|
|
528
|
-
const outputDir =
|
|
540
|
+
const outputDir = path7.join(themePath, "dist");
|
|
529
541
|
await fs6.mkdir(outputDir, { recursive: true });
|
|
530
|
-
const outputPath =
|
|
542
|
+
const outputPath = path7.join(outputDir, "preview-runtime.js");
|
|
531
543
|
const locations = [
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
544
|
+
path7.join(__dirname, "..", "preview", "preview-app.tsx"),
|
|
545
|
+
path7.join(__dirname, "preview", "preview-app.tsx"),
|
|
546
|
+
path7.join(__dirname, "..", "..", "src", "preview", "preview-app.tsx")
|
|
535
547
|
];
|
|
536
548
|
let previewEntryPath = null;
|
|
537
549
|
for (const loc of locations) {
|
|
@@ -539,7 +551,7 @@ async function compilePreviewRuntime(themePath) {
|
|
|
539
551
|
await fs6.access(loc);
|
|
540
552
|
previewEntryPath = loc;
|
|
541
553
|
break;
|
|
542
|
-
} catch
|
|
554
|
+
} catch {
|
|
543
555
|
}
|
|
544
556
|
}
|
|
545
557
|
if (!previewEntryPath) {
|
|
@@ -579,10 +591,13 @@ ${locations.join("\n")}`
|
|
|
579
591
|
"zlib"
|
|
580
592
|
];
|
|
581
593
|
for (const mod of nodeBuiltins) {
|
|
582
|
-
build2.onResolve(
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
594
|
+
build2.onResolve(
|
|
595
|
+
{ filter: new RegExp(`^${mod.replace("/", "\\/")}$`) },
|
|
596
|
+
() => ({
|
|
597
|
+
path: mod,
|
|
598
|
+
namespace: "node-stub"
|
|
599
|
+
})
|
|
600
|
+
);
|
|
586
601
|
}
|
|
587
602
|
build2.onLoad({ filter: /.*/, namespace: "node-stub" }, (args) => {
|
|
588
603
|
const stubs = {
|
|
@@ -596,8 +611,7 @@ ${locations.join("\n")}`
|
|
|
596
611
|
};
|
|
597
612
|
});
|
|
598
613
|
build2.onResolve({ filter: /^lucide-react/ }, async (args) => {
|
|
599
|
-
|
|
600
|
-
if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
|
|
614
|
+
if (args.pluginData?.skipStub) return void 0;
|
|
601
615
|
try {
|
|
602
616
|
const result = await build2.resolve(args.path, {
|
|
603
617
|
kind: args.kind,
|
|
@@ -607,7 +621,7 @@ ${locations.join("\n")}`
|
|
|
607
621
|
pluginData: { skipStub: true }
|
|
608
622
|
});
|
|
609
623
|
if (!result.errors.length) return result;
|
|
610
|
-
} catch
|
|
624
|
+
} catch {
|
|
611
625
|
}
|
|
612
626
|
return { path: args.path, namespace: "lucide-stub" };
|
|
613
627
|
});
|
|
@@ -629,8 +643,7 @@ export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true :
|
|
|
629
643
|
loader: "jsx"
|
|
630
644
|
}));
|
|
631
645
|
build2.onResolve({ filter: /^framer-motion/ }, async (args) => {
|
|
632
|
-
|
|
633
|
-
if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
|
|
646
|
+
if (args.pluginData?.skipStub) return void 0;
|
|
634
647
|
try {
|
|
635
648
|
const result = await build2.resolve(args.path, {
|
|
636
649
|
kind: args.kind,
|
|
@@ -640,7 +653,7 @@ export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true :
|
|
|
640
653
|
pluginData: { skipStub: true }
|
|
641
654
|
});
|
|
642
655
|
if (!result.errors.length) return result;
|
|
643
|
-
} catch
|
|
656
|
+
} catch {
|
|
644
657
|
}
|
|
645
658
|
return { path: args.path, namespace: "motion-stub" };
|
|
646
659
|
});
|
|
@@ -654,8 +667,59 @@ export default { motion, AnimatePresence };
|
|
|
654
667
|
`.trim(),
|
|
655
668
|
loader: "jsx"
|
|
656
669
|
}));
|
|
670
|
+
build2.onResolve({ filter: /^next\// }, async (args) => {
|
|
671
|
+
if (args.pluginData?.skipStub) return void 0;
|
|
672
|
+
try {
|
|
673
|
+
const result = await build2.resolve(args.path, {
|
|
674
|
+
kind: args.kind,
|
|
675
|
+
resolveDir: args.resolveDir,
|
|
676
|
+
importer: args.importer,
|
|
677
|
+
namespace: "file",
|
|
678
|
+
pluginData: { skipStub: true }
|
|
679
|
+
});
|
|
680
|
+
if (!result.errors.length) return result;
|
|
681
|
+
} catch {
|
|
682
|
+
}
|
|
683
|
+
return { path: args.path, namespace: "next-stub" };
|
|
684
|
+
});
|
|
685
|
+
build2.onLoad({ filter: /.*/, namespace: "next-stub" }, (args) => {
|
|
686
|
+
const stubs = {
|
|
687
|
+
"next/image": `
|
|
688
|
+
const Image = (props) => {
|
|
689
|
+
const { src, alt, width, height, fill, priority, ...rest } = props;
|
|
690
|
+
const imgSrc = typeof src === 'object' ? src.src : src;
|
|
691
|
+
return React.createElement('img', { src: imgSrc, alt, width: fill ? undefined : width, height: fill ? undefined : height, loading: priority ? 'eager' : 'lazy', ...rest });
|
|
692
|
+
};
|
|
693
|
+
import React from 'react';
|
|
694
|
+
export default Image;
|
|
695
|
+
`,
|
|
696
|
+
"next/link": `
|
|
697
|
+
const Link = ({ href, children, ...rest }) => React.createElement('a', { href, ...rest }, children);
|
|
698
|
+
import React from 'react';
|
|
699
|
+
export default Link;
|
|
700
|
+
`,
|
|
701
|
+
"next/navigation": `
|
|
702
|
+
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(){} }; }
|
|
703
|
+
export function usePathname() { return window.location.pathname; }
|
|
704
|
+
export function useSearchParams() { return new URLSearchParams(window.location.search); }
|
|
705
|
+
export function useParams() { return {}; }
|
|
706
|
+
export function redirect(url) { window.location.href = url; }
|
|
707
|
+
export function notFound() { throw new Error('Not Found'); }
|
|
708
|
+
`,
|
|
709
|
+
"next/headers": `
|
|
710
|
+
export function cookies() { return { get(){}, getAll(){ return []; }, set(){}, delete(){}, has(){ return false; } }; }
|
|
711
|
+
export function headers() { return new Headers(); }
|
|
712
|
+
`
|
|
713
|
+
};
|
|
714
|
+
return {
|
|
715
|
+
contents: stubs[args.path] || "export default {};",
|
|
716
|
+
loader: "jsx"
|
|
717
|
+
};
|
|
718
|
+
});
|
|
657
719
|
}
|
|
658
720
|
};
|
|
721
|
+
const shimPath = path7.join(outputDir, ".process-shim-preview.js");
|
|
722
|
+
await fs6.writeFile(shimPath, PROCESS_SHIM);
|
|
659
723
|
await esbuild.build({
|
|
660
724
|
entryPoints: [previewEntryPath],
|
|
661
725
|
bundle: true,
|
|
@@ -665,6 +729,7 @@ export default { motion, AnimatePresence };
|
|
|
665
729
|
// Bundle React + core INTO the output (NOT externalized)
|
|
666
730
|
external: [],
|
|
667
731
|
plugins: [serverStubPlugin],
|
|
732
|
+
inject: [shimPath],
|
|
668
733
|
minify: false,
|
|
669
734
|
sourcemap: true,
|
|
670
735
|
target: "es2020",
|
|
@@ -672,6 +737,12 @@ export default { motion, AnimatePresence };
|
|
|
672
737
|
jsxImportSource: "react",
|
|
673
738
|
define: {
|
|
674
739
|
"process.env.NODE_ENV": JSON.stringify("development"),
|
|
740
|
+
"process.env.NEXT_PUBLIC_API_URL": JSON.stringify(
|
|
741
|
+
process.env.NEXT_PUBLIC_API_URL || ""
|
|
742
|
+
),
|
|
743
|
+
"process.env.NEXT_PUBLIC_COMPANY_ID": JSON.stringify(
|
|
744
|
+
process.env.NEXT_PUBLIC_COMPANY_ID || ""
|
|
745
|
+
),
|
|
675
746
|
global: "globalThis"
|
|
676
747
|
},
|
|
677
748
|
loader: { ".tsx": "tsx", ".ts": "ts" },
|
|
@@ -682,13 +753,16 @@ export default { motion, AnimatePresence };
|
|
|
682
753
|
"ignored-bare-import": "silent"
|
|
683
754
|
}
|
|
684
755
|
});
|
|
756
|
+
try {
|
|
757
|
+
await fs6.unlink(shimPath);
|
|
758
|
+
} catch {
|
|
759
|
+
}
|
|
685
760
|
return outputPath;
|
|
686
761
|
}
|
|
687
|
-
var
|
|
762
|
+
var PROCESS_SHIM, reactGlobalPlugin;
|
|
688
763
|
var init_compile_theme = __esm({
|
|
689
764
|
"src/utils/compile-theme.ts"() {
|
|
690
765
|
init_logger();
|
|
691
|
-
import_meta = {};
|
|
692
766
|
PROCESS_SHIM = `
|
|
693
767
|
if (typeof process === "undefined") {
|
|
694
768
|
globalThis.process = {
|
|
@@ -869,18 +943,18 @@ async function renderTemplate(templatePath, data) {
|
|
|
869
943
|
return ejs.render(template, data);
|
|
870
944
|
}
|
|
871
945
|
async function writeFile(filePath, content) {
|
|
872
|
-
await fs.ensureDir(
|
|
946
|
+
await fs.ensureDir(path7.dirname(filePath));
|
|
873
947
|
await fs.writeFile(filePath, content, "utf-8");
|
|
874
948
|
}
|
|
875
949
|
function getTemplatesDir() {
|
|
876
950
|
const locations = [
|
|
877
|
-
|
|
951
|
+
path7.join(__dirname, "../../templates"),
|
|
878
952
|
// Development
|
|
879
|
-
|
|
953
|
+
path7.join(__dirname, "../templates"),
|
|
880
954
|
// Production (dist/)
|
|
881
|
-
|
|
955
|
+
path7.join(process.cwd(), "templates"),
|
|
882
956
|
// Fallback
|
|
883
|
-
|
|
957
|
+
path7.join(process.cwd(), "packages/cli/templates")
|
|
884
958
|
// Monorepo
|
|
885
959
|
];
|
|
886
960
|
for (const location of locations) {
|
|
@@ -892,7 +966,7 @@ function getTemplatesDir() {
|
|
|
892
966
|
}
|
|
893
967
|
async function copyTemplate(templateName, targetDir, data) {
|
|
894
968
|
const templatesDir = getTemplatesDir();
|
|
895
|
-
const templateDir =
|
|
969
|
+
const templateDir = path7.join(templatesDir, templateName);
|
|
896
970
|
if (!fs.existsSync(templateDir)) {
|
|
897
971
|
throw new Error(
|
|
898
972
|
`Template "${templateName}" not found at ${templateDir}. Available templates: ${fs.readdirSync(templatesDir).join(", ")}`
|
|
@@ -901,8 +975,8 @@ async function copyTemplate(templateName, targetDir, data) {
|
|
|
901
975
|
await fs.ensureDir(targetDir);
|
|
902
976
|
const files = await fs.readdir(templateDir);
|
|
903
977
|
for (const file of files) {
|
|
904
|
-
const templatePath =
|
|
905
|
-
const targetPath =
|
|
978
|
+
const templatePath = path7.join(templateDir, file);
|
|
979
|
+
const targetPath = path7.join(targetDir, file);
|
|
906
980
|
const stat = await fs.stat(templatePath);
|
|
907
981
|
if (stat.isDirectory()) {
|
|
908
982
|
await copyTemplateDir(templatePath, targetPath, data);
|
|
@@ -919,8 +993,8 @@ async function copyTemplateDir(templateDir, targetDir, data) {
|
|
|
919
993
|
await fs.ensureDir(targetDir);
|
|
920
994
|
const files = await fs.readdir(templateDir);
|
|
921
995
|
for (const file of files) {
|
|
922
|
-
const templatePath =
|
|
923
|
-
const targetPath =
|
|
996
|
+
const templatePath = path7.join(templateDir, file);
|
|
997
|
+
const targetPath = path7.join(targetDir, file);
|
|
924
998
|
const stat = await fs.stat(templatePath);
|
|
925
999
|
if (stat.isDirectory()) {
|
|
926
1000
|
await copyTemplateDir(templatePath, targetPath, data);
|
|
@@ -935,32 +1009,32 @@ async function copyTemplateDir(templateDir, targetDir, data) {
|
|
|
935
1009
|
}
|
|
936
1010
|
function getProjectRoot() {
|
|
937
1011
|
let currentDir = process.cwd();
|
|
938
|
-
while (currentDir !==
|
|
939
|
-
const packageJsonPath =
|
|
1012
|
+
while (currentDir !== path7.parse(currentDir).root) {
|
|
1013
|
+
const packageJsonPath = path7.join(currentDir, "package.json");
|
|
940
1014
|
if (fs.existsSync(packageJsonPath)) {
|
|
941
1015
|
const packageJson = fs.readJsonSync(packageJsonPath);
|
|
942
|
-
if (packageJson.workspaces || fs.existsSync(
|
|
1016
|
+
if (packageJson.workspaces || fs.existsSync(path7.join(currentDir, "src/themes")) || fs.existsSync(path7.join(currentDir, "themes"))) {
|
|
943
1017
|
return currentDir;
|
|
944
1018
|
}
|
|
945
1019
|
}
|
|
946
|
-
currentDir =
|
|
1020
|
+
currentDir = path7.dirname(currentDir);
|
|
947
1021
|
}
|
|
948
1022
|
return process.cwd();
|
|
949
1023
|
}
|
|
950
1024
|
function getThemesDir() {
|
|
951
1025
|
const root = getProjectRoot();
|
|
952
|
-
if (fs.existsSync(
|
|
953
|
-
return
|
|
954
|
-
if (fs.existsSync(
|
|
955
|
-
return
|
|
956
|
-
return
|
|
1026
|
+
if (fs.existsSync(path7.join(root, "themes")))
|
|
1027
|
+
return path7.join(root, "themes");
|
|
1028
|
+
if (fs.existsSync(path7.join(root, "src/themes")))
|
|
1029
|
+
return path7.join(root, "src/themes");
|
|
1030
|
+
return path7.dirname(root);
|
|
957
1031
|
}
|
|
958
1032
|
function getFeaturesDir() {
|
|
959
|
-
return
|
|
1033
|
+
return path7.join(getProjectRoot(), "src/features");
|
|
960
1034
|
}
|
|
961
1035
|
function isOneXProject() {
|
|
962
1036
|
const root = getProjectRoot();
|
|
963
|
-
return fs.existsSync(
|
|
1037
|
+
return fs.existsSync(path7.join(root, "themes")) || fs.existsSync(path7.join(root, "src/themes")) || fs.existsSync(path7.join(root, "theme.config.ts")) || fs.existsSync(path7.join(root, "bundle-entry.ts"));
|
|
964
1038
|
}
|
|
965
1039
|
function ensureOneXProject() {
|
|
966
1040
|
if (!isOneXProject()) {
|
|
@@ -976,13 +1050,13 @@ function listThemes() {
|
|
|
976
1050
|
return [];
|
|
977
1051
|
}
|
|
978
1052
|
return fs.readdirSync(themesDir).filter((name) => {
|
|
979
|
-
const themePath =
|
|
980
|
-
return fs.statSync(themePath).isDirectory() && (fs.existsSync(
|
|
1053
|
+
const themePath = path7.join(themesDir, name);
|
|
1054
|
+
return fs.statSync(themePath).isDirectory() && (fs.existsSync(path7.join(themePath, "theme.config.ts")) || fs.existsSync(path7.join(themePath, "bundle-entry.ts")) || fs.existsSync(path7.join(themePath, "manifest.ts")));
|
|
981
1055
|
});
|
|
982
1056
|
}
|
|
983
1057
|
function themeExists(themeName) {
|
|
984
|
-
const themePath =
|
|
985
|
-
return fs.existsSync(themePath) && (fs.existsSync(
|
|
1058
|
+
const themePath = path7.join(getThemesDir(), themeName);
|
|
1059
|
+
return fs.existsSync(themePath) && (fs.existsSync(path7.join(themePath, "theme.config.ts")) || fs.existsSync(path7.join(themePath, "bundle-entry.ts")) || fs.existsSync(path7.join(themePath, "manifest.ts")));
|
|
986
1060
|
}
|
|
987
1061
|
function detectPackageManager() {
|
|
988
1062
|
const userAgent = process.env.npm_config_user_agent || "";
|
|
@@ -990,9 +1064,9 @@ function detectPackageManager() {
|
|
|
990
1064
|
if (userAgent.includes("yarn")) return "yarn";
|
|
991
1065
|
if (userAgent.includes("bun")) return "bun";
|
|
992
1066
|
const cwd = process.cwd();
|
|
993
|
-
if (fs.existsSync(
|
|
994
|
-
if (fs.existsSync(
|
|
995
|
-
if (fs.existsSync(
|
|
1067
|
+
if (fs.existsSync(path7.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
1068
|
+
if (fs.existsSync(path7.join(cwd, "yarn.lock"))) return "yarn";
|
|
1069
|
+
if (fs.existsSync(path7.join(cwd, "bun.lockb"))) return "bun";
|
|
996
1070
|
return "npm";
|
|
997
1071
|
}
|
|
998
1072
|
async function installDependencies(projectPath, packageManager = "npm") {
|
|
@@ -1026,7 +1100,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
1026
1100
|
if (!validateThemeName(kebabName)) {
|
|
1027
1101
|
return "Invalid project name. Use lowercase letters, numbers, and hyphens only.";
|
|
1028
1102
|
}
|
|
1029
|
-
if (fs2.existsSync(
|
|
1103
|
+
if (fs2.existsSync(path7.join(process.cwd(), kebabName))) {
|
|
1030
1104
|
return `Directory "${kebabName}" already exists`;
|
|
1031
1105
|
}
|
|
1032
1106
|
return true;
|
|
@@ -1037,7 +1111,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
1037
1111
|
} else {
|
|
1038
1112
|
name = toKebabCase(projectName);
|
|
1039
1113
|
}
|
|
1040
|
-
const projectPath =
|
|
1114
|
+
const projectPath = path7.join(process.cwd(), name);
|
|
1041
1115
|
if (fs2.existsSync(projectPath)) {
|
|
1042
1116
|
logger.error(`Directory "${name}" already exists.`);
|
|
1043
1117
|
process.exit(1);
|
|
@@ -1100,38 +1174,38 @@ async function initCommand(projectName, options = {}) {
|
|
|
1100
1174
|
try {
|
|
1101
1175
|
fs2.mkdirSync(projectPath, { recursive: true });
|
|
1102
1176
|
await copyTemplate(template, projectPath, data);
|
|
1103
|
-
const srcPath =
|
|
1177
|
+
const srcPath = path7.join(projectPath, "src");
|
|
1104
1178
|
fs2.mkdirSync(srcPath, { recursive: true });
|
|
1105
1179
|
const manifestContent = generateManifest(data);
|
|
1106
|
-
await writeFile(
|
|
1180
|
+
await writeFile(path7.join(srcPath, "manifest.ts"), manifestContent);
|
|
1107
1181
|
const configContent = generateThemeConfig(data);
|
|
1108
|
-
await writeFile(
|
|
1182
|
+
await writeFile(path7.join(srcPath, "config.ts"), configContent);
|
|
1109
1183
|
const layoutContent = generateThemeLayout(data);
|
|
1110
|
-
await writeFile(
|
|
1184
|
+
await writeFile(path7.join(srcPath, "layout.ts"), layoutContent);
|
|
1111
1185
|
const indexContent = generateThemeIndex(data);
|
|
1112
|
-
await writeFile(
|
|
1113
|
-
const sectionsPath =
|
|
1186
|
+
await writeFile(path7.join(srcPath, "index.ts"), indexContent);
|
|
1187
|
+
const sectionsPath = path7.join(srcPath, "sections");
|
|
1114
1188
|
fs2.mkdirSync(sectionsPath, { recursive: true });
|
|
1115
1189
|
await writeFile(
|
|
1116
|
-
|
|
1190
|
+
path7.join(sectionsPath, "README.md"),
|
|
1117
1191
|
`# ${displayName} Sections
|
|
1118
1192
|
|
|
1119
1193
|
Add your theme-specific sections here.
|
|
1120
1194
|
`
|
|
1121
1195
|
);
|
|
1122
|
-
const blocksPath =
|
|
1196
|
+
const blocksPath = path7.join(srcPath, "blocks");
|
|
1123
1197
|
fs2.mkdirSync(blocksPath, { recursive: true });
|
|
1124
1198
|
await writeFile(
|
|
1125
|
-
|
|
1199
|
+
path7.join(blocksPath, "README.md"),
|
|
1126
1200
|
`# ${displayName} Blocks
|
|
1127
1201
|
|
|
1128
1202
|
Add your theme-specific blocks here.
|
|
1129
1203
|
`
|
|
1130
1204
|
);
|
|
1131
|
-
const pagesPath =
|
|
1205
|
+
const pagesPath = path7.join(srcPath, "pages");
|
|
1132
1206
|
fs2.mkdirSync(pagesPath, { recursive: true });
|
|
1133
1207
|
const homePageContent = generateHomePage(data);
|
|
1134
|
-
await writeFile(
|
|
1208
|
+
await writeFile(path7.join(pagesPath, "home.ts"), homePageContent);
|
|
1135
1209
|
logger.stopSpinner(true, "Project structure created!");
|
|
1136
1210
|
if (options.git) {
|
|
1137
1211
|
logger.startSpinner("Initializing git repository...");
|
|
@@ -1143,7 +1217,7 @@ Add your theme-specific blocks here.
|
|
|
1143
1217
|
stdio: "ignore"
|
|
1144
1218
|
});
|
|
1145
1219
|
logger.stopSpinner(true, "Git repository initialized!");
|
|
1146
|
-
} catch
|
|
1220
|
+
} catch {
|
|
1147
1221
|
logger.stopSpinner(false, "Failed to initialize git");
|
|
1148
1222
|
}
|
|
1149
1223
|
}
|
|
@@ -1154,7 +1228,7 @@ Add your theme-specific blocks here.
|
|
|
1154
1228
|
try {
|
|
1155
1229
|
await installDependencies(projectPath, packageManager);
|
|
1156
1230
|
logger.stopSpinner(true, "Dependencies installed!");
|
|
1157
|
-
} catch
|
|
1231
|
+
} catch {
|
|
1158
1232
|
logger.stopSpinner(false, "Failed to install dependencies");
|
|
1159
1233
|
logger.info(
|
|
1160
1234
|
"You can install dependencies manually by running: cd " + name + " && npm install"
|
|
@@ -1430,10 +1504,10 @@ async function createSectionCommand(name, options) {
|
|
|
1430
1504
|
ensureOneXProject();
|
|
1431
1505
|
if (!options.theme) {
|
|
1432
1506
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
1433
|
-
(f) => fs.existsSync(
|
|
1507
|
+
(f) => fs.existsSync(path7.join(process.cwd(), f))
|
|
1434
1508
|
);
|
|
1435
1509
|
if (isStandaloneTheme) {
|
|
1436
|
-
options.theme =
|
|
1510
|
+
options.theme = path7.basename(process.cwd());
|
|
1437
1511
|
}
|
|
1438
1512
|
}
|
|
1439
1513
|
const sectionName = toKebabCase(name);
|
|
@@ -1496,35 +1570,35 @@ async function createSectionCommand(name, options) {
|
|
|
1496
1570
|
};
|
|
1497
1571
|
logger.startSpinner("Creating section files...");
|
|
1498
1572
|
try {
|
|
1499
|
-
const themePath =
|
|
1500
|
-
const sectionPath =
|
|
1573
|
+
const themePath = path7.join(getThemesDir(), themeName);
|
|
1574
|
+
const sectionPath = path7.join(themePath, "sections", sectionName);
|
|
1501
1575
|
const schemaContent = generateSectionSchema(data);
|
|
1502
1576
|
await writeFile(
|
|
1503
|
-
|
|
1577
|
+
path7.join(sectionPath, `${sectionName}.schema.ts`),
|
|
1504
1578
|
schemaContent
|
|
1505
1579
|
);
|
|
1506
1580
|
if (createTemplate) {
|
|
1507
1581
|
const templateContent = generateSectionTemplate(data);
|
|
1508
1582
|
await writeFile(
|
|
1509
|
-
|
|
1583
|
+
path7.join(sectionPath, `${sectionName}-default.tsx`),
|
|
1510
1584
|
templateContent
|
|
1511
1585
|
);
|
|
1512
1586
|
}
|
|
1513
1587
|
const indexContent = generateSectionIndex(data, createTemplate);
|
|
1514
|
-
await writeFile(
|
|
1588
|
+
await writeFile(path7.join(sectionPath, "index.ts"), indexContent);
|
|
1515
1589
|
logger.stopSpinner(true, "Section files created successfully!");
|
|
1516
1590
|
logger.newLine();
|
|
1517
1591
|
logger.section("Next steps:");
|
|
1518
1592
|
logger.log(
|
|
1519
|
-
` 1. Edit schema: ${
|
|
1593
|
+
` 1. Edit schema: ${path7.relative(process.cwd(), path7.join(sectionPath, `${sectionName}.schema.ts`))}`
|
|
1520
1594
|
);
|
|
1521
1595
|
if (createTemplate) {
|
|
1522
1596
|
logger.log(
|
|
1523
|
-
` 2. Edit template: ${
|
|
1597
|
+
` 2. Edit template: ${path7.relative(process.cwd(), path7.join(sectionPath, `${sectionName}-default.tsx`))}`
|
|
1524
1598
|
);
|
|
1525
1599
|
}
|
|
1526
1600
|
logger.log(
|
|
1527
|
-
` 3. Add to theme manifest: ${
|
|
1601
|
+
` 3. Add to theme manifest: ${path7.relative(process.cwd(), path7.join(themePath, "manifest.ts"))}`
|
|
1528
1602
|
);
|
|
1529
1603
|
logger.newLine();
|
|
1530
1604
|
logger.success("Section created successfully!");
|
|
@@ -1672,10 +1746,10 @@ async function createBlockCommand(name, options) {
|
|
|
1672
1746
|
ensureOneXProject();
|
|
1673
1747
|
if (!options.theme) {
|
|
1674
1748
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
1675
|
-
(f) => fs.existsSync(
|
|
1749
|
+
(f) => fs.existsSync(path7.join(process.cwd(), f))
|
|
1676
1750
|
);
|
|
1677
1751
|
if (isStandaloneTheme) {
|
|
1678
|
-
options.theme =
|
|
1752
|
+
options.theme = path7.basename(process.cwd());
|
|
1679
1753
|
}
|
|
1680
1754
|
}
|
|
1681
1755
|
const blockName = toKebabCase(name);
|
|
@@ -1750,24 +1824,24 @@ async function createBlockCommand(name, options) {
|
|
|
1750
1824
|
};
|
|
1751
1825
|
logger.startSpinner("Creating block files...");
|
|
1752
1826
|
try {
|
|
1753
|
-
const blockPath = scope === "shared" ?
|
|
1827
|
+
const blockPath = scope === "shared" ? path7.join(getFeaturesDir(), "blocks", blockName) : path7.join(getThemesDir(), themeName, "blocks", blockName);
|
|
1754
1828
|
const schemaContent = generateBlockSchema(data);
|
|
1755
1829
|
await writeFile(
|
|
1756
|
-
|
|
1830
|
+
path7.join(blockPath, `${blockName}.schema.ts`),
|
|
1757
1831
|
schemaContent
|
|
1758
1832
|
);
|
|
1759
1833
|
const componentContent = generateBlockComponent(data);
|
|
1760
|
-
await writeFile(
|
|
1834
|
+
await writeFile(path7.join(blockPath, `${blockName}.tsx`), componentContent);
|
|
1761
1835
|
const indexContent = generateBlockIndex(data);
|
|
1762
|
-
await writeFile(
|
|
1836
|
+
await writeFile(path7.join(blockPath, "index.ts"), indexContent);
|
|
1763
1837
|
logger.stopSpinner(true, "Block files created successfully!");
|
|
1764
1838
|
logger.newLine();
|
|
1765
1839
|
logger.section("Next steps:");
|
|
1766
1840
|
logger.log(
|
|
1767
|
-
` 1. Edit schema: ${
|
|
1841
|
+
` 1. Edit schema: ${path7.relative(process.cwd(), path7.join(blockPath, `${blockName}.schema.ts`))}`
|
|
1768
1842
|
);
|
|
1769
1843
|
logger.log(
|
|
1770
|
-
` 2. Edit component: ${
|
|
1844
|
+
` 2. Edit component: ${path7.relative(process.cwd(), path7.join(blockPath, `${blockName}.tsx`))}`
|
|
1771
1845
|
);
|
|
1772
1846
|
logger.log(
|
|
1773
1847
|
` 3. Register in block registry: src/lib/registry/block-registry.ts`
|
|
@@ -1945,31 +2019,31 @@ async function createComponentCommand(name, options) {
|
|
|
1945
2019
|
};
|
|
1946
2020
|
logger.startSpinner("Creating component files...");
|
|
1947
2021
|
try {
|
|
1948
|
-
const componentPath =
|
|
2022
|
+
const componentPath = path7.join(
|
|
1949
2023
|
getFeaturesDir(),
|
|
1950
2024
|
"components",
|
|
1951
2025
|
componentName
|
|
1952
2026
|
);
|
|
1953
2027
|
const schemaContent = generateComponentSchema(data);
|
|
1954
2028
|
await writeFile(
|
|
1955
|
-
|
|
2029
|
+
path7.join(componentPath, `${componentName}.schema.ts`),
|
|
1956
2030
|
schemaContent
|
|
1957
2031
|
);
|
|
1958
2032
|
const componentContent = generateComponent(data);
|
|
1959
2033
|
await writeFile(
|
|
1960
|
-
|
|
2034
|
+
path7.join(componentPath, `${componentName}.tsx`),
|
|
1961
2035
|
componentContent
|
|
1962
2036
|
);
|
|
1963
2037
|
const indexContent = generateComponentIndex(data);
|
|
1964
|
-
await writeFile(
|
|
2038
|
+
await writeFile(path7.join(componentPath, "index.ts"), indexContent);
|
|
1965
2039
|
logger.stopSpinner(true, "Component files created successfully!");
|
|
1966
2040
|
logger.newLine();
|
|
1967
2041
|
logger.section("Next steps:");
|
|
1968
2042
|
logger.log(
|
|
1969
|
-
` 1. Edit schema: ${
|
|
2043
|
+
` 1. Edit schema: ${path7.relative(process.cwd(), path7.join(componentPath, `${componentName}.schema.ts`))}`
|
|
1970
2044
|
);
|
|
1971
2045
|
logger.log(
|
|
1972
|
-
` 2. Edit component: ${
|
|
2046
|
+
` 2. Edit component: ${path7.relative(process.cwd(), path7.join(componentPath, `${componentName}.tsx`))}`
|
|
1973
2047
|
);
|
|
1974
2048
|
logger.log(
|
|
1975
2049
|
` 3. Register in component registry: src/lib/registry/component-registry.ts`
|
|
@@ -2126,13 +2200,13 @@ async function listSections(themeFilter) {
|
|
|
2126
2200
|
return;
|
|
2127
2201
|
}
|
|
2128
2202
|
for (const theme of themes) {
|
|
2129
|
-
const sectionsDir =
|
|
2203
|
+
const sectionsDir = path7.join(getThemesDir(), theme, "sections");
|
|
2130
2204
|
if (!fs.existsSync(sectionsDir)) {
|
|
2131
2205
|
continue;
|
|
2132
2206
|
}
|
|
2133
2207
|
const sections = fs.readdirSync(sectionsDir).filter((name) => {
|
|
2134
|
-
const sectionPath =
|
|
2135
|
-
return fs.statSync(sectionPath).isDirectory() && fs.existsSync(
|
|
2208
|
+
const sectionPath = path7.join(sectionsDir, name);
|
|
2209
|
+
return fs.statSync(sectionPath).isDirectory() && fs.existsSync(path7.join(sectionPath, "index.ts"));
|
|
2136
2210
|
});
|
|
2137
2211
|
if (sections.length > 0) {
|
|
2138
2212
|
logger.log(chalk4.cyan(`
|
|
@@ -2146,11 +2220,11 @@ async function listSections(themeFilter) {
|
|
|
2146
2220
|
}
|
|
2147
2221
|
async function listBlocks(themeFilter) {
|
|
2148
2222
|
logger.section("\u{1F9F1} Blocks");
|
|
2149
|
-
const sharedBlocksDir =
|
|
2223
|
+
const sharedBlocksDir = path7.join(getFeaturesDir(), "blocks");
|
|
2150
2224
|
if (fs.existsSync(sharedBlocksDir)) {
|
|
2151
2225
|
const sharedBlocks = fs.readdirSync(sharedBlocksDir).filter((name) => {
|
|
2152
|
-
const blockPath =
|
|
2153
|
-
return fs.statSync(blockPath).isDirectory() && fs.existsSync(
|
|
2226
|
+
const blockPath = path7.join(sharedBlocksDir, name);
|
|
2227
|
+
return fs.statSync(blockPath).isDirectory() && fs.existsSync(path7.join(blockPath, "index.ts"));
|
|
2154
2228
|
});
|
|
2155
2229
|
if (sharedBlocks.length > 0) {
|
|
2156
2230
|
logger.log(chalk4.cyan("\n Shared:"));
|
|
@@ -2161,13 +2235,13 @@ async function listBlocks(themeFilter) {
|
|
|
2161
2235
|
}
|
|
2162
2236
|
const themes = themeFilter ? [themeFilter] : listThemes();
|
|
2163
2237
|
for (const theme of themes) {
|
|
2164
|
-
const blocksDir =
|
|
2238
|
+
const blocksDir = path7.join(getThemesDir(), theme, "blocks");
|
|
2165
2239
|
if (!fs.existsSync(blocksDir)) {
|
|
2166
2240
|
continue;
|
|
2167
2241
|
}
|
|
2168
2242
|
const blocks = fs.readdirSync(blocksDir).filter((name) => {
|
|
2169
|
-
const blockPath =
|
|
2170
|
-
return fs.statSync(blockPath).isDirectory() && fs.existsSync(
|
|
2243
|
+
const blockPath = path7.join(blocksDir, name);
|
|
2244
|
+
return fs.statSync(blockPath).isDirectory() && fs.existsSync(path7.join(blockPath, "index.ts"));
|
|
2171
2245
|
});
|
|
2172
2246
|
if (blocks.length > 0) {
|
|
2173
2247
|
logger.log(chalk4.cyan(`
|
|
@@ -2181,14 +2255,14 @@ async function listBlocks(themeFilter) {
|
|
|
2181
2255
|
}
|
|
2182
2256
|
async function listComponents() {
|
|
2183
2257
|
logger.section("\u2699\uFE0F Components");
|
|
2184
|
-
const componentsDir =
|
|
2258
|
+
const componentsDir = path7.join(getFeaturesDir(), "components");
|
|
2185
2259
|
if (!fs.existsSync(componentsDir)) {
|
|
2186
2260
|
logger.warning("No components directory found");
|
|
2187
2261
|
return;
|
|
2188
2262
|
}
|
|
2189
2263
|
const components = fs.readdirSync(componentsDir).filter((name) => {
|
|
2190
|
-
const componentPath =
|
|
2191
|
-
return fs.statSync(componentPath).isDirectory() && fs.existsSync(
|
|
2264
|
+
const componentPath = path7.join(componentsDir, name);
|
|
2265
|
+
return fs.statSync(componentPath).isDirectory() && fs.existsSync(path7.join(componentPath, "index.ts"));
|
|
2192
2266
|
});
|
|
2193
2267
|
if (components.length === 0) {
|
|
2194
2268
|
logger.warning("No components found");
|
|
@@ -2209,11 +2283,11 @@ async function listThemesInfo() {
|
|
|
2209
2283
|
}
|
|
2210
2284
|
logger.log("");
|
|
2211
2285
|
for (const theme of themes) {
|
|
2212
|
-
const themeDir =
|
|
2286
|
+
const themeDir = path7.join(getThemesDir(), theme);
|
|
2213
2287
|
const candidates = ["theme.config.ts", "bundle-entry.ts", "manifest.ts"];
|
|
2214
2288
|
let manifestContent = "";
|
|
2215
2289
|
for (const candidate of candidates) {
|
|
2216
|
-
const candidatePath =
|
|
2290
|
+
const candidatePath = path7.join(themeDir, candidate);
|
|
2217
2291
|
if (fs.existsSync(candidatePath)) {
|
|
2218
2292
|
manifestContent = fs.readFileSync(candidatePath, "utf-8");
|
|
2219
2293
|
break;
|
|
@@ -2236,21 +2310,20 @@ async function listThemesInfo() {
|
|
|
2236
2310
|
// src/commands/build.ts
|
|
2237
2311
|
init_logger();
|
|
2238
2312
|
async function buildCommand(options) {
|
|
2239
|
-
var _a;
|
|
2240
2313
|
logger.header("Build Theme");
|
|
2241
2314
|
let themePath;
|
|
2242
2315
|
let themeName;
|
|
2243
2316
|
if (options.theme) {
|
|
2244
2317
|
themeName = options.theme;
|
|
2245
2318
|
try {
|
|
2246
|
-
const workspaceThemePath =
|
|
2319
|
+
const workspaceThemePath = path7.join(getThemesDir(), themeName);
|
|
2247
2320
|
if (fs.existsSync(workspaceThemePath)) {
|
|
2248
2321
|
themePath = workspaceThemePath;
|
|
2249
2322
|
} else {
|
|
2250
|
-
themePath =
|
|
2323
|
+
themePath = path7.join(process.cwd(), themeName);
|
|
2251
2324
|
}
|
|
2252
|
-
} catch
|
|
2253
|
-
themePath =
|
|
2325
|
+
} catch {
|
|
2326
|
+
themePath = path7.join(process.cwd(), themeName);
|
|
2254
2327
|
}
|
|
2255
2328
|
if (!fs.existsSync(themePath)) {
|
|
2256
2329
|
logger.error(`Theme "${themeName}" not found.`);
|
|
@@ -2261,10 +2334,10 @@ async function buildCommand(options) {
|
|
|
2261
2334
|
"theme.config.ts",
|
|
2262
2335
|
"bundle-entry.ts",
|
|
2263
2336
|
"manifest.ts"
|
|
2264
|
-
].some((f) => fs.existsSync(
|
|
2337
|
+
].some((f) => fs.existsSync(path7.join(process.cwd(), f)));
|
|
2265
2338
|
if (isThemeDir) {
|
|
2266
2339
|
themePath = process.cwd();
|
|
2267
|
-
themeName =
|
|
2340
|
+
themeName = path7.basename(themePath);
|
|
2268
2341
|
logger.info(`Building current theme: ${themeName}`);
|
|
2269
2342
|
} else {
|
|
2270
2343
|
logger.error(
|
|
@@ -2273,7 +2346,7 @@ async function buildCommand(options) {
|
|
|
2273
2346
|
process.exit(1);
|
|
2274
2347
|
}
|
|
2275
2348
|
}
|
|
2276
|
-
const packageJsonPath =
|
|
2349
|
+
const packageJsonPath = path7.join(themePath, "package.json");
|
|
2277
2350
|
const hasPkgJson = fs.existsSync(packageJsonPath);
|
|
2278
2351
|
if (!hasPkgJson) {
|
|
2279
2352
|
logger.warning(
|
|
@@ -2306,7 +2379,7 @@ async function buildCommand(options) {
|
|
|
2306
2379
|
}
|
|
2307
2380
|
logger.stopSpinner(true, "Lint passed");
|
|
2308
2381
|
const pkgJson = fs.readJsonSync(packageJsonPath);
|
|
2309
|
-
const buildScript =
|
|
2382
|
+
const buildScript = pkgJson.scripts?.build || "";
|
|
2310
2383
|
const isRecursive = buildScript.includes("onex build") || buildScript.includes("onex-cli build");
|
|
2311
2384
|
logger.startSpinner(
|
|
2312
2385
|
options.watch ? "Building (watch mode)..." : "Building..."
|
|
@@ -2329,9 +2402,9 @@ async function buildCommand(options) {
|
|
|
2329
2402
|
logger.success("\u2713 Theme built successfully!");
|
|
2330
2403
|
logger.newLine();
|
|
2331
2404
|
logger.info(`Theme: ${themeName}`);
|
|
2332
|
-
const distPath =
|
|
2405
|
+
const distPath = path7.join(themePath, "dist");
|
|
2333
2406
|
if (fs.existsSync(distPath)) {
|
|
2334
|
-
logger.log(`Output: ${
|
|
2407
|
+
logger.log(`Output: ${path7.relative(process.cwd(), distPath)}`);
|
|
2335
2408
|
const files = fs.readdirSync(distPath);
|
|
2336
2409
|
logger.log(`Files: ${files.length}`);
|
|
2337
2410
|
}
|
|
@@ -2401,11 +2474,11 @@ function getBucketName(env) {
|
|
|
2401
2474
|
return environment === "production" ? "onex-themes-prod" : "onex-themes-staging";
|
|
2402
2475
|
}
|
|
2403
2476
|
async function findCompiledThemeDir(themeId, version) {
|
|
2404
|
-
const searchPaths = [
|
|
2477
|
+
const searchPaths = [path7.resolve(process.cwd(), "dist")];
|
|
2405
2478
|
for (const dir of searchPaths) {
|
|
2406
2479
|
if (await fs.pathExists(dir)) {
|
|
2407
|
-
const hasManifest = await fs.pathExists(
|
|
2408
|
-
const hasThemeEntry = await fs.pathExists(
|
|
2480
|
+
const hasManifest = await fs.pathExists(path7.join(dir, "manifest.json"));
|
|
2481
|
+
const hasThemeEntry = await fs.pathExists(path7.join(dir, "bundle-entry.js")) || await fs.pathExists(path7.join(dir, "theme.config.js")) || await fs.pathExists(path7.join(dir, "index.js"));
|
|
2409
2482
|
if (hasManifest || hasThemeEntry) {
|
|
2410
2483
|
return dir;
|
|
2411
2484
|
}
|
|
@@ -2414,8 +2487,7 @@ async function findCompiledThemeDir(themeId, version) {
|
|
|
2414
2487
|
return null;
|
|
2415
2488
|
}
|
|
2416
2489
|
async function readManifest() {
|
|
2417
|
-
|
|
2418
|
-
const manifestTsPath = path.resolve(process.cwd(), "manifest.ts");
|
|
2490
|
+
const manifestTsPath = path7.resolve(process.cwd(), "manifest.ts");
|
|
2419
2491
|
if (await fs.pathExists(manifestTsPath)) {
|
|
2420
2492
|
try {
|
|
2421
2493
|
const module = await import(manifestTsPath);
|
|
@@ -2424,11 +2496,11 @@ async function readManifest() {
|
|
|
2424
2496
|
logger.warning("Failed to import manifest.ts, trying package.json");
|
|
2425
2497
|
}
|
|
2426
2498
|
}
|
|
2427
|
-
const packageJsonPath =
|
|
2499
|
+
const packageJsonPath = path7.resolve(process.cwd(), "package.json");
|
|
2428
2500
|
if (await fs.pathExists(packageJsonPath)) {
|
|
2429
2501
|
const pkg = await fs.readJson(packageJsonPath);
|
|
2430
2502
|
return {
|
|
2431
|
-
themeId:
|
|
2503
|
+
themeId: pkg.name?.replace("@onex-themes/", "") || "unknown",
|
|
2432
2504
|
version: pkg.version || "1.0.0"
|
|
2433
2505
|
};
|
|
2434
2506
|
}
|
|
@@ -2458,13 +2530,13 @@ async function findSourceDir(themeId, explicitDir) {
|
|
|
2458
2530
|
}
|
|
2459
2531
|
const searchPaths = [
|
|
2460
2532
|
process.cwd(),
|
|
2461
|
-
|
|
2462
|
-
|
|
2533
|
+
path7.resolve(process.cwd(), `../../themes/${themeId}`),
|
|
2534
|
+
path7.resolve(process.cwd(), `../themes/${themeId}`)
|
|
2463
2535
|
];
|
|
2464
2536
|
const markers = ["theme.config.ts", "bundle-entry.ts"];
|
|
2465
2537
|
for (const dir of searchPaths) {
|
|
2466
2538
|
for (const marker of markers) {
|
|
2467
|
-
if (await fs.pathExists(
|
|
2539
|
+
if (await fs.pathExists(path7.join(dir, marker))) {
|
|
2468
2540
|
return dir;
|
|
2469
2541
|
}
|
|
2470
2542
|
}
|
|
@@ -2516,7 +2588,7 @@ async function uploadCommand(options) {
|
|
|
2516
2588
|
spinner.succeed(`Found compiled theme at: ${compiledDir}`);
|
|
2517
2589
|
spinner.start("Creating bundle.zip...");
|
|
2518
2590
|
const tmpDir = os.tmpdir();
|
|
2519
|
-
const bundleZipPath =
|
|
2591
|
+
const bundleZipPath = path7.join(tmpDir, `${themeId}-${version}-bundle.zip`);
|
|
2520
2592
|
await createZipFromDir(compiledDir, bundleZipPath);
|
|
2521
2593
|
const bundleZipBuffer = await fs.readFile(bundleZipPath);
|
|
2522
2594
|
const bundleSizeMB = (bundleZipBuffer.length / 1024 / 1024).toFixed(2);
|
|
@@ -2570,7 +2642,7 @@ async function uploadCommand(options) {
|
|
|
2570
2642
|
if (sourceDir) {
|
|
2571
2643
|
spinner.succeed(`Found source at: ${sourceDir}`);
|
|
2572
2644
|
spinner.start("Creating source.zip...");
|
|
2573
|
-
const sourceZipPath =
|
|
2645
|
+
const sourceZipPath = path7.join(
|
|
2574
2646
|
tmpDir,
|
|
2575
2647
|
`${themeId}-${version}-source.zip`
|
|
2576
2648
|
);
|
|
@@ -2672,39 +2744,15 @@ function getBucketName2(env) {
|
|
|
2672
2744
|
}
|
|
2673
2745
|
async function streamToString(stream) {
|
|
2674
2746
|
const chunks = [];
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
const chunk = temp.value;
|
|
2678
|
-
chunks.push(Buffer.from(chunk));
|
|
2679
|
-
}
|
|
2680
|
-
} catch (temp) {
|
|
2681
|
-
error = [temp];
|
|
2682
|
-
} finally {
|
|
2683
|
-
try {
|
|
2684
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
2685
|
-
} finally {
|
|
2686
|
-
if (error)
|
|
2687
|
-
throw error[0];
|
|
2688
|
-
}
|
|
2747
|
+
for await (const chunk of stream) {
|
|
2748
|
+
chunks.push(Buffer.from(chunk));
|
|
2689
2749
|
}
|
|
2690
2750
|
return Buffer.concat(chunks).toString("utf-8");
|
|
2691
2751
|
}
|
|
2692
2752
|
async function streamToBuffer(stream) {
|
|
2693
2753
|
const chunks = [];
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
const chunk = temp.value;
|
|
2697
|
-
chunks.push(Buffer.from(chunk));
|
|
2698
|
-
}
|
|
2699
|
-
} catch (temp) {
|
|
2700
|
-
error = [temp];
|
|
2701
|
-
} finally {
|
|
2702
|
-
try {
|
|
2703
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
2704
|
-
} finally {
|
|
2705
|
-
if (error)
|
|
2706
|
-
throw error[0];
|
|
2707
|
-
}
|
|
2754
|
+
for await (const chunk of stream) {
|
|
2755
|
+
chunks.push(Buffer.from(chunk));
|
|
2708
2756
|
}
|
|
2709
2757
|
return Buffer.concat(chunks);
|
|
2710
2758
|
}
|
|
@@ -2726,11 +2774,10 @@ async function resolveLatestVersion(s3Client, bucket, themeId) {
|
|
|
2726
2774
|
}
|
|
2727
2775
|
}
|
|
2728
2776
|
async function createCompatibilityFiles(outputDir, manifest) {
|
|
2729
|
-
|
|
2730
|
-
const entryFile = ((_a = manifest.output) == null ? void 0 : _a.entry) || "bundle-entry.js";
|
|
2777
|
+
const entryFile = manifest.output?.entry || "bundle-entry.js";
|
|
2731
2778
|
if (entryFile !== "bundle-entry.js" && entryFile.startsWith("bundle-entry-")) {
|
|
2732
|
-
const hashedPath =
|
|
2733
|
-
const stablePath =
|
|
2779
|
+
const hashedPath = path7.join(outputDir, entryFile);
|
|
2780
|
+
const stablePath = path7.join(outputDir, "bundle-entry.js");
|
|
2734
2781
|
if (await fs.pathExists(hashedPath)) {
|
|
2735
2782
|
await fs.copy(hashedPath, stablePath);
|
|
2736
2783
|
const mapPath = hashedPath + ".map";
|
|
@@ -2739,13 +2786,13 @@ async function createCompatibilityFiles(outputDir, manifest) {
|
|
|
2739
2786
|
}
|
|
2740
2787
|
}
|
|
2741
2788
|
}
|
|
2742
|
-
const sectionsRegistryPath =
|
|
2789
|
+
const sectionsRegistryPath = path7.join(outputDir, "sections-registry.js");
|
|
2743
2790
|
const content = `// Re-export all sections from bundle-entry
|
|
2744
2791
|
// This file exists to maintain compatibility with the import path
|
|
2745
2792
|
export * from './bundle-entry.js';
|
|
2746
2793
|
`;
|
|
2747
2794
|
await fs.writeFile(sectionsRegistryPath, content, "utf-8");
|
|
2748
|
-
const pkgJsonPath =
|
|
2795
|
+
const pkgJsonPath = path7.join(outputDir, "package.json");
|
|
2749
2796
|
await fs.writeFile(pkgJsonPath, '{\n "type": "module"\n}\n', "utf-8");
|
|
2750
2797
|
}
|
|
2751
2798
|
function showDownloadFailureHelp(themeId, bucket) {
|
|
@@ -2828,7 +2875,7 @@ async function downloadCommand(options) {
|
|
|
2828
2875
|
zip.extractAllTo(outputDir, true);
|
|
2829
2876
|
const entries = zip.getEntries().filter((e) => !e.isDirectory);
|
|
2830
2877
|
spinner.succeed(`Extracted ${entries.length} files to ${outputDir}`);
|
|
2831
|
-
const manifestPath =
|
|
2878
|
+
const manifestPath = path7.join(outputDir, "manifest.json");
|
|
2832
2879
|
const manifest = await fs.readJson(manifestPath);
|
|
2833
2880
|
await createCompatibilityFiles(outputDir, manifest);
|
|
2834
2881
|
console.log();
|
|
@@ -2898,39 +2945,15 @@ function getBucketName3(env) {
|
|
|
2898
2945
|
}
|
|
2899
2946
|
async function streamToString2(stream) {
|
|
2900
2947
|
const chunks = [];
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
const chunk = temp.value;
|
|
2904
|
-
chunks.push(Buffer.from(chunk));
|
|
2905
|
-
}
|
|
2906
|
-
} catch (temp) {
|
|
2907
|
-
error = [temp];
|
|
2908
|
-
} finally {
|
|
2909
|
-
try {
|
|
2910
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
2911
|
-
} finally {
|
|
2912
|
-
if (error)
|
|
2913
|
-
throw error[0];
|
|
2914
|
-
}
|
|
2948
|
+
for await (const chunk of stream) {
|
|
2949
|
+
chunks.push(Buffer.from(chunk));
|
|
2915
2950
|
}
|
|
2916
2951
|
return Buffer.concat(chunks).toString("utf-8");
|
|
2917
2952
|
}
|
|
2918
2953
|
async function streamToBuffer2(stream) {
|
|
2919
2954
|
const chunks = [];
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
const chunk = temp.value;
|
|
2923
|
-
chunks.push(Buffer.from(chunk));
|
|
2924
|
-
}
|
|
2925
|
-
} catch (temp) {
|
|
2926
|
-
error = [temp];
|
|
2927
|
-
} finally {
|
|
2928
|
-
try {
|
|
2929
|
-
more && (temp = iter.return) && await temp.call(iter);
|
|
2930
|
-
} finally {
|
|
2931
|
-
if (error)
|
|
2932
|
-
throw error[0];
|
|
2933
|
-
}
|
|
2955
|
+
for await (const chunk of stream) {
|
|
2956
|
+
chunks.push(Buffer.from(chunk));
|
|
2934
2957
|
}
|
|
2935
2958
|
return Buffer.concat(chunks);
|
|
2936
2959
|
}
|
|
@@ -2986,7 +3009,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
2986
3009
|
const oldPrefix = `${oldName}-`;
|
|
2987
3010
|
const newPrefix = `${newName}-`;
|
|
2988
3011
|
const newDisplayName = newName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
2989
|
-
const pkgPath =
|
|
3012
|
+
const pkgPath = path7.join(themeDir, "package.json");
|
|
2990
3013
|
if (await fs.pathExists(pkgPath)) {
|
|
2991
3014
|
const pkg = await fs.readJson(pkgPath);
|
|
2992
3015
|
pkg.name = `@onex-themes/${newName}`;
|
|
@@ -2999,7 +3022,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
2999
3022
|
pkg.version = "1.0.0";
|
|
3000
3023
|
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3001
3024
|
}
|
|
3002
|
-
const configPath =
|
|
3025
|
+
const configPath = path7.join(themeDir, "theme.config.ts");
|
|
3003
3026
|
if (await fs.pathExists(configPath)) {
|
|
3004
3027
|
let content = await fs.readFile(configPath, "utf-8");
|
|
3005
3028
|
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
@@ -3009,7 +3032,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3009
3032
|
);
|
|
3010
3033
|
await fs.writeFile(configPath, content);
|
|
3011
3034
|
}
|
|
3012
|
-
const layoutPath =
|
|
3035
|
+
const layoutPath = path7.join(themeDir, "theme.layout.ts");
|
|
3013
3036
|
if (await fs.pathExists(layoutPath)) {
|
|
3014
3037
|
let content = await fs.readFile(layoutPath, "utf-8");
|
|
3015
3038
|
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
@@ -3022,7 +3045,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3022
3045
|
const oldDisplayName = oldName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3023
3046
|
const tsFiles = await glob("**/*.ts", { cwd: themeDir, nodir: true });
|
|
3024
3047
|
for (const file of tsFiles) {
|
|
3025
|
-
const filePath =
|
|
3048
|
+
const filePath = path7.join(themeDir, file);
|
|
3026
3049
|
let content = await fs.readFile(filePath, "utf-8");
|
|
3027
3050
|
const original = content;
|
|
3028
3051
|
content = content.replace(
|
|
@@ -3051,7 +3074,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3051
3074
|
const spinner = ora("Initializing clone...").start();
|
|
3052
3075
|
try {
|
|
3053
3076
|
const bucket = options.bucket || getBucketName3(options.environment);
|
|
3054
|
-
const outputDir = options.output ||
|
|
3077
|
+
const outputDir = options.output || path7.resolve(process.cwd(), newName);
|
|
3055
3078
|
const s3Client = getS3Client3();
|
|
3056
3079
|
if (await fs.pathExists(outputDir)) {
|
|
3057
3080
|
spinner.fail(chalk4.red(`Directory already exists: ${outputDir}`));
|
|
@@ -3106,9 +3129,22 @@ async function cloneCommand(themeName, options) {
|
|
|
3106
3129
|
spinner.succeed(
|
|
3107
3130
|
`Renamed theme: ${chalk4.gray(themeName)} \u2192 ${chalk4.cyan(newName)}`
|
|
3108
3131
|
);
|
|
3132
|
+
const envExamplePath = path7.join(outputDir, ".env.example");
|
|
3133
|
+
if (!await fs.pathExists(envExamplePath)) {
|
|
3134
|
+
await fs.writeFile(
|
|
3135
|
+
envExamplePath,
|
|
3136
|
+
[
|
|
3137
|
+
"# API Configuration (enables real data in preview)",
|
|
3138
|
+
"# Get your Company ID from the OneX dashboard",
|
|
3139
|
+
"NEXT_PUBLIC_API_URL=https://api-dev.onexeos.com",
|
|
3140
|
+
"NEXT_PUBLIC_COMPANY_ID=",
|
|
3141
|
+
""
|
|
3142
|
+
].join("\n")
|
|
3143
|
+
);
|
|
3144
|
+
}
|
|
3109
3145
|
if (options.install !== false) {
|
|
3110
3146
|
const hasPkgJson = await fs.pathExists(
|
|
3111
|
-
|
|
3147
|
+
path7.join(outputDir, "package.json")
|
|
3112
3148
|
);
|
|
3113
3149
|
if (hasPkgJson) {
|
|
3114
3150
|
spinner.start("Installing dependencies...");
|
|
@@ -3135,7 +3171,8 @@ async function cloneCommand(themeName, options) {
|
|
|
3135
3171
|
console.log(chalk4.cyan(" Files: ") + chalk4.white(entries.length));
|
|
3136
3172
|
console.log();
|
|
3137
3173
|
console.log(chalk4.cyan("Next steps:"));
|
|
3138
|
-
console.log(chalk4.gray(` cd ${
|
|
3174
|
+
console.log(chalk4.gray(` cd ${path7.relative(process.cwd(), outputDir)}`));
|
|
3175
|
+
console.log(chalk4.gray(" cp .env.example .env # then add your Company ID"));
|
|
3139
3176
|
if (options.install === false) {
|
|
3140
3177
|
console.log(chalk4.gray(" pnpm install"));
|
|
3141
3178
|
}
|