@onexapis/cli 1.1.3 → 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 +198 -192
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +197 -191
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +154 -148
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +153 -147
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -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');
|
|
@@ -41,7 +41,7 @@ function _interopNamespace(e) {
|
|
|
41
41
|
var chalk4__default = /*#__PURE__*/_interopDefault(chalk4);
|
|
42
42
|
var ora__default = /*#__PURE__*/_interopDefault(ora);
|
|
43
43
|
var esbuild__namespace = /*#__PURE__*/_interopNamespace(esbuild);
|
|
44
|
-
var
|
|
44
|
+
var path7__default = /*#__PURE__*/_interopDefault(path7);
|
|
45
45
|
var fs6__default = /*#__PURE__*/_interopDefault(fs6);
|
|
46
46
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
47
47
|
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
@@ -135,12 +135,12 @@ __export(compile_theme_exports, {
|
|
|
135
135
|
async function resolveNodeModulesFile(startDir, relativePath) {
|
|
136
136
|
let dir = startDir;
|
|
137
137
|
while (true) {
|
|
138
|
-
const candidate =
|
|
138
|
+
const candidate = path7__default.default.join(dir, "node_modules", relativePath);
|
|
139
139
|
try {
|
|
140
140
|
await fs6__default.default.access(candidate);
|
|
141
141
|
return candidate;
|
|
142
142
|
} catch {
|
|
143
|
-
const parent =
|
|
143
|
+
const parent = path7__default.default.dirname(dir);
|
|
144
144
|
if (parent === dir) break;
|
|
145
145
|
dir = parent;
|
|
146
146
|
}
|
|
@@ -166,10 +166,16 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
166
166
|
namedExports = exportsBySubpath[cacheKey];
|
|
167
167
|
} else {
|
|
168
168
|
const distFileName = subpath ? `${subpath}.mjs` : "index.mjs";
|
|
169
|
-
|
|
169
|
+
let distPath = await resolveNodeModulesFile(
|
|
170
170
|
themePath,
|
|
171
|
-
|
|
171
|
+
path7__default.default.join("@onexapis", "core", "dist", distFileName)
|
|
172
172
|
);
|
|
173
|
+
if (!distPath) {
|
|
174
|
+
distPath = await resolveNodeModulesFile(
|
|
175
|
+
__dirname,
|
|
176
|
+
path7__default.default.join("@onexapis", "core", "dist", distFileName)
|
|
177
|
+
);
|
|
178
|
+
}
|
|
173
179
|
try {
|
|
174
180
|
if (!distPath) throw new Error("not found");
|
|
175
181
|
const distContent = await fs6__default.default.readFile(distPath, "utf-8");
|
|
@@ -222,7 +228,7 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
222
228
|
const pages = {};
|
|
223
229
|
for (const ext of [".ts", ".js"]) {
|
|
224
230
|
try {
|
|
225
|
-
const mod = await jiti.import(
|
|
231
|
+
const mod = await jiti.import(path7__default.default.join(themePath, `theme.config${ext}`));
|
|
226
232
|
themeConfig = mod.default || mod;
|
|
227
233
|
break;
|
|
228
234
|
} catch {
|
|
@@ -230,20 +236,20 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
230
236
|
}
|
|
231
237
|
for (const ext of [".ts", ".js"]) {
|
|
232
238
|
try {
|
|
233
|
-
const mod = await jiti.import(
|
|
239
|
+
const mod = await jiti.import(path7__default.default.join(themePath, `theme.layout${ext}`));
|
|
234
240
|
layoutConfig = mod.default || mod;
|
|
235
241
|
break;
|
|
236
242
|
} catch {
|
|
237
243
|
}
|
|
238
244
|
}
|
|
239
|
-
const pagesDir =
|
|
245
|
+
const pagesDir = path7__default.default.join(themePath, "pages");
|
|
240
246
|
try {
|
|
241
247
|
const files = await fs6__default.default.readdir(pagesDir);
|
|
242
248
|
for (const file of files) {
|
|
243
249
|
if (!file.match(/\.(ts|js)$/)) continue;
|
|
244
250
|
const name = file.replace(/\.(ts|js)$/, "");
|
|
245
251
|
try {
|
|
246
|
-
const mod = await jiti.import(
|
|
252
|
+
const mod = await jiti.import(path7__default.default.join(pagesDir, file));
|
|
247
253
|
const config = mod.default || mod;
|
|
248
254
|
pages[name] = {
|
|
249
255
|
id: name,
|
|
@@ -259,7 +265,7 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
259
265
|
} catch {
|
|
260
266
|
}
|
|
261
267
|
await fs6__default.default.writeFile(
|
|
262
|
-
|
|
268
|
+
path7__default.default.join(outputDir, "theme-data.json"),
|
|
263
269
|
JSON.stringify(
|
|
264
270
|
{
|
|
265
271
|
themeId,
|
|
@@ -282,17 +288,17 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
282
288
|
exports.logger.info(`Generated theme-data.json (${Object.keys(pages).length} pages)`);
|
|
283
289
|
}
|
|
284
290
|
async function contentHashEntry(outputDir) {
|
|
285
|
-
const entryPath =
|
|
286
|
-
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");
|
|
287
293
|
const oldFiles = await glob.glob("bundle-entry-*.js*", { cwd: outputDir });
|
|
288
294
|
for (const f of oldFiles) {
|
|
289
|
-
await fs6__default.default.unlink(
|
|
295
|
+
await fs6__default.default.unlink(path7__default.default.join(outputDir, f));
|
|
290
296
|
}
|
|
291
297
|
let entryContent;
|
|
292
298
|
try {
|
|
293
299
|
entryContent = await fs6__default.default.readFile(entryPath, "utf-8");
|
|
294
300
|
} catch {
|
|
295
|
-
const indexPath =
|
|
301
|
+
const indexPath = path7__default.default.join(outputDir, "index.js");
|
|
296
302
|
try {
|
|
297
303
|
entryContent = await fs6__default.default.readFile(indexPath, "utf-8");
|
|
298
304
|
} catch {
|
|
@@ -301,17 +307,17 @@ async function contentHashEntry(outputDir) {
|
|
|
301
307
|
}
|
|
302
308
|
const hash2 = crypto__default.default.createHash("sha256").update(entryContent).digest("hex").slice(0, 8);
|
|
303
309
|
const hashedName2 = `bundle-entry-${hash2}.js`;
|
|
304
|
-
const indexMapPath =
|
|
310
|
+
const indexMapPath = path7__default.default.join(outputDir, "index.js.map");
|
|
305
311
|
const hashedMapName2 = `bundle-entry-${hash2}.js.map`;
|
|
306
312
|
entryContent = entryContent.replace(
|
|
307
313
|
/\/\/# sourceMappingURL=index\.js\.map/,
|
|
308
314
|
`//# sourceMappingURL=${hashedMapName2}`
|
|
309
315
|
);
|
|
310
|
-
await fs6__default.default.writeFile(
|
|
316
|
+
await fs6__default.default.writeFile(path7__default.default.join(outputDir, hashedName2), entryContent);
|
|
311
317
|
await fs6__default.default.unlink(indexPath);
|
|
312
318
|
try {
|
|
313
319
|
await fs6__default.default.access(indexMapPath);
|
|
314
|
-
await fs6__default.default.rename(indexMapPath,
|
|
320
|
+
await fs6__default.default.rename(indexMapPath, path7__default.default.join(outputDir, hashedMapName2));
|
|
315
321
|
} catch {
|
|
316
322
|
}
|
|
317
323
|
exports.logger.info(`Entry hashed: ${hashedName2}`);
|
|
@@ -324,11 +330,11 @@ async function contentHashEntry(outputDir) {
|
|
|
324
330
|
/\/\/# sourceMappingURL=bundle-entry\.js\.map/,
|
|
325
331
|
`//# sourceMappingURL=${hashedMapName}`
|
|
326
332
|
);
|
|
327
|
-
await fs6__default.default.writeFile(
|
|
333
|
+
await fs6__default.default.writeFile(path7__default.default.join(outputDir, hashedName), entryContent);
|
|
328
334
|
await fs6__default.default.unlink(entryPath);
|
|
329
335
|
try {
|
|
330
336
|
await fs6__default.default.access(mapPath);
|
|
331
|
-
await fs6__default.default.rename(mapPath,
|
|
337
|
+
await fs6__default.default.rename(mapPath, path7__default.default.join(outputDir, hashedMapName));
|
|
332
338
|
} catch {
|
|
333
339
|
}
|
|
334
340
|
exports.logger.info(`Entry hashed: ${hashedName}`);
|
|
@@ -340,7 +346,7 @@ async function extractDataRequirements(themePath) {
|
|
|
340
346
|
const requirements = {};
|
|
341
347
|
for (const file of schemaFiles) {
|
|
342
348
|
try {
|
|
343
|
-
const mod = await jiti.import(
|
|
349
|
+
const mod = await jiti.import(path7__default.default.join(themePath, file));
|
|
344
350
|
const exports$1 = mod;
|
|
345
351
|
for (const value of Object.values(exports$1)) {
|
|
346
352
|
if (value && typeof value === "object" && typeof value.type === "string" && value.dataRequirements && typeof value.dataRequirements === "object") {
|
|
@@ -360,7 +366,7 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
360
366
|
let themeId = themeName;
|
|
361
367
|
try {
|
|
362
368
|
const pkgContent = await fs6__default.default.readFile(
|
|
363
|
-
|
|
369
|
+
path7__default.default.join(themePath, "package.json"),
|
|
364
370
|
"utf-8"
|
|
365
371
|
);
|
|
366
372
|
const pkg = JSON.parse(pkgContent);
|
|
@@ -378,7 +384,7 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
378
384
|
const dataRequirements = await extractDataRequirements(themePath);
|
|
379
385
|
let hasThemeConfig = false;
|
|
380
386
|
try {
|
|
381
|
-
await fs6__default.default.access(
|
|
387
|
+
await fs6__default.default.access(path7__default.default.join(themePath, "theme.config.ts"));
|
|
382
388
|
hasThemeConfig = true;
|
|
383
389
|
} catch {
|
|
384
390
|
}
|
|
@@ -420,21 +426,21 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
420
426
|
dataRequirements
|
|
421
427
|
};
|
|
422
428
|
await fs6__default.default.writeFile(
|
|
423
|
-
|
|
429
|
+
path7__default.default.join(outputDir, "manifest.json"),
|
|
424
430
|
JSON.stringify(manifest, null, 2)
|
|
425
431
|
);
|
|
426
432
|
}
|
|
427
433
|
async function compileStandaloneTheme(themePath, themeName) {
|
|
428
|
-
const outputDir =
|
|
429
|
-
const bundleEntry =
|
|
430
|
-
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");
|
|
431
437
|
let entryPoint = indexEntry;
|
|
432
438
|
try {
|
|
433
439
|
await fs6__default.default.access(bundleEntry);
|
|
434
440
|
entryPoint = bundleEntry;
|
|
435
441
|
} catch {
|
|
436
442
|
}
|
|
437
|
-
const shimPath =
|
|
443
|
+
const shimPath = path7__default.default.join(outputDir, ".process-shim.js");
|
|
438
444
|
await fs6__default.default.mkdir(outputDir, { recursive: true });
|
|
439
445
|
await fs6__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
440
446
|
const buildOptions = {
|
|
@@ -508,16 +514,16 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
508
514
|
}
|
|
509
515
|
}
|
|
510
516
|
async function compileStandaloneThemeDev(themePath, themeName) {
|
|
511
|
-
const outputDir =
|
|
512
|
-
const bundleEntry =
|
|
513
|
-
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");
|
|
514
520
|
let entryPoint = indexEntry;
|
|
515
521
|
try {
|
|
516
522
|
await fs6__default.default.access(bundleEntry);
|
|
517
523
|
entryPoint = bundleEntry;
|
|
518
524
|
} catch {
|
|
519
525
|
}
|
|
520
|
-
const shimPath =
|
|
526
|
+
const shimPath = path7__default.default.join(outputDir, ".process-shim.js");
|
|
521
527
|
await fs6__default.default.mkdir(outputDir, { recursive: true });
|
|
522
528
|
await fs6__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
523
529
|
const buildOptions = {
|
|
@@ -568,13 +574,13 @@ async function compileStandaloneThemeDev(themePath, themeName) {
|
|
|
568
574
|
return { context: context2, outputDir };
|
|
569
575
|
}
|
|
570
576
|
async function compilePreviewRuntime(themePath) {
|
|
571
|
-
const outputDir =
|
|
577
|
+
const outputDir = path7__default.default.join(themePath, "dist");
|
|
572
578
|
await fs6__default.default.mkdir(outputDir, { recursive: true });
|
|
573
|
-
const outputPath =
|
|
579
|
+
const outputPath = path7__default.default.join(outputDir, "preview-runtime.js");
|
|
574
580
|
const locations = [
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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")
|
|
578
584
|
];
|
|
579
585
|
let previewEntryPath = null;
|
|
580
586
|
for (const loc of locations) {
|
|
@@ -749,7 +755,7 @@ export function headers() { return new Headers(); }
|
|
|
749
755
|
});
|
|
750
756
|
}
|
|
751
757
|
};
|
|
752
|
-
const shimPath =
|
|
758
|
+
const shimPath = path7__default.default.join(outputDir, ".process-shim-preview.js");
|
|
753
759
|
await fs6__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
754
760
|
await esbuild__namespace.build({
|
|
755
761
|
entryPoints: [previewEntryPath],
|
|
@@ -974,18 +980,18 @@ async function renderTemplate(templatePath, data) {
|
|
|
974
980
|
return ejs__default.default.render(template, data);
|
|
975
981
|
}
|
|
976
982
|
async function writeFile(filePath, content) {
|
|
977
|
-
await fs__default.default.ensureDir(
|
|
983
|
+
await fs__default.default.ensureDir(path7__default.default.dirname(filePath));
|
|
978
984
|
await fs__default.default.writeFile(filePath, content, "utf-8");
|
|
979
985
|
}
|
|
980
986
|
function getTemplatesDir() {
|
|
981
987
|
const locations = [
|
|
982
|
-
|
|
988
|
+
path7__default.default.join(__dirname, "../../templates"),
|
|
983
989
|
// Development
|
|
984
|
-
|
|
990
|
+
path7__default.default.join(__dirname, "../templates"),
|
|
985
991
|
// Production (dist/)
|
|
986
|
-
|
|
992
|
+
path7__default.default.join(process.cwd(), "templates"),
|
|
987
993
|
// Fallback
|
|
988
|
-
|
|
994
|
+
path7__default.default.join(process.cwd(), "packages/cli/templates")
|
|
989
995
|
// Monorepo
|
|
990
996
|
];
|
|
991
997
|
for (const location of locations) {
|
|
@@ -997,7 +1003,7 @@ function getTemplatesDir() {
|
|
|
997
1003
|
}
|
|
998
1004
|
async function copyTemplate(templateName, targetDir, data) {
|
|
999
1005
|
const templatesDir = getTemplatesDir();
|
|
1000
|
-
const templateDir =
|
|
1006
|
+
const templateDir = path7__default.default.join(templatesDir, templateName);
|
|
1001
1007
|
if (!fs__default.default.existsSync(templateDir)) {
|
|
1002
1008
|
throw new Error(
|
|
1003
1009
|
`Template "${templateName}" not found at ${templateDir}. Available templates: ${fs__default.default.readdirSync(templatesDir).join(", ")}`
|
|
@@ -1006,8 +1012,8 @@ async function copyTemplate(templateName, targetDir, data) {
|
|
|
1006
1012
|
await fs__default.default.ensureDir(targetDir);
|
|
1007
1013
|
const files = await fs__default.default.readdir(templateDir);
|
|
1008
1014
|
for (const file of files) {
|
|
1009
|
-
const templatePath =
|
|
1010
|
-
const targetPath =
|
|
1015
|
+
const templatePath = path7__default.default.join(templateDir, file);
|
|
1016
|
+
const targetPath = path7__default.default.join(targetDir, file);
|
|
1011
1017
|
const stat = await fs__default.default.stat(templatePath);
|
|
1012
1018
|
if (stat.isDirectory()) {
|
|
1013
1019
|
await copyTemplateDir(templatePath, targetPath, data);
|
|
@@ -1024,8 +1030,8 @@ async function copyTemplateDir(templateDir, targetDir, data) {
|
|
|
1024
1030
|
await fs__default.default.ensureDir(targetDir);
|
|
1025
1031
|
const files = await fs__default.default.readdir(templateDir);
|
|
1026
1032
|
for (const file of files) {
|
|
1027
|
-
const templatePath =
|
|
1028
|
-
const targetPath =
|
|
1033
|
+
const templatePath = path7__default.default.join(templateDir, file);
|
|
1034
|
+
const targetPath = path7__default.default.join(targetDir, file);
|
|
1029
1035
|
const stat = await fs__default.default.stat(templatePath);
|
|
1030
1036
|
if (stat.isDirectory()) {
|
|
1031
1037
|
await copyTemplateDir(templatePath, targetPath, data);
|
|
@@ -1040,32 +1046,32 @@ async function copyTemplateDir(templateDir, targetDir, data) {
|
|
|
1040
1046
|
}
|
|
1041
1047
|
function getProjectRoot() {
|
|
1042
1048
|
let currentDir = process.cwd();
|
|
1043
|
-
while (currentDir !==
|
|
1044
|
-
const packageJsonPath =
|
|
1049
|
+
while (currentDir !== path7__default.default.parse(currentDir).root) {
|
|
1050
|
+
const packageJsonPath = path7__default.default.join(currentDir, "package.json");
|
|
1045
1051
|
if (fs__default.default.existsSync(packageJsonPath)) {
|
|
1046
1052
|
const packageJson = fs__default.default.readJsonSync(packageJsonPath);
|
|
1047
|
-
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"))) {
|
|
1048
1054
|
return currentDir;
|
|
1049
1055
|
}
|
|
1050
1056
|
}
|
|
1051
|
-
currentDir =
|
|
1057
|
+
currentDir = path7__default.default.dirname(currentDir);
|
|
1052
1058
|
}
|
|
1053
1059
|
return process.cwd();
|
|
1054
1060
|
}
|
|
1055
1061
|
function getThemesDir() {
|
|
1056
1062
|
const root = getProjectRoot();
|
|
1057
|
-
if (fs__default.default.existsSync(
|
|
1058
|
-
return
|
|
1059
|
-
if (fs__default.default.existsSync(
|
|
1060
|
-
return
|
|
1061
|
-
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);
|
|
1062
1068
|
}
|
|
1063
1069
|
function getFeaturesDir() {
|
|
1064
|
-
return
|
|
1070
|
+
return path7__default.default.join(getProjectRoot(), "src/features");
|
|
1065
1071
|
}
|
|
1066
1072
|
function isOneXProject() {
|
|
1067
1073
|
const root = getProjectRoot();
|
|
1068
|
-
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"));
|
|
1069
1075
|
}
|
|
1070
1076
|
function ensureOneXProject() {
|
|
1071
1077
|
if (!isOneXProject()) {
|
|
@@ -1081,13 +1087,13 @@ function listThemes() {
|
|
|
1081
1087
|
return [];
|
|
1082
1088
|
}
|
|
1083
1089
|
return fs__default.default.readdirSync(themesDir).filter((name) => {
|
|
1084
|
-
const themePath =
|
|
1085
|
-
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")));
|
|
1086
1092
|
});
|
|
1087
1093
|
}
|
|
1088
1094
|
function themeExists(themeName) {
|
|
1089
|
-
const themePath =
|
|
1090
|
-
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")));
|
|
1091
1097
|
}
|
|
1092
1098
|
function detectPackageManager() {
|
|
1093
1099
|
const userAgent = process.env.npm_config_user_agent || "";
|
|
@@ -1095,9 +1101,9 @@ function detectPackageManager() {
|
|
|
1095
1101
|
if (userAgent.includes("yarn")) return "yarn";
|
|
1096
1102
|
if (userAgent.includes("bun")) return "bun";
|
|
1097
1103
|
const cwd = process.cwd();
|
|
1098
|
-
if (fs__default.default.existsSync(
|
|
1099
|
-
if (fs__default.default.existsSync(
|
|
1100
|
-
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";
|
|
1101
1107
|
return "npm";
|
|
1102
1108
|
}
|
|
1103
1109
|
async function installDependencies(projectPath, packageManager = "npm") {
|
|
@@ -1131,7 +1137,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
1131
1137
|
if (!validateThemeName(kebabName)) {
|
|
1132
1138
|
return "Invalid project name. Use lowercase letters, numbers, and hyphens only.";
|
|
1133
1139
|
}
|
|
1134
|
-
if (fs2__default.default.existsSync(
|
|
1140
|
+
if (fs2__default.default.existsSync(path7__default.default.join(process.cwd(), kebabName))) {
|
|
1135
1141
|
return `Directory "${kebabName}" already exists`;
|
|
1136
1142
|
}
|
|
1137
1143
|
return true;
|
|
@@ -1142,7 +1148,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
1142
1148
|
} else {
|
|
1143
1149
|
name = toKebabCase(projectName);
|
|
1144
1150
|
}
|
|
1145
|
-
const projectPath =
|
|
1151
|
+
const projectPath = path7__default.default.join(process.cwd(), name);
|
|
1146
1152
|
if (fs2__default.default.existsSync(projectPath)) {
|
|
1147
1153
|
exports.logger.error(`Directory "${name}" already exists.`);
|
|
1148
1154
|
process.exit(1);
|
|
@@ -1205,38 +1211,38 @@ async function initCommand(projectName, options = {}) {
|
|
|
1205
1211
|
try {
|
|
1206
1212
|
fs2__default.default.mkdirSync(projectPath, { recursive: true });
|
|
1207
1213
|
await copyTemplate(template, projectPath, data);
|
|
1208
|
-
const srcPath =
|
|
1214
|
+
const srcPath = path7__default.default.join(projectPath, "src");
|
|
1209
1215
|
fs2__default.default.mkdirSync(srcPath, { recursive: true });
|
|
1210
1216
|
const manifestContent = generateManifest(data);
|
|
1211
|
-
await writeFile(
|
|
1217
|
+
await writeFile(path7__default.default.join(srcPath, "manifest.ts"), manifestContent);
|
|
1212
1218
|
const configContent = generateThemeConfig(data);
|
|
1213
|
-
await writeFile(
|
|
1219
|
+
await writeFile(path7__default.default.join(srcPath, "config.ts"), configContent);
|
|
1214
1220
|
const layoutContent = generateThemeLayout(data);
|
|
1215
|
-
await writeFile(
|
|
1221
|
+
await writeFile(path7__default.default.join(srcPath, "layout.ts"), layoutContent);
|
|
1216
1222
|
const indexContent = generateThemeIndex(data);
|
|
1217
|
-
await writeFile(
|
|
1218
|
-
const sectionsPath =
|
|
1223
|
+
await writeFile(path7__default.default.join(srcPath, "index.ts"), indexContent);
|
|
1224
|
+
const sectionsPath = path7__default.default.join(srcPath, "sections");
|
|
1219
1225
|
fs2__default.default.mkdirSync(sectionsPath, { recursive: true });
|
|
1220
1226
|
await writeFile(
|
|
1221
|
-
|
|
1227
|
+
path7__default.default.join(sectionsPath, "README.md"),
|
|
1222
1228
|
`# ${displayName} Sections
|
|
1223
1229
|
|
|
1224
1230
|
Add your theme-specific sections here.
|
|
1225
1231
|
`
|
|
1226
1232
|
);
|
|
1227
|
-
const blocksPath =
|
|
1233
|
+
const blocksPath = path7__default.default.join(srcPath, "blocks");
|
|
1228
1234
|
fs2__default.default.mkdirSync(blocksPath, { recursive: true });
|
|
1229
1235
|
await writeFile(
|
|
1230
|
-
|
|
1236
|
+
path7__default.default.join(blocksPath, "README.md"),
|
|
1231
1237
|
`# ${displayName} Blocks
|
|
1232
1238
|
|
|
1233
1239
|
Add your theme-specific blocks here.
|
|
1234
1240
|
`
|
|
1235
1241
|
);
|
|
1236
|
-
const pagesPath =
|
|
1242
|
+
const pagesPath = path7__default.default.join(srcPath, "pages");
|
|
1237
1243
|
fs2__default.default.mkdirSync(pagesPath, { recursive: true });
|
|
1238
1244
|
const homePageContent = generateHomePage(data);
|
|
1239
|
-
await writeFile(
|
|
1245
|
+
await writeFile(path7__default.default.join(pagesPath, "home.ts"), homePageContent);
|
|
1240
1246
|
exports.logger.stopSpinner(true, "Project structure created!");
|
|
1241
1247
|
if (options.git) {
|
|
1242
1248
|
exports.logger.startSpinner("Initializing git repository...");
|
|
@@ -1535,10 +1541,10 @@ async function createSectionCommand(name, options) {
|
|
|
1535
1541
|
ensureOneXProject();
|
|
1536
1542
|
if (!options.theme) {
|
|
1537
1543
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
1538
|
-
(f) => fs__default.default.existsSync(
|
|
1544
|
+
(f) => fs__default.default.existsSync(path7__default.default.join(process.cwd(), f))
|
|
1539
1545
|
);
|
|
1540
1546
|
if (isStandaloneTheme) {
|
|
1541
|
-
options.theme =
|
|
1547
|
+
options.theme = path7__default.default.basename(process.cwd());
|
|
1542
1548
|
}
|
|
1543
1549
|
}
|
|
1544
1550
|
const sectionName = toKebabCase(name);
|
|
@@ -1601,35 +1607,35 @@ async function createSectionCommand(name, options) {
|
|
|
1601
1607
|
};
|
|
1602
1608
|
exports.logger.startSpinner("Creating section files...");
|
|
1603
1609
|
try {
|
|
1604
|
-
const themePath =
|
|
1605
|
-
const sectionPath =
|
|
1610
|
+
const themePath = path7__default.default.join(getThemesDir(), themeName);
|
|
1611
|
+
const sectionPath = path7__default.default.join(themePath, "sections", sectionName);
|
|
1606
1612
|
const schemaContent = generateSectionSchema(data);
|
|
1607
1613
|
await writeFile(
|
|
1608
|
-
|
|
1614
|
+
path7__default.default.join(sectionPath, `${sectionName}.schema.ts`),
|
|
1609
1615
|
schemaContent
|
|
1610
1616
|
);
|
|
1611
1617
|
if (createTemplate) {
|
|
1612
1618
|
const templateContent = generateSectionTemplate(data);
|
|
1613
1619
|
await writeFile(
|
|
1614
|
-
|
|
1620
|
+
path7__default.default.join(sectionPath, `${sectionName}-default.tsx`),
|
|
1615
1621
|
templateContent
|
|
1616
1622
|
);
|
|
1617
1623
|
}
|
|
1618
1624
|
const indexContent = generateSectionIndex(data, createTemplate);
|
|
1619
|
-
await writeFile(
|
|
1625
|
+
await writeFile(path7__default.default.join(sectionPath, "index.ts"), indexContent);
|
|
1620
1626
|
exports.logger.stopSpinner(true, "Section files created successfully!");
|
|
1621
1627
|
exports.logger.newLine();
|
|
1622
1628
|
exports.logger.section("Next steps:");
|
|
1623
1629
|
exports.logger.log(
|
|
1624
|
-
` 1. Edit schema: ${
|
|
1630
|
+
` 1. Edit schema: ${path7__default.default.relative(process.cwd(), path7__default.default.join(sectionPath, `${sectionName}.schema.ts`))}`
|
|
1625
1631
|
);
|
|
1626
1632
|
if (createTemplate) {
|
|
1627
1633
|
exports.logger.log(
|
|
1628
|
-
` 2. Edit template: ${
|
|
1634
|
+
` 2. Edit template: ${path7__default.default.relative(process.cwd(), path7__default.default.join(sectionPath, `${sectionName}-default.tsx`))}`
|
|
1629
1635
|
);
|
|
1630
1636
|
}
|
|
1631
1637
|
exports.logger.log(
|
|
1632
|
-
` 3. Add to theme manifest: ${
|
|
1638
|
+
` 3. Add to theme manifest: ${path7__default.default.relative(process.cwd(), path7__default.default.join(themePath, "manifest.ts"))}`
|
|
1633
1639
|
);
|
|
1634
1640
|
exports.logger.newLine();
|
|
1635
1641
|
exports.logger.success("Section created successfully!");
|
|
@@ -1777,10 +1783,10 @@ async function createBlockCommand(name, options) {
|
|
|
1777
1783
|
ensureOneXProject();
|
|
1778
1784
|
if (!options.theme) {
|
|
1779
1785
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
1780
|
-
(f) => fs__default.default.existsSync(
|
|
1786
|
+
(f) => fs__default.default.existsSync(path7__default.default.join(process.cwd(), f))
|
|
1781
1787
|
);
|
|
1782
1788
|
if (isStandaloneTheme) {
|
|
1783
|
-
options.theme =
|
|
1789
|
+
options.theme = path7__default.default.basename(process.cwd());
|
|
1784
1790
|
}
|
|
1785
1791
|
}
|
|
1786
1792
|
const blockName = toKebabCase(name);
|
|
@@ -1855,24 +1861,24 @@ async function createBlockCommand(name, options) {
|
|
|
1855
1861
|
};
|
|
1856
1862
|
exports.logger.startSpinner("Creating block files...");
|
|
1857
1863
|
try {
|
|
1858
|
-
const blockPath = scope === "shared" ?
|
|
1864
|
+
const blockPath = scope === "shared" ? path7__default.default.join(getFeaturesDir(), "blocks", blockName) : path7__default.default.join(getThemesDir(), themeName, "blocks", blockName);
|
|
1859
1865
|
const schemaContent = generateBlockSchema(data);
|
|
1860
1866
|
await writeFile(
|
|
1861
|
-
|
|
1867
|
+
path7__default.default.join(blockPath, `${blockName}.schema.ts`),
|
|
1862
1868
|
schemaContent
|
|
1863
1869
|
);
|
|
1864
1870
|
const componentContent = generateBlockComponent(data);
|
|
1865
|
-
await writeFile(
|
|
1871
|
+
await writeFile(path7__default.default.join(blockPath, `${blockName}.tsx`), componentContent);
|
|
1866
1872
|
const indexContent = generateBlockIndex(data);
|
|
1867
|
-
await writeFile(
|
|
1873
|
+
await writeFile(path7__default.default.join(blockPath, "index.ts"), indexContent);
|
|
1868
1874
|
exports.logger.stopSpinner(true, "Block files created successfully!");
|
|
1869
1875
|
exports.logger.newLine();
|
|
1870
1876
|
exports.logger.section("Next steps:");
|
|
1871
1877
|
exports.logger.log(
|
|
1872
|
-
` 1. Edit schema: ${
|
|
1878
|
+
` 1. Edit schema: ${path7__default.default.relative(process.cwd(), path7__default.default.join(blockPath, `${blockName}.schema.ts`))}`
|
|
1873
1879
|
);
|
|
1874
1880
|
exports.logger.log(
|
|
1875
|
-
` 2. Edit component: ${
|
|
1881
|
+
` 2. Edit component: ${path7__default.default.relative(process.cwd(), path7__default.default.join(blockPath, `${blockName}.tsx`))}`
|
|
1876
1882
|
);
|
|
1877
1883
|
exports.logger.log(
|
|
1878
1884
|
` 3. Register in block registry: src/lib/registry/block-registry.ts`
|
|
@@ -2050,31 +2056,31 @@ async function createComponentCommand(name, options) {
|
|
|
2050
2056
|
};
|
|
2051
2057
|
exports.logger.startSpinner("Creating component files...");
|
|
2052
2058
|
try {
|
|
2053
|
-
const componentPath =
|
|
2059
|
+
const componentPath = path7__default.default.join(
|
|
2054
2060
|
getFeaturesDir(),
|
|
2055
2061
|
"components",
|
|
2056
2062
|
componentName
|
|
2057
2063
|
);
|
|
2058
2064
|
const schemaContent = generateComponentSchema(data);
|
|
2059
2065
|
await writeFile(
|
|
2060
|
-
|
|
2066
|
+
path7__default.default.join(componentPath, `${componentName}.schema.ts`),
|
|
2061
2067
|
schemaContent
|
|
2062
2068
|
);
|
|
2063
2069
|
const componentContent = generateComponent(data);
|
|
2064
2070
|
await writeFile(
|
|
2065
|
-
|
|
2071
|
+
path7__default.default.join(componentPath, `${componentName}.tsx`),
|
|
2066
2072
|
componentContent
|
|
2067
2073
|
);
|
|
2068
2074
|
const indexContent = generateComponentIndex(data);
|
|
2069
|
-
await writeFile(
|
|
2075
|
+
await writeFile(path7__default.default.join(componentPath, "index.ts"), indexContent);
|
|
2070
2076
|
exports.logger.stopSpinner(true, "Component files created successfully!");
|
|
2071
2077
|
exports.logger.newLine();
|
|
2072
2078
|
exports.logger.section("Next steps:");
|
|
2073
2079
|
exports.logger.log(
|
|
2074
|
-
` 1. Edit schema: ${
|
|
2080
|
+
` 1. Edit schema: ${path7__default.default.relative(process.cwd(), path7__default.default.join(componentPath, `${componentName}.schema.ts`))}`
|
|
2075
2081
|
);
|
|
2076
2082
|
exports.logger.log(
|
|
2077
|
-
` 2. Edit component: ${
|
|
2083
|
+
` 2. Edit component: ${path7__default.default.relative(process.cwd(), path7__default.default.join(componentPath, `${componentName}.tsx`))}`
|
|
2078
2084
|
);
|
|
2079
2085
|
exports.logger.log(
|
|
2080
2086
|
` 3. Register in component registry: src/lib/registry/component-registry.ts`
|
|
@@ -2231,13 +2237,13 @@ async function listSections(themeFilter) {
|
|
|
2231
2237
|
return;
|
|
2232
2238
|
}
|
|
2233
2239
|
for (const theme of themes) {
|
|
2234
|
-
const sectionsDir =
|
|
2240
|
+
const sectionsDir = path7__default.default.join(getThemesDir(), theme, "sections");
|
|
2235
2241
|
if (!fs__default.default.existsSync(sectionsDir)) {
|
|
2236
2242
|
continue;
|
|
2237
2243
|
}
|
|
2238
2244
|
const sections = fs__default.default.readdirSync(sectionsDir).filter((name) => {
|
|
2239
|
-
const sectionPath =
|
|
2240
|
-
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"));
|
|
2241
2247
|
});
|
|
2242
2248
|
if (sections.length > 0) {
|
|
2243
2249
|
exports.logger.log(chalk4__default.default.cyan(`
|
|
@@ -2251,11 +2257,11 @@ async function listSections(themeFilter) {
|
|
|
2251
2257
|
}
|
|
2252
2258
|
async function listBlocks(themeFilter) {
|
|
2253
2259
|
exports.logger.section("\u{1F9F1} Blocks");
|
|
2254
|
-
const sharedBlocksDir =
|
|
2260
|
+
const sharedBlocksDir = path7__default.default.join(getFeaturesDir(), "blocks");
|
|
2255
2261
|
if (fs__default.default.existsSync(sharedBlocksDir)) {
|
|
2256
2262
|
const sharedBlocks = fs__default.default.readdirSync(sharedBlocksDir).filter((name) => {
|
|
2257
|
-
const blockPath =
|
|
2258
|
-
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"));
|
|
2259
2265
|
});
|
|
2260
2266
|
if (sharedBlocks.length > 0) {
|
|
2261
2267
|
exports.logger.log(chalk4__default.default.cyan("\n Shared:"));
|
|
@@ -2266,13 +2272,13 @@ async function listBlocks(themeFilter) {
|
|
|
2266
2272
|
}
|
|
2267
2273
|
const themes = themeFilter ? [themeFilter] : listThemes();
|
|
2268
2274
|
for (const theme of themes) {
|
|
2269
|
-
const blocksDir =
|
|
2275
|
+
const blocksDir = path7__default.default.join(getThemesDir(), theme, "blocks");
|
|
2270
2276
|
if (!fs__default.default.existsSync(blocksDir)) {
|
|
2271
2277
|
continue;
|
|
2272
2278
|
}
|
|
2273
2279
|
const blocks = fs__default.default.readdirSync(blocksDir).filter((name) => {
|
|
2274
|
-
const blockPath =
|
|
2275
|
-
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"));
|
|
2276
2282
|
});
|
|
2277
2283
|
if (blocks.length > 0) {
|
|
2278
2284
|
exports.logger.log(chalk4__default.default.cyan(`
|
|
@@ -2286,14 +2292,14 @@ async function listBlocks(themeFilter) {
|
|
|
2286
2292
|
}
|
|
2287
2293
|
async function listComponents() {
|
|
2288
2294
|
exports.logger.section("\u2699\uFE0F Components");
|
|
2289
|
-
const componentsDir =
|
|
2295
|
+
const componentsDir = path7__default.default.join(getFeaturesDir(), "components");
|
|
2290
2296
|
if (!fs__default.default.existsSync(componentsDir)) {
|
|
2291
2297
|
exports.logger.warning("No components directory found");
|
|
2292
2298
|
return;
|
|
2293
2299
|
}
|
|
2294
2300
|
const components = fs__default.default.readdirSync(componentsDir).filter((name) => {
|
|
2295
|
-
const componentPath =
|
|
2296
|
-
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"));
|
|
2297
2303
|
});
|
|
2298
2304
|
if (components.length === 0) {
|
|
2299
2305
|
exports.logger.warning("No components found");
|
|
@@ -2314,11 +2320,11 @@ async function listThemesInfo() {
|
|
|
2314
2320
|
}
|
|
2315
2321
|
exports.logger.log("");
|
|
2316
2322
|
for (const theme of themes) {
|
|
2317
|
-
const themeDir =
|
|
2323
|
+
const themeDir = path7__default.default.join(getThemesDir(), theme);
|
|
2318
2324
|
const candidates = ["theme.config.ts", "bundle-entry.ts", "manifest.ts"];
|
|
2319
2325
|
let manifestContent = "";
|
|
2320
2326
|
for (const candidate of candidates) {
|
|
2321
|
-
const candidatePath =
|
|
2327
|
+
const candidatePath = path7__default.default.join(themeDir, candidate);
|
|
2322
2328
|
if (fs__default.default.existsSync(candidatePath)) {
|
|
2323
2329
|
manifestContent = fs__default.default.readFileSync(candidatePath, "utf-8");
|
|
2324
2330
|
break;
|
|
@@ -2347,14 +2353,14 @@ async function buildCommand(options) {
|
|
|
2347
2353
|
if (options.theme) {
|
|
2348
2354
|
themeName = options.theme;
|
|
2349
2355
|
try {
|
|
2350
|
-
const workspaceThemePath =
|
|
2356
|
+
const workspaceThemePath = path7__default.default.join(getThemesDir(), themeName);
|
|
2351
2357
|
if (fs__default.default.existsSync(workspaceThemePath)) {
|
|
2352
2358
|
themePath = workspaceThemePath;
|
|
2353
2359
|
} else {
|
|
2354
|
-
themePath =
|
|
2360
|
+
themePath = path7__default.default.join(process.cwd(), themeName);
|
|
2355
2361
|
}
|
|
2356
2362
|
} catch {
|
|
2357
|
-
themePath =
|
|
2363
|
+
themePath = path7__default.default.join(process.cwd(), themeName);
|
|
2358
2364
|
}
|
|
2359
2365
|
if (!fs__default.default.existsSync(themePath)) {
|
|
2360
2366
|
exports.logger.error(`Theme "${themeName}" not found.`);
|
|
@@ -2365,10 +2371,10 @@ async function buildCommand(options) {
|
|
|
2365
2371
|
"theme.config.ts",
|
|
2366
2372
|
"bundle-entry.ts",
|
|
2367
2373
|
"manifest.ts"
|
|
2368
|
-
].some((f) => fs__default.default.existsSync(
|
|
2374
|
+
].some((f) => fs__default.default.existsSync(path7__default.default.join(process.cwd(), f)));
|
|
2369
2375
|
if (isThemeDir) {
|
|
2370
2376
|
themePath = process.cwd();
|
|
2371
|
-
themeName =
|
|
2377
|
+
themeName = path7__default.default.basename(themePath);
|
|
2372
2378
|
exports.logger.info(`Building current theme: ${themeName}`);
|
|
2373
2379
|
} else {
|
|
2374
2380
|
exports.logger.error(
|
|
@@ -2377,7 +2383,7 @@ async function buildCommand(options) {
|
|
|
2377
2383
|
process.exit(1);
|
|
2378
2384
|
}
|
|
2379
2385
|
}
|
|
2380
|
-
const packageJsonPath =
|
|
2386
|
+
const packageJsonPath = path7__default.default.join(themePath, "package.json");
|
|
2381
2387
|
const hasPkgJson = fs__default.default.existsSync(packageJsonPath);
|
|
2382
2388
|
if (!hasPkgJson) {
|
|
2383
2389
|
exports.logger.warning(
|
|
@@ -2433,9 +2439,9 @@ async function buildCommand(options) {
|
|
|
2433
2439
|
exports.logger.success("\u2713 Theme built successfully!");
|
|
2434
2440
|
exports.logger.newLine();
|
|
2435
2441
|
exports.logger.info(`Theme: ${themeName}`);
|
|
2436
|
-
const distPath =
|
|
2442
|
+
const distPath = path7__default.default.join(themePath, "dist");
|
|
2437
2443
|
if (fs__default.default.existsSync(distPath)) {
|
|
2438
|
-
exports.logger.log(`Output: ${
|
|
2444
|
+
exports.logger.log(`Output: ${path7__default.default.relative(process.cwd(), distPath)}`);
|
|
2439
2445
|
const files = fs__default.default.readdirSync(distPath);
|
|
2440
2446
|
exports.logger.log(`Files: ${files.length}`);
|
|
2441
2447
|
}
|
|
@@ -2505,11 +2511,11 @@ function getBucketName(env) {
|
|
|
2505
2511
|
return environment === "production" ? "onex-themes-prod" : "onex-themes-staging";
|
|
2506
2512
|
}
|
|
2507
2513
|
async function findCompiledThemeDir(themeId, version) {
|
|
2508
|
-
const searchPaths = [
|
|
2514
|
+
const searchPaths = [path7__default.default.resolve(process.cwd(), "dist")];
|
|
2509
2515
|
for (const dir of searchPaths) {
|
|
2510
2516
|
if (await fs__default.default.pathExists(dir)) {
|
|
2511
|
-
const hasManifest = await fs__default.default.pathExists(
|
|
2512
|
-
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"));
|
|
2513
2519
|
if (hasManifest || hasThemeEntry) {
|
|
2514
2520
|
return dir;
|
|
2515
2521
|
}
|
|
@@ -2518,7 +2524,7 @@ async function findCompiledThemeDir(themeId, version) {
|
|
|
2518
2524
|
return null;
|
|
2519
2525
|
}
|
|
2520
2526
|
async function readManifest() {
|
|
2521
|
-
const manifestTsPath =
|
|
2527
|
+
const manifestTsPath = path7__default.default.resolve(process.cwd(), "manifest.ts");
|
|
2522
2528
|
if (await fs__default.default.pathExists(manifestTsPath)) {
|
|
2523
2529
|
try {
|
|
2524
2530
|
const module = await import(manifestTsPath);
|
|
@@ -2527,7 +2533,7 @@ async function readManifest() {
|
|
|
2527
2533
|
exports.logger.warning("Failed to import manifest.ts, trying package.json");
|
|
2528
2534
|
}
|
|
2529
2535
|
}
|
|
2530
|
-
const packageJsonPath =
|
|
2536
|
+
const packageJsonPath = path7__default.default.resolve(process.cwd(), "package.json");
|
|
2531
2537
|
if (await fs__default.default.pathExists(packageJsonPath)) {
|
|
2532
2538
|
const pkg = await fs__default.default.readJson(packageJsonPath);
|
|
2533
2539
|
return {
|
|
@@ -2561,13 +2567,13 @@ async function findSourceDir(themeId, explicitDir) {
|
|
|
2561
2567
|
}
|
|
2562
2568
|
const searchPaths = [
|
|
2563
2569
|
process.cwd(),
|
|
2564
|
-
|
|
2565
|
-
|
|
2570
|
+
path7__default.default.resolve(process.cwd(), `../../themes/${themeId}`),
|
|
2571
|
+
path7__default.default.resolve(process.cwd(), `../themes/${themeId}`)
|
|
2566
2572
|
];
|
|
2567
2573
|
const markers = ["theme.config.ts", "bundle-entry.ts"];
|
|
2568
2574
|
for (const dir of searchPaths) {
|
|
2569
2575
|
for (const marker of markers) {
|
|
2570
|
-
if (await fs__default.default.pathExists(
|
|
2576
|
+
if (await fs__default.default.pathExists(path7__default.default.join(dir, marker))) {
|
|
2571
2577
|
return dir;
|
|
2572
2578
|
}
|
|
2573
2579
|
}
|
|
@@ -2619,7 +2625,7 @@ async function uploadCommand(options) {
|
|
|
2619
2625
|
spinner.succeed(`Found compiled theme at: ${compiledDir}`);
|
|
2620
2626
|
spinner.start("Creating bundle.zip...");
|
|
2621
2627
|
const tmpDir = os__default.default.tmpdir();
|
|
2622
|
-
const bundleZipPath =
|
|
2628
|
+
const bundleZipPath = path7__default.default.join(tmpDir, `${themeId}-${version}-bundle.zip`);
|
|
2623
2629
|
await createZipFromDir(compiledDir, bundleZipPath);
|
|
2624
2630
|
const bundleZipBuffer = await fs__default.default.readFile(bundleZipPath);
|
|
2625
2631
|
const bundleSizeMB = (bundleZipBuffer.length / 1024 / 1024).toFixed(2);
|
|
@@ -2673,7 +2679,7 @@ async function uploadCommand(options) {
|
|
|
2673
2679
|
if (sourceDir) {
|
|
2674
2680
|
spinner.succeed(`Found source at: ${sourceDir}`);
|
|
2675
2681
|
spinner.start("Creating source.zip...");
|
|
2676
|
-
const sourceZipPath =
|
|
2682
|
+
const sourceZipPath = path7__default.default.join(
|
|
2677
2683
|
tmpDir,
|
|
2678
2684
|
`${themeId}-${version}-source.zip`
|
|
2679
2685
|
);
|
|
@@ -2807,8 +2813,8 @@ async function resolveLatestVersion(s3Client, bucket, themeId) {
|
|
|
2807
2813
|
async function createCompatibilityFiles(outputDir, manifest) {
|
|
2808
2814
|
const entryFile = manifest.output?.entry || "bundle-entry.js";
|
|
2809
2815
|
if (entryFile !== "bundle-entry.js" && entryFile.startsWith("bundle-entry-")) {
|
|
2810
|
-
const hashedPath =
|
|
2811
|
-
const stablePath =
|
|
2816
|
+
const hashedPath = path7__default.default.join(outputDir, entryFile);
|
|
2817
|
+
const stablePath = path7__default.default.join(outputDir, "bundle-entry.js");
|
|
2812
2818
|
if (await fs__default.default.pathExists(hashedPath)) {
|
|
2813
2819
|
await fs__default.default.copy(hashedPath, stablePath);
|
|
2814
2820
|
const mapPath = hashedPath + ".map";
|
|
@@ -2817,13 +2823,13 @@ async function createCompatibilityFiles(outputDir, manifest) {
|
|
|
2817
2823
|
}
|
|
2818
2824
|
}
|
|
2819
2825
|
}
|
|
2820
|
-
const sectionsRegistryPath =
|
|
2826
|
+
const sectionsRegistryPath = path7__default.default.join(outputDir, "sections-registry.js");
|
|
2821
2827
|
const content = `// Re-export all sections from bundle-entry
|
|
2822
2828
|
// This file exists to maintain compatibility with the import path
|
|
2823
2829
|
export * from './bundle-entry.js';
|
|
2824
2830
|
`;
|
|
2825
2831
|
await fs__default.default.writeFile(sectionsRegistryPath, content, "utf-8");
|
|
2826
|
-
const pkgJsonPath =
|
|
2832
|
+
const pkgJsonPath = path7__default.default.join(outputDir, "package.json");
|
|
2827
2833
|
await fs__default.default.writeFile(pkgJsonPath, '{\n "type": "module"\n}\n', "utf-8");
|
|
2828
2834
|
}
|
|
2829
2835
|
function showDownloadFailureHelp(themeId, bucket) {
|
|
@@ -2906,7 +2912,7 @@ async function downloadCommand(options) {
|
|
|
2906
2912
|
zip.extractAllTo(outputDir, true);
|
|
2907
2913
|
const entries = zip.getEntries().filter((e) => !e.isDirectory);
|
|
2908
2914
|
spinner.succeed(`Extracted ${entries.length} files to ${outputDir}`);
|
|
2909
|
-
const manifestPath =
|
|
2915
|
+
const manifestPath = path7__default.default.join(outputDir, "manifest.json");
|
|
2910
2916
|
const manifest = await fs__default.default.readJson(manifestPath);
|
|
2911
2917
|
await createCompatibilityFiles(outputDir, manifest);
|
|
2912
2918
|
console.log();
|
|
@@ -3040,7 +3046,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3040
3046
|
const oldPrefix = `${oldName}-`;
|
|
3041
3047
|
const newPrefix = `${newName}-`;
|
|
3042
3048
|
const newDisplayName = newName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3043
|
-
const pkgPath =
|
|
3049
|
+
const pkgPath = path7__default.default.join(themeDir, "package.json");
|
|
3044
3050
|
if (await fs__default.default.pathExists(pkgPath)) {
|
|
3045
3051
|
const pkg = await fs__default.default.readJson(pkgPath);
|
|
3046
3052
|
pkg.name = `@onex-themes/${newName}`;
|
|
@@ -3053,7 +3059,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3053
3059
|
pkg.version = "1.0.0";
|
|
3054
3060
|
await fs__default.default.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3055
3061
|
}
|
|
3056
|
-
const configPath =
|
|
3062
|
+
const configPath = path7__default.default.join(themeDir, "theme.config.ts");
|
|
3057
3063
|
if (await fs__default.default.pathExists(configPath)) {
|
|
3058
3064
|
let content = await fs__default.default.readFile(configPath, "utf-8");
|
|
3059
3065
|
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
@@ -3063,7 +3069,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3063
3069
|
);
|
|
3064
3070
|
await fs__default.default.writeFile(configPath, content);
|
|
3065
3071
|
}
|
|
3066
|
-
const layoutPath =
|
|
3072
|
+
const layoutPath = path7__default.default.join(themeDir, "theme.layout.ts");
|
|
3067
3073
|
if (await fs__default.default.pathExists(layoutPath)) {
|
|
3068
3074
|
let content = await fs__default.default.readFile(layoutPath, "utf-8");
|
|
3069
3075
|
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
@@ -3076,7 +3082,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3076
3082
|
const oldDisplayName = oldName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3077
3083
|
const tsFiles = await glob.glob("**/*.ts", { cwd: themeDir, nodir: true });
|
|
3078
3084
|
for (const file of tsFiles) {
|
|
3079
|
-
const filePath =
|
|
3085
|
+
const filePath = path7__default.default.join(themeDir, file);
|
|
3080
3086
|
let content = await fs__default.default.readFile(filePath, "utf-8");
|
|
3081
3087
|
const original = content;
|
|
3082
3088
|
content = content.replace(
|
|
@@ -3105,7 +3111,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3105
3111
|
const spinner = ora__default.default("Initializing clone...").start();
|
|
3106
3112
|
try {
|
|
3107
3113
|
const bucket = options.bucket || getBucketName3(options.environment);
|
|
3108
|
-
const outputDir = options.output ||
|
|
3114
|
+
const outputDir = options.output || path7__default.default.resolve(process.cwd(), newName);
|
|
3109
3115
|
const s3Client = getS3Client3();
|
|
3110
3116
|
if (await fs__default.default.pathExists(outputDir)) {
|
|
3111
3117
|
spinner.fail(chalk4__default.default.red(`Directory already exists: ${outputDir}`));
|
|
@@ -3160,7 +3166,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3160
3166
|
spinner.succeed(
|
|
3161
3167
|
`Renamed theme: ${chalk4__default.default.gray(themeName)} \u2192 ${chalk4__default.default.cyan(newName)}`
|
|
3162
3168
|
);
|
|
3163
|
-
const envExamplePath =
|
|
3169
|
+
const envExamplePath = path7__default.default.join(outputDir, ".env.example");
|
|
3164
3170
|
if (!await fs__default.default.pathExists(envExamplePath)) {
|
|
3165
3171
|
await fs__default.default.writeFile(
|
|
3166
3172
|
envExamplePath,
|
|
@@ -3175,7 +3181,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3175
3181
|
}
|
|
3176
3182
|
if (options.install !== false) {
|
|
3177
3183
|
const hasPkgJson = await fs__default.default.pathExists(
|
|
3178
|
-
|
|
3184
|
+
path7__default.default.join(outputDir, "package.json")
|
|
3179
3185
|
);
|
|
3180
3186
|
if (hasPkgJson) {
|
|
3181
3187
|
spinner.start("Installing dependencies...");
|
|
@@ -3202,7 +3208,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3202
3208
|
console.log(chalk4__default.default.cyan(" Files: ") + chalk4__default.default.white(entries.length));
|
|
3203
3209
|
console.log();
|
|
3204
3210
|
console.log(chalk4__default.default.cyan("Next steps:"));
|
|
3205
|
-
console.log(chalk4__default.default.gray(` cd ${
|
|
3211
|
+
console.log(chalk4__default.default.gray(` cd ${path7__default.default.relative(process.cwd(), outputDir)}`));
|
|
3206
3212
|
console.log(chalk4__default.default.gray(" cp .env.example .env # then add your Company ID"));
|
|
3207
3213
|
if (options.install === false) {
|
|
3208
3214
|
console.log(chalk4__default.default.gray(" pnpm install"));
|