@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.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';
|
|
@@ -98,12 +98,12 @@ __export(compile_theme_exports, {
|
|
|
98
98
|
async function resolveNodeModulesFile(startDir, relativePath) {
|
|
99
99
|
let dir = startDir;
|
|
100
100
|
while (true) {
|
|
101
|
-
const candidate =
|
|
101
|
+
const candidate = path7.join(dir, "node_modules", relativePath);
|
|
102
102
|
try {
|
|
103
103
|
await fs6.access(candidate);
|
|
104
104
|
return candidate;
|
|
105
105
|
} catch {
|
|
106
|
-
const parent =
|
|
106
|
+
const parent = path7.dirname(dir);
|
|
107
107
|
if (parent === dir) break;
|
|
108
108
|
dir = parent;
|
|
109
109
|
}
|
|
@@ -129,10 +129,16 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
129
129
|
namedExports = exportsBySubpath[cacheKey];
|
|
130
130
|
} else {
|
|
131
131
|
const distFileName = subpath ? `${subpath}.mjs` : "index.mjs";
|
|
132
|
-
|
|
132
|
+
let distPath = await resolveNodeModulesFile(
|
|
133
133
|
themePath,
|
|
134
|
-
|
|
134
|
+
path7.join("@onexapis", "core", "dist", distFileName)
|
|
135
135
|
);
|
|
136
|
+
if (!distPath) {
|
|
137
|
+
distPath = await resolveNodeModulesFile(
|
|
138
|
+
__dirname,
|
|
139
|
+
path7.join("@onexapis", "core", "dist", distFileName)
|
|
140
|
+
);
|
|
141
|
+
}
|
|
136
142
|
try {
|
|
137
143
|
if (!distPath) throw new Error("not found");
|
|
138
144
|
const distContent = await fs6.readFile(distPath, "utf-8");
|
|
@@ -185,7 +191,7 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
185
191
|
const pages = {};
|
|
186
192
|
for (const ext of [".ts", ".js"]) {
|
|
187
193
|
try {
|
|
188
|
-
const mod = await jiti.import(
|
|
194
|
+
const mod = await jiti.import(path7.join(themePath, `theme.config${ext}`));
|
|
189
195
|
themeConfig = mod.default || mod;
|
|
190
196
|
break;
|
|
191
197
|
} catch {
|
|
@@ -193,20 +199,20 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
193
199
|
}
|
|
194
200
|
for (const ext of [".ts", ".js"]) {
|
|
195
201
|
try {
|
|
196
|
-
const mod = await jiti.import(
|
|
202
|
+
const mod = await jiti.import(path7.join(themePath, `theme.layout${ext}`));
|
|
197
203
|
layoutConfig = mod.default || mod;
|
|
198
204
|
break;
|
|
199
205
|
} catch {
|
|
200
206
|
}
|
|
201
207
|
}
|
|
202
|
-
const pagesDir =
|
|
208
|
+
const pagesDir = path7.join(themePath, "pages");
|
|
203
209
|
try {
|
|
204
210
|
const files = await fs6.readdir(pagesDir);
|
|
205
211
|
for (const file of files) {
|
|
206
212
|
if (!file.match(/\.(ts|js)$/)) continue;
|
|
207
213
|
const name = file.replace(/\.(ts|js)$/, "");
|
|
208
214
|
try {
|
|
209
|
-
const mod = await jiti.import(
|
|
215
|
+
const mod = await jiti.import(path7.join(pagesDir, file));
|
|
210
216
|
const config = mod.default || mod;
|
|
211
217
|
pages[name] = {
|
|
212
218
|
id: name,
|
|
@@ -222,7 +228,7 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
222
228
|
} catch {
|
|
223
229
|
}
|
|
224
230
|
await fs6.writeFile(
|
|
225
|
-
|
|
231
|
+
path7.join(outputDir, "theme-data.json"),
|
|
226
232
|
JSON.stringify(
|
|
227
233
|
{
|
|
228
234
|
themeId,
|
|
@@ -245,17 +251,17 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
245
251
|
logger.info(`Generated theme-data.json (${Object.keys(pages).length} pages)`);
|
|
246
252
|
}
|
|
247
253
|
async function contentHashEntry(outputDir) {
|
|
248
|
-
const entryPath =
|
|
249
|
-
const mapPath =
|
|
254
|
+
const entryPath = path7.join(outputDir, "bundle-entry.js");
|
|
255
|
+
const mapPath = path7.join(outputDir, "bundle-entry.js.map");
|
|
250
256
|
const oldFiles = await glob("bundle-entry-*.js*", { cwd: outputDir });
|
|
251
257
|
for (const f of oldFiles) {
|
|
252
|
-
await fs6.unlink(
|
|
258
|
+
await fs6.unlink(path7.join(outputDir, f));
|
|
253
259
|
}
|
|
254
260
|
let entryContent;
|
|
255
261
|
try {
|
|
256
262
|
entryContent = await fs6.readFile(entryPath, "utf-8");
|
|
257
263
|
} catch {
|
|
258
|
-
const indexPath =
|
|
264
|
+
const indexPath = path7.join(outputDir, "index.js");
|
|
259
265
|
try {
|
|
260
266
|
entryContent = await fs6.readFile(indexPath, "utf-8");
|
|
261
267
|
} catch {
|
|
@@ -264,17 +270,17 @@ async function contentHashEntry(outputDir) {
|
|
|
264
270
|
}
|
|
265
271
|
const hash2 = crypto.createHash("sha256").update(entryContent).digest("hex").slice(0, 8);
|
|
266
272
|
const hashedName2 = `bundle-entry-${hash2}.js`;
|
|
267
|
-
const indexMapPath =
|
|
273
|
+
const indexMapPath = path7.join(outputDir, "index.js.map");
|
|
268
274
|
const hashedMapName2 = `bundle-entry-${hash2}.js.map`;
|
|
269
275
|
entryContent = entryContent.replace(
|
|
270
276
|
/\/\/# sourceMappingURL=index\.js\.map/,
|
|
271
277
|
`//# sourceMappingURL=${hashedMapName2}`
|
|
272
278
|
);
|
|
273
|
-
await fs6.writeFile(
|
|
279
|
+
await fs6.writeFile(path7.join(outputDir, hashedName2), entryContent);
|
|
274
280
|
await fs6.unlink(indexPath);
|
|
275
281
|
try {
|
|
276
282
|
await fs6.access(indexMapPath);
|
|
277
|
-
await fs6.rename(indexMapPath,
|
|
283
|
+
await fs6.rename(indexMapPath, path7.join(outputDir, hashedMapName2));
|
|
278
284
|
} catch {
|
|
279
285
|
}
|
|
280
286
|
logger.info(`Entry hashed: ${hashedName2}`);
|
|
@@ -287,11 +293,11 @@ async function contentHashEntry(outputDir) {
|
|
|
287
293
|
/\/\/# sourceMappingURL=bundle-entry\.js\.map/,
|
|
288
294
|
`//# sourceMappingURL=${hashedMapName}`
|
|
289
295
|
);
|
|
290
|
-
await fs6.writeFile(
|
|
296
|
+
await fs6.writeFile(path7.join(outputDir, hashedName), entryContent);
|
|
291
297
|
await fs6.unlink(entryPath);
|
|
292
298
|
try {
|
|
293
299
|
await fs6.access(mapPath);
|
|
294
|
-
await fs6.rename(mapPath,
|
|
300
|
+
await fs6.rename(mapPath, path7.join(outputDir, hashedMapName));
|
|
295
301
|
} catch {
|
|
296
302
|
}
|
|
297
303
|
logger.info(`Entry hashed: ${hashedName}`);
|
|
@@ -303,7 +309,7 @@ async function extractDataRequirements(themePath) {
|
|
|
303
309
|
const requirements = {};
|
|
304
310
|
for (const file of schemaFiles) {
|
|
305
311
|
try {
|
|
306
|
-
const mod = await jiti.import(
|
|
312
|
+
const mod = await jiti.import(path7.join(themePath, file));
|
|
307
313
|
const exports$1 = mod;
|
|
308
314
|
for (const value of Object.values(exports$1)) {
|
|
309
315
|
if (value && typeof value === "object" && typeof value.type === "string" && value.dataRequirements && typeof value.dataRequirements === "object") {
|
|
@@ -323,7 +329,7 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
323
329
|
let themeId = themeName;
|
|
324
330
|
try {
|
|
325
331
|
const pkgContent = await fs6.readFile(
|
|
326
|
-
|
|
332
|
+
path7.join(themePath, "package.json"),
|
|
327
333
|
"utf-8"
|
|
328
334
|
);
|
|
329
335
|
const pkg = JSON.parse(pkgContent);
|
|
@@ -341,7 +347,7 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
341
347
|
const dataRequirements = await extractDataRequirements(themePath);
|
|
342
348
|
let hasThemeConfig = false;
|
|
343
349
|
try {
|
|
344
|
-
await fs6.access(
|
|
350
|
+
await fs6.access(path7.join(themePath, "theme.config.ts"));
|
|
345
351
|
hasThemeConfig = true;
|
|
346
352
|
} catch {
|
|
347
353
|
}
|
|
@@ -383,21 +389,21 @@ async function generateManifest2(themeName, themePath, outputDir) {
|
|
|
383
389
|
dataRequirements
|
|
384
390
|
};
|
|
385
391
|
await fs6.writeFile(
|
|
386
|
-
|
|
392
|
+
path7.join(outputDir, "manifest.json"),
|
|
387
393
|
JSON.stringify(manifest, null, 2)
|
|
388
394
|
);
|
|
389
395
|
}
|
|
390
396
|
async function compileStandaloneTheme(themePath, themeName) {
|
|
391
|
-
const outputDir =
|
|
392
|
-
const bundleEntry =
|
|
393
|
-
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");
|
|
394
400
|
let entryPoint = indexEntry;
|
|
395
401
|
try {
|
|
396
402
|
await fs6.access(bundleEntry);
|
|
397
403
|
entryPoint = bundleEntry;
|
|
398
404
|
} catch {
|
|
399
405
|
}
|
|
400
|
-
const shimPath =
|
|
406
|
+
const shimPath = path7.join(outputDir, ".process-shim.js");
|
|
401
407
|
await fs6.mkdir(outputDir, { recursive: true });
|
|
402
408
|
await fs6.writeFile(shimPath, PROCESS_SHIM);
|
|
403
409
|
const buildOptions = {
|
|
@@ -471,16 +477,16 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
471
477
|
}
|
|
472
478
|
}
|
|
473
479
|
async function compileStandaloneThemeDev(themePath, themeName) {
|
|
474
|
-
const outputDir =
|
|
475
|
-
const bundleEntry =
|
|
476
|
-
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");
|
|
477
483
|
let entryPoint = indexEntry;
|
|
478
484
|
try {
|
|
479
485
|
await fs6.access(bundleEntry);
|
|
480
486
|
entryPoint = bundleEntry;
|
|
481
487
|
} catch {
|
|
482
488
|
}
|
|
483
|
-
const shimPath =
|
|
489
|
+
const shimPath = path7.join(outputDir, ".process-shim.js");
|
|
484
490
|
await fs6.mkdir(outputDir, { recursive: true });
|
|
485
491
|
await fs6.writeFile(shimPath, PROCESS_SHIM);
|
|
486
492
|
const buildOptions = {
|
|
@@ -531,13 +537,13 @@ async function compileStandaloneThemeDev(themePath, themeName) {
|
|
|
531
537
|
return { context: context2, outputDir };
|
|
532
538
|
}
|
|
533
539
|
async function compilePreviewRuntime(themePath) {
|
|
534
|
-
const outputDir =
|
|
540
|
+
const outputDir = path7.join(themePath, "dist");
|
|
535
541
|
await fs6.mkdir(outputDir, { recursive: true });
|
|
536
|
-
const outputPath =
|
|
542
|
+
const outputPath = path7.join(outputDir, "preview-runtime.js");
|
|
537
543
|
const locations = [
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
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")
|
|
541
547
|
];
|
|
542
548
|
let previewEntryPath = null;
|
|
543
549
|
for (const loc of locations) {
|
|
@@ -712,7 +718,7 @@ export function headers() { return new Headers(); }
|
|
|
712
718
|
});
|
|
713
719
|
}
|
|
714
720
|
};
|
|
715
|
-
const shimPath =
|
|
721
|
+
const shimPath = path7.join(outputDir, ".process-shim-preview.js");
|
|
716
722
|
await fs6.writeFile(shimPath, PROCESS_SHIM);
|
|
717
723
|
await esbuild.build({
|
|
718
724
|
entryPoints: [previewEntryPath],
|
|
@@ -937,18 +943,18 @@ async function renderTemplate(templatePath, data) {
|
|
|
937
943
|
return ejs.render(template, data);
|
|
938
944
|
}
|
|
939
945
|
async function writeFile(filePath, content) {
|
|
940
|
-
await fs.ensureDir(
|
|
946
|
+
await fs.ensureDir(path7.dirname(filePath));
|
|
941
947
|
await fs.writeFile(filePath, content, "utf-8");
|
|
942
948
|
}
|
|
943
949
|
function getTemplatesDir() {
|
|
944
950
|
const locations = [
|
|
945
|
-
|
|
951
|
+
path7.join(__dirname, "../../templates"),
|
|
946
952
|
// Development
|
|
947
|
-
|
|
953
|
+
path7.join(__dirname, "../templates"),
|
|
948
954
|
// Production (dist/)
|
|
949
|
-
|
|
955
|
+
path7.join(process.cwd(), "templates"),
|
|
950
956
|
// Fallback
|
|
951
|
-
|
|
957
|
+
path7.join(process.cwd(), "packages/cli/templates")
|
|
952
958
|
// Monorepo
|
|
953
959
|
];
|
|
954
960
|
for (const location of locations) {
|
|
@@ -960,7 +966,7 @@ function getTemplatesDir() {
|
|
|
960
966
|
}
|
|
961
967
|
async function copyTemplate(templateName, targetDir, data) {
|
|
962
968
|
const templatesDir = getTemplatesDir();
|
|
963
|
-
const templateDir =
|
|
969
|
+
const templateDir = path7.join(templatesDir, templateName);
|
|
964
970
|
if (!fs.existsSync(templateDir)) {
|
|
965
971
|
throw new Error(
|
|
966
972
|
`Template "${templateName}" not found at ${templateDir}. Available templates: ${fs.readdirSync(templatesDir).join(", ")}`
|
|
@@ -969,8 +975,8 @@ async function copyTemplate(templateName, targetDir, data) {
|
|
|
969
975
|
await fs.ensureDir(targetDir);
|
|
970
976
|
const files = await fs.readdir(templateDir);
|
|
971
977
|
for (const file of files) {
|
|
972
|
-
const templatePath =
|
|
973
|
-
const targetPath =
|
|
978
|
+
const templatePath = path7.join(templateDir, file);
|
|
979
|
+
const targetPath = path7.join(targetDir, file);
|
|
974
980
|
const stat = await fs.stat(templatePath);
|
|
975
981
|
if (stat.isDirectory()) {
|
|
976
982
|
await copyTemplateDir(templatePath, targetPath, data);
|
|
@@ -987,8 +993,8 @@ async function copyTemplateDir(templateDir, targetDir, data) {
|
|
|
987
993
|
await fs.ensureDir(targetDir);
|
|
988
994
|
const files = await fs.readdir(templateDir);
|
|
989
995
|
for (const file of files) {
|
|
990
|
-
const templatePath =
|
|
991
|
-
const targetPath =
|
|
996
|
+
const templatePath = path7.join(templateDir, file);
|
|
997
|
+
const targetPath = path7.join(targetDir, file);
|
|
992
998
|
const stat = await fs.stat(templatePath);
|
|
993
999
|
if (stat.isDirectory()) {
|
|
994
1000
|
await copyTemplateDir(templatePath, targetPath, data);
|
|
@@ -1003,32 +1009,32 @@ async function copyTemplateDir(templateDir, targetDir, data) {
|
|
|
1003
1009
|
}
|
|
1004
1010
|
function getProjectRoot() {
|
|
1005
1011
|
let currentDir = process.cwd();
|
|
1006
|
-
while (currentDir !==
|
|
1007
|
-
const packageJsonPath =
|
|
1012
|
+
while (currentDir !== path7.parse(currentDir).root) {
|
|
1013
|
+
const packageJsonPath = path7.join(currentDir, "package.json");
|
|
1008
1014
|
if (fs.existsSync(packageJsonPath)) {
|
|
1009
1015
|
const packageJson = fs.readJsonSync(packageJsonPath);
|
|
1010
|
-
if (packageJson.workspaces || fs.existsSync(
|
|
1016
|
+
if (packageJson.workspaces || fs.existsSync(path7.join(currentDir, "src/themes")) || fs.existsSync(path7.join(currentDir, "themes"))) {
|
|
1011
1017
|
return currentDir;
|
|
1012
1018
|
}
|
|
1013
1019
|
}
|
|
1014
|
-
currentDir =
|
|
1020
|
+
currentDir = path7.dirname(currentDir);
|
|
1015
1021
|
}
|
|
1016
1022
|
return process.cwd();
|
|
1017
1023
|
}
|
|
1018
1024
|
function getThemesDir() {
|
|
1019
1025
|
const root = getProjectRoot();
|
|
1020
|
-
if (fs.existsSync(
|
|
1021
|
-
return
|
|
1022
|
-
if (fs.existsSync(
|
|
1023
|
-
return
|
|
1024
|
-
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);
|
|
1025
1031
|
}
|
|
1026
1032
|
function getFeaturesDir() {
|
|
1027
|
-
return
|
|
1033
|
+
return path7.join(getProjectRoot(), "src/features");
|
|
1028
1034
|
}
|
|
1029
1035
|
function isOneXProject() {
|
|
1030
1036
|
const root = getProjectRoot();
|
|
1031
|
-
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"));
|
|
1032
1038
|
}
|
|
1033
1039
|
function ensureOneXProject() {
|
|
1034
1040
|
if (!isOneXProject()) {
|
|
@@ -1044,13 +1050,13 @@ function listThemes() {
|
|
|
1044
1050
|
return [];
|
|
1045
1051
|
}
|
|
1046
1052
|
return fs.readdirSync(themesDir).filter((name) => {
|
|
1047
|
-
const themePath =
|
|
1048
|
-
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")));
|
|
1049
1055
|
});
|
|
1050
1056
|
}
|
|
1051
1057
|
function themeExists(themeName) {
|
|
1052
|
-
const themePath =
|
|
1053
|
-
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")));
|
|
1054
1060
|
}
|
|
1055
1061
|
function detectPackageManager() {
|
|
1056
1062
|
const userAgent = process.env.npm_config_user_agent || "";
|
|
@@ -1058,9 +1064,9 @@ function detectPackageManager() {
|
|
|
1058
1064
|
if (userAgent.includes("yarn")) return "yarn";
|
|
1059
1065
|
if (userAgent.includes("bun")) return "bun";
|
|
1060
1066
|
const cwd = process.cwd();
|
|
1061
|
-
if (fs.existsSync(
|
|
1062
|
-
if (fs.existsSync(
|
|
1063
|
-
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";
|
|
1064
1070
|
return "npm";
|
|
1065
1071
|
}
|
|
1066
1072
|
async function installDependencies(projectPath, packageManager = "npm") {
|
|
@@ -1094,7 +1100,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
1094
1100
|
if (!validateThemeName(kebabName)) {
|
|
1095
1101
|
return "Invalid project name. Use lowercase letters, numbers, and hyphens only.";
|
|
1096
1102
|
}
|
|
1097
|
-
if (fs2.existsSync(
|
|
1103
|
+
if (fs2.existsSync(path7.join(process.cwd(), kebabName))) {
|
|
1098
1104
|
return `Directory "${kebabName}" already exists`;
|
|
1099
1105
|
}
|
|
1100
1106
|
return true;
|
|
@@ -1105,7 +1111,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
1105
1111
|
} else {
|
|
1106
1112
|
name = toKebabCase(projectName);
|
|
1107
1113
|
}
|
|
1108
|
-
const projectPath =
|
|
1114
|
+
const projectPath = path7.join(process.cwd(), name);
|
|
1109
1115
|
if (fs2.existsSync(projectPath)) {
|
|
1110
1116
|
logger.error(`Directory "${name}" already exists.`);
|
|
1111
1117
|
process.exit(1);
|
|
@@ -1168,38 +1174,38 @@ async function initCommand(projectName, options = {}) {
|
|
|
1168
1174
|
try {
|
|
1169
1175
|
fs2.mkdirSync(projectPath, { recursive: true });
|
|
1170
1176
|
await copyTemplate(template, projectPath, data);
|
|
1171
|
-
const srcPath =
|
|
1177
|
+
const srcPath = path7.join(projectPath, "src");
|
|
1172
1178
|
fs2.mkdirSync(srcPath, { recursive: true });
|
|
1173
1179
|
const manifestContent = generateManifest(data);
|
|
1174
|
-
await writeFile(
|
|
1180
|
+
await writeFile(path7.join(srcPath, "manifest.ts"), manifestContent);
|
|
1175
1181
|
const configContent = generateThemeConfig(data);
|
|
1176
|
-
await writeFile(
|
|
1182
|
+
await writeFile(path7.join(srcPath, "config.ts"), configContent);
|
|
1177
1183
|
const layoutContent = generateThemeLayout(data);
|
|
1178
|
-
await writeFile(
|
|
1184
|
+
await writeFile(path7.join(srcPath, "layout.ts"), layoutContent);
|
|
1179
1185
|
const indexContent = generateThemeIndex(data);
|
|
1180
|
-
await writeFile(
|
|
1181
|
-
const sectionsPath =
|
|
1186
|
+
await writeFile(path7.join(srcPath, "index.ts"), indexContent);
|
|
1187
|
+
const sectionsPath = path7.join(srcPath, "sections");
|
|
1182
1188
|
fs2.mkdirSync(sectionsPath, { recursive: true });
|
|
1183
1189
|
await writeFile(
|
|
1184
|
-
|
|
1190
|
+
path7.join(sectionsPath, "README.md"),
|
|
1185
1191
|
`# ${displayName} Sections
|
|
1186
1192
|
|
|
1187
1193
|
Add your theme-specific sections here.
|
|
1188
1194
|
`
|
|
1189
1195
|
);
|
|
1190
|
-
const blocksPath =
|
|
1196
|
+
const blocksPath = path7.join(srcPath, "blocks");
|
|
1191
1197
|
fs2.mkdirSync(blocksPath, { recursive: true });
|
|
1192
1198
|
await writeFile(
|
|
1193
|
-
|
|
1199
|
+
path7.join(blocksPath, "README.md"),
|
|
1194
1200
|
`# ${displayName} Blocks
|
|
1195
1201
|
|
|
1196
1202
|
Add your theme-specific blocks here.
|
|
1197
1203
|
`
|
|
1198
1204
|
);
|
|
1199
|
-
const pagesPath =
|
|
1205
|
+
const pagesPath = path7.join(srcPath, "pages");
|
|
1200
1206
|
fs2.mkdirSync(pagesPath, { recursive: true });
|
|
1201
1207
|
const homePageContent = generateHomePage(data);
|
|
1202
|
-
await writeFile(
|
|
1208
|
+
await writeFile(path7.join(pagesPath, "home.ts"), homePageContent);
|
|
1203
1209
|
logger.stopSpinner(true, "Project structure created!");
|
|
1204
1210
|
if (options.git) {
|
|
1205
1211
|
logger.startSpinner("Initializing git repository...");
|
|
@@ -1498,10 +1504,10 @@ async function createSectionCommand(name, options) {
|
|
|
1498
1504
|
ensureOneXProject();
|
|
1499
1505
|
if (!options.theme) {
|
|
1500
1506
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
1501
|
-
(f) => fs.existsSync(
|
|
1507
|
+
(f) => fs.existsSync(path7.join(process.cwd(), f))
|
|
1502
1508
|
);
|
|
1503
1509
|
if (isStandaloneTheme) {
|
|
1504
|
-
options.theme =
|
|
1510
|
+
options.theme = path7.basename(process.cwd());
|
|
1505
1511
|
}
|
|
1506
1512
|
}
|
|
1507
1513
|
const sectionName = toKebabCase(name);
|
|
@@ -1564,35 +1570,35 @@ async function createSectionCommand(name, options) {
|
|
|
1564
1570
|
};
|
|
1565
1571
|
logger.startSpinner("Creating section files...");
|
|
1566
1572
|
try {
|
|
1567
|
-
const themePath =
|
|
1568
|
-
const sectionPath =
|
|
1573
|
+
const themePath = path7.join(getThemesDir(), themeName);
|
|
1574
|
+
const sectionPath = path7.join(themePath, "sections", sectionName);
|
|
1569
1575
|
const schemaContent = generateSectionSchema(data);
|
|
1570
1576
|
await writeFile(
|
|
1571
|
-
|
|
1577
|
+
path7.join(sectionPath, `${sectionName}.schema.ts`),
|
|
1572
1578
|
schemaContent
|
|
1573
1579
|
);
|
|
1574
1580
|
if (createTemplate) {
|
|
1575
1581
|
const templateContent = generateSectionTemplate(data);
|
|
1576
1582
|
await writeFile(
|
|
1577
|
-
|
|
1583
|
+
path7.join(sectionPath, `${sectionName}-default.tsx`),
|
|
1578
1584
|
templateContent
|
|
1579
1585
|
);
|
|
1580
1586
|
}
|
|
1581
1587
|
const indexContent = generateSectionIndex(data, createTemplate);
|
|
1582
|
-
await writeFile(
|
|
1588
|
+
await writeFile(path7.join(sectionPath, "index.ts"), indexContent);
|
|
1583
1589
|
logger.stopSpinner(true, "Section files created successfully!");
|
|
1584
1590
|
logger.newLine();
|
|
1585
1591
|
logger.section("Next steps:");
|
|
1586
1592
|
logger.log(
|
|
1587
|
-
` 1. Edit schema: ${
|
|
1593
|
+
` 1. Edit schema: ${path7.relative(process.cwd(), path7.join(sectionPath, `${sectionName}.schema.ts`))}`
|
|
1588
1594
|
);
|
|
1589
1595
|
if (createTemplate) {
|
|
1590
1596
|
logger.log(
|
|
1591
|
-
` 2. Edit template: ${
|
|
1597
|
+
` 2. Edit template: ${path7.relative(process.cwd(), path7.join(sectionPath, `${sectionName}-default.tsx`))}`
|
|
1592
1598
|
);
|
|
1593
1599
|
}
|
|
1594
1600
|
logger.log(
|
|
1595
|
-
` 3. Add to theme manifest: ${
|
|
1601
|
+
` 3. Add to theme manifest: ${path7.relative(process.cwd(), path7.join(themePath, "manifest.ts"))}`
|
|
1596
1602
|
);
|
|
1597
1603
|
logger.newLine();
|
|
1598
1604
|
logger.success("Section created successfully!");
|
|
@@ -1740,10 +1746,10 @@ async function createBlockCommand(name, options) {
|
|
|
1740
1746
|
ensureOneXProject();
|
|
1741
1747
|
if (!options.theme) {
|
|
1742
1748
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
1743
|
-
(f) => fs.existsSync(
|
|
1749
|
+
(f) => fs.existsSync(path7.join(process.cwd(), f))
|
|
1744
1750
|
);
|
|
1745
1751
|
if (isStandaloneTheme) {
|
|
1746
|
-
options.theme =
|
|
1752
|
+
options.theme = path7.basename(process.cwd());
|
|
1747
1753
|
}
|
|
1748
1754
|
}
|
|
1749
1755
|
const blockName = toKebabCase(name);
|
|
@@ -1818,24 +1824,24 @@ async function createBlockCommand(name, options) {
|
|
|
1818
1824
|
};
|
|
1819
1825
|
logger.startSpinner("Creating block files...");
|
|
1820
1826
|
try {
|
|
1821
|
-
const blockPath = scope === "shared" ?
|
|
1827
|
+
const blockPath = scope === "shared" ? path7.join(getFeaturesDir(), "blocks", blockName) : path7.join(getThemesDir(), themeName, "blocks", blockName);
|
|
1822
1828
|
const schemaContent = generateBlockSchema(data);
|
|
1823
1829
|
await writeFile(
|
|
1824
|
-
|
|
1830
|
+
path7.join(blockPath, `${blockName}.schema.ts`),
|
|
1825
1831
|
schemaContent
|
|
1826
1832
|
);
|
|
1827
1833
|
const componentContent = generateBlockComponent(data);
|
|
1828
|
-
await writeFile(
|
|
1834
|
+
await writeFile(path7.join(blockPath, `${blockName}.tsx`), componentContent);
|
|
1829
1835
|
const indexContent = generateBlockIndex(data);
|
|
1830
|
-
await writeFile(
|
|
1836
|
+
await writeFile(path7.join(blockPath, "index.ts"), indexContent);
|
|
1831
1837
|
logger.stopSpinner(true, "Block files created successfully!");
|
|
1832
1838
|
logger.newLine();
|
|
1833
1839
|
logger.section("Next steps:");
|
|
1834
1840
|
logger.log(
|
|
1835
|
-
` 1. Edit schema: ${
|
|
1841
|
+
` 1. Edit schema: ${path7.relative(process.cwd(), path7.join(blockPath, `${blockName}.schema.ts`))}`
|
|
1836
1842
|
);
|
|
1837
1843
|
logger.log(
|
|
1838
|
-
` 2. Edit component: ${
|
|
1844
|
+
` 2. Edit component: ${path7.relative(process.cwd(), path7.join(blockPath, `${blockName}.tsx`))}`
|
|
1839
1845
|
);
|
|
1840
1846
|
logger.log(
|
|
1841
1847
|
` 3. Register in block registry: src/lib/registry/block-registry.ts`
|
|
@@ -2013,31 +2019,31 @@ async function createComponentCommand(name, options) {
|
|
|
2013
2019
|
};
|
|
2014
2020
|
logger.startSpinner("Creating component files...");
|
|
2015
2021
|
try {
|
|
2016
|
-
const componentPath =
|
|
2022
|
+
const componentPath = path7.join(
|
|
2017
2023
|
getFeaturesDir(),
|
|
2018
2024
|
"components",
|
|
2019
2025
|
componentName
|
|
2020
2026
|
);
|
|
2021
2027
|
const schemaContent = generateComponentSchema(data);
|
|
2022
2028
|
await writeFile(
|
|
2023
|
-
|
|
2029
|
+
path7.join(componentPath, `${componentName}.schema.ts`),
|
|
2024
2030
|
schemaContent
|
|
2025
2031
|
);
|
|
2026
2032
|
const componentContent = generateComponent(data);
|
|
2027
2033
|
await writeFile(
|
|
2028
|
-
|
|
2034
|
+
path7.join(componentPath, `${componentName}.tsx`),
|
|
2029
2035
|
componentContent
|
|
2030
2036
|
);
|
|
2031
2037
|
const indexContent = generateComponentIndex(data);
|
|
2032
|
-
await writeFile(
|
|
2038
|
+
await writeFile(path7.join(componentPath, "index.ts"), indexContent);
|
|
2033
2039
|
logger.stopSpinner(true, "Component files created successfully!");
|
|
2034
2040
|
logger.newLine();
|
|
2035
2041
|
logger.section("Next steps:");
|
|
2036
2042
|
logger.log(
|
|
2037
|
-
` 1. Edit schema: ${
|
|
2043
|
+
` 1. Edit schema: ${path7.relative(process.cwd(), path7.join(componentPath, `${componentName}.schema.ts`))}`
|
|
2038
2044
|
);
|
|
2039
2045
|
logger.log(
|
|
2040
|
-
` 2. Edit component: ${
|
|
2046
|
+
` 2. Edit component: ${path7.relative(process.cwd(), path7.join(componentPath, `${componentName}.tsx`))}`
|
|
2041
2047
|
);
|
|
2042
2048
|
logger.log(
|
|
2043
2049
|
` 3. Register in component registry: src/lib/registry/component-registry.ts`
|
|
@@ -2194,13 +2200,13 @@ async function listSections(themeFilter) {
|
|
|
2194
2200
|
return;
|
|
2195
2201
|
}
|
|
2196
2202
|
for (const theme of themes) {
|
|
2197
|
-
const sectionsDir =
|
|
2203
|
+
const sectionsDir = path7.join(getThemesDir(), theme, "sections");
|
|
2198
2204
|
if (!fs.existsSync(sectionsDir)) {
|
|
2199
2205
|
continue;
|
|
2200
2206
|
}
|
|
2201
2207
|
const sections = fs.readdirSync(sectionsDir).filter((name) => {
|
|
2202
|
-
const sectionPath =
|
|
2203
|
-
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"));
|
|
2204
2210
|
});
|
|
2205
2211
|
if (sections.length > 0) {
|
|
2206
2212
|
logger.log(chalk4.cyan(`
|
|
@@ -2214,11 +2220,11 @@ async function listSections(themeFilter) {
|
|
|
2214
2220
|
}
|
|
2215
2221
|
async function listBlocks(themeFilter) {
|
|
2216
2222
|
logger.section("\u{1F9F1} Blocks");
|
|
2217
|
-
const sharedBlocksDir =
|
|
2223
|
+
const sharedBlocksDir = path7.join(getFeaturesDir(), "blocks");
|
|
2218
2224
|
if (fs.existsSync(sharedBlocksDir)) {
|
|
2219
2225
|
const sharedBlocks = fs.readdirSync(sharedBlocksDir).filter((name) => {
|
|
2220
|
-
const blockPath =
|
|
2221
|
-
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"));
|
|
2222
2228
|
});
|
|
2223
2229
|
if (sharedBlocks.length > 0) {
|
|
2224
2230
|
logger.log(chalk4.cyan("\n Shared:"));
|
|
@@ -2229,13 +2235,13 @@ async function listBlocks(themeFilter) {
|
|
|
2229
2235
|
}
|
|
2230
2236
|
const themes = themeFilter ? [themeFilter] : listThemes();
|
|
2231
2237
|
for (const theme of themes) {
|
|
2232
|
-
const blocksDir =
|
|
2238
|
+
const blocksDir = path7.join(getThemesDir(), theme, "blocks");
|
|
2233
2239
|
if (!fs.existsSync(blocksDir)) {
|
|
2234
2240
|
continue;
|
|
2235
2241
|
}
|
|
2236
2242
|
const blocks = fs.readdirSync(blocksDir).filter((name) => {
|
|
2237
|
-
const blockPath =
|
|
2238
|
-
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"));
|
|
2239
2245
|
});
|
|
2240
2246
|
if (blocks.length > 0) {
|
|
2241
2247
|
logger.log(chalk4.cyan(`
|
|
@@ -2249,14 +2255,14 @@ async function listBlocks(themeFilter) {
|
|
|
2249
2255
|
}
|
|
2250
2256
|
async function listComponents() {
|
|
2251
2257
|
logger.section("\u2699\uFE0F Components");
|
|
2252
|
-
const componentsDir =
|
|
2258
|
+
const componentsDir = path7.join(getFeaturesDir(), "components");
|
|
2253
2259
|
if (!fs.existsSync(componentsDir)) {
|
|
2254
2260
|
logger.warning("No components directory found");
|
|
2255
2261
|
return;
|
|
2256
2262
|
}
|
|
2257
2263
|
const components = fs.readdirSync(componentsDir).filter((name) => {
|
|
2258
|
-
const componentPath =
|
|
2259
|
-
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"));
|
|
2260
2266
|
});
|
|
2261
2267
|
if (components.length === 0) {
|
|
2262
2268
|
logger.warning("No components found");
|
|
@@ -2277,11 +2283,11 @@ async function listThemesInfo() {
|
|
|
2277
2283
|
}
|
|
2278
2284
|
logger.log("");
|
|
2279
2285
|
for (const theme of themes) {
|
|
2280
|
-
const themeDir =
|
|
2286
|
+
const themeDir = path7.join(getThemesDir(), theme);
|
|
2281
2287
|
const candidates = ["theme.config.ts", "bundle-entry.ts", "manifest.ts"];
|
|
2282
2288
|
let manifestContent = "";
|
|
2283
2289
|
for (const candidate of candidates) {
|
|
2284
|
-
const candidatePath =
|
|
2290
|
+
const candidatePath = path7.join(themeDir, candidate);
|
|
2285
2291
|
if (fs.existsSync(candidatePath)) {
|
|
2286
2292
|
manifestContent = fs.readFileSync(candidatePath, "utf-8");
|
|
2287
2293
|
break;
|
|
@@ -2310,14 +2316,14 @@ async function buildCommand(options) {
|
|
|
2310
2316
|
if (options.theme) {
|
|
2311
2317
|
themeName = options.theme;
|
|
2312
2318
|
try {
|
|
2313
|
-
const workspaceThemePath =
|
|
2319
|
+
const workspaceThemePath = path7.join(getThemesDir(), themeName);
|
|
2314
2320
|
if (fs.existsSync(workspaceThemePath)) {
|
|
2315
2321
|
themePath = workspaceThemePath;
|
|
2316
2322
|
} else {
|
|
2317
|
-
themePath =
|
|
2323
|
+
themePath = path7.join(process.cwd(), themeName);
|
|
2318
2324
|
}
|
|
2319
2325
|
} catch {
|
|
2320
|
-
themePath =
|
|
2326
|
+
themePath = path7.join(process.cwd(), themeName);
|
|
2321
2327
|
}
|
|
2322
2328
|
if (!fs.existsSync(themePath)) {
|
|
2323
2329
|
logger.error(`Theme "${themeName}" not found.`);
|
|
@@ -2328,10 +2334,10 @@ async function buildCommand(options) {
|
|
|
2328
2334
|
"theme.config.ts",
|
|
2329
2335
|
"bundle-entry.ts",
|
|
2330
2336
|
"manifest.ts"
|
|
2331
|
-
].some((f) => fs.existsSync(
|
|
2337
|
+
].some((f) => fs.existsSync(path7.join(process.cwd(), f)));
|
|
2332
2338
|
if (isThemeDir) {
|
|
2333
2339
|
themePath = process.cwd();
|
|
2334
|
-
themeName =
|
|
2340
|
+
themeName = path7.basename(themePath);
|
|
2335
2341
|
logger.info(`Building current theme: ${themeName}`);
|
|
2336
2342
|
} else {
|
|
2337
2343
|
logger.error(
|
|
@@ -2340,7 +2346,7 @@ async function buildCommand(options) {
|
|
|
2340
2346
|
process.exit(1);
|
|
2341
2347
|
}
|
|
2342
2348
|
}
|
|
2343
|
-
const packageJsonPath =
|
|
2349
|
+
const packageJsonPath = path7.join(themePath, "package.json");
|
|
2344
2350
|
const hasPkgJson = fs.existsSync(packageJsonPath);
|
|
2345
2351
|
if (!hasPkgJson) {
|
|
2346
2352
|
logger.warning(
|
|
@@ -2396,9 +2402,9 @@ async function buildCommand(options) {
|
|
|
2396
2402
|
logger.success("\u2713 Theme built successfully!");
|
|
2397
2403
|
logger.newLine();
|
|
2398
2404
|
logger.info(`Theme: ${themeName}`);
|
|
2399
|
-
const distPath =
|
|
2405
|
+
const distPath = path7.join(themePath, "dist");
|
|
2400
2406
|
if (fs.existsSync(distPath)) {
|
|
2401
|
-
logger.log(`Output: ${
|
|
2407
|
+
logger.log(`Output: ${path7.relative(process.cwd(), distPath)}`);
|
|
2402
2408
|
const files = fs.readdirSync(distPath);
|
|
2403
2409
|
logger.log(`Files: ${files.length}`);
|
|
2404
2410
|
}
|
|
@@ -2468,11 +2474,11 @@ function getBucketName(env) {
|
|
|
2468
2474
|
return environment === "production" ? "onex-themes-prod" : "onex-themes-staging";
|
|
2469
2475
|
}
|
|
2470
2476
|
async function findCompiledThemeDir(themeId, version) {
|
|
2471
|
-
const searchPaths = [
|
|
2477
|
+
const searchPaths = [path7.resolve(process.cwd(), "dist")];
|
|
2472
2478
|
for (const dir of searchPaths) {
|
|
2473
2479
|
if (await fs.pathExists(dir)) {
|
|
2474
|
-
const hasManifest = await fs.pathExists(
|
|
2475
|
-
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"));
|
|
2476
2482
|
if (hasManifest || hasThemeEntry) {
|
|
2477
2483
|
return dir;
|
|
2478
2484
|
}
|
|
@@ -2481,7 +2487,7 @@ async function findCompiledThemeDir(themeId, version) {
|
|
|
2481
2487
|
return null;
|
|
2482
2488
|
}
|
|
2483
2489
|
async function readManifest() {
|
|
2484
|
-
const manifestTsPath =
|
|
2490
|
+
const manifestTsPath = path7.resolve(process.cwd(), "manifest.ts");
|
|
2485
2491
|
if (await fs.pathExists(manifestTsPath)) {
|
|
2486
2492
|
try {
|
|
2487
2493
|
const module = await import(manifestTsPath);
|
|
@@ -2490,7 +2496,7 @@ async function readManifest() {
|
|
|
2490
2496
|
logger.warning("Failed to import manifest.ts, trying package.json");
|
|
2491
2497
|
}
|
|
2492
2498
|
}
|
|
2493
|
-
const packageJsonPath =
|
|
2499
|
+
const packageJsonPath = path7.resolve(process.cwd(), "package.json");
|
|
2494
2500
|
if (await fs.pathExists(packageJsonPath)) {
|
|
2495
2501
|
const pkg = await fs.readJson(packageJsonPath);
|
|
2496
2502
|
return {
|
|
@@ -2524,13 +2530,13 @@ async function findSourceDir(themeId, explicitDir) {
|
|
|
2524
2530
|
}
|
|
2525
2531
|
const searchPaths = [
|
|
2526
2532
|
process.cwd(),
|
|
2527
|
-
|
|
2528
|
-
|
|
2533
|
+
path7.resolve(process.cwd(), `../../themes/${themeId}`),
|
|
2534
|
+
path7.resolve(process.cwd(), `../themes/${themeId}`)
|
|
2529
2535
|
];
|
|
2530
2536
|
const markers = ["theme.config.ts", "bundle-entry.ts"];
|
|
2531
2537
|
for (const dir of searchPaths) {
|
|
2532
2538
|
for (const marker of markers) {
|
|
2533
|
-
if (await fs.pathExists(
|
|
2539
|
+
if (await fs.pathExists(path7.join(dir, marker))) {
|
|
2534
2540
|
return dir;
|
|
2535
2541
|
}
|
|
2536
2542
|
}
|
|
@@ -2582,7 +2588,7 @@ async function uploadCommand(options) {
|
|
|
2582
2588
|
spinner.succeed(`Found compiled theme at: ${compiledDir}`);
|
|
2583
2589
|
spinner.start("Creating bundle.zip...");
|
|
2584
2590
|
const tmpDir = os.tmpdir();
|
|
2585
|
-
const bundleZipPath =
|
|
2591
|
+
const bundleZipPath = path7.join(tmpDir, `${themeId}-${version}-bundle.zip`);
|
|
2586
2592
|
await createZipFromDir(compiledDir, bundleZipPath);
|
|
2587
2593
|
const bundleZipBuffer = await fs.readFile(bundleZipPath);
|
|
2588
2594
|
const bundleSizeMB = (bundleZipBuffer.length / 1024 / 1024).toFixed(2);
|
|
@@ -2636,7 +2642,7 @@ async function uploadCommand(options) {
|
|
|
2636
2642
|
if (sourceDir) {
|
|
2637
2643
|
spinner.succeed(`Found source at: ${sourceDir}`);
|
|
2638
2644
|
spinner.start("Creating source.zip...");
|
|
2639
|
-
const sourceZipPath =
|
|
2645
|
+
const sourceZipPath = path7.join(
|
|
2640
2646
|
tmpDir,
|
|
2641
2647
|
`${themeId}-${version}-source.zip`
|
|
2642
2648
|
);
|
|
@@ -2770,8 +2776,8 @@ async function resolveLatestVersion(s3Client, bucket, themeId) {
|
|
|
2770
2776
|
async function createCompatibilityFiles(outputDir, manifest) {
|
|
2771
2777
|
const entryFile = manifest.output?.entry || "bundle-entry.js";
|
|
2772
2778
|
if (entryFile !== "bundle-entry.js" && entryFile.startsWith("bundle-entry-")) {
|
|
2773
|
-
const hashedPath =
|
|
2774
|
-
const stablePath =
|
|
2779
|
+
const hashedPath = path7.join(outputDir, entryFile);
|
|
2780
|
+
const stablePath = path7.join(outputDir, "bundle-entry.js");
|
|
2775
2781
|
if (await fs.pathExists(hashedPath)) {
|
|
2776
2782
|
await fs.copy(hashedPath, stablePath);
|
|
2777
2783
|
const mapPath = hashedPath + ".map";
|
|
@@ -2780,13 +2786,13 @@ async function createCompatibilityFiles(outputDir, manifest) {
|
|
|
2780
2786
|
}
|
|
2781
2787
|
}
|
|
2782
2788
|
}
|
|
2783
|
-
const sectionsRegistryPath =
|
|
2789
|
+
const sectionsRegistryPath = path7.join(outputDir, "sections-registry.js");
|
|
2784
2790
|
const content = `// Re-export all sections from bundle-entry
|
|
2785
2791
|
// This file exists to maintain compatibility with the import path
|
|
2786
2792
|
export * from './bundle-entry.js';
|
|
2787
2793
|
`;
|
|
2788
2794
|
await fs.writeFile(sectionsRegistryPath, content, "utf-8");
|
|
2789
|
-
const pkgJsonPath =
|
|
2795
|
+
const pkgJsonPath = path7.join(outputDir, "package.json");
|
|
2790
2796
|
await fs.writeFile(pkgJsonPath, '{\n "type": "module"\n}\n', "utf-8");
|
|
2791
2797
|
}
|
|
2792
2798
|
function showDownloadFailureHelp(themeId, bucket) {
|
|
@@ -2869,7 +2875,7 @@ async function downloadCommand(options) {
|
|
|
2869
2875
|
zip.extractAllTo(outputDir, true);
|
|
2870
2876
|
const entries = zip.getEntries().filter((e) => !e.isDirectory);
|
|
2871
2877
|
spinner.succeed(`Extracted ${entries.length} files to ${outputDir}`);
|
|
2872
|
-
const manifestPath =
|
|
2878
|
+
const manifestPath = path7.join(outputDir, "manifest.json");
|
|
2873
2879
|
const manifest = await fs.readJson(manifestPath);
|
|
2874
2880
|
await createCompatibilityFiles(outputDir, manifest);
|
|
2875
2881
|
console.log();
|
|
@@ -3003,7 +3009,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3003
3009
|
const oldPrefix = `${oldName}-`;
|
|
3004
3010
|
const newPrefix = `${newName}-`;
|
|
3005
3011
|
const newDisplayName = newName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3006
|
-
const pkgPath =
|
|
3012
|
+
const pkgPath = path7.join(themeDir, "package.json");
|
|
3007
3013
|
if (await fs.pathExists(pkgPath)) {
|
|
3008
3014
|
const pkg = await fs.readJson(pkgPath);
|
|
3009
3015
|
pkg.name = `@onex-themes/${newName}`;
|
|
@@ -3016,7 +3022,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3016
3022
|
pkg.version = "1.0.0";
|
|
3017
3023
|
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3018
3024
|
}
|
|
3019
|
-
const configPath =
|
|
3025
|
+
const configPath = path7.join(themeDir, "theme.config.ts");
|
|
3020
3026
|
if (await fs.pathExists(configPath)) {
|
|
3021
3027
|
let content = await fs.readFile(configPath, "utf-8");
|
|
3022
3028
|
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
@@ -3026,7 +3032,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3026
3032
|
);
|
|
3027
3033
|
await fs.writeFile(configPath, content);
|
|
3028
3034
|
}
|
|
3029
|
-
const layoutPath =
|
|
3035
|
+
const layoutPath = path7.join(themeDir, "theme.layout.ts");
|
|
3030
3036
|
if (await fs.pathExists(layoutPath)) {
|
|
3031
3037
|
let content = await fs.readFile(layoutPath, "utf-8");
|
|
3032
3038
|
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
@@ -3039,7 +3045,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3039
3045
|
const oldDisplayName = oldName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3040
3046
|
const tsFiles = await glob("**/*.ts", { cwd: themeDir, nodir: true });
|
|
3041
3047
|
for (const file of tsFiles) {
|
|
3042
|
-
const filePath =
|
|
3048
|
+
const filePath = path7.join(themeDir, file);
|
|
3043
3049
|
let content = await fs.readFile(filePath, "utf-8");
|
|
3044
3050
|
const original = content;
|
|
3045
3051
|
content = content.replace(
|
|
@@ -3068,7 +3074,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3068
3074
|
const spinner = ora("Initializing clone...").start();
|
|
3069
3075
|
try {
|
|
3070
3076
|
const bucket = options.bucket || getBucketName3(options.environment);
|
|
3071
|
-
const outputDir = options.output ||
|
|
3077
|
+
const outputDir = options.output || path7.resolve(process.cwd(), newName);
|
|
3072
3078
|
const s3Client = getS3Client3();
|
|
3073
3079
|
if (await fs.pathExists(outputDir)) {
|
|
3074
3080
|
spinner.fail(chalk4.red(`Directory already exists: ${outputDir}`));
|
|
@@ -3123,7 +3129,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3123
3129
|
spinner.succeed(
|
|
3124
3130
|
`Renamed theme: ${chalk4.gray(themeName)} \u2192 ${chalk4.cyan(newName)}`
|
|
3125
3131
|
);
|
|
3126
|
-
const envExamplePath =
|
|
3132
|
+
const envExamplePath = path7.join(outputDir, ".env.example");
|
|
3127
3133
|
if (!await fs.pathExists(envExamplePath)) {
|
|
3128
3134
|
await fs.writeFile(
|
|
3129
3135
|
envExamplePath,
|
|
@@ -3138,7 +3144,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3138
3144
|
}
|
|
3139
3145
|
if (options.install !== false) {
|
|
3140
3146
|
const hasPkgJson = await fs.pathExists(
|
|
3141
|
-
|
|
3147
|
+
path7.join(outputDir, "package.json")
|
|
3142
3148
|
);
|
|
3143
3149
|
if (hasPkgJson) {
|
|
3144
3150
|
spinner.start("Installing dependencies...");
|
|
@@ -3165,7 +3171,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3165
3171
|
console.log(chalk4.cyan(" Files: ") + chalk4.white(entries.length));
|
|
3166
3172
|
console.log();
|
|
3167
3173
|
console.log(chalk4.cyan("Next steps:"));
|
|
3168
|
-
console.log(chalk4.gray(` cd ${
|
|
3174
|
+
console.log(chalk4.gray(` cd ${path7.relative(process.cwd(), outputDir)}`));
|
|
3169
3175
|
console.log(chalk4.gray(" cp .env.example .env # then add your Company ID"));
|
|
3170
3176
|
if (options.install === false) {
|
|
3171
3177
|
console.log(chalk4.gray(" pnpm install"));
|