@onexapis/cli 1.0.4 → 1.1.1
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/README.md +65 -63
- package/dist/cli.js +1150 -105
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1125 -103
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1018 -237
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +852 -90
- package/dist/index.mjs.map +1 -1
- package/dist/preview/preview-app.tsx +368 -0
- package/package.json +7 -2
package/dist/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chalk4 = require('chalk');
|
|
4
|
+
var ora = require('ora');
|
|
5
|
+
var esbuild = require('esbuild');
|
|
3
6
|
var path = require('path');
|
|
7
|
+
var fs6 = require('fs/promises');
|
|
8
|
+
var crypto = require('crypto');
|
|
9
|
+
var glob = require('glob');
|
|
4
10
|
var fs2 = require('fs');
|
|
5
11
|
var child_process = require('child_process');
|
|
6
12
|
var inquirer = require('inquirer');
|
|
7
|
-
var chalk4 = require('chalk');
|
|
8
|
-
var ora = require('ora');
|
|
9
13
|
var fs = require('fs-extra');
|
|
10
14
|
var ejs = require('ejs');
|
|
11
15
|
var clientS3 = require('@aws-sdk/client-s3');
|
|
@@ -15,17 +19,40 @@ var AdmZip = require('adm-zip');
|
|
|
15
19
|
|
|
16
20
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
21
|
|
|
22
|
+
function _interopNamespace(e) {
|
|
23
|
+
if (e && e.__esModule) return e;
|
|
24
|
+
var n = Object.create(null);
|
|
25
|
+
if (e) {
|
|
26
|
+
Object.keys(e).forEach(function (k) {
|
|
27
|
+
if (k !== 'default') {
|
|
28
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
29
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () { return e[k]; }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
n.default = e;
|
|
37
|
+
return Object.freeze(n);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var chalk4__default = /*#__PURE__*/_interopDefault(chalk4);
|
|
41
|
+
var ora__default = /*#__PURE__*/_interopDefault(ora);
|
|
42
|
+
var esbuild__namespace = /*#__PURE__*/_interopNamespace(esbuild);
|
|
18
43
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
44
|
+
var fs6__default = /*#__PURE__*/_interopDefault(fs6);
|
|
45
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
19
46
|
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
20
47
|
var inquirer__default = /*#__PURE__*/_interopDefault(inquirer);
|
|
21
|
-
var chalk4__default = /*#__PURE__*/_interopDefault(chalk4);
|
|
22
|
-
var ora__default = /*#__PURE__*/_interopDefault(ora);
|
|
23
48
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
24
49
|
var ejs__default = /*#__PURE__*/_interopDefault(ejs);
|
|
25
50
|
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
26
51
|
var archiver__default = /*#__PURE__*/_interopDefault(archiver);
|
|
27
52
|
var AdmZip__default = /*#__PURE__*/_interopDefault(AdmZip);
|
|
28
53
|
|
|
54
|
+
var __defProp = Object.defineProperty;
|
|
55
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
29
56
|
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
|
|
30
57
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
31
58
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -33,58 +60,703 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
33
60
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
34
61
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
35
62
|
});
|
|
63
|
+
var __esm = (fn, res) => function __init() {
|
|
64
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
65
|
+
};
|
|
66
|
+
var __export = (target, all) => {
|
|
67
|
+
for (var name in all)
|
|
68
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
69
|
+
};
|
|
36
70
|
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
71
|
+
exports.Logger = void 0; exports.logger = void 0;
|
|
72
|
+
var init_logger = __esm({
|
|
73
|
+
"src/utils/logger.ts"() {
|
|
74
|
+
exports.Logger = class {
|
|
75
|
+
constructor() {
|
|
76
|
+
this.spinner = null;
|
|
77
|
+
}
|
|
78
|
+
success(message) {
|
|
79
|
+
console.log(chalk4__default.default.green("\u2713"), message);
|
|
80
|
+
}
|
|
81
|
+
error(message) {
|
|
82
|
+
console.log(chalk4__default.default.red("\u2717"), message);
|
|
83
|
+
}
|
|
84
|
+
warning(message) {
|
|
85
|
+
console.log(chalk4__default.default.yellow("\u26A0"), message);
|
|
86
|
+
}
|
|
87
|
+
info(message) {
|
|
88
|
+
console.log(chalk4__default.default.blue("\u2139"), message);
|
|
89
|
+
}
|
|
90
|
+
log(message) {
|
|
91
|
+
console.log(message);
|
|
92
|
+
}
|
|
93
|
+
startSpinner(message) {
|
|
94
|
+
this.spinner = ora__default.default(message).start();
|
|
95
|
+
}
|
|
96
|
+
stopSpinner(success = true, message) {
|
|
97
|
+
if (!this.spinner) return;
|
|
98
|
+
if (success) {
|
|
99
|
+
this.spinner.succeed(message);
|
|
100
|
+
} else {
|
|
101
|
+
this.spinner.fail(message);
|
|
102
|
+
}
|
|
103
|
+
this.spinner = null;
|
|
104
|
+
}
|
|
105
|
+
updateSpinner(message) {
|
|
106
|
+
if (this.spinner) {
|
|
107
|
+
this.spinner.text = message;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
newLine() {
|
|
111
|
+
console.log();
|
|
112
|
+
}
|
|
113
|
+
header(message) {
|
|
114
|
+
console.log();
|
|
115
|
+
console.log(chalk4__default.default.bold.cyan(message));
|
|
116
|
+
console.log(chalk4__default.default.cyan("=".repeat(message.length)));
|
|
117
|
+
console.log();
|
|
118
|
+
}
|
|
119
|
+
section(message) {
|
|
120
|
+
console.log();
|
|
121
|
+
console.log(chalk4__default.default.bold(message));
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
exports.logger = new exports.Logger();
|
|
46
125
|
}
|
|
47
|
-
|
|
48
|
-
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// src/utils/compile-theme.ts
|
|
129
|
+
var compile_theme_exports = {};
|
|
130
|
+
__export(compile_theme_exports, {
|
|
131
|
+
compilePreviewRuntime: () => compilePreviewRuntime,
|
|
132
|
+
compileStandaloneTheme: () => compileStandaloneTheme,
|
|
133
|
+
compileStandaloneThemeDev: () => compileStandaloneThemeDev,
|
|
134
|
+
generateManifest: () => generateManifest2
|
|
135
|
+
});
|
|
136
|
+
async function resolveNodeModulesFile(startDir, relativePath) {
|
|
137
|
+
let dir = startDir;
|
|
138
|
+
while (true) {
|
|
139
|
+
const candidate = path__default.default.join(dir, "node_modules", relativePath);
|
|
140
|
+
try {
|
|
141
|
+
await fs6__default.default.access(candidate);
|
|
142
|
+
return candidate;
|
|
143
|
+
} catch (e) {
|
|
144
|
+
const parent = path__default.default.dirname(dir);
|
|
145
|
+
if (parent === dir) break;
|
|
146
|
+
dir = parent;
|
|
147
|
+
}
|
|
49
148
|
}
|
|
50
|
-
|
|
51
|
-
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
function createCoreGlobalPlugin(themePath) {
|
|
152
|
+
const exportsBySubpath = {};
|
|
153
|
+
return {
|
|
154
|
+
name: "core-global",
|
|
155
|
+
setup(build2) {
|
|
156
|
+
build2.onResolve({ filter: /^@onexapis\/core(\/.*)?$/ }, (args) => ({
|
|
157
|
+
path: args.path,
|
|
158
|
+
namespace: "core-global"
|
|
159
|
+
}));
|
|
160
|
+
build2.onLoad({ filter: /.*/, namespace: "core-global" }, async (args) => {
|
|
161
|
+
const match = args.path.match(/^@onexapis\/core(\/(.+))?$/);
|
|
162
|
+
const subpath = (match == null ? void 0 : match[2]) || "";
|
|
163
|
+
const moduleAccess = subpath ? `['${subpath}']` : "";
|
|
164
|
+
let namedExports = [];
|
|
165
|
+
const cacheKey = subpath || "__root__";
|
|
166
|
+
if (exportsBySubpath[cacheKey]) {
|
|
167
|
+
namedExports = exportsBySubpath[cacheKey];
|
|
168
|
+
} else {
|
|
169
|
+
const distFileName = subpath ? `${subpath}.mjs` : "index.mjs";
|
|
170
|
+
const distPath = await resolveNodeModulesFile(
|
|
171
|
+
themePath,
|
|
172
|
+
path__default.default.join("@onexapis", "core", "dist", distFileName)
|
|
173
|
+
);
|
|
174
|
+
try {
|
|
175
|
+
if (!distPath) throw new Error("not found");
|
|
176
|
+
const distContent = await fs6__default.default.readFile(distPath, "utf-8");
|
|
177
|
+
const exportMatches = distContent.matchAll(/export\s*\{([^}]+)\}/g);
|
|
178
|
+
for (const m of exportMatches) {
|
|
179
|
+
const names = m[1].split(",").map((n) => {
|
|
180
|
+
const parts = n.trim().split(/\s+as\s+/);
|
|
181
|
+
return (parts[1] || parts[0]).trim();
|
|
182
|
+
}).filter((n) => n.length > 0);
|
|
183
|
+
namedExports.push(...names);
|
|
184
|
+
}
|
|
185
|
+
namedExports = [...new Set(namedExports)];
|
|
186
|
+
} catch (e) {
|
|
187
|
+
}
|
|
188
|
+
exportsBySubpath[cacheKey] = namedExports;
|
|
189
|
+
}
|
|
190
|
+
const namedExportLines = namedExports.length > 0 ? `
|
|
191
|
+
export const {
|
|
192
|
+
${namedExports.join(",\n ")}
|
|
193
|
+
} = _module;
|
|
194
|
+
` : "";
|
|
195
|
+
return {
|
|
196
|
+
contents: `
|
|
197
|
+
if (!globalThis.__ONEX_CORE__) {
|
|
198
|
+
throw new Error('[Theme Bundle] @onexapis/core not initialized. Ensure globalThis.__ONEX_CORE__ is set before loading theme.');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const _module = globalThis.__ONEX_CORE__${moduleAccess};
|
|
202
|
+
if (!_module) {
|
|
203
|
+
const subpath = ${subpath ? `'${subpath}'` : "null"};
|
|
204
|
+
const modulePath = subpath ? '/' + subpath : '';
|
|
205
|
+
const moduleKey = subpath ? '["' + subpath + '"]' : '';
|
|
206
|
+
throw new Error('[Theme Bundle] @onexapis/core' + modulePath + ' not available in globalThis.__ONEX_CORE__' + moduleKey);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export default _module;
|
|
210
|
+
${namedExportLines}
|
|
211
|
+
`.trim(),
|
|
212
|
+
loader: "js"
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
async function contentHashEntry(outputDir) {
|
|
219
|
+
const entryPath = path__default.default.join(outputDir, "bundle-entry.js");
|
|
220
|
+
const mapPath = path__default.default.join(outputDir, "bundle-entry.js.map");
|
|
221
|
+
const oldFiles = await glob.glob("bundle-entry-*.js*", { cwd: outputDir });
|
|
222
|
+
for (const f of oldFiles) {
|
|
223
|
+
await fs6__default.default.unlink(path__default.default.join(outputDir, f));
|
|
52
224
|
}
|
|
53
|
-
|
|
54
|
-
|
|
225
|
+
let entryContent;
|
|
226
|
+
try {
|
|
227
|
+
entryContent = await fs6__default.default.readFile(entryPath, "utf-8");
|
|
228
|
+
} catch (e) {
|
|
229
|
+
const indexPath = path__default.default.join(outputDir, "index.js");
|
|
230
|
+
try {
|
|
231
|
+
entryContent = await fs6__default.default.readFile(indexPath, "utf-8");
|
|
232
|
+
} catch (e2) {
|
|
233
|
+
exports.logger.warning("No entry file found in output, skipping content hash");
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const hash2 = crypto__default.default.createHash("sha256").update(entryContent).digest("hex").slice(0, 8);
|
|
237
|
+
const hashedName2 = `bundle-entry-${hash2}.js`;
|
|
238
|
+
const indexMapPath = path__default.default.join(outputDir, "index.js.map");
|
|
239
|
+
const hashedMapName2 = `bundle-entry-${hash2}.js.map`;
|
|
240
|
+
entryContent = entryContent.replace(
|
|
241
|
+
/\/\/# sourceMappingURL=index\.js\.map/,
|
|
242
|
+
`//# sourceMappingURL=${hashedMapName2}`
|
|
243
|
+
);
|
|
244
|
+
await fs6__default.default.writeFile(path__default.default.join(outputDir, hashedName2), entryContent);
|
|
245
|
+
await fs6__default.default.unlink(indexPath);
|
|
246
|
+
try {
|
|
247
|
+
await fs6__default.default.access(indexMapPath);
|
|
248
|
+
await fs6__default.default.rename(indexMapPath, path__default.default.join(outputDir, hashedMapName2));
|
|
249
|
+
} catch (e2) {
|
|
250
|
+
}
|
|
251
|
+
exports.logger.info(`Entry hashed: ${hashedName2}`);
|
|
252
|
+
return;
|
|
55
253
|
}
|
|
56
|
-
|
|
57
|
-
|
|
254
|
+
const hash = crypto__default.default.createHash("sha256").update(entryContent).digest("hex").slice(0, 8);
|
|
255
|
+
const hashedName = `bundle-entry-${hash}.js`;
|
|
256
|
+
const hashedMapName = `bundle-entry-${hash}.js.map`;
|
|
257
|
+
entryContent = entryContent.replace(
|
|
258
|
+
/\/\/# sourceMappingURL=bundle-entry\.js\.map/,
|
|
259
|
+
`//# sourceMappingURL=${hashedMapName}`
|
|
260
|
+
);
|
|
261
|
+
await fs6__default.default.writeFile(path__default.default.join(outputDir, hashedName), entryContent);
|
|
262
|
+
await fs6__default.default.unlink(entryPath);
|
|
263
|
+
try {
|
|
264
|
+
await fs6__default.default.access(mapPath);
|
|
265
|
+
await fs6__default.default.rename(mapPath, path__default.default.join(outputDir, hashedMapName));
|
|
266
|
+
} catch (e) {
|
|
58
267
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
268
|
+
exports.logger.info(`Entry hashed: ${hashedName}`);
|
|
269
|
+
}
|
|
270
|
+
async function generateManifest2(themeName, themePath, outputDir) {
|
|
271
|
+
let version = "1.0.0";
|
|
272
|
+
let themeId = themeName;
|
|
273
|
+
try {
|
|
274
|
+
const pkgContent = await fs6__default.default.readFile(
|
|
275
|
+
path__default.default.join(themePath, "package.json"),
|
|
276
|
+
"utf-8"
|
|
277
|
+
);
|
|
278
|
+
const pkg = JSON.parse(pkgContent);
|
|
279
|
+
version = pkg.version || version;
|
|
280
|
+
if (pkg.name) {
|
|
281
|
+
themeId = pkg.name.replace(/^@onex-themes\//, "");
|
|
65
282
|
}
|
|
66
|
-
|
|
283
|
+
} catch (e) {
|
|
67
284
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
285
|
+
const [sectionFiles, blockFiles, schemaFiles] = await Promise.all([
|
|
286
|
+
glob.glob("sections/**/index.ts", { cwd: themePath }),
|
|
287
|
+
glob.glob("blocks/**/index.ts", { cwd: themePath }),
|
|
288
|
+
glob.glob("**/*.schema.ts", { cwd: themePath })
|
|
289
|
+
]);
|
|
290
|
+
let hasThemeConfig = false;
|
|
291
|
+
try {
|
|
292
|
+
await fs6__default.default.access(path__default.default.join(themePath, "theme.config.ts"));
|
|
293
|
+
hasThemeConfig = true;
|
|
294
|
+
} catch (e) {
|
|
295
|
+
}
|
|
296
|
+
const allFiles = await glob.glob("**/*", { cwd: outputDir, nodir: true });
|
|
297
|
+
const jsFiles = allFiles.filter((f) => f.endsWith(".js"));
|
|
298
|
+
const cssFiles = allFiles.filter((f) => f.endsWith(".css"));
|
|
299
|
+
const entryFile = jsFiles.find((f) => f.includes("bundle-entry")) || "bundle-entry.js";
|
|
300
|
+
const manifest = {
|
|
301
|
+
themeId,
|
|
302
|
+
version,
|
|
303
|
+
name: themeId.charAt(0).toUpperCase() + themeId.slice(1),
|
|
304
|
+
compiledAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
305
|
+
format: "esm",
|
|
306
|
+
platform: "browser",
|
|
307
|
+
target: "es2020",
|
|
308
|
+
counts: {
|
|
309
|
+
sections: sectionFiles.length,
|
|
310
|
+
blocks: blockFiles.length,
|
|
311
|
+
schemas: schemaFiles.length
|
|
312
|
+
},
|
|
313
|
+
output: {
|
|
314
|
+
entry: entryFile,
|
|
315
|
+
chunks: jsFiles.filter((f) => f !== entryFile && !f.endsWith(".map")),
|
|
316
|
+
assets: allFiles.filter(
|
|
317
|
+
(f) => [".png", ".jpg", ".jpeg", ".svg", ".gif", ".webp"].some(
|
|
318
|
+
(ext) => f.endsWith(ext)
|
|
319
|
+
)
|
|
320
|
+
),
|
|
321
|
+
stylesheets: cssFiles
|
|
322
|
+
},
|
|
323
|
+
external: ["react", "react-dom", "@onexapis/core"],
|
|
324
|
+
source: {
|
|
325
|
+
sections: sectionFiles,
|
|
326
|
+
blocks: blockFiles,
|
|
327
|
+
schemas: schemaFiles,
|
|
328
|
+
hasThemeConfig
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
await fs6__default.default.writeFile(
|
|
332
|
+
path__default.default.join(outputDir, "manifest.json"),
|
|
333
|
+
JSON.stringify(manifest, null, 2)
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
async function compileStandaloneTheme(themePath, themeName) {
|
|
337
|
+
const outputDir = path__default.default.join(themePath, "dist");
|
|
338
|
+
const bundleEntry = path__default.default.join(themePath, "bundle-entry.ts");
|
|
339
|
+
const indexEntry = path__default.default.join(themePath, "index.ts");
|
|
340
|
+
let entryPoint = indexEntry;
|
|
341
|
+
try {
|
|
342
|
+
await fs6__default.default.access(bundleEntry);
|
|
343
|
+
entryPoint = bundleEntry;
|
|
344
|
+
} catch (e) {
|
|
345
|
+
}
|
|
346
|
+
const shimPath = path__default.default.join(outputDir, ".process-shim.js");
|
|
347
|
+
await fs6__default.default.mkdir(outputDir, { recursive: true });
|
|
348
|
+
await fs6__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
349
|
+
const buildOptions = {
|
|
350
|
+
entryPoints: [entryPoint],
|
|
351
|
+
bundle: true,
|
|
352
|
+
platform: "browser",
|
|
353
|
+
format: "esm",
|
|
354
|
+
outdir: outputDir,
|
|
355
|
+
splitting: false,
|
|
356
|
+
chunkNames: "[name]-[hash]",
|
|
357
|
+
banner: {
|
|
358
|
+
js: '"use client";'
|
|
359
|
+
},
|
|
360
|
+
plugins: [reactGlobalPlugin, createCoreGlobalPlugin(themePath)],
|
|
361
|
+
external: [],
|
|
362
|
+
alias: {
|
|
363
|
+
events: "events/",
|
|
364
|
+
buffer: "buffer/"
|
|
365
|
+
},
|
|
366
|
+
inject: [shimPath],
|
|
367
|
+
define: {
|
|
368
|
+
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
369
|
+
global: "globalThis"
|
|
370
|
+
},
|
|
371
|
+
minify: true,
|
|
372
|
+
sourcemap: true,
|
|
373
|
+
logLevel: "warning",
|
|
374
|
+
target: "es2020",
|
|
375
|
+
jsx: "automatic",
|
|
376
|
+
jsxImportSource: "react",
|
|
377
|
+
loader: {
|
|
378
|
+
".tsx": "tsx",
|
|
379
|
+
".ts": "ts",
|
|
380
|
+
".jpg": "file",
|
|
381
|
+
".jpeg": "file",
|
|
382
|
+
".png": "file",
|
|
383
|
+
".gif": "file",
|
|
384
|
+
".svg": "file",
|
|
385
|
+
".webp": "file"
|
|
386
|
+
},
|
|
387
|
+
assetNames: "assets/[name]-[hash]",
|
|
388
|
+
publicPath: "./",
|
|
389
|
+
metafile: true
|
|
390
|
+
};
|
|
391
|
+
try {
|
|
392
|
+
const result = await esbuild__namespace.build(buildOptions);
|
|
393
|
+
try {
|
|
394
|
+
await fs6__default.default.unlink(shimPath);
|
|
395
|
+
} catch (e) {
|
|
396
|
+
}
|
|
397
|
+
await contentHashEntry(outputDir);
|
|
398
|
+
await generateManifest2(themeName, themePath, outputDir);
|
|
399
|
+
if (result.metafile) {
|
|
400
|
+
const outputs = result.metafile.outputs;
|
|
401
|
+
let totalSize = 0;
|
|
402
|
+
for (const output of Object.values(outputs)) {
|
|
403
|
+
totalSize += output.bytes;
|
|
404
|
+
}
|
|
405
|
+
const totalKB = (totalSize / 1024).toFixed(2);
|
|
406
|
+
exports.logger.info(`Bundle size: ${totalKB} KB`);
|
|
407
|
+
}
|
|
408
|
+
return true;
|
|
409
|
+
} catch (error) {
|
|
410
|
+
try {
|
|
411
|
+
await fs6__default.default.unlink(shimPath);
|
|
412
|
+
} catch (e) {
|
|
71
413
|
}
|
|
414
|
+
exports.logger.error(`esbuild compilation failed: ${error}`);
|
|
415
|
+
return false;
|
|
72
416
|
}
|
|
73
|
-
|
|
74
|
-
|
|
417
|
+
}
|
|
418
|
+
async function compileStandaloneThemeDev(themePath, themeName) {
|
|
419
|
+
const outputDir = path__default.default.join(themePath, "dist");
|
|
420
|
+
const bundleEntry = path__default.default.join(themePath, "bundle-entry.ts");
|
|
421
|
+
const indexEntry = path__default.default.join(themePath, "index.ts");
|
|
422
|
+
let entryPoint = indexEntry;
|
|
423
|
+
try {
|
|
424
|
+
await fs6__default.default.access(bundleEntry);
|
|
425
|
+
entryPoint = bundleEntry;
|
|
426
|
+
} catch (e) {
|
|
427
|
+
}
|
|
428
|
+
const shimPath = path__default.default.join(outputDir, ".process-shim.js");
|
|
429
|
+
await fs6__default.default.mkdir(outputDir, { recursive: true });
|
|
430
|
+
await fs6__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
431
|
+
const buildOptions = {
|
|
432
|
+
entryPoints: [entryPoint],
|
|
433
|
+
bundle: true,
|
|
434
|
+
platform: "browser",
|
|
435
|
+
format: "esm",
|
|
436
|
+
outdir: outputDir,
|
|
437
|
+
splitting: false,
|
|
438
|
+
banner: {
|
|
439
|
+
js: '"use client";'
|
|
440
|
+
},
|
|
441
|
+
plugins: [reactGlobalPlugin, createCoreGlobalPlugin(themePath)],
|
|
442
|
+
external: [],
|
|
443
|
+
alias: {
|
|
444
|
+
events: "events/",
|
|
445
|
+
buffer: "buffer/"
|
|
446
|
+
},
|
|
447
|
+
inject: [shimPath],
|
|
448
|
+
define: {
|
|
449
|
+
"process.env.NODE_ENV": JSON.stringify("development"),
|
|
450
|
+
global: "globalThis"
|
|
451
|
+
},
|
|
452
|
+
minify: false,
|
|
453
|
+
sourcemap: true,
|
|
454
|
+
logLevel: "warning",
|
|
455
|
+
target: "es2020",
|
|
456
|
+
jsx: "automatic",
|
|
457
|
+
jsxImportSource: "react",
|
|
458
|
+
loader: {
|
|
459
|
+
".tsx": "tsx",
|
|
460
|
+
".ts": "ts",
|
|
461
|
+
".jpg": "file",
|
|
462
|
+
".jpeg": "file",
|
|
463
|
+
".png": "file",
|
|
464
|
+
".gif": "file",
|
|
465
|
+
".svg": "file",
|
|
466
|
+
".webp": "file"
|
|
467
|
+
},
|
|
468
|
+
assetNames: "assets/[name]-[hash]",
|
|
469
|
+
publicPath: "./",
|
|
470
|
+
metafile: true
|
|
471
|
+
};
|
|
472
|
+
const context2 = await esbuild__namespace.context(buildOptions);
|
|
473
|
+
await context2.rebuild();
|
|
474
|
+
await generateManifest2(themeName, themePath, outputDir);
|
|
475
|
+
return { context: context2, outputDir };
|
|
476
|
+
}
|
|
477
|
+
async function compilePreviewRuntime(themePath) {
|
|
478
|
+
const outputDir = path__default.default.join(themePath, "dist");
|
|
479
|
+
await fs6__default.default.mkdir(outputDir, { recursive: true });
|
|
480
|
+
const outputPath = path__default.default.join(outputDir, "preview-runtime.js");
|
|
481
|
+
const locations = [
|
|
482
|
+
path__default.default.join(__dirname, "..", "preview", "preview-app.tsx"),
|
|
483
|
+
path__default.default.join(__dirname, "preview", "preview-app.tsx"),
|
|
484
|
+
path__default.default.join(__dirname, "..", "..", "src", "preview", "preview-app.tsx")
|
|
485
|
+
];
|
|
486
|
+
let previewEntryPath = null;
|
|
487
|
+
for (const loc of locations) {
|
|
488
|
+
try {
|
|
489
|
+
await fs6__default.default.access(loc);
|
|
490
|
+
previewEntryPath = loc;
|
|
491
|
+
break;
|
|
492
|
+
} catch (e) {
|
|
493
|
+
}
|
|
75
494
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
495
|
+
if (!previewEntryPath) {
|
|
496
|
+
throw new Error(
|
|
497
|
+
`Preview app source not found. Searched:
|
|
498
|
+
${locations.join("\n")}`
|
|
499
|
+
);
|
|
81
500
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
501
|
+
const serverStubPlugin = {
|
|
502
|
+
name: "server-stub",
|
|
503
|
+
setup(build2) {
|
|
504
|
+
build2.onResolve({ filter: /^server-only$/ }, () => ({
|
|
505
|
+
path: "server-only",
|
|
506
|
+
namespace: "server-stub"
|
|
507
|
+
}));
|
|
508
|
+
build2.onLoad({ filter: /.*/, namespace: "server-stub" }, () => ({
|
|
509
|
+
contents: "// server-only stub for browser",
|
|
510
|
+
loader: "js"
|
|
511
|
+
}));
|
|
512
|
+
const nodeBuiltins = [
|
|
513
|
+
"fs",
|
|
514
|
+
"fs/promises",
|
|
515
|
+
"path",
|
|
516
|
+
"os",
|
|
517
|
+
"crypto",
|
|
518
|
+
"stream",
|
|
519
|
+
"url",
|
|
520
|
+
"http",
|
|
521
|
+
"https",
|
|
522
|
+
"net",
|
|
523
|
+
"tls",
|
|
524
|
+
"child_process",
|
|
525
|
+
"util",
|
|
526
|
+
"events",
|
|
527
|
+
"buffer",
|
|
528
|
+
"querystring",
|
|
529
|
+
"zlib"
|
|
530
|
+
];
|
|
531
|
+
for (const mod of nodeBuiltins) {
|
|
532
|
+
build2.onResolve({ filter: new RegExp(`^${mod.replace("/", "\\/")}$`) }, () => ({
|
|
533
|
+
path: mod,
|
|
534
|
+
namespace: "node-stub"
|
|
535
|
+
}));
|
|
536
|
+
}
|
|
537
|
+
build2.onLoad({ filter: /.*/, namespace: "node-stub" }, (args) => {
|
|
538
|
+
const stubs = {
|
|
539
|
+
events: "export class EventEmitter { on(){return this} off(){return this} emit(){return false} addListener(){return this} removeListener(){return this} } export default { EventEmitter };",
|
|
540
|
+
path: "export function join(){return ''} export function resolve(){return ''} export function dirname(){return ''} export function basename(){return ''} export function extname(){return ''} export default {};",
|
|
541
|
+
fs: "export const promises = {}; export function readFileSync(){return ''} export function existsSync(){return false} export default {};"
|
|
542
|
+
};
|
|
543
|
+
return {
|
|
544
|
+
contents: stubs[args.path] || "export default {};",
|
|
545
|
+
loader: "js"
|
|
546
|
+
};
|
|
547
|
+
});
|
|
548
|
+
build2.onResolve({ filter: /^lucide-react/ }, async (args) => {
|
|
549
|
+
var _a;
|
|
550
|
+
if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
|
|
551
|
+
try {
|
|
552
|
+
const result = await build2.resolve(args.path, {
|
|
553
|
+
kind: args.kind,
|
|
554
|
+
resolveDir: args.resolveDir,
|
|
555
|
+
importer: args.importer,
|
|
556
|
+
namespace: "file",
|
|
557
|
+
pluginData: { skipStub: true }
|
|
558
|
+
});
|
|
559
|
+
if (!result.errors.length) return result;
|
|
560
|
+
} catch (e) {
|
|
561
|
+
}
|
|
562
|
+
return { path: args.path, namespace: "lucide-stub" };
|
|
563
|
+
});
|
|
564
|
+
build2.onLoad({ filter: /.*/, namespace: "lucide-stub" }, () => ({
|
|
565
|
+
// Provide all icon names used by @onexapis/core as no-op SVG stub components
|
|
566
|
+
contents: `
|
|
567
|
+
const icon = (props) => null;
|
|
568
|
+
export { icon as Check, icon as ChevronDown, icon as XCircle, icon as AlertTriangle };
|
|
569
|
+
export { icon as CheckCircle, icon as Info, icon as X, icon as XIcon };
|
|
570
|
+
export { icon as CircleIcon, icon as Star, icon as ShoppingCart };
|
|
571
|
+
export { icon as ChevronRight, icon as ChevronLeft, icon as ChevronUp };
|
|
572
|
+
export { icon as Search, icon as Menu, icon as Heart, icon as User };
|
|
573
|
+
export { icon as Trash2, icon as Plus, icon as Minus, icon as Eye, icon as EyeOff };
|
|
574
|
+
export { icon as ArrowRight, icon as ArrowLeft, icon as ExternalLink, icon as Mail };
|
|
575
|
+
export { icon as Phone, icon as MapPin, icon as Calendar, icon as Clock };
|
|
576
|
+
export { icon as Facebook, icon as Twitter, icon as Instagram, icon as Linkedin, icon as Github };
|
|
577
|
+
export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true : icon });
|
|
578
|
+
`.trim(),
|
|
579
|
+
loader: "jsx"
|
|
580
|
+
}));
|
|
581
|
+
build2.onResolve({ filter: /^framer-motion/ }, async (args) => {
|
|
582
|
+
var _a;
|
|
583
|
+
if ((_a = args.pluginData) == null ? void 0 : _a.skipStub) return void 0;
|
|
584
|
+
try {
|
|
585
|
+
const result = await build2.resolve(args.path, {
|
|
586
|
+
kind: args.kind,
|
|
587
|
+
resolveDir: args.resolveDir,
|
|
588
|
+
importer: args.importer,
|
|
589
|
+
namespace: "file",
|
|
590
|
+
pluginData: { skipStub: true }
|
|
591
|
+
});
|
|
592
|
+
if (!result.errors.length) return result;
|
|
593
|
+
} catch (e) {
|
|
594
|
+
}
|
|
595
|
+
return { path: args.path, namespace: "motion-stub" };
|
|
596
|
+
});
|
|
597
|
+
build2.onLoad({ filter: /.*/, namespace: "motion-stub" }, () => ({
|
|
598
|
+
contents: `
|
|
599
|
+
const stub = (props) => props.children || null;
|
|
600
|
+
const handler = { get: (_, name) => name === '__esModule' ? true : stub };
|
|
601
|
+
export const motion = new Proxy({}, handler);
|
|
602
|
+
export const AnimatePresence = stub;
|
|
603
|
+
export default { motion, AnimatePresence };
|
|
604
|
+
`.trim(),
|
|
605
|
+
loader: "jsx"
|
|
606
|
+
}));
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
await esbuild__namespace.build({
|
|
610
|
+
entryPoints: [previewEntryPath],
|
|
611
|
+
bundle: true,
|
|
612
|
+
platform: "browser",
|
|
613
|
+
format: "esm",
|
|
614
|
+
outfile: outputPath,
|
|
615
|
+
// Bundle React + core INTO the output (NOT externalized)
|
|
616
|
+
external: [],
|
|
617
|
+
plugins: [serverStubPlugin],
|
|
618
|
+
minify: false,
|
|
619
|
+
sourcemap: true,
|
|
620
|
+
target: "es2020",
|
|
621
|
+
jsx: "automatic",
|
|
622
|
+
jsxImportSource: "react",
|
|
623
|
+
define: {
|
|
624
|
+
"process.env.NODE_ENV": JSON.stringify("development"),
|
|
625
|
+
global: "globalThis"
|
|
626
|
+
},
|
|
627
|
+
loader: { ".tsx": "tsx", ".ts": "ts" },
|
|
628
|
+
// Force CJS resolution to avoid sideEffects:false dropping ESM chunk imports
|
|
629
|
+
conditions: ["require", "default"],
|
|
630
|
+
mainFields: ["main"],
|
|
631
|
+
logOverride: {
|
|
632
|
+
"ignored-bare-import": "silent"
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
return outputPath;
|
|
636
|
+
}
|
|
637
|
+
var PROCESS_SHIM, reactGlobalPlugin;
|
|
638
|
+
var init_compile_theme = __esm({
|
|
639
|
+
"src/utils/compile-theme.ts"() {
|
|
640
|
+
init_logger();
|
|
641
|
+
PROCESS_SHIM = `
|
|
642
|
+
if (typeof process === "undefined") {
|
|
643
|
+
globalThis.process = {
|
|
644
|
+
env: {},
|
|
645
|
+
browser: true,
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
`;
|
|
649
|
+
reactGlobalPlugin = {
|
|
650
|
+
name: "react-global",
|
|
651
|
+
setup(build2) {
|
|
652
|
+
build2.onResolve({ filter: /^react$/ }, () => ({
|
|
653
|
+
path: "react-external",
|
|
654
|
+
namespace: "react-global"
|
|
655
|
+
}));
|
|
656
|
+
build2.onResolve({ filter: /^react-dom$/ }, () => ({
|
|
657
|
+
path: "react-dom-external",
|
|
658
|
+
namespace: "react-global"
|
|
659
|
+
}));
|
|
660
|
+
build2.onResolve({ filter: /^react\/jsx-runtime$/ }, () => ({
|
|
661
|
+
path: "react-jsx-runtime-external",
|
|
662
|
+
namespace: "react-global"
|
|
663
|
+
}));
|
|
664
|
+
build2.onLoad({ filter: /.*/, namespace: "react-global" }, (args) => {
|
|
665
|
+
if (args.path === "react-external") {
|
|
666
|
+
return {
|
|
667
|
+
contents: `
|
|
668
|
+
if (!globalThis.__ONEX_REACT__) {
|
|
669
|
+
throw new Error('[Theme Bundle] React not initialized. Ensure globalThis.__ONEX_REACT__ is set before loading theme.');
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
const React = globalThis.__ONEX_REACT__;
|
|
673
|
+
export default React;
|
|
674
|
+
|
|
675
|
+
export const {
|
|
676
|
+
useState,
|
|
677
|
+
useEffect,
|
|
678
|
+
useContext,
|
|
679
|
+
useReducer,
|
|
680
|
+
useCallback,
|
|
681
|
+
useMemo,
|
|
682
|
+
useRef,
|
|
683
|
+
useImperativeHandle,
|
|
684
|
+
useLayoutEffect,
|
|
685
|
+
useDebugValue,
|
|
686
|
+
useDeferredValue,
|
|
687
|
+
useTransition,
|
|
688
|
+
useId,
|
|
689
|
+
useSyncExternalStore,
|
|
690
|
+
useInsertionEffect,
|
|
691
|
+
createContext,
|
|
692
|
+
forwardRef,
|
|
693
|
+
lazy,
|
|
694
|
+
memo,
|
|
695
|
+
startTransition,
|
|
696
|
+
createElement,
|
|
697
|
+
cloneElement,
|
|
698
|
+
isValidElement,
|
|
699
|
+
Children,
|
|
700
|
+
Fragment,
|
|
701
|
+
Profiler,
|
|
702
|
+
StrictMode,
|
|
703
|
+
Suspense,
|
|
704
|
+
Component,
|
|
705
|
+
PureComponent,
|
|
706
|
+
useActionState,
|
|
707
|
+
use,
|
|
708
|
+
} = React;
|
|
709
|
+
`.trim(),
|
|
710
|
+
loader: "js"
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
if (args.path === "react-dom-external") {
|
|
714
|
+
return {
|
|
715
|
+
contents: `
|
|
716
|
+
if (!globalThis.__ONEX_REACT_DOM__) {
|
|
717
|
+
throw new Error('[Theme Bundle] ReactDOM not initialized. Ensure globalThis.__ONEX_REACT_DOM__ is set before loading theme.');
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
const ReactDOM = globalThis.__ONEX_REACT_DOM__;
|
|
721
|
+
export default ReactDOM;
|
|
722
|
+
|
|
723
|
+
export const {
|
|
724
|
+
createRoot,
|
|
725
|
+
hydrateRoot,
|
|
726
|
+
flushSync,
|
|
727
|
+
createPortal,
|
|
728
|
+
findDOMNode,
|
|
729
|
+
render,
|
|
730
|
+
hydrate,
|
|
731
|
+
unmountComponentAtNode,
|
|
732
|
+
} = ReactDOM;
|
|
733
|
+
`.trim(),
|
|
734
|
+
loader: "js"
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
if (args.path === "react-jsx-runtime-external") {
|
|
738
|
+
return {
|
|
739
|
+
contents: `
|
|
740
|
+
if (!globalThis.__ONEX_JSX_RUNTIME__) {
|
|
741
|
+
throw new Error('[Theme Bundle] React JSX runtime not initialized. Ensure globalThis.__ONEX_JSX_RUNTIME__ is set before loading theme.');
|
|
742
|
+
}
|
|
743
|
+
const _jsxRuntime = globalThis.__ONEX_JSX_RUNTIME__;
|
|
744
|
+
export const jsx = _jsxRuntime.jsx;
|
|
745
|
+
export const jsxs = _jsxRuntime.jsxs;
|
|
746
|
+
export const Fragment = _jsxRuntime.Fragment;
|
|
747
|
+
`.trim(),
|
|
748
|
+
loader: "js"
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
return null;
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
};
|
|
85
755
|
}
|
|
86
|
-
};
|
|
87
|
-
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
// src/commands/init.ts
|
|
759
|
+
init_logger();
|
|
88
760
|
|
|
89
761
|
// src/utils/validators.ts
|
|
90
762
|
function validateName(name) {
|
|
@@ -104,8 +776,8 @@ function validateThemeName(name) {
|
|
|
104
776
|
return /^[a-z][a-z0-9-]*$/.test(name);
|
|
105
777
|
}
|
|
106
778
|
function pathExists(filePath) {
|
|
107
|
-
const
|
|
108
|
-
return
|
|
779
|
+
const fs11 = __require("fs-extra");
|
|
780
|
+
return fs11.existsSync(filePath);
|
|
109
781
|
}
|
|
110
782
|
function validateCategory(category) {
|
|
111
783
|
const validCategories = [
|
|
@@ -138,6 +810,9 @@ function getValidCategories() {
|
|
|
138
810
|
"contact"
|
|
139
811
|
];
|
|
140
812
|
}
|
|
813
|
+
|
|
814
|
+
// src/utils/file-helpers.ts
|
|
815
|
+
init_logger();
|
|
141
816
|
async function renderTemplate(templatePath, data) {
|
|
142
817
|
const template = await fs__default.default.readFile(templatePath, "utf-8");
|
|
143
818
|
return ejs__default.default.render(template, data);
|
|
@@ -223,8 +898,10 @@ function getProjectRoot() {
|
|
|
223
898
|
}
|
|
224
899
|
function getThemesDir() {
|
|
225
900
|
const root = getProjectRoot();
|
|
226
|
-
if (fs__default.default.existsSync(path__default.default.join(root, "themes")))
|
|
227
|
-
|
|
901
|
+
if (fs__default.default.existsSync(path__default.default.join(root, "themes")))
|
|
902
|
+
return path__default.default.join(root, "themes");
|
|
903
|
+
if (fs__default.default.existsSync(path__default.default.join(root, "src/themes")))
|
|
904
|
+
return path__default.default.join(root, "src/themes");
|
|
228
905
|
return path__default.default.dirname(root);
|
|
229
906
|
}
|
|
230
907
|
function getFeaturesDir() {
|
|
@@ -236,7 +913,7 @@ function isOneXProject() {
|
|
|
236
913
|
}
|
|
237
914
|
function ensureOneXProject() {
|
|
238
915
|
if (!isOneXProject()) {
|
|
239
|
-
logger.error(
|
|
916
|
+
exports.logger.error(
|
|
240
917
|
"Not in a OneX project. Please run this command from a OneX project root."
|
|
241
918
|
);
|
|
242
919
|
process.exit(1);
|
|
@@ -284,7 +961,7 @@ async function installDependencies(projectPath, packageManager = "npm") {
|
|
|
284
961
|
|
|
285
962
|
// src/commands/init.ts
|
|
286
963
|
async function initCommand(projectName, options = {}) {
|
|
287
|
-
logger.header("Create New OneX Theme Project");
|
|
964
|
+
exports.logger.header("Create New OneX Theme Project");
|
|
288
965
|
let name;
|
|
289
966
|
if (!projectName) {
|
|
290
967
|
const { inputName } = await inquirer__default.default.prompt([
|
|
@@ -311,7 +988,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
311
988
|
}
|
|
312
989
|
const projectPath = path__default.default.join(process.cwd(), name);
|
|
313
990
|
if (fs2__default.default.existsSync(projectPath)) {
|
|
314
|
-
logger.error(`Directory "${name}" already exists.`);
|
|
991
|
+
exports.logger.error(`Directory "${name}" already exists.`);
|
|
315
992
|
process.exit(1);
|
|
316
993
|
}
|
|
317
994
|
let displayName;
|
|
@@ -368,7 +1045,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
368
1045
|
author,
|
|
369
1046
|
template
|
|
370
1047
|
};
|
|
371
|
-
logger.startSpinner("Creating project structure...");
|
|
1048
|
+
exports.logger.startSpinner("Creating project structure...");
|
|
372
1049
|
try {
|
|
373
1050
|
fs2__default.default.mkdirSync(projectPath, { recursive: true });
|
|
374
1051
|
await copyTemplate(template, projectPath, data);
|
|
@@ -404,9 +1081,9 @@ Add your theme-specific blocks here.
|
|
|
404
1081
|
fs2__default.default.mkdirSync(pagesPath, { recursive: true });
|
|
405
1082
|
const homePageContent = generateHomePage(data);
|
|
406
1083
|
await writeFile(path__default.default.join(pagesPath, "home.ts"), homePageContent);
|
|
407
|
-
logger.stopSpinner(true, "Project structure created!");
|
|
1084
|
+
exports.logger.stopSpinner(true, "Project structure created!");
|
|
408
1085
|
if (options.git) {
|
|
409
|
-
logger.startSpinner("Initializing git repository...");
|
|
1086
|
+
exports.logger.startSpinner("Initializing git repository...");
|
|
410
1087
|
try {
|
|
411
1088
|
child_process.execSync("git init", { cwd: projectPath, stdio: "ignore" });
|
|
412
1089
|
child_process.execSync("git add .", { cwd: projectPath, stdio: "ignore" });
|
|
@@ -414,52 +1091,52 @@ Add your theme-specific blocks here.
|
|
|
414
1091
|
cwd: projectPath,
|
|
415
1092
|
stdio: "ignore"
|
|
416
1093
|
});
|
|
417
|
-
logger.stopSpinner(true, "Git repository initialized!");
|
|
1094
|
+
exports.logger.stopSpinner(true, "Git repository initialized!");
|
|
418
1095
|
} catch (e) {
|
|
419
|
-
logger.stopSpinner(false, "Failed to initialize git");
|
|
1096
|
+
exports.logger.stopSpinner(false, "Failed to initialize git");
|
|
420
1097
|
}
|
|
421
1098
|
}
|
|
422
1099
|
if (!options.noInstall) {
|
|
423
|
-
logger.newLine();
|
|
1100
|
+
exports.logger.newLine();
|
|
424
1101
|
const packageManager = detectPackageManager();
|
|
425
|
-
logger.startSpinner(`Installing dependencies with ${packageManager}...`);
|
|
1102
|
+
exports.logger.startSpinner(`Installing dependencies with ${packageManager}...`);
|
|
426
1103
|
try {
|
|
427
1104
|
await installDependencies(projectPath, packageManager);
|
|
428
|
-
logger.stopSpinner(true, "Dependencies installed!");
|
|
1105
|
+
exports.logger.stopSpinner(true, "Dependencies installed!");
|
|
429
1106
|
} catch (e) {
|
|
430
|
-
logger.stopSpinner(false, "Failed to install dependencies");
|
|
431
|
-
logger.info(
|
|
1107
|
+
exports.logger.stopSpinner(false, "Failed to install dependencies");
|
|
1108
|
+
exports.logger.info(
|
|
432
1109
|
"You can install dependencies manually by running: cd " + name + " && npm install"
|
|
433
1110
|
);
|
|
434
1111
|
}
|
|
435
1112
|
}
|
|
436
|
-
logger.newLine();
|
|
437
|
-
logger.section("Success! \u{1F389}");
|
|
438
|
-
logger.newLine();
|
|
439
|
-
logger.info(`Created OneX theme project at: ${projectPath}`);
|
|
440
|
-
logger.newLine();
|
|
441
|
-
logger.section("Next steps:");
|
|
442
|
-
logger.log(` cd ${name}`);
|
|
1113
|
+
exports.logger.newLine();
|
|
1114
|
+
exports.logger.section("Success! \u{1F389}");
|
|
1115
|
+
exports.logger.newLine();
|
|
1116
|
+
exports.logger.info(`Created OneX theme project at: ${projectPath}`);
|
|
1117
|
+
exports.logger.newLine();
|
|
1118
|
+
exports.logger.section("Next steps:");
|
|
1119
|
+
exports.logger.log(` cd ${name}`);
|
|
443
1120
|
if (options.noInstall) {
|
|
444
|
-
logger.log(` npm install`);
|
|
445
|
-
}
|
|
446
|
-
logger.log(` npm run build # Build your theme`);
|
|
447
|
-
logger.log(` npm run dev # Start development mode`);
|
|
448
|
-
logger.newLine();
|
|
449
|
-
logger.section("Theme structure:");
|
|
450
|
-
logger.log(" src/manifest.ts - Theme manifest and exports");
|
|
451
|
-
logger.log(
|
|
1121
|
+
exports.logger.log(` npm install`);
|
|
1122
|
+
}
|
|
1123
|
+
exports.logger.log(` npm run build # Build your theme`);
|
|
1124
|
+
exports.logger.log(` npm run dev # Start development mode`);
|
|
1125
|
+
exports.logger.newLine();
|
|
1126
|
+
exports.logger.section("Theme structure:");
|
|
1127
|
+
exports.logger.log(" src/manifest.ts - Theme manifest and exports");
|
|
1128
|
+
exports.logger.log(
|
|
452
1129
|
" src/config.ts - Design tokens (colors, typography, etc.)"
|
|
453
1130
|
);
|
|
454
|
-
logger.log(" src/layout.ts - Header and footer configuration");
|
|
455
|
-
logger.log(" src/sections/ - Custom sections for your theme");
|
|
456
|
-
logger.log(" src/blocks/ - Reusable blocks");
|
|
457
|
-
logger.log(" src/pages/ - Page configurations");
|
|
458
|
-
logger.newLine();
|
|
459
|
-
logger.success(`Happy theming! \u{1F3A8}`);
|
|
1131
|
+
exports.logger.log(" src/layout.ts - Header and footer configuration");
|
|
1132
|
+
exports.logger.log(" src/sections/ - Custom sections for your theme");
|
|
1133
|
+
exports.logger.log(" src/blocks/ - Reusable blocks");
|
|
1134
|
+
exports.logger.log(" src/pages/ - Page configurations");
|
|
1135
|
+
exports.logger.newLine();
|
|
1136
|
+
exports.logger.success(`Happy theming! \u{1F3A8}`);
|
|
460
1137
|
} catch (error) {
|
|
461
|
-
logger.stopSpinner(false, "Failed to create project");
|
|
462
|
-
logger.error(
|
|
1138
|
+
exports.logger.stopSpinner(false, "Failed to create project");
|
|
1139
|
+
exports.logger.error(
|
|
463
1140
|
error instanceof Error ? error.message : "Unknown error occurred"
|
|
464
1141
|
);
|
|
465
1142
|
if (fs2__default.default.existsSync(projectPath)) {
|
|
@@ -694,8 +1371,11 @@ export const homePageConfig: PageConfig = {
|
|
|
694
1371
|
};
|
|
695
1372
|
`;
|
|
696
1373
|
}
|
|
1374
|
+
|
|
1375
|
+
// src/commands/create-section.ts
|
|
1376
|
+
init_logger();
|
|
697
1377
|
async function createSectionCommand(name, options) {
|
|
698
|
-
logger.header("Create New Section");
|
|
1378
|
+
exports.logger.header("Create New Section");
|
|
699
1379
|
ensureOneXProject();
|
|
700
1380
|
if (!options.theme) {
|
|
701
1381
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
@@ -707,7 +1387,7 @@ async function createSectionCommand(name, options) {
|
|
|
707
1387
|
}
|
|
708
1388
|
const sectionName = toKebabCase(name);
|
|
709
1389
|
if (!validateName(sectionName)) {
|
|
710
|
-
logger.error(
|
|
1390
|
+
exports.logger.error(
|
|
711
1391
|
`Invalid section name: ${sectionName}. Use kebab-case (e.g., hero, featured-products)`
|
|
712
1392
|
);
|
|
713
1393
|
process.exit(1);
|
|
@@ -752,7 +1432,7 @@ async function createSectionCommand(name, options) {
|
|
|
752
1432
|
const description = answers.description;
|
|
753
1433
|
const createTemplate = answers.createTemplate;
|
|
754
1434
|
if (!themeExists(themeName)) {
|
|
755
|
-
logger.error(`Theme "${themeName}" does not exist.`);
|
|
1435
|
+
exports.logger.error(`Theme "${themeName}" does not exist.`);
|
|
756
1436
|
process.exit(1);
|
|
757
1437
|
}
|
|
758
1438
|
const data = {
|
|
@@ -763,7 +1443,7 @@ async function createSectionCommand(name, options) {
|
|
|
763
1443
|
displayName,
|
|
764
1444
|
description
|
|
765
1445
|
};
|
|
766
|
-
logger.startSpinner("Creating section files...");
|
|
1446
|
+
exports.logger.startSpinner("Creating section files...");
|
|
767
1447
|
try {
|
|
768
1448
|
const themePath = path__default.default.join(getThemesDir(), themeName);
|
|
769
1449
|
const sectionPath = path__default.default.join(themePath, "sections", sectionName);
|
|
@@ -781,25 +1461,25 @@ async function createSectionCommand(name, options) {
|
|
|
781
1461
|
}
|
|
782
1462
|
const indexContent = generateSectionIndex(data, createTemplate);
|
|
783
1463
|
await writeFile(path__default.default.join(sectionPath, "index.ts"), indexContent);
|
|
784
|
-
logger.stopSpinner(true, "Section files created successfully!");
|
|
785
|
-
logger.newLine();
|
|
786
|
-
logger.section("Next steps:");
|
|
787
|
-
logger.log(
|
|
1464
|
+
exports.logger.stopSpinner(true, "Section files created successfully!");
|
|
1465
|
+
exports.logger.newLine();
|
|
1466
|
+
exports.logger.section("Next steps:");
|
|
1467
|
+
exports.logger.log(
|
|
788
1468
|
` 1. Edit schema: ${path__default.default.relative(process.cwd(), path__default.default.join(sectionPath, `${sectionName}.schema.ts`))}`
|
|
789
1469
|
);
|
|
790
1470
|
if (createTemplate) {
|
|
791
|
-
logger.log(
|
|
1471
|
+
exports.logger.log(
|
|
792
1472
|
` 2. Edit template: ${path__default.default.relative(process.cwd(), path__default.default.join(sectionPath, `${sectionName}-default.tsx`))}`
|
|
793
1473
|
);
|
|
794
1474
|
}
|
|
795
|
-
logger.log(
|
|
1475
|
+
exports.logger.log(
|
|
796
1476
|
` 3. Add to theme manifest: ${path__default.default.relative(process.cwd(), path__default.default.join(themePath, "manifest.ts"))}`
|
|
797
1477
|
);
|
|
798
|
-
logger.newLine();
|
|
799
|
-
logger.success("Section created successfully!");
|
|
1478
|
+
exports.logger.newLine();
|
|
1479
|
+
exports.logger.success("Section created successfully!");
|
|
800
1480
|
} catch (error) {
|
|
801
|
-
logger.stopSpinner(false, "Failed to create section");
|
|
802
|
-
logger.error(
|
|
1481
|
+
exports.logger.stopSpinner(false, "Failed to create section");
|
|
1482
|
+
exports.logger.error(
|
|
803
1483
|
error instanceof Error ? error.message : "Unknown error occurred"
|
|
804
1484
|
);
|
|
805
1485
|
process.exit(1);
|
|
@@ -933,8 +1613,11 @@ export { ${data.sectionName}Schema } from "./${data.sectionName}.schema";
|
|
|
933
1613
|
${hasTemplate ? `export { ${data.sectionNamePascal}Default } from "./${data.sectionName}-default";` : ""}
|
|
934
1614
|
`;
|
|
935
1615
|
}
|
|
1616
|
+
|
|
1617
|
+
// src/commands/create-block.ts
|
|
1618
|
+
init_logger();
|
|
936
1619
|
async function createBlockCommand(name, options) {
|
|
937
|
-
logger.header("Create New Block");
|
|
1620
|
+
exports.logger.header("Create New Block");
|
|
938
1621
|
ensureOneXProject();
|
|
939
1622
|
if (!options.theme) {
|
|
940
1623
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
@@ -946,7 +1629,7 @@ async function createBlockCommand(name, options) {
|
|
|
946
1629
|
}
|
|
947
1630
|
const blockName = toKebabCase(name);
|
|
948
1631
|
if (!validateName(blockName)) {
|
|
949
|
-
logger.error(
|
|
1632
|
+
exports.logger.error(
|
|
950
1633
|
`Invalid block name: ${blockName}. Use kebab-case (e.g., product-card, testimonial-item)`
|
|
951
1634
|
);
|
|
952
1635
|
process.exit(1);
|
|
@@ -1001,7 +1684,7 @@ async function createBlockCommand(name, options) {
|
|
|
1001
1684
|
const hasComponents = answers.hasComponents;
|
|
1002
1685
|
const hasNestedBlocks = answers.hasNestedBlocks;
|
|
1003
1686
|
if (scope === "theme" && !themeExists(themeName)) {
|
|
1004
|
-
logger.error(`Theme "${themeName}" does not exist.`);
|
|
1687
|
+
exports.logger.error(`Theme "${themeName}" does not exist.`);
|
|
1005
1688
|
process.exit(1);
|
|
1006
1689
|
}
|
|
1007
1690
|
const data = {
|
|
@@ -1014,7 +1697,7 @@ async function createBlockCommand(name, options) {
|
|
|
1014
1697
|
scope,
|
|
1015
1698
|
themeName
|
|
1016
1699
|
};
|
|
1017
|
-
logger.startSpinner("Creating block files...");
|
|
1700
|
+
exports.logger.startSpinner("Creating block files...");
|
|
1018
1701
|
try {
|
|
1019
1702
|
const blockPath = scope === "shared" ? path__default.default.join(getFeaturesDir(), "blocks", blockName) : path__default.default.join(getThemesDir(), themeName, "blocks", blockName);
|
|
1020
1703
|
const schemaContent = generateBlockSchema(data);
|
|
@@ -1026,23 +1709,23 @@ async function createBlockCommand(name, options) {
|
|
|
1026
1709
|
await writeFile(path__default.default.join(blockPath, `${blockName}.tsx`), componentContent);
|
|
1027
1710
|
const indexContent = generateBlockIndex(data);
|
|
1028
1711
|
await writeFile(path__default.default.join(blockPath, "index.ts"), indexContent);
|
|
1029
|
-
logger.stopSpinner(true, "Block files created successfully!");
|
|
1030
|
-
logger.newLine();
|
|
1031
|
-
logger.section("Next steps:");
|
|
1032
|
-
logger.log(
|
|
1712
|
+
exports.logger.stopSpinner(true, "Block files created successfully!");
|
|
1713
|
+
exports.logger.newLine();
|
|
1714
|
+
exports.logger.section("Next steps:");
|
|
1715
|
+
exports.logger.log(
|
|
1033
1716
|
` 1. Edit schema: ${path__default.default.relative(process.cwd(), path__default.default.join(blockPath, `${blockName}.schema.ts`))}`
|
|
1034
1717
|
);
|
|
1035
|
-
logger.log(
|
|
1718
|
+
exports.logger.log(
|
|
1036
1719
|
` 2. Edit component: ${path__default.default.relative(process.cwd(), path__default.default.join(blockPath, `${blockName}.tsx`))}`
|
|
1037
1720
|
);
|
|
1038
|
-
logger.log(
|
|
1721
|
+
exports.logger.log(
|
|
1039
1722
|
` 3. Register in block registry: src/lib/registry/block-registry.ts`
|
|
1040
1723
|
);
|
|
1041
|
-
logger.newLine();
|
|
1042
|
-
logger.success("Block created successfully!");
|
|
1724
|
+
exports.logger.newLine();
|
|
1725
|
+
exports.logger.success("Block created successfully!");
|
|
1043
1726
|
} catch (error) {
|
|
1044
|
-
logger.stopSpinner(false, "Failed to create block");
|
|
1045
|
-
logger.error(
|
|
1727
|
+
exports.logger.stopSpinner(false, "Failed to create block");
|
|
1728
|
+
exports.logger.error(
|
|
1046
1729
|
error instanceof Error ? error.message : "Unknown error occurred"
|
|
1047
1730
|
);
|
|
1048
1731
|
process.exit(1);
|
|
@@ -1157,12 +1840,15 @@ export { ${data.blockName}Definition } from "./${data.blockName}.schema";
|
|
|
1157
1840
|
export { ${data.blockNamePascal} } from "./${data.blockName}";
|
|
1158
1841
|
`;
|
|
1159
1842
|
}
|
|
1843
|
+
|
|
1844
|
+
// src/commands/create-component.ts
|
|
1845
|
+
init_logger();
|
|
1160
1846
|
async function createComponentCommand(name, options) {
|
|
1161
|
-
logger.header("Create New Component");
|
|
1847
|
+
exports.logger.header("Create New Component");
|
|
1162
1848
|
ensureOneXProject();
|
|
1163
1849
|
const componentName = toKebabCase(name);
|
|
1164
1850
|
if (!validateName(componentName)) {
|
|
1165
|
-
logger.error(
|
|
1851
|
+
exports.logger.error(
|
|
1166
1852
|
`Invalid component name: ${componentName}. Use kebab-case (e.g., button, icon-badge)`
|
|
1167
1853
|
);
|
|
1168
1854
|
process.exit(1);
|
|
@@ -1206,7 +1892,7 @@ async function createComponentCommand(name, options) {
|
|
|
1206
1892
|
displayName,
|
|
1207
1893
|
description
|
|
1208
1894
|
};
|
|
1209
|
-
logger.startSpinner("Creating component files...");
|
|
1895
|
+
exports.logger.startSpinner("Creating component files...");
|
|
1210
1896
|
try {
|
|
1211
1897
|
const componentPath = path__default.default.join(
|
|
1212
1898
|
getFeaturesDir(),
|
|
@@ -1225,23 +1911,23 @@ async function createComponentCommand(name, options) {
|
|
|
1225
1911
|
);
|
|
1226
1912
|
const indexContent = generateComponentIndex(data);
|
|
1227
1913
|
await writeFile(path__default.default.join(componentPath, "index.ts"), indexContent);
|
|
1228
|
-
logger.stopSpinner(true, "Component files created successfully!");
|
|
1229
|
-
logger.newLine();
|
|
1230
|
-
logger.section("Next steps:");
|
|
1231
|
-
logger.log(
|
|
1914
|
+
exports.logger.stopSpinner(true, "Component files created successfully!");
|
|
1915
|
+
exports.logger.newLine();
|
|
1916
|
+
exports.logger.section("Next steps:");
|
|
1917
|
+
exports.logger.log(
|
|
1232
1918
|
` 1. Edit schema: ${path__default.default.relative(process.cwd(), path__default.default.join(componentPath, `${componentName}.schema.ts`))}`
|
|
1233
1919
|
);
|
|
1234
|
-
logger.log(
|
|
1920
|
+
exports.logger.log(
|
|
1235
1921
|
` 2. Edit component: ${path__default.default.relative(process.cwd(), path__default.default.join(componentPath, `${componentName}.tsx`))}`
|
|
1236
1922
|
);
|
|
1237
|
-
logger.log(
|
|
1923
|
+
exports.logger.log(
|
|
1238
1924
|
` 3. Register in component registry: src/lib/registry/component-registry.ts`
|
|
1239
1925
|
);
|
|
1240
|
-
logger.newLine();
|
|
1241
|
-
logger.success("Component created successfully!");
|
|
1926
|
+
exports.logger.newLine();
|
|
1927
|
+
exports.logger.success("Component created successfully!");
|
|
1242
1928
|
} catch (error) {
|
|
1243
|
-
logger.stopSpinner(false, "Failed to create component");
|
|
1244
|
-
logger.error(
|
|
1929
|
+
exports.logger.stopSpinner(false, "Failed to create component");
|
|
1930
|
+
exports.logger.error(
|
|
1245
1931
|
error instanceof Error ? error.message : "Unknown error occurred"
|
|
1246
1932
|
);
|
|
1247
1933
|
process.exit(1);
|
|
@@ -1361,8 +2047,11 @@ export { ${data.componentName}Definition } from "./${data.componentName}.schema"
|
|
|
1361
2047
|
export { ${data.componentNamePascal} } from "./${data.componentName}";
|
|
1362
2048
|
`;
|
|
1363
2049
|
}
|
|
2050
|
+
|
|
2051
|
+
// src/commands/list.ts
|
|
2052
|
+
init_logger();
|
|
1364
2053
|
async function listCommand(options) {
|
|
1365
|
-
logger.header("OneX Project Inventory");
|
|
2054
|
+
exports.logger.header("OneX Project Inventory");
|
|
1366
2055
|
ensureOneXProject();
|
|
1367
2056
|
const showAll = !options.sections && !options.blocks && !options.components;
|
|
1368
2057
|
if (showAll || options.sections) {
|
|
@@ -1379,10 +2068,10 @@ async function listCommand(options) {
|
|
|
1379
2068
|
}
|
|
1380
2069
|
}
|
|
1381
2070
|
async function listSections(themeFilter) {
|
|
1382
|
-
logger.section("\u{1F4C4} Sections");
|
|
2071
|
+
exports.logger.section("\u{1F4C4} Sections");
|
|
1383
2072
|
const themes = themeFilter ? [themeFilter] : listThemes();
|
|
1384
2073
|
if (themes.length === 0) {
|
|
1385
|
-
logger.warning("No themes found");
|
|
2074
|
+
exports.logger.warning("No themes found");
|
|
1386
2075
|
return;
|
|
1387
2076
|
}
|
|
1388
2077
|
for (const theme of themes) {
|
|
@@ -1395,17 +2084,17 @@ async function listSections(themeFilter) {
|
|
|
1395
2084
|
return fs__default.default.statSync(sectionPath).isDirectory() && fs__default.default.existsSync(path__default.default.join(sectionPath, "index.ts"));
|
|
1396
2085
|
});
|
|
1397
2086
|
if (sections.length > 0) {
|
|
1398
|
-
logger.log(chalk4__default.default.cyan(`
|
|
2087
|
+
exports.logger.log(chalk4__default.default.cyan(`
|
|
1399
2088
|
${theme}:`));
|
|
1400
2089
|
sections.forEach((section) => {
|
|
1401
|
-
logger.log(` \u2022 ${section}`);
|
|
2090
|
+
exports.logger.log(` \u2022 ${section}`);
|
|
1402
2091
|
});
|
|
1403
2092
|
}
|
|
1404
2093
|
}
|
|
1405
|
-
logger.newLine();
|
|
2094
|
+
exports.logger.newLine();
|
|
1406
2095
|
}
|
|
1407
2096
|
async function listBlocks(themeFilter) {
|
|
1408
|
-
logger.section("\u{1F9F1} Blocks");
|
|
2097
|
+
exports.logger.section("\u{1F9F1} Blocks");
|
|
1409
2098
|
const sharedBlocksDir = path__default.default.join(getFeaturesDir(), "blocks");
|
|
1410
2099
|
if (fs__default.default.existsSync(sharedBlocksDir)) {
|
|
1411
2100
|
const sharedBlocks = fs__default.default.readdirSync(sharedBlocksDir).filter((name) => {
|
|
@@ -1413,9 +2102,9 @@ async function listBlocks(themeFilter) {
|
|
|
1413
2102
|
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(path__default.default.join(blockPath, "index.ts"));
|
|
1414
2103
|
});
|
|
1415
2104
|
if (sharedBlocks.length > 0) {
|
|
1416
|
-
logger.log(chalk4__default.default.cyan("\n Shared:"));
|
|
2105
|
+
exports.logger.log(chalk4__default.default.cyan("\n Shared:"));
|
|
1417
2106
|
sharedBlocks.forEach((block) => {
|
|
1418
|
-
logger.log(` \u2022 ${block}`);
|
|
2107
|
+
exports.logger.log(` \u2022 ${block}`);
|
|
1419
2108
|
});
|
|
1420
2109
|
}
|
|
1421
2110
|
}
|
|
@@ -1430,20 +2119,20 @@ async function listBlocks(themeFilter) {
|
|
|
1430
2119
|
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(path__default.default.join(blockPath, "index.ts"));
|
|
1431
2120
|
});
|
|
1432
2121
|
if (blocks.length > 0) {
|
|
1433
|
-
logger.log(chalk4__default.default.cyan(`
|
|
2122
|
+
exports.logger.log(chalk4__default.default.cyan(`
|
|
1434
2123
|
${theme}:`));
|
|
1435
2124
|
blocks.forEach((block) => {
|
|
1436
|
-
logger.log(` \u2022 ${block}`);
|
|
2125
|
+
exports.logger.log(` \u2022 ${block}`);
|
|
1437
2126
|
});
|
|
1438
2127
|
}
|
|
1439
2128
|
}
|
|
1440
|
-
logger.newLine();
|
|
2129
|
+
exports.logger.newLine();
|
|
1441
2130
|
}
|
|
1442
2131
|
async function listComponents() {
|
|
1443
|
-
logger.section("\u2699\uFE0F Components");
|
|
2132
|
+
exports.logger.section("\u2699\uFE0F Components");
|
|
1444
2133
|
const componentsDir = path__default.default.join(getFeaturesDir(), "components");
|
|
1445
2134
|
if (!fs__default.default.existsSync(componentsDir)) {
|
|
1446
|
-
logger.warning("No components directory found");
|
|
2135
|
+
exports.logger.warning("No components directory found");
|
|
1447
2136
|
return;
|
|
1448
2137
|
}
|
|
1449
2138
|
const components = fs__default.default.readdirSync(componentsDir).filter((name) => {
|
|
@@ -1451,23 +2140,23 @@ async function listComponents() {
|
|
|
1451
2140
|
return fs__default.default.statSync(componentPath).isDirectory() && fs__default.default.existsSync(path__default.default.join(componentPath, "index.ts"));
|
|
1452
2141
|
});
|
|
1453
2142
|
if (components.length === 0) {
|
|
1454
|
-
logger.warning("No components found");
|
|
2143
|
+
exports.logger.warning("No components found");
|
|
1455
2144
|
return;
|
|
1456
2145
|
}
|
|
1457
|
-
logger.log("");
|
|
2146
|
+
exports.logger.log("");
|
|
1458
2147
|
components.forEach((component) => {
|
|
1459
|
-
logger.log(` \u2022 ${component}`);
|
|
2148
|
+
exports.logger.log(` \u2022 ${component}`);
|
|
1460
2149
|
});
|
|
1461
|
-
logger.newLine();
|
|
2150
|
+
exports.logger.newLine();
|
|
1462
2151
|
}
|
|
1463
2152
|
async function listThemesInfo() {
|
|
1464
|
-
logger.section("\u{1F3A8} Themes");
|
|
2153
|
+
exports.logger.section("\u{1F3A8} Themes");
|
|
1465
2154
|
const themes = listThemes();
|
|
1466
2155
|
if (themes.length === 0) {
|
|
1467
|
-
logger.warning("No themes found");
|
|
2156
|
+
exports.logger.warning("No themes found");
|
|
1468
2157
|
return;
|
|
1469
2158
|
}
|
|
1470
|
-
logger.log("");
|
|
2159
|
+
exports.logger.log("");
|
|
1471
2160
|
for (const theme of themes) {
|
|
1472
2161
|
const themeDir = path__default.default.join(getThemesDir(), theme);
|
|
1473
2162
|
const candidates = ["theme.config.ts", "bundle-entry.ts", "manifest.ts"];
|
|
@@ -1485,15 +2174,19 @@ async function listThemesInfo() {
|
|
|
1485
2174
|
const displayName = nameMatch ? nameMatch[1] : theme;
|
|
1486
2175
|
const version = versionMatch ? versionMatch[1] : "unknown";
|
|
1487
2176
|
const description = descMatch ? descMatch[1] : "";
|
|
1488
|
-
logger.log(chalk4__default.default.cyan(` ${displayName}`) + chalk4__default.default.gray(` (v${version})`));
|
|
2177
|
+
exports.logger.log(chalk4__default.default.cyan(` ${displayName}`) + chalk4__default.default.gray(` (v${version})`));
|
|
1489
2178
|
if (description) {
|
|
1490
|
-
logger.log(chalk4__default.default.gray(` ${description}`));
|
|
2179
|
+
exports.logger.log(chalk4__default.default.gray(` ${description}`));
|
|
1491
2180
|
}
|
|
1492
2181
|
}
|
|
1493
|
-
logger.newLine();
|
|
2182
|
+
exports.logger.newLine();
|
|
1494
2183
|
}
|
|
2184
|
+
|
|
2185
|
+
// src/commands/build.ts
|
|
2186
|
+
init_logger();
|
|
1495
2187
|
async function buildCommand(options) {
|
|
1496
|
-
|
|
2188
|
+
var _a;
|
|
2189
|
+
exports.logger.header("Build Theme");
|
|
1497
2190
|
let themePath;
|
|
1498
2191
|
let themeName;
|
|
1499
2192
|
if (options.theme) {
|
|
@@ -1509,17 +2202,21 @@ async function buildCommand(options) {
|
|
|
1509
2202
|
themePath = path__default.default.join(process.cwd(), themeName);
|
|
1510
2203
|
}
|
|
1511
2204
|
if (!fs__default.default.existsSync(themePath)) {
|
|
1512
|
-
logger.error(`Theme "${themeName}" not found.`);
|
|
2205
|
+
exports.logger.error(`Theme "${themeName}" not found.`);
|
|
1513
2206
|
process.exit(1);
|
|
1514
2207
|
}
|
|
1515
2208
|
} else {
|
|
1516
|
-
const isThemeDir = [
|
|
2209
|
+
const isThemeDir = [
|
|
2210
|
+
"theme.config.ts",
|
|
2211
|
+
"bundle-entry.ts",
|
|
2212
|
+
"manifest.ts"
|
|
2213
|
+
].some((f) => fs__default.default.existsSync(path__default.default.join(process.cwd(), f)));
|
|
1517
2214
|
if (isThemeDir) {
|
|
1518
2215
|
themePath = process.cwd();
|
|
1519
2216
|
themeName = path__default.default.basename(themePath);
|
|
1520
|
-
logger.info(`Building current theme: ${themeName}`);
|
|
2217
|
+
exports.logger.info(`Building current theme: ${themeName}`);
|
|
1521
2218
|
} else {
|
|
1522
|
-
logger.error(
|
|
2219
|
+
exports.logger.error(
|
|
1523
2220
|
"Not in a theme directory and no --theme specified. Run from theme root or use --theme flag."
|
|
1524
2221
|
);
|
|
1525
2222
|
process.exit(1);
|
|
@@ -1528,55 +2225,64 @@ async function buildCommand(options) {
|
|
|
1528
2225
|
const packageJsonPath = path__default.default.join(themePath, "package.json");
|
|
1529
2226
|
const hasPkgJson = fs__default.default.existsSync(packageJsonPath);
|
|
1530
2227
|
if (!hasPkgJson) {
|
|
1531
|
-
logger.warning(
|
|
2228
|
+
exports.logger.warning(
|
|
1532
2229
|
"No package.json found in theme. Skipping build (themes in monorepo are built via turbo)."
|
|
1533
2230
|
);
|
|
1534
|
-
logger.newLine();
|
|
1535
|
-
logger.info("To build all packages, run:");
|
|
1536
|
-
logger.log(" pnpm turbo build");
|
|
1537
|
-
logger.newLine();
|
|
1538
|
-
logger.info("To build specific theme components:");
|
|
1539
|
-
logger.log(" pnpm turbo build --filter=./src/themes/*");
|
|
2231
|
+
exports.logger.newLine();
|
|
2232
|
+
exports.logger.info("To build all packages, run:");
|
|
2233
|
+
exports.logger.log(" pnpm turbo build");
|
|
2234
|
+
exports.logger.newLine();
|
|
2235
|
+
exports.logger.info("To build specific theme components:");
|
|
2236
|
+
exports.logger.log(" pnpm turbo build --filter=./src/themes/*");
|
|
1540
2237
|
return;
|
|
1541
2238
|
}
|
|
1542
|
-
logger.newLine();
|
|
1543
|
-
logger.section("Build Steps");
|
|
1544
|
-
logger.startSpinner("Running type check...");
|
|
2239
|
+
exports.logger.newLine();
|
|
2240
|
+
exports.logger.section("Build Steps");
|
|
2241
|
+
exports.logger.startSpinner("Running type check...");
|
|
1545
2242
|
const typeCheckSuccess = await runCommand("pnpm", ["type-check"], themePath);
|
|
1546
2243
|
if (!typeCheckSuccess) {
|
|
1547
|
-
logger.stopSpinner(false, "Type check failed");
|
|
1548
|
-
logger.error("Fix type errors before building.");
|
|
2244
|
+
exports.logger.stopSpinner(false, "Type check failed");
|
|
2245
|
+
exports.logger.error("Fix type errors before building.");
|
|
1549
2246
|
process.exit(1);
|
|
1550
2247
|
}
|
|
1551
|
-
logger.stopSpinner(true, "Type check passed");
|
|
1552
|
-
logger.startSpinner("Running linter...");
|
|
2248
|
+
exports.logger.stopSpinner(true, "Type check passed");
|
|
2249
|
+
exports.logger.startSpinner("Running linter...");
|
|
1553
2250
|
const lintSuccess = await runCommand("pnpm", ["lint"], themePath);
|
|
1554
2251
|
if (!lintSuccess) {
|
|
1555
|
-
logger.stopSpinner(false, "Lint failed");
|
|
1556
|
-
logger.error("Fix lint errors before building.");
|
|
2252
|
+
exports.logger.stopSpinner(false, "Lint failed");
|
|
2253
|
+
exports.logger.error("Fix lint errors before building.");
|
|
1557
2254
|
process.exit(1);
|
|
1558
2255
|
}
|
|
1559
|
-
logger.stopSpinner(true, "Lint passed");
|
|
1560
|
-
const
|
|
1561
|
-
|
|
2256
|
+
exports.logger.stopSpinner(true, "Lint passed");
|
|
2257
|
+
const pkgJson = fs__default.default.readJsonSync(packageJsonPath);
|
|
2258
|
+
const buildScript = ((_a = pkgJson.scripts) == null ? void 0 : _a.build) || "";
|
|
2259
|
+
const isRecursive = buildScript.includes("onex build") || buildScript.includes("onex-cli build");
|
|
2260
|
+
exports.logger.startSpinner(
|
|
1562
2261
|
options.watch ? "Building (watch mode)..." : "Building..."
|
|
1563
2262
|
);
|
|
1564
|
-
|
|
2263
|
+
let buildSuccess;
|
|
2264
|
+
if (isRecursive) {
|
|
2265
|
+
const { compileStandaloneTheme: compileStandaloneTheme2 } = await Promise.resolve().then(() => (init_compile_theme(), compile_theme_exports));
|
|
2266
|
+
buildSuccess = await compileStandaloneTheme2(themePath, themeName);
|
|
2267
|
+
} else {
|
|
2268
|
+
const buildArgs = options.watch ? ["build", "--watch"] : ["build"];
|
|
2269
|
+
buildSuccess = await runCommand("pnpm", buildArgs, themePath);
|
|
2270
|
+
}
|
|
1565
2271
|
if (!buildSuccess && !options.watch) {
|
|
1566
|
-
logger.stopSpinner(false, "Build failed");
|
|
2272
|
+
exports.logger.stopSpinner(false, "Build failed");
|
|
1567
2273
|
process.exit(1);
|
|
1568
2274
|
}
|
|
1569
2275
|
if (!options.watch) {
|
|
1570
|
-
logger.stopSpinner(true, "Build complete");
|
|
1571
|
-
logger.newLine();
|
|
1572
|
-
logger.success("\u2713 Theme built successfully!");
|
|
1573
|
-
logger.newLine();
|
|
1574
|
-
logger.info(`Theme: ${themeName}`);
|
|
2276
|
+
exports.logger.stopSpinner(true, "Build complete");
|
|
2277
|
+
exports.logger.newLine();
|
|
2278
|
+
exports.logger.success("\u2713 Theme built successfully!");
|
|
2279
|
+
exports.logger.newLine();
|
|
2280
|
+
exports.logger.info(`Theme: ${themeName}`);
|
|
1575
2281
|
const distPath = path__default.default.join(themePath, "dist");
|
|
1576
2282
|
if (fs__default.default.existsSync(distPath)) {
|
|
1577
|
-
logger.log(`Output: ${path__default.default.relative(process.cwd(), distPath)}`);
|
|
2283
|
+
exports.logger.log(`Output: ${path__default.default.relative(process.cwd(), distPath)}`);
|
|
1578
2284
|
const files = fs__default.default.readdirSync(distPath);
|
|
1579
|
-
logger.log(`Files: ${files.length}`);
|
|
2285
|
+
exports.logger.log(`Files: ${files.length}`);
|
|
1580
2286
|
}
|
|
1581
2287
|
}
|
|
1582
2288
|
}
|
|
@@ -1602,6 +2308,9 @@ function runCommand(command, args, cwd) {
|
|
|
1602
2308
|
});
|
|
1603
2309
|
});
|
|
1604
2310
|
}
|
|
2311
|
+
|
|
2312
|
+
// src/commands/upload.ts
|
|
2313
|
+
init_logger();
|
|
1605
2314
|
function getS3Client() {
|
|
1606
2315
|
const adapterMode = (process.env.ADAPTER_MODE || "aws").trim().toLowerCase();
|
|
1607
2316
|
if (adapterMode === "vps") {
|
|
@@ -1641,21 +2350,12 @@ function getBucketName(env) {
|
|
|
1641
2350
|
return environment === "production" ? "onex-themes-prod" : "onex-themes-staging";
|
|
1642
2351
|
}
|
|
1643
2352
|
async function findCompiledThemeDir(themeId, version) {
|
|
1644
|
-
const searchPaths = [
|
|
1645
|
-
path__default.default.resolve(process.cwd(), "dist"),
|
|
1646
|
-
path__default.default.resolve(
|
|
1647
|
-
process.cwd(),
|
|
1648
|
-
`../../apps/api-server/compiled-themes/${themeId}@${version}`
|
|
1649
|
-
),
|
|
1650
|
-
path__default.default.resolve(
|
|
1651
|
-
process.cwd(),
|
|
1652
|
-
`../api-server/compiled-themes/${themeId}@${version}`
|
|
1653
|
-
)
|
|
1654
|
-
];
|
|
2353
|
+
const searchPaths = [path__default.default.resolve(process.cwd(), "dist")];
|
|
1655
2354
|
for (const dir of searchPaths) {
|
|
1656
2355
|
if (await fs__default.default.pathExists(dir)) {
|
|
1657
|
-
const
|
|
1658
|
-
|
|
2356
|
+
const hasManifest = await fs__default.default.pathExists(path__default.default.join(dir, "manifest.json"));
|
|
2357
|
+
const hasThemeEntry = await fs__default.default.pathExists(path__default.default.join(dir, "bundle-entry.js")) || await fs__default.default.pathExists(path__default.default.join(dir, "theme.config.js")) || await fs__default.default.pathExists(path__default.default.join(dir, "index.js"));
|
|
2358
|
+
if (hasManifest || hasThemeEntry) {
|
|
1659
2359
|
return dir;
|
|
1660
2360
|
}
|
|
1661
2361
|
}
|
|
@@ -1670,7 +2370,7 @@ async function readManifest() {
|
|
|
1670
2370
|
const module = await import(manifestTsPath);
|
|
1671
2371
|
return module.default || module;
|
|
1672
2372
|
} catch (error) {
|
|
1673
|
-
logger.warning("Failed to import manifest.ts, trying package.json");
|
|
2373
|
+
exports.logger.warning("Failed to import manifest.ts, trying package.json");
|
|
1674
2374
|
}
|
|
1675
2375
|
}
|
|
1676
2376
|
const packageJsonPath = path__default.default.resolve(process.cwd(), "package.json");
|
|
@@ -1735,7 +2435,7 @@ async function updateLatestPointer(s3Client, bucket, themeId, version) {
|
|
|
1735
2435
|
);
|
|
1736
2436
|
}
|
|
1737
2437
|
async function uploadCommand(options) {
|
|
1738
|
-
logger.header("Upload Theme to S3");
|
|
2438
|
+
exports.logger.header("Upload Theme to S3");
|
|
1739
2439
|
const spinner = ora__default.default("Preparing theme upload...").start();
|
|
1740
2440
|
try {
|
|
1741
2441
|
let themeId;
|
|
@@ -1758,13 +2458,8 @@ async function uploadCommand(options) {
|
|
|
1758
2458
|
`Compiled theme not found for ${themeId}@${version}. Run 'onex build' first.`
|
|
1759
2459
|
)
|
|
1760
2460
|
);
|
|
1761
|
-
logger.info(
|
|
1762
|
-
|
|
1763
|
-
`Expected locations:
|
|
1764
|
-
- ./dist/
|
|
1765
|
-
- ../../apps/api-server/compiled-themes/${themeId}@${version}/`
|
|
1766
|
-
)
|
|
1767
|
-
);
|
|
2461
|
+
exports.logger.info(chalk4__default.default.gray(`Expected location:
|
|
2462
|
+
- ./dist/`));
|
|
1768
2463
|
process.exit(1);
|
|
1769
2464
|
}
|
|
1770
2465
|
spinner.succeed(`Found compiled theme at: ${compiledDir}`);
|
|
@@ -1864,16 +2559,14 @@ async function uploadCommand(options) {
|
|
|
1864
2559
|
await updateLatestPointer(s3Client, bucket, themeId, version);
|
|
1865
2560
|
spinner.succeed("Updated latest.json pointer");
|
|
1866
2561
|
console.log();
|
|
1867
|
-
logger.success(chalk4__default.default.green.bold("Theme uploaded successfully!"));
|
|
2562
|
+
exports.logger.success(chalk4__default.default.green.bold("Theme uploaded successfully!"));
|
|
1868
2563
|
console.log();
|
|
1869
2564
|
console.log(
|
|
1870
2565
|
chalk4__default.default.cyan(" Theme: ") + chalk4__default.default.white(`${themeId}@${version}`)
|
|
1871
2566
|
);
|
|
1872
2567
|
console.log(chalk4__default.default.cyan(" Bucket: ") + chalk4__default.default.white(bucket));
|
|
1873
2568
|
console.log(
|
|
1874
|
-
chalk4__default.default.cyan(" Files: ") + chalk4__default.default.white(
|
|
1875
|
-
`bundle.zip${sourceUploaded ? " + source.zip" : ""}`
|
|
1876
|
-
)
|
|
2569
|
+
chalk4__default.default.cyan(" Files: ") + chalk4__default.default.white(`bundle.zip${sourceUploaded ? " + source.zip" : ""}`)
|
|
1877
2570
|
);
|
|
1878
2571
|
console.log(
|
|
1879
2572
|
chalk4__default.default.cyan(" Path: ") + chalk4__default.default.gray(`s3://${bucket}/themes/${themeId}/${version}/`)
|
|
@@ -1881,10 +2574,13 @@ async function uploadCommand(options) {
|
|
|
1881
2574
|
console.log();
|
|
1882
2575
|
} catch (error) {
|
|
1883
2576
|
spinner.fail(chalk4__default.default.red(`Upload failed: ${error.message}`));
|
|
1884
|
-
logger.error(error.stack || error.message);
|
|
2577
|
+
exports.logger.error(error.stack || error.message);
|
|
1885
2578
|
process.exit(1);
|
|
1886
2579
|
}
|
|
1887
2580
|
}
|
|
2581
|
+
|
|
2582
|
+
// src/commands/download.ts
|
|
2583
|
+
init_logger();
|
|
1888
2584
|
function getS3Client2() {
|
|
1889
2585
|
const adapterMode = (process.env.ADAPTER_MODE || "aws").trim().toLowerCase();
|
|
1890
2586
|
if (adapterMode === "vps") {
|
|
@@ -2003,7 +2699,7 @@ export * from './bundle-entry.js';
|
|
|
2003
2699
|
}
|
|
2004
2700
|
function showDownloadFailureHelp(themeId, bucket) {
|
|
2005
2701
|
console.log();
|
|
2006
|
-
logger.error(chalk4__default.default.red.bold("Theme download failed"));
|
|
2702
|
+
exports.logger.error(chalk4__default.default.red.bold("Theme download failed"));
|
|
2007
2703
|
console.log();
|
|
2008
2704
|
console.log(chalk4__default.default.yellow("Possible reasons:"));
|
|
2009
2705
|
console.log(chalk4__default.default.gray(" 1. Theme not uploaded to S3 yet"));
|
|
@@ -2032,15 +2728,11 @@ function showDownloadFailureHelp(themeId, bucket) {
|
|
|
2032
2728
|
);
|
|
2033
2729
|
console.log();
|
|
2034
2730
|
console.log(chalk4__default.default.white("4. Verify theme exists in S3:"));
|
|
2035
|
-
console.log(
|
|
2036
|
-
chalk4__default.default.gray(
|
|
2037
|
-
` aws s3 ls s3://${bucket}/themes/${themeId}/`
|
|
2038
|
-
)
|
|
2039
|
-
);
|
|
2731
|
+
console.log(chalk4__default.default.gray(` aws s3 ls s3://${bucket}/themes/${themeId}/`));
|
|
2040
2732
|
console.log();
|
|
2041
2733
|
}
|
|
2042
2734
|
async function downloadCommand(options) {
|
|
2043
|
-
logger.header("Download Theme from S3");
|
|
2735
|
+
exports.logger.header("Download Theme from S3");
|
|
2044
2736
|
const spinner = ora__default.default("Initializing download...").start();
|
|
2045
2737
|
try {
|
|
2046
2738
|
const themeId = options.themeId || process.env.NEXT_PUBLIC_THEME_ID || process.env.THEME_ID;
|
|
@@ -2089,7 +2781,7 @@ async function downloadCommand(options) {
|
|
|
2089
2781
|
const manifest = await fs__default.default.readJson(manifestPath);
|
|
2090
2782
|
await createCompatibilityFiles(outputDir, manifest);
|
|
2091
2783
|
console.log();
|
|
2092
|
-
logger.success(chalk4__default.default.green.bold("Theme downloaded successfully!"));
|
|
2784
|
+
exports.logger.success(chalk4__default.default.green.bold("Theme downloaded successfully!"));
|
|
2093
2785
|
console.log();
|
|
2094
2786
|
console.log(
|
|
2095
2787
|
chalk4__default.default.cyan(" Theme: ") + chalk4__default.default.white(`${themeId}@${resolvedVersion}`)
|
|
@@ -2105,13 +2797,16 @@ async function downloadCommand(options) {
|
|
|
2105
2797
|
console.log();
|
|
2106
2798
|
} catch (error) {
|
|
2107
2799
|
spinner.fail(chalk4__default.default.red("Download failed"));
|
|
2108
|
-
logger.error(error.message);
|
|
2800
|
+
exports.logger.error(error.message);
|
|
2109
2801
|
const themeId = options.themeId || process.env.NEXT_PUBLIC_THEME_ID || "unknown";
|
|
2110
2802
|
const bucket = options.bucket || getBucketName2(options.environment);
|
|
2111
2803
|
showDownloadFailureHelp(themeId, bucket);
|
|
2112
2804
|
process.exit(1);
|
|
2113
2805
|
}
|
|
2114
2806
|
}
|
|
2807
|
+
|
|
2808
|
+
// src/commands/clone.ts
|
|
2809
|
+
init_logger();
|
|
2115
2810
|
function getS3Client3() {
|
|
2116
2811
|
const adapterMode = (process.env.ADAPTER_MODE || "aws").trim().toLowerCase();
|
|
2117
2812
|
if (adapterMode === "vps") {
|
|
@@ -2215,18 +2910,101 @@ function runInstall(cwd) {
|
|
|
2215
2910
|
proc.on("error", () => resolve(false));
|
|
2216
2911
|
});
|
|
2217
2912
|
}
|
|
2913
|
+
async function promptThemeName(originalName) {
|
|
2914
|
+
const { default: inquirer5 } = await import('inquirer');
|
|
2915
|
+
const { themeName } = await inquirer5.prompt([
|
|
2916
|
+
{
|
|
2917
|
+
type: "input",
|
|
2918
|
+
name: "themeName",
|
|
2919
|
+
message: "New theme name (kebab-case):",
|
|
2920
|
+
default: `my-${originalName}`,
|
|
2921
|
+
validate: (input) => {
|
|
2922
|
+
if (!/^[a-z][a-z0-9-]*$/.test(input)) {
|
|
2923
|
+
return "Theme name must be kebab-case (lowercase letters, numbers, hyphens)";
|
|
2924
|
+
}
|
|
2925
|
+
if (input === originalName) {
|
|
2926
|
+
return `Name must differ from the original theme "${originalName}"`;
|
|
2927
|
+
}
|
|
2928
|
+
return true;
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
]);
|
|
2932
|
+
return themeName;
|
|
2933
|
+
}
|
|
2934
|
+
async function renameTheme(themeDir, oldName, newName) {
|
|
2935
|
+
const oldPrefix = `${oldName}-`;
|
|
2936
|
+
const newPrefix = `${newName}-`;
|
|
2937
|
+
const newDisplayName = newName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
2938
|
+
const pkgPath = path__default.default.join(themeDir, "package.json");
|
|
2939
|
+
if (await fs__default.default.pathExists(pkgPath)) {
|
|
2940
|
+
const pkg = await fs__default.default.readJson(pkgPath);
|
|
2941
|
+
pkg.name = `@onex-themes/${newName}`;
|
|
2942
|
+
if (pkg.description) {
|
|
2943
|
+
pkg.description = pkg.description.replace(
|
|
2944
|
+
new RegExp(oldName, "gi"),
|
|
2945
|
+
newDisplayName
|
|
2946
|
+
);
|
|
2947
|
+
}
|
|
2948
|
+
pkg.version = "1.0.0";
|
|
2949
|
+
await fs__default.default.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
2950
|
+
}
|
|
2951
|
+
const configPath = path__default.default.join(themeDir, "theme.config.ts");
|
|
2952
|
+
if (await fs__default.default.pathExists(configPath)) {
|
|
2953
|
+
let content = await fs__default.default.readFile(configPath, "utf-8");
|
|
2954
|
+
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
2955
|
+
content = content.replace(
|
|
2956
|
+
/name:\s*"[^"]*Theme"/,
|
|
2957
|
+
`name: "${newDisplayName} Theme"`
|
|
2958
|
+
);
|
|
2959
|
+
await fs__default.default.writeFile(configPath, content);
|
|
2960
|
+
}
|
|
2961
|
+
const layoutPath = path__default.default.join(themeDir, "theme.layout.ts");
|
|
2962
|
+
if (await fs__default.default.pathExists(layoutPath)) {
|
|
2963
|
+
let content = await fs__default.default.readFile(layoutPath, "utf-8");
|
|
2964
|
+
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
2965
|
+
content = content.replace(
|
|
2966
|
+
/name:\s*"[^"]*Theme"/,
|
|
2967
|
+
`name: "${newDisplayName} Theme"`
|
|
2968
|
+
);
|
|
2969
|
+
await fs__default.default.writeFile(layoutPath, content);
|
|
2970
|
+
}
|
|
2971
|
+
const oldDisplayName = oldName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
2972
|
+
const tsFiles = await glob.glob("**/*.ts", { cwd: themeDir, nodir: true });
|
|
2973
|
+
for (const file of tsFiles) {
|
|
2974
|
+
const filePath = path__default.default.join(themeDir, file);
|
|
2975
|
+
let content = await fs__default.default.readFile(filePath, "utf-8");
|
|
2976
|
+
const original = content;
|
|
2977
|
+
content = content.replace(
|
|
2978
|
+
new RegExp(`"${oldPrefix}`, "g"),
|
|
2979
|
+
`"${newPrefix}`
|
|
2980
|
+
);
|
|
2981
|
+
content = content.replace(
|
|
2982
|
+
new RegExp(`themeId:\\s*"${oldName}"`, "g"),
|
|
2983
|
+
`themeId: "${newName}"`
|
|
2984
|
+
);
|
|
2985
|
+
content = content.replace(
|
|
2986
|
+
new RegExp(`${oldDisplayName} Theme`, "g"),
|
|
2987
|
+
`${newDisplayName} Theme`
|
|
2988
|
+
);
|
|
2989
|
+
if (content !== original) {
|
|
2990
|
+
await fs__default.default.writeFile(filePath, content);
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2218
2994
|
async function cloneCommand(themeName, options) {
|
|
2219
|
-
logger.header("Clone Theme Source");
|
|
2995
|
+
exports.logger.header("Clone Theme Source");
|
|
2996
|
+
let newName = options.name;
|
|
2997
|
+
if (!newName) {
|
|
2998
|
+
newName = await promptThemeName(themeName);
|
|
2999
|
+
}
|
|
2220
3000
|
const spinner = ora__default.default("Initializing clone...").start();
|
|
2221
3001
|
try {
|
|
2222
3002
|
const bucket = options.bucket || getBucketName3(options.environment);
|
|
2223
|
-
const outputDir = options.output || path__default.default.resolve(process.cwd(),
|
|
3003
|
+
const outputDir = options.output || path__default.default.resolve(process.cwd(), newName);
|
|
2224
3004
|
const s3Client = getS3Client3();
|
|
2225
3005
|
if (await fs__default.default.pathExists(outputDir)) {
|
|
2226
|
-
spinner.fail(
|
|
2227
|
-
|
|
2228
|
-
);
|
|
2229
|
-
logger.info(
|
|
3006
|
+
spinner.fail(chalk4__default.default.red(`Directory already exists: ${outputDir}`));
|
|
3007
|
+
exports.logger.info(
|
|
2230
3008
|
chalk4__default.default.gray(
|
|
2231
3009
|
"Use -o to specify a different output directory, or remove the existing directory."
|
|
2232
3010
|
)
|
|
@@ -2239,9 +3017,7 @@ async function cloneCommand(themeName, options) {
|
|
|
2239
3017
|
version = await resolveLatestVersion2(s3Client, bucket, themeName);
|
|
2240
3018
|
spinner.succeed(`Resolved latest version: ${chalk4__default.default.cyan(version)}`);
|
|
2241
3019
|
}
|
|
2242
|
-
spinner.start(
|
|
2243
|
-
`Downloading source.zip for ${themeName}@${version}...`
|
|
2244
|
-
);
|
|
3020
|
+
spinner.start(`Downloading source.zip for ${themeName}@${version}...`);
|
|
2245
3021
|
const s3Key = `themes/${themeName}/${version}/source.zip`;
|
|
2246
3022
|
let zipBuffer;
|
|
2247
3023
|
try {
|
|
@@ -2259,9 +3035,7 @@ async function cloneCommand(themeName, options) {
|
|
|
2259
3035
|
chalk4__default.default.yellow("The theme source may not have been uploaded yet.")
|
|
2260
3036
|
);
|
|
2261
3037
|
console.log(
|
|
2262
|
-
chalk4__default.default.gray(
|
|
2263
|
-
`Upload source with: onex upload --theme ${themeName}`
|
|
2264
|
-
)
|
|
3038
|
+
chalk4__default.default.gray(`Upload source with: onex upload --theme ${themeName}`)
|
|
2265
3039
|
);
|
|
2266
3040
|
console.log();
|
|
2267
3041
|
process.exit(1);
|
|
@@ -2274,6 +3048,13 @@ async function cloneCommand(themeName, options) {
|
|
|
2274
3048
|
zip.extractAllTo(outputDir, true);
|
|
2275
3049
|
const entries = zip.getEntries().filter((e) => !e.isDirectory);
|
|
2276
3050
|
spinner.succeed(`Extracted ${entries.length} files`);
|
|
3051
|
+
spinner.start(
|
|
3052
|
+
`Renaming theme: ${chalk4__default.default.gray(themeName)} \u2192 ${chalk4__default.default.cyan(newName)}...`
|
|
3053
|
+
);
|
|
3054
|
+
await renameTheme(outputDir, themeName, newName);
|
|
3055
|
+
spinner.succeed(
|
|
3056
|
+
`Renamed theme: ${chalk4__default.default.gray(themeName)} \u2192 ${chalk4__default.default.cyan(newName)}`
|
|
3057
|
+
);
|
|
2277
3058
|
if (options.install !== false) {
|
|
2278
3059
|
const hasPkgJson = await fs__default.default.pathExists(
|
|
2279
3060
|
path__default.default.join(outputDir, "package.json")
|
|
@@ -2293,18 +3074,17 @@ async function cloneCommand(themeName, options) {
|
|
|
2293
3074
|
}
|
|
2294
3075
|
}
|
|
2295
3076
|
console.log();
|
|
2296
|
-
logger.success(chalk4__default.default.green.bold("Theme cloned successfully!"));
|
|
3077
|
+
exports.logger.success(chalk4__default.default.green.bold("Theme cloned successfully!"));
|
|
2297
3078
|
console.log();
|
|
2298
3079
|
console.log(
|
|
2299
|
-
chalk4__default.default.cyan("
|
|
3080
|
+
chalk4__default.default.cyan(" Source: ") + chalk4__default.default.gray(`${themeName}@${version}`)
|
|
2300
3081
|
);
|
|
3082
|
+
console.log(chalk4__default.default.cyan(" Theme: ") + chalk4__default.default.white(newName));
|
|
2301
3083
|
console.log(chalk4__default.default.cyan(" Location: ") + chalk4__default.default.white(outputDir));
|
|
2302
3084
|
console.log(chalk4__default.default.cyan(" Files: ") + chalk4__default.default.white(entries.length));
|
|
2303
3085
|
console.log();
|
|
2304
3086
|
console.log(chalk4__default.default.cyan("Next steps:"));
|
|
2305
|
-
console.log(
|
|
2306
|
-
chalk4__default.default.gray(` cd ${path__default.default.relative(process.cwd(), outputDir)}`)
|
|
2307
|
-
);
|
|
3087
|
+
console.log(chalk4__default.default.gray(` cd ${path__default.default.relative(process.cwd(), outputDir)}`));
|
|
2308
3088
|
if (options.install === false) {
|
|
2309
3089
|
console.log(chalk4__default.default.gray(" pnpm install"));
|
|
2310
3090
|
}
|
|
@@ -2312,12 +3092,14 @@ async function cloneCommand(themeName, options) {
|
|
|
2312
3092
|
console.log();
|
|
2313
3093
|
} catch (error) {
|
|
2314
3094
|
spinner.fail(chalk4__default.default.red(`Clone failed: ${error.message}`));
|
|
2315
|
-
logger.error(error.stack || error.message);
|
|
3095
|
+
exports.logger.error(error.stack || error.message);
|
|
2316
3096
|
process.exit(1);
|
|
2317
3097
|
}
|
|
2318
3098
|
}
|
|
2319
3099
|
|
|
2320
|
-
|
|
3100
|
+
// src/index.ts
|
|
3101
|
+
init_logger();
|
|
3102
|
+
|
|
2321
3103
|
exports.buildCommand = buildCommand;
|
|
2322
3104
|
exports.cloneCommand = cloneCommand;
|
|
2323
3105
|
exports.copyTemplate = copyTemplate;
|
|
@@ -2336,7 +3118,6 @@ exports.installDependencies = installDependencies;
|
|
|
2336
3118
|
exports.isOneXProject = isOneXProject;
|
|
2337
3119
|
exports.listCommand = listCommand;
|
|
2338
3120
|
exports.listThemes = listThemes;
|
|
2339
|
-
exports.logger = logger;
|
|
2340
3121
|
exports.pathExists = pathExists;
|
|
2341
3122
|
exports.renderTemplate = renderTemplate;
|
|
2342
3123
|
exports.themeExists = themeExists;
|