@onexapis/cli 1.1.38 → 1.1.39
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 +384 -380
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +381 -376
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +258 -293
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +255 -289
- package/dist/index.mjs.map +1 -1
- package/dist/preview/preview-app.tsx +13 -5
- package/package.json +1 -3
- package/templates/default/AUTH_AND_PROFILE.md +167 -0
- package/templates/default/CLAUDE.md +334 -1
- package/templates/default/LAYOUT.md +195 -0
- package/templates/default/bundle-entry.ts +5 -0
- package/templates/default/esbuild.config.js +20 -0
- package/templates/default/hooks/index.ts +26 -0
- package/templates/default/hooks/use-forgot-password-form.ts +90 -0
- package/templates/default/hooks/use-login-form.ts +102 -0
- package/templates/default/hooks/use-profile-form.ts +255 -0
- package/templates/default/hooks/use-register-form.ts +154 -0
- package/templates/default/hooks/use-verify-code-form.ts +224 -0
- package/templates/default/index.ts +21 -1
- package/templates/default/pages/about.ts +2 -2
- package/templates/default/pages/forgot-password.ts +39 -0
- package/templates/default/pages/home.ts +4 -4
- package/templates/default/pages/login.ts +39 -0
- package/templates/default/pages/profile.ts +39 -0
- package/templates/default/pages/register.ts +39 -0
- package/templates/default/pages/showcase.ts +7 -7
- package/templates/default/pages/verify-code.ts +39 -0
- package/templates/default/sections/about/about.schema.ts +1 -1
- package/templates/default/sections/auth-forgot-password/auth-forgot-password-default.tsx +192 -0
- package/templates/default/sections/auth-forgot-password/auth-forgot-password.schema.ts +150 -0
- package/templates/default/sections/auth-forgot-password/index.ts +14 -0
- package/templates/default/sections/auth-login/auth-login-default.tsx +238 -0
- package/templates/default/sections/auth-login/auth-login.schema.ts +171 -0
- package/templates/default/sections/auth-login/index.ts +14 -0
- package/templates/default/sections/auth-register/auth-register-default.tsx +327 -0
- package/templates/default/sections/auth-register/auth-register.schema.ts +188 -0
- package/templates/default/sections/auth-register/index.ts +14 -0
- package/templates/default/sections/auth-verify-code/auth-verify-code-default.tsx +209 -0
- package/templates/default/sections/auth-verify-code/auth-verify-code.schema.ts +150 -0
- package/templates/default/sections/auth-verify-code/index.ts +14 -0
- package/templates/default/sections/cta/cta.schema.ts +1 -1
- package/templates/default/sections/features/features.schema.ts +1 -1
- package/templates/default/sections/footer/footer-default.tsx +214 -0
- package/templates/default/sections/footer/footer.schema.ts +170 -0
- package/templates/default/sections/footer/index.ts +14 -0
- package/templates/default/sections/gallery/gallery.schema.ts +1 -1
- package/templates/default/sections/header/header-default.tsx +322 -0
- package/templates/default/sections/header/header.schema.ts +168 -0
- package/templates/default/sections/header/index.ts +14 -0
- package/templates/default/sections/hero/hero.schema.ts +1 -1
- package/templates/default/sections/profile/index.ts +14 -0
- package/templates/default/sections/profile/profile-default.tsx +522 -0
- package/templates/default/sections/profile/profile.schema.ts +228 -0
- package/templates/default/sections/stats/stats.schema.ts +1 -1
- package/templates/default/sections/testimonials/testimonials.schema.ts +1 -1
- package/templates/default/sections-registry.ts +28 -0
- package/templates/default/theme.layout.ts +71 -2
package/dist/index.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
var chalk4 = require('chalk');
|
|
4
4
|
var ora = require('ora');
|
|
5
5
|
var esbuild = require('esbuild');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var path8 = require('path');
|
|
7
|
+
var fs7 = require('fs/promises');
|
|
8
8
|
var crypto = require('crypto');
|
|
9
9
|
var glob = require('glob');
|
|
10
10
|
var module$1 = require('module');
|
|
11
|
-
var
|
|
12
|
-
var
|
|
11
|
+
var fs3 = require('fs');
|
|
12
|
+
var child_process = require('child_process');
|
|
13
13
|
var inquirer = require('inquirer');
|
|
14
14
|
var fs = require('fs-extra');
|
|
15
15
|
var ejs = require('ejs');
|
|
@@ -42,11 +42,10 @@ function _interopNamespace(e) {
|
|
|
42
42
|
var chalk4__default = /*#__PURE__*/_interopDefault(chalk4);
|
|
43
43
|
var ora__default = /*#__PURE__*/_interopDefault(ora);
|
|
44
44
|
var esbuild__namespace = /*#__PURE__*/_interopNamespace(esbuild);
|
|
45
|
-
var
|
|
46
|
-
var
|
|
45
|
+
var path8__default = /*#__PURE__*/_interopDefault(path8);
|
|
46
|
+
var fs7__default = /*#__PURE__*/_interopDefault(fs7);
|
|
47
47
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
48
|
-
var
|
|
49
|
-
var spawn2__default = /*#__PURE__*/_interopDefault(spawn2);
|
|
48
|
+
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
50
49
|
var inquirer__default = /*#__PURE__*/_interopDefault(inquirer);
|
|
51
50
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
52
51
|
var ejs__default = /*#__PURE__*/_interopDefault(ejs);
|
|
@@ -140,8 +139,8 @@ async function generateThemeCSS(themePath, outDir) {
|
|
|
140
139
|
const tailwindcss = (await import('tailwindcss')).default;
|
|
141
140
|
const tailwindConfig = {
|
|
142
141
|
content: [
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
path8__default.default.join(themePath, "sections/**/*.{ts,tsx}"),
|
|
143
|
+
path8__default.default.join(themePath, "components/**/*.{ts,tsx}")
|
|
145
144
|
],
|
|
146
145
|
theme: { extend: {} },
|
|
147
146
|
plugins: []
|
|
@@ -151,7 +150,7 @@ async function generateThemeCSS(themePath, outDir) {
|
|
|
151
150
|
inputCSS,
|
|
152
151
|
{ from: void 0 }
|
|
153
152
|
);
|
|
154
|
-
await
|
|
153
|
+
await fs7__default.default.writeFile(path8__default.default.join(outDir, "bundle.css"), result.css);
|
|
155
154
|
exports.logger.info("Generated bundle.css");
|
|
156
155
|
} catch (err) {
|
|
157
156
|
exports.logger.warning(
|
|
@@ -162,12 +161,12 @@ async function generateThemeCSS(themePath, outDir) {
|
|
|
162
161
|
async function resolveNodeModulesFile(startDir, relativePath) {
|
|
163
162
|
let dir = startDir;
|
|
164
163
|
while (true) {
|
|
165
|
-
const candidate =
|
|
164
|
+
const candidate = path8__default.default.join(dir, "node_modules", relativePath);
|
|
166
165
|
try {
|
|
167
|
-
await
|
|
166
|
+
await fs7__default.default.access(candidate);
|
|
168
167
|
return candidate;
|
|
169
168
|
} catch {
|
|
170
|
-
const parent =
|
|
169
|
+
const parent = path8__default.default.dirname(dir);
|
|
171
170
|
if (parent === dir) break;
|
|
172
171
|
dir = parent;
|
|
173
172
|
}
|
|
@@ -191,7 +190,7 @@ async function scanImportsFromPackage(sourceDir, packageName) {
|
|
|
191
190
|
});
|
|
192
191
|
for (const file of sourceFiles) {
|
|
193
192
|
try {
|
|
194
|
-
const content = await
|
|
193
|
+
const content = await fs7__default.default.readFile(path8__default.default.join(sourceDir, file), "utf-8");
|
|
195
194
|
for (const match of content.matchAll(namespaceImportRegex)) {
|
|
196
195
|
const subpath = match[1] ? match[1].slice(1) : "";
|
|
197
196
|
if (!result[subpath]) result[subpath] = /* @__PURE__ */ new Set();
|
|
@@ -245,17 +244,17 @@ function createCoreGlobalPlugin(themePath) {
|
|
|
245
244
|
const distFileName = subpath ? `${subpath}.mjs` : "index.mjs";
|
|
246
245
|
let distPath = await resolveNodeModulesFile(
|
|
247
246
|
themePath,
|
|
248
|
-
|
|
247
|
+
path8__default.default.join("@onexapis", "core", "dist", distFileName)
|
|
249
248
|
);
|
|
250
249
|
if (!distPath) {
|
|
251
250
|
distPath = await resolveNodeModulesFile(
|
|
252
251
|
__dirname,
|
|
253
|
-
|
|
252
|
+
path8__default.default.join("@onexapis", "core", "dist", distFileName)
|
|
254
253
|
);
|
|
255
254
|
}
|
|
256
255
|
try {
|
|
257
256
|
if (!distPath) throw new Error("not found");
|
|
258
|
-
const distContent = await
|
|
257
|
+
const distContent = await fs7__default.default.readFile(distPath, "utf-8");
|
|
259
258
|
const exportMatches = distContent.matchAll(/export\s*\{([^}]+)\}/g);
|
|
260
259
|
for (const m of exportMatches) {
|
|
261
260
|
const names = m[1].split(",").map((n) => {
|
|
@@ -484,7 +483,7 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
484
483
|
const pages = {};
|
|
485
484
|
for (const ext of [".ts", ".js"]) {
|
|
486
485
|
try {
|
|
487
|
-
const mod = await jiti.import(
|
|
486
|
+
const mod = await jiti.import(path8__default.default.join(themePath, `theme.config${ext}`));
|
|
488
487
|
themeConfig = mod.default || mod;
|
|
489
488
|
break;
|
|
490
489
|
} catch {
|
|
@@ -492,20 +491,20 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
492
491
|
}
|
|
493
492
|
for (const ext of [".ts", ".js"]) {
|
|
494
493
|
try {
|
|
495
|
-
const mod = await jiti.import(
|
|
494
|
+
const mod = await jiti.import(path8__default.default.join(themePath, `theme.layout${ext}`));
|
|
496
495
|
layoutConfig = mod.default || mod;
|
|
497
496
|
break;
|
|
498
497
|
} catch {
|
|
499
498
|
}
|
|
500
499
|
}
|
|
501
500
|
const schemas = {};
|
|
502
|
-
const sectionsDir =
|
|
501
|
+
const sectionsDir = path8__default.default.join(themePath, "sections");
|
|
503
502
|
try {
|
|
504
|
-
const sectionDirs = await
|
|
503
|
+
const sectionDirs = await fs7__default.default.readdir(sectionsDir);
|
|
505
504
|
for (const dir of sectionDirs) {
|
|
506
|
-
const schemaFile =
|
|
505
|
+
const schemaFile = path8__default.default.join(sectionsDir, dir, `${dir}.schema.ts`);
|
|
507
506
|
try {
|
|
508
|
-
await
|
|
507
|
+
await fs7__default.default.access(schemaFile);
|
|
509
508
|
const mod = await jiti.import(schemaFile);
|
|
510
509
|
for (const [key, value] of Object.entries(mod)) {
|
|
511
510
|
if (key.endsWith("Schema") && value && typeof value === "object" && value.type) {
|
|
@@ -517,14 +516,14 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
517
516
|
}
|
|
518
517
|
} catch {
|
|
519
518
|
}
|
|
520
|
-
const pagesDir =
|
|
519
|
+
const pagesDir = path8__default.default.join(themePath, "pages");
|
|
521
520
|
try {
|
|
522
|
-
const files = await
|
|
521
|
+
const files = await fs7__default.default.readdir(pagesDir);
|
|
523
522
|
for (const file of files) {
|
|
524
523
|
if (!file.match(/\.(ts|js)$/)) continue;
|
|
525
524
|
const name = file.replace(/\.(ts|js)$/, "");
|
|
526
525
|
try {
|
|
527
|
-
const mod = await jiti.import(
|
|
526
|
+
const mod = await jiti.import(path8__default.default.join(pagesDir, file));
|
|
528
527
|
const config = mod.default || mod;
|
|
529
528
|
const sections = (config.sections || []).map((section) => {
|
|
530
529
|
const schema = schemas[section.type];
|
|
@@ -552,8 +551,8 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
552
551
|
}
|
|
553
552
|
} catch {
|
|
554
553
|
}
|
|
555
|
-
await
|
|
556
|
-
|
|
554
|
+
await fs7__default.default.writeFile(
|
|
555
|
+
path8__default.default.join(outputDir, "theme-data.json"),
|
|
557
556
|
JSON.stringify(
|
|
558
557
|
{
|
|
559
558
|
themeId,
|
|
@@ -576,36 +575,36 @@ async function generateThemeData(themePath, outputDir, themeId) {
|
|
|
576
575
|
exports.logger.info(`Generated theme-data.json (${Object.keys(pages).length} pages)`);
|
|
577
576
|
}
|
|
578
577
|
async function contentHashEntry(outputDir) {
|
|
579
|
-
const entryPath =
|
|
580
|
-
const mapPath =
|
|
578
|
+
const entryPath = path8__default.default.join(outputDir, "bundle-entry.js");
|
|
579
|
+
const mapPath = path8__default.default.join(outputDir, "bundle-entry.js.map");
|
|
581
580
|
const oldFiles = await glob.glob("bundle-entry-*.js*", { cwd: outputDir });
|
|
582
581
|
for (const f of oldFiles) {
|
|
583
|
-
await
|
|
582
|
+
await fs7__default.default.unlink(path8__default.default.join(outputDir, f));
|
|
584
583
|
}
|
|
585
584
|
let entryContent;
|
|
586
585
|
try {
|
|
587
|
-
entryContent = await
|
|
586
|
+
entryContent = await fs7__default.default.readFile(entryPath, "utf-8");
|
|
588
587
|
} catch {
|
|
589
|
-
const indexPath =
|
|
588
|
+
const indexPath = path8__default.default.join(outputDir, "index.js");
|
|
590
589
|
try {
|
|
591
|
-
entryContent = await
|
|
590
|
+
entryContent = await fs7__default.default.readFile(indexPath, "utf-8");
|
|
592
591
|
} catch {
|
|
593
592
|
exports.logger.warning("No entry file found in output, skipping content hash");
|
|
594
593
|
return;
|
|
595
594
|
}
|
|
596
595
|
const hash2 = crypto__default.default.createHash("sha256").update(entryContent).digest("hex").slice(0, 8);
|
|
597
596
|
const hashedName2 = `bundle-entry-${hash2}.js`;
|
|
598
|
-
const indexMapPath =
|
|
597
|
+
const indexMapPath = path8__default.default.join(outputDir, "index.js.map");
|
|
599
598
|
const hashedMapName2 = `bundle-entry-${hash2}.js.map`;
|
|
600
599
|
entryContent = entryContent.replace(
|
|
601
600
|
/\/\/# sourceMappingURL=index\.js\.map/,
|
|
602
601
|
`//# sourceMappingURL=${hashedMapName2}`
|
|
603
602
|
);
|
|
604
|
-
await
|
|
605
|
-
await
|
|
603
|
+
await fs7__default.default.writeFile(path8__default.default.join(outputDir, hashedName2), entryContent);
|
|
604
|
+
await fs7__default.default.unlink(indexPath);
|
|
606
605
|
try {
|
|
607
|
-
await
|
|
608
|
-
await
|
|
606
|
+
await fs7__default.default.access(indexMapPath);
|
|
607
|
+
await fs7__default.default.rename(indexMapPath, path8__default.default.join(outputDir, hashedMapName2));
|
|
609
608
|
} catch {
|
|
610
609
|
}
|
|
611
610
|
exports.logger.info(`Entry hashed: ${hashedName2}`);
|
|
@@ -618,11 +617,11 @@ async function contentHashEntry(outputDir) {
|
|
|
618
617
|
/\/\/# sourceMappingURL=bundle-entry\.js\.map/,
|
|
619
618
|
`//# sourceMappingURL=${hashedMapName}`
|
|
620
619
|
);
|
|
621
|
-
await
|
|
622
|
-
await
|
|
620
|
+
await fs7__default.default.writeFile(path8__default.default.join(outputDir, hashedName), entryContent);
|
|
621
|
+
await fs7__default.default.unlink(entryPath);
|
|
623
622
|
try {
|
|
624
|
-
await
|
|
625
|
-
await
|
|
623
|
+
await fs7__default.default.access(mapPath);
|
|
624
|
+
await fs7__default.default.rename(mapPath, path8__default.default.join(outputDir, hashedMapName));
|
|
626
625
|
} catch {
|
|
627
626
|
}
|
|
628
627
|
exports.logger.info(`Entry hashed: ${hashedName}`);
|
|
@@ -634,7 +633,7 @@ async function extractDataRequirements(themePath) {
|
|
|
634
633
|
const requirements = {};
|
|
635
634
|
for (const file of schemaFiles) {
|
|
636
635
|
try {
|
|
637
|
-
const mod = await jiti.import(
|
|
636
|
+
const mod = await jiti.import(path8__default.default.join(themePath, file));
|
|
638
637
|
const exports$1 = mod;
|
|
639
638
|
for (const value of Object.values(exports$1)) {
|
|
640
639
|
if (value && typeof value === "object" && typeof value.type === "string" && value.dataRequirements && typeof value.dataRequirements === "object") {
|
|
@@ -653,8 +652,8 @@ async function generateManifest(themeName, themePath, outputDir) {
|
|
|
653
652
|
let version = "1.0.0";
|
|
654
653
|
let themeId = themeName;
|
|
655
654
|
try {
|
|
656
|
-
const pkgContent = await
|
|
657
|
-
|
|
655
|
+
const pkgContent = await fs7__default.default.readFile(
|
|
656
|
+
path8__default.default.join(themePath, "package.json"),
|
|
658
657
|
"utf-8"
|
|
659
658
|
);
|
|
660
659
|
const pkg = JSON.parse(pkgContent);
|
|
@@ -672,7 +671,7 @@ async function generateManifest(themeName, themePath, outputDir) {
|
|
|
672
671
|
const dataRequirements = await extractDataRequirements(themePath);
|
|
673
672
|
let hasThemeConfig = false;
|
|
674
673
|
try {
|
|
675
|
-
await
|
|
674
|
+
await fs7__default.default.access(path8__default.default.join(themePath, "theme.config.ts"));
|
|
676
675
|
hasThemeConfig = true;
|
|
677
676
|
} catch {
|
|
678
677
|
}
|
|
@@ -713,24 +712,24 @@ async function generateManifest(themeName, themePath, outputDir) {
|
|
|
713
712
|
// Section data requirements for server-side prefetching (keyed by section type)
|
|
714
713
|
dataRequirements
|
|
715
714
|
};
|
|
716
|
-
await
|
|
717
|
-
|
|
715
|
+
await fs7__default.default.writeFile(
|
|
716
|
+
path8__default.default.join(outputDir, "manifest.json"),
|
|
718
717
|
JSON.stringify(manifest, null, 2)
|
|
719
718
|
);
|
|
720
719
|
}
|
|
721
720
|
async function compileStandaloneTheme(themePath, themeName) {
|
|
722
|
-
const outputDir =
|
|
723
|
-
const bundleEntry =
|
|
724
|
-
const indexEntry =
|
|
721
|
+
const outputDir = path8__default.default.join(themePath, "dist");
|
|
722
|
+
const bundleEntry = path8__default.default.join(themePath, "bundle-entry.ts");
|
|
723
|
+
const indexEntry = path8__default.default.join(themePath, "index.ts");
|
|
725
724
|
let entryPoint = indexEntry;
|
|
726
725
|
try {
|
|
727
|
-
await
|
|
726
|
+
await fs7__default.default.access(bundleEntry);
|
|
728
727
|
entryPoint = bundleEntry;
|
|
729
728
|
} catch {
|
|
730
729
|
}
|
|
731
|
-
const shimPath =
|
|
732
|
-
await
|
|
733
|
-
await
|
|
730
|
+
const shimPath = path8__default.default.join(outputDir, ".process-shim.js");
|
|
731
|
+
await fs7__default.default.mkdir(outputDir, { recursive: true });
|
|
732
|
+
await fs7__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
734
733
|
const buildOptions = {
|
|
735
734
|
entryPoints: [entryPoint],
|
|
736
735
|
bundle: true,
|
|
@@ -780,7 +779,7 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
780
779
|
try {
|
|
781
780
|
const result = await esbuild__namespace.build(buildOptions);
|
|
782
781
|
try {
|
|
783
|
-
await
|
|
782
|
+
await fs7__default.default.unlink(shimPath);
|
|
784
783
|
} catch {
|
|
785
784
|
}
|
|
786
785
|
await contentHashEntry(outputDir);
|
|
@@ -799,7 +798,7 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
799
798
|
return true;
|
|
800
799
|
} catch (error) {
|
|
801
800
|
try {
|
|
802
|
-
await
|
|
801
|
+
await fs7__default.default.unlink(shimPath);
|
|
803
802
|
} catch {
|
|
804
803
|
}
|
|
805
804
|
exports.logger.error(`esbuild compilation failed: ${error}`);
|
|
@@ -807,18 +806,18 @@ async function compileStandaloneTheme(themePath, themeName) {
|
|
|
807
806
|
}
|
|
808
807
|
}
|
|
809
808
|
async function compileStandaloneThemeDev(themePath, themeName) {
|
|
810
|
-
const outputDir =
|
|
811
|
-
const bundleEntry =
|
|
812
|
-
const indexEntry =
|
|
809
|
+
const outputDir = path8__default.default.join(themePath, "dist");
|
|
810
|
+
const bundleEntry = path8__default.default.join(themePath, "bundle-entry.ts");
|
|
811
|
+
const indexEntry = path8__default.default.join(themePath, "index.ts");
|
|
813
812
|
let entryPoint = indexEntry;
|
|
814
813
|
try {
|
|
815
|
-
await
|
|
814
|
+
await fs7__default.default.access(bundleEntry);
|
|
816
815
|
entryPoint = bundleEntry;
|
|
817
816
|
} catch {
|
|
818
817
|
}
|
|
819
|
-
const shimPath =
|
|
820
|
-
await
|
|
821
|
-
await
|
|
818
|
+
const shimPath = path8__default.default.join(outputDir, ".process-shim.js");
|
|
819
|
+
await fs7__default.default.mkdir(outputDir, { recursive: true });
|
|
820
|
+
await fs7__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
822
821
|
const buildOptions = {
|
|
823
822
|
entryPoints: [entryPoint],
|
|
824
823
|
bundle: true,
|
|
@@ -871,18 +870,18 @@ async function compileStandaloneThemeDev(themePath, themeName) {
|
|
|
871
870
|
return { context: context2, outputDir };
|
|
872
871
|
}
|
|
873
872
|
async function compilePreviewRuntime(themePath) {
|
|
874
|
-
const outputDir =
|
|
875
|
-
await
|
|
876
|
-
const outputPath =
|
|
873
|
+
const outputDir = path8__default.default.join(themePath, "dist");
|
|
874
|
+
await fs7__default.default.mkdir(outputDir, { recursive: true });
|
|
875
|
+
const outputPath = path8__default.default.join(outputDir, "preview-runtime.js");
|
|
877
876
|
const locations = [
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
877
|
+
path8__default.default.join(__dirname, "..", "preview", "preview-app.tsx"),
|
|
878
|
+
path8__default.default.join(__dirname, "preview", "preview-app.tsx"),
|
|
879
|
+
path8__default.default.join(__dirname, "..", "..", "src", "preview", "preview-app.tsx")
|
|
881
880
|
];
|
|
882
881
|
let previewEntryPath = null;
|
|
883
882
|
for (const loc of locations) {
|
|
884
883
|
try {
|
|
885
|
-
await
|
|
884
|
+
await fs7__default.default.access(loc);
|
|
886
885
|
previewEntryPath = loc;
|
|
887
886
|
break;
|
|
888
887
|
} catch {
|
|
@@ -965,10 +964,10 @@ ${locations.join("\n")}`
|
|
|
965
964
|
if (!lucideScanned) {
|
|
966
965
|
lucideScanned = true;
|
|
967
966
|
const coreSrcCandidates = [
|
|
968
|
-
|
|
969
|
-
|
|
967
|
+
path8__default.default.join(themePath, "node_modules", "@onexapis", "core", "src"),
|
|
968
|
+
path8__default.default.join(themePath, "..", "..", "packages", "core", "src"),
|
|
970
969
|
// monorepo sibling
|
|
971
|
-
|
|
970
|
+
path8__default.default.join(
|
|
972
971
|
__dirname,
|
|
973
972
|
"..",
|
|
974
973
|
"..",
|
|
@@ -983,7 +982,7 @@ ${locations.join("\n")}`
|
|
|
983
982
|
let coreSourceDir = null;
|
|
984
983
|
for (const candidate of coreSrcCandidates) {
|
|
985
984
|
try {
|
|
986
|
-
await
|
|
985
|
+
await fs7__default.default.access(candidate);
|
|
987
986
|
coreSourceDir = candidate;
|
|
988
987
|
break;
|
|
989
988
|
} catch {
|
|
@@ -1002,21 +1001,21 @@ ${locations.join("\n")}`
|
|
|
1002
1001
|
}
|
|
1003
1002
|
} else {
|
|
1004
1003
|
const coreDistCandidates = [
|
|
1005
|
-
|
|
1004
|
+
path8__default.default.join(themePath, "node_modules", "@onexapis", "core", "dist")
|
|
1006
1005
|
];
|
|
1007
1006
|
const resolvedDist = await resolveNodeModulesFile(
|
|
1008
1007
|
__dirname,
|
|
1009
|
-
|
|
1008
|
+
path8__default.default.join("@onexapis", "core", "dist")
|
|
1010
1009
|
);
|
|
1011
1010
|
if (resolvedDist) coreDistCandidates.push(resolvedDist);
|
|
1012
1011
|
for (const candidate of coreDistCandidates) {
|
|
1013
1012
|
try {
|
|
1014
|
-
await
|
|
1013
|
+
await fs7__default.default.access(candidate);
|
|
1015
1014
|
const mjsFiles = await glob.glob("*.mjs", { cwd: candidate });
|
|
1016
1015
|
const importRegex = /import\s*\{([^}]+)\}\s*from\s*["']lucide-react["']/g;
|
|
1017
1016
|
for (const file of mjsFiles) {
|
|
1018
|
-
const content = await
|
|
1019
|
-
|
|
1017
|
+
const content = await fs7__default.default.readFile(
|
|
1018
|
+
path8__default.default.join(candidate, file),
|
|
1020
1019
|
"utf-8"
|
|
1021
1020
|
);
|
|
1022
1021
|
for (const match of content.matchAll(importRegex)) {
|
|
@@ -1071,7 +1070,7 @@ export default new Proxy({}, { get: (_, name) => name === '__esModule' ? true :
|
|
|
1071
1070
|
const req = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) || __filename);
|
|
1072
1071
|
const cjsPath = req.resolve("framer-motion");
|
|
1073
1072
|
const pkgDir = cjsPath.replace(/[/\\]dist[/\\].*$/, "");
|
|
1074
|
-
const esmEntry =
|
|
1073
|
+
const esmEntry = path8__default.default.join(pkgDir, "dist", "es", "index.mjs");
|
|
1075
1074
|
const { existsSync } = await import('fs');
|
|
1076
1075
|
if (existsSync(esmEntry)) {
|
|
1077
1076
|
return { path: esmEntry, namespace: "file" };
|
|
@@ -1170,8 +1169,8 @@ export function headers() { return new Headers(); }
|
|
|
1170
1169
|
});
|
|
1171
1170
|
}
|
|
1172
1171
|
};
|
|
1173
|
-
const shimPath =
|
|
1174
|
-
await
|
|
1172
|
+
const shimPath = path8__default.default.join(outputDir, ".process-shim-preview.js");
|
|
1173
|
+
await fs7__default.default.writeFile(shimPath, PROCESS_SHIM);
|
|
1175
1174
|
await esbuild__namespace.build({
|
|
1176
1175
|
entryPoints: [previewEntryPath],
|
|
1177
1176
|
bundle: true,
|
|
@@ -1206,7 +1205,7 @@ export function headers() { return new Headers(); }
|
|
|
1206
1205
|
}
|
|
1207
1206
|
});
|
|
1208
1207
|
try {
|
|
1209
|
-
await
|
|
1208
|
+
await fs7__default.default.unlink(shimPath);
|
|
1210
1209
|
} catch {
|
|
1211
1210
|
}
|
|
1212
1211
|
return outputPath;
|
|
@@ -1353,8 +1352,8 @@ function validateThemeName(name) {
|
|
|
1353
1352
|
return /^[a-z][a-z0-9-]*$/.test(name);
|
|
1354
1353
|
}
|
|
1355
1354
|
function pathExists(filePath) {
|
|
1356
|
-
const
|
|
1357
|
-
return
|
|
1355
|
+
const fs12 = __require("fs-extra");
|
|
1356
|
+
return fs12.existsSync(filePath);
|
|
1358
1357
|
}
|
|
1359
1358
|
function validateCategory(category) {
|
|
1360
1359
|
const validCategories = [
|
|
@@ -1395,18 +1394,18 @@ async function renderTemplate(templatePath, data) {
|
|
|
1395
1394
|
return ejs__default.default.render(template, data);
|
|
1396
1395
|
}
|
|
1397
1396
|
async function writeFile(filePath, content) {
|
|
1398
|
-
await fs__default.default.ensureDir(
|
|
1397
|
+
await fs__default.default.ensureDir(path8__default.default.dirname(filePath));
|
|
1399
1398
|
await fs__default.default.writeFile(filePath, content, "utf-8");
|
|
1400
1399
|
}
|
|
1401
1400
|
function getTemplatesDir() {
|
|
1402
1401
|
const locations = [
|
|
1403
|
-
|
|
1402
|
+
path8__default.default.join(__dirname, "../../templates"),
|
|
1404
1403
|
// Development
|
|
1405
|
-
|
|
1404
|
+
path8__default.default.join(__dirname, "../templates"),
|
|
1406
1405
|
// Production (dist/)
|
|
1407
|
-
|
|
1406
|
+
path8__default.default.join(process.cwd(), "templates"),
|
|
1408
1407
|
// Fallback
|
|
1409
|
-
|
|
1408
|
+
path8__default.default.join(process.cwd(), "packages/cli/templates")
|
|
1410
1409
|
// Monorepo
|
|
1411
1410
|
];
|
|
1412
1411
|
for (const location of locations) {
|
|
@@ -1418,7 +1417,7 @@ function getTemplatesDir() {
|
|
|
1418
1417
|
}
|
|
1419
1418
|
async function copyTemplate(templateName, targetDir, data) {
|
|
1420
1419
|
const templatesDir = getTemplatesDir();
|
|
1421
|
-
const templateDir =
|
|
1420
|
+
const templateDir = path8__default.default.join(templatesDir, templateName);
|
|
1422
1421
|
if (!fs__default.default.existsSync(templateDir)) {
|
|
1423
1422
|
throw new Error(
|
|
1424
1423
|
`Template "${templateName}" not found at ${templateDir}. Available templates: ${fs__default.default.readdirSync(templatesDir).join(", ")}`
|
|
@@ -1427,8 +1426,8 @@ async function copyTemplate(templateName, targetDir, data) {
|
|
|
1427
1426
|
await fs__default.default.ensureDir(targetDir);
|
|
1428
1427
|
const files = await fs__default.default.readdir(templateDir);
|
|
1429
1428
|
for (const file of files) {
|
|
1430
|
-
const templatePath =
|
|
1431
|
-
const targetPath =
|
|
1429
|
+
const templatePath = path8__default.default.join(templateDir, file);
|
|
1430
|
+
const targetPath = path8__default.default.join(targetDir, file);
|
|
1432
1431
|
const stat = await fs__default.default.stat(templatePath);
|
|
1433
1432
|
if (stat.isDirectory()) {
|
|
1434
1433
|
await copyTemplateDir(templatePath, targetPath, data);
|
|
@@ -1445,8 +1444,8 @@ async function copyTemplateDir(templateDir, targetDir, data) {
|
|
|
1445
1444
|
await fs__default.default.ensureDir(targetDir);
|
|
1446
1445
|
const files = await fs__default.default.readdir(templateDir);
|
|
1447
1446
|
for (const file of files) {
|
|
1448
|
-
const templatePath =
|
|
1449
|
-
const targetPath =
|
|
1447
|
+
const templatePath = path8__default.default.join(templateDir, file);
|
|
1448
|
+
const targetPath = path8__default.default.join(targetDir, file);
|
|
1450
1449
|
const stat = await fs__default.default.stat(templatePath);
|
|
1451
1450
|
if (stat.isDirectory()) {
|
|
1452
1451
|
await copyTemplateDir(templatePath, targetPath, data);
|
|
@@ -1461,32 +1460,32 @@ async function copyTemplateDir(templateDir, targetDir, data) {
|
|
|
1461
1460
|
}
|
|
1462
1461
|
function getProjectRoot() {
|
|
1463
1462
|
let currentDir = process.cwd();
|
|
1464
|
-
while (currentDir !==
|
|
1465
|
-
const packageJsonPath =
|
|
1463
|
+
while (currentDir !== path8__default.default.parse(currentDir).root) {
|
|
1464
|
+
const packageJsonPath = path8__default.default.join(currentDir, "package.json");
|
|
1466
1465
|
if (fs__default.default.existsSync(packageJsonPath)) {
|
|
1467
1466
|
const packageJson = fs__default.default.readJsonSync(packageJsonPath);
|
|
1468
|
-
if (packageJson.workspaces || fs__default.default.existsSync(
|
|
1467
|
+
if (packageJson.workspaces || fs__default.default.existsSync(path8__default.default.join(currentDir, "src/themes")) || fs__default.default.existsSync(path8__default.default.join(currentDir, "themes"))) {
|
|
1469
1468
|
return currentDir;
|
|
1470
1469
|
}
|
|
1471
1470
|
}
|
|
1472
|
-
currentDir =
|
|
1471
|
+
currentDir = path8__default.default.dirname(currentDir);
|
|
1473
1472
|
}
|
|
1474
1473
|
return process.cwd();
|
|
1475
1474
|
}
|
|
1476
1475
|
function getThemesDir() {
|
|
1477
1476
|
const root = getProjectRoot();
|
|
1478
|
-
if (fs__default.default.existsSync(
|
|
1479
|
-
return
|
|
1480
|
-
if (fs__default.default.existsSync(
|
|
1481
|
-
return
|
|
1482
|
-
return
|
|
1477
|
+
if (fs__default.default.existsSync(path8__default.default.join(root, "themes")))
|
|
1478
|
+
return path8__default.default.join(root, "themes");
|
|
1479
|
+
if (fs__default.default.existsSync(path8__default.default.join(root, "src/themes")))
|
|
1480
|
+
return path8__default.default.join(root, "src/themes");
|
|
1481
|
+
return path8__default.default.dirname(root);
|
|
1483
1482
|
}
|
|
1484
1483
|
function getFeaturesDir() {
|
|
1485
|
-
return
|
|
1484
|
+
return path8__default.default.join(getProjectRoot(), "src/features");
|
|
1486
1485
|
}
|
|
1487
1486
|
function isOneXProject() {
|
|
1488
1487
|
const root = getProjectRoot();
|
|
1489
|
-
return fs__default.default.existsSync(
|
|
1488
|
+
return fs__default.default.existsSync(path8__default.default.join(root, "themes")) || fs__default.default.existsSync(path8__default.default.join(root, "src/themes")) || fs__default.default.existsSync(path8__default.default.join(root, "theme.config.ts")) || fs__default.default.existsSync(path8__default.default.join(root, "bundle-entry.ts"));
|
|
1490
1489
|
}
|
|
1491
1490
|
function ensureOneXProject() {
|
|
1492
1491
|
if (!isOneXProject()) {
|
|
@@ -1502,13 +1501,13 @@ function listThemes() {
|
|
|
1502
1501
|
return [];
|
|
1503
1502
|
}
|
|
1504
1503
|
return fs__default.default.readdirSync(themesDir).filter((name) => {
|
|
1505
|
-
const themePath =
|
|
1506
|
-
return fs__default.default.statSync(themePath).isDirectory() && (fs__default.default.existsSync(
|
|
1504
|
+
const themePath = path8__default.default.join(themesDir, name);
|
|
1505
|
+
return fs__default.default.statSync(themePath).isDirectory() && (fs__default.default.existsSync(path8__default.default.join(themePath, "theme.config.ts")) || fs__default.default.existsSync(path8__default.default.join(themePath, "bundle-entry.ts")) || fs__default.default.existsSync(path8__default.default.join(themePath, "manifest.ts")));
|
|
1507
1506
|
});
|
|
1508
1507
|
}
|
|
1509
1508
|
function themeExists(themeName) {
|
|
1510
|
-
const themePath =
|
|
1511
|
-
return fs__default.default.existsSync(themePath) && (fs__default.default.existsSync(
|
|
1509
|
+
const themePath = path8__default.default.join(getThemesDir(), themeName);
|
|
1510
|
+
return fs__default.default.existsSync(themePath) && (fs__default.default.existsSync(path8__default.default.join(themePath, "theme.config.ts")) || fs__default.default.existsSync(path8__default.default.join(themePath, "bundle-entry.ts")) || fs__default.default.existsSync(path8__default.default.join(themePath, "manifest.ts")));
|
|
1512
1511
|
}
|
|
1513
1512
|
function detectPackageManager() {
|
|
1514
1513
|
const userAgent = process.env.npm_config_user_agent || "";
|
|
@@ -1516,92 +1515,30 @@ function detectPackageManager() {
|
|
|
1516
1515
|
if (userAgent.includes("yarn")) return "yarn";
|
|
1517
1516
|
if (userAgent.includes("bun")) return "bun";
|
|
1518
1517
|
const cwd = process.cwd();
|
|
1519
|
-
if (fs__default.default.existsSync(
|
|
1520
|
-
if (fs__default.default.existsSync(
|
|
1521
|
-
if (fs__default.default.existsSync(
|
|
1518
|
+
if (fs__default.default.existsSync(path8__default.default.join(cwd, "pnpm-lock.yaml"))) return "pnpm";
|
|
1519
|
+
if (fs__default.default.existsSync(path8__default.default.join(cwd, "yarn.lock"))) return "yarn";
|
|
1520
|
+
if (fs__default.default.existsSync(path8__default.default.join(cwd, "bun.lockb"))) return "bun";
|
|
1522
1521
|
return "npm";
|
|
1523
1522
|
}
|
|
1524
1523
|
async function installDependencies(projectPath, packageManager = "npm") {
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1524
|
+
return new Promise((resolve, reject) => {
|
|
1525
|
+
try {
|
|
1526
|
+
const installCmd = packageManager === "yarn" ? "yarn" : `${packageManager} install`;
|
|
1527
|
+
child_process.execSync(installCmd, {
|
|
1528
|
+
cwd: projectPath,
|
|
1529
|
+
stdio: "inherit"
|
|
1530
|
+
});
|
|
1531
|
+
resolve();
|
|
1532
|
+
} catch (error) {
|
|
1533
|
+
reject(error);
|
|
1534
|
+
}
|
|
1529
1535
|
});
|
|
1530
|
-
if (result.status !== 0) {
|
|
1531
|
-
throw new Error(
|
|
1532
|
-
`${packageManager} install failed with exit code ${result.status}`
|
|
1533
|
-
);
|
|
1534
|
-
}
|
|
1535
1536
|
}
|
|
1536
|
-
var AUTH_DIR =
|
|
1537
|
-
|
|
1537
|
+
var AUTH_DIR = path8__default.default.join(os__default.default.homedir(), ".onexthm");
|
|
1538
|
+
path8__default.default.join(AUTH_DIR, "auth.json");
|
|
1538
1539
|
function getApiUrl() {
|
|
1539
1540
|
return process.env.ONEXTHM_API_URL || process.env.NEXT_PUBLIC_API_URL || "https://platform-dev.onexeos.com";
|
|
1540
1541
|
}
|
|
1541
|
-
function getNpxCommand() {
|
|
1542
|
-
return process.platform === "win32" ? "npx.cmd" : "npx";
|
|
1543
|
-
}
|
|
1544
|
-
function getDefaultMcpConfig() {
|
|
1545
|
-
return {
|
|
1546
|
-
mcpServers: {
|
|
1547
|
-
onexthm: {
|
|
1548
|
-
command: getNpxCommand(),
|
|
1549
|
-
args: ["-y", "@onexapis/theme-mcp"]
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1554
|
-
function ensureMcpJson(projectPath, figmaApiKey) {
|
|
1555
|
-
const mcpJsonPath = path9__default.default.join(projectPath, ".mcp.json");
|
|
1556
|
-
const npx = getNpxCommand();
|
|
1557
|
-
let mcpConfig;
|
|
1558
|
-
if (fs4__default.default.existsSync(mcpJsonPath)) {
|
|
1559
|
-
try {
|
|
1560
|
-
mcpConfig = JSON.parse(fs4__default.default.readFileSync(mcpJsonPath, "utf-8"));
|
|
1561
|
-
if (!mcpConfig.mcpServers) {
|
|
1562
|
-
mcpConfig.mcpServers = {};
|
|
1563
|
-
}
|
|
1564
|
-
} catch {
|
|
1565
|
-
mcpConfig = getDefaultMcpConfig();
|
|
1566
|
-
}
|
|
1567
|
-
} else {
|
|
1568
|
-
mcpConfig = getDefaultMcpConfig();
|
|
1569
|
-
}
|
|
1570
|
-
mcpConfig.mcpServers.onexthm = {
|
|
1571
|
-
command: npx,
|
|
1572
|
-
args: ["-y", "@onexapis/theme-mcp"]
|
|
1573
|
-
};
|
|
1574
|
-
if (figmaApiKey) {
|
|
1575
|
-
mcpConfig.mcpServers.figma = {
|
|
1576
|
-
command: npx,
|
|
1577
|
-
args: [
|
|
1578
|
-
"-y",
|
|
1579
|
-
"figma-developer-mcp",
|
|
1580
|
-
`--figma-api-key=${figmaApiKey}`,
|
|
1581
|
-
"--stdio"
|
|
1582
|
-
]
|
|
1583
|
-
};
|
|
1584
|
-
} else {
|
|
1585
|
-
delete mcpConfig.mcpServers.figma;
|
|
1586
|
-
}
|
|
1587
|
-
fs4__default.default.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2) + "\n");
|
|
1588
|
-
ensureThemeMcpDependency(projectPath);
|
|
1589
|
-
}
|
|
1590
|
-
function ensureThemeMcpDependency(projectPath) {
|
|
1591
|
-
const pkgJsonPath = path9__default.default.join(projectPath, "package.json");
|
|
1592
|
-
if (!fs4__default.default.existsSync(pkgJsonPath)) return;
|
|
1593
|
-
try {
|
|
1594
|
-
const pkg = JSON.parse(fs4__default.default.readFileSync(pkgJsonPath, "utf-8"));
|
|
1595
|
-
if (!pkg.devDependencies) {
|
|
1596
|
-
pkg.devDependencies = {};
|
|
1597
|
-
}
|
|
1598
|
-
if (!pkg.devDependencies["@onexapis/theme-mcp"]) {
|
|
1599
|
-
pkg.devDependencies["@onexapis/theme-mcp"] = "^0.1.0";
|
|
1600
|
-
fs4__default.default.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
1601
|
-
}
|
|
1602
|
-
} catch {
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
1542
|
|
|
1606
1543
|
// src/commands/init.ts
|
|
1607
1544
|
async function initCommand(projectName, options = {}) {
|
|
@@ -1619,7 +1556,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
1619
1556
|
if (!validateThemeName(kebabName)) {
|
|
1620
1557
|
return "Invalid project name. Use lowercase letters, numbers, and hyphens only.";
|
|
1621
1558
|
}
|
|
1622
|
-
if (
|
|
1559
|
+
if (fs3__default.default.existsSync(path8__default.default.join(process.cwd(), kebabName))) {
|
|
1623
1560
|
return `Directory "${kebabName}" already exists`;
|
|
1624
1561
|
}
|
|
1625
1562
|
return true;
|
|
@@ -1630,8 +1567,8 @@ async function initCommand(projectName, options = {}) {
|
|
|
1630
1567
|
} else {
|
|
1631
1568
|
name = toKebabCase(projectName);
|
|
1632
1569
|
}
|
|
1633
|
-
const projectPath =
|
|
1634
|
-
if (
|
|
1570
|
+
const projectPath = path8__default.default.join(process.cwd(), name);
|
|
1571
|
+
if (fs3__default.default.existsSync(projectPath)) {
|
|
1635
1572
|
exports.logger.error(`Directory "${name}" already exists.`);
|
|
1636
1573
|
process.exit(1);
|
|
1637
1574
|
}
|
|
@@ -1737,7 +1674,7 @@ async function initCommand(projectName, options = {}) {
|
|
|
1737
1674
|
}
|
|
1738
1675
|
exports.logger.startSpinner("Creating project structure...");
|
|
1739
1676
|
try {
|
|
1740
|
-
|
|
1677
|
+
fs3__default.default.mkdirSync(projectPath, { recursive: true });
|
|
1741
1678
|
await copyTemplate(template, projectPath, data);
|
|
1742
1679
|
await renameThemeInFiles(
|
|
1743
1680
|
projectPath,
|
|
@@ -1746,14 +1683,28 @@ async function initCommand(projectName, options = {}) {
|
|
|
1746
1683
|
description,
|
|
1747
1684
|
author
|
|
1748
1685
|
);
|
|
1749
|
-
|
|
1686
|
+
const mcpJsonPath = path8__default.default.join(projectPath, ".mcp.json");
|
|
1687
|
+
if (fs3__default.default.existsSync(mcpJsonPath)) {
|
|
1688
|
+
let mcpContent = fs3__default.default.readFileSync(mcpJsonPath, "utf-8");
|
|
1689
|
+
if (figmaApiKey) {
|
|
1690
|
+
mcpContent = mcpContent.replace("__FIGMA_API_KEY__", figmaApiKey);
|
|
1691
|
+
} else {
|
|
1692
|
+
try {
|
|
1693
|
+
const mcpJson = JSON.parse(mcpContent);
|
|
1694
|
+
delete mcpJson.mcpServers.figma;
|
|
1695
|
+
mcpContent = JSON.stringify(mcpJson, null, 2) + "\n";
|
|
1696
|
+
} catch {
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
fs3__default.default.writeFileSync(mcpJsonPath, mcpContent, "utf-8");
|
|
1700
|
+
}
|
|
1750
1701
|
exports.logger.stopSpinner(true, "Project structure created!");
|
|
1751
1702
|
if (options.git) {
|
|
1752
1703
|
exports.logger.startSpinner("Initializing git repository...");
|
|
1753
1704
|
try {
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1705
|
+
child_process.execSync("git init", { cwd: projectPath, stdio: "ignore" });
|
|
1706
|
+
child_process.execSync("git add .", { cwd: projectPath, stdio: "ignore" });
|
|
1707
|
+
child_process.execSync('git commit -m "Initial commit from onexthm init"', {
|
|
1757
1708
|
cwd: projectPath,
|
|
1758
1709
|
stdio: "ignore"
|
|
1759
1710
|
});
|
|
@@ -1805,16 +1756,16 @@ async function initCommand(projectName, options = {}) {
|
|
|
1805
1756
|
exports.logger.error(
|
|
1806
1757
|
error instanceof Error ? error.message : "Unknown error occurred"
|
|
1807
1758
|
);
|
|
1808
|
-
if (
|
|
1809
|
-
|
|
1759
|
+
if (fs3__default.default.existsSync(projectPath)) {
|
|
1760
|
+
fs3__default.default.rmSync(projectPath, { recursive: true, force: true });
|
|
1810
1761
|
}
|
|
1811
1762
|
process.exit(1);
|
|
1812
1763
|
}
|
|
1813
1764
|
}
|
|
1814
1765
|
async function renameThemeInFiles(projectPath, themeName, displayName, description, author) {
|
|
1815
|
-
const configPath =
|
|
1816
|
-
if (
|
|
1817
|
-
let content =
|
|
1766
|
+
const configPath = path8__default.default.join(projectPath, "theme.config.ts");
|
|
1767
|
+
if (fs3__default.default.existsSync(configPath)) {
|
|
1768
|
+
let content = fs3__default.default.readFileSync(configPath, "utf-8");
|
|
1818
1769
|
content = content.replace(
|
|
1819
1770
|
/name: "My Simple Theme"/,
|
|
1820
1771
|
`name: "${displayName}"`
|
|
@@ -1823,11 +1774,11 @@ async function renameThemeInFiles(projectPath, themeName, displayName, descripti
|
|
|
1823
1774
|
/description: ".*?"/,
|
|
1824
1775
|
`description: "${description}"`
|
|
1825
1776
|
);
|
|
1826
|
-
|
|
1777
|
+
fs3__default.default.writeFileSync(configPath, content, "utf-8");
|
|
1827
1778
|
}
|
|
1828
|
-
const pkgPath =
|
|
1829
|
-
if (
|
|
1830
|
-
let content =
|
|
1779
|
+
const pkgPath = path8__default.default.join(projectPath, "package.json");
|
|
1780
|
+
if (fs3__default.default.existsSync(pkgPath)) {
|
|
1781
|
+
let content = fs3__default.default.readFileSync(pkgPath, "utf-8");
|
|
1831
1782
|
content = content.replace(
|
|
1832
1783
|
/@onex-themes\/my-simple/g,
|
|
1833
1784
|
`@onex-themes/${themeName}`
|
|
@@ -1836,7 +1787,7 @@ async function renameThemeInFiles(projectPath, themeName, displayName, descripti
|
|
|
1836
1787
|
/"description": ".*?"/,
|
|
1837
1788
|
`"description": "${description}"`
|
|
1838
1789
|
);
|
|
1839
|
-
|
|
1790
|
+
fs3__default.default.writeFileSync(pkgPath, content, "utf-8");
|
|
1840
1791
|
}
|
|
1841
1792
|
}
|
|
1842
1793
|
|
|
@@ -1847,10 +1798,10 @@ async function createSectionCommand(name, options) {
|
|
|
1847
1798
|
ensureOneXProject();
|
|
1848
1799
|
if (!options.theme) {
|
|
1849
1800
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
1850
|
-
(f) => fs__default.default.existsSync(
|
|
1801
|
+
(f) => fs__default.default.existsSync(path8__default.default.join(process.cwd(), f))
|
|
1851
1802
|
);
|
|
1852
1803
|
if (isStandaloneTheme) {
|
|
1853
|
-
options.theme =
|
|
1804
|
+
options.theme = path8__default.default.basename(process.cwd());
|
|
1854
1805
|
}
|
|
1855
1806
|
}
|
|
1856
1807
|
const sectionName = toKebabCase(name);
|
|
@@ -1913,35 +1864,35 @@ async function createSectionCommand(name, options) {
|
|
|
1913
1864
|
};
|
|
1914
1865
|
exports.logger.startSpinner("Creating section files...");
|
|
1915
1866
|
try {
|
|
1916
|
-
const themePath =
|
|
1917
|
-
const sectionPath =
|
|
1867
|
+
const themePath = path8__default.default.join(getThemesDir(), themeName);
|
|
1868
|
+
const sectionPath = path8__default.default.join(themePath, "sections", sectionName);
|
|
1918
1869
|
const schemaContent = generateSectionSchema(data);
|
|
1919
1870
|
await writeFile(
|
|
1920
|
-
|
|
1871
|
+
path8__default.default.join(sectionPath, `${sectionName}.schema.ts`),
|
|
1921
1872
|
schemaContent
|
|
1922
1873
|
);
|
|
1923
1874
|
if (createTemplate) {
|
|
1924
1875
|
const templateContent = generateSectionTemplate(data);
|
|
1925
1876
|
await writeFile(
|
|
1926
|
-
|
|
1877
|
+
path8__default.default.join(sectionPath, `${sectionName}-default.tsx`),
|
|
1927
1878
|
templateContent
|
|
1928
1879
|
);
|
|
1929
1880
|
}
|
|
1930
1881
|
const indexContent = generateSectionIndex(data, createTemplate);
|
|
1931
|
-
await writeFile(
|
|
1882
|
+
await writeFile(path8__default.default.join(sectionPath, "index.ts"), indexContent);
|
|
1932
1883
|
exports.logger.stopSpinner(true, "Section files created successfully!");
|
|
1933
1884
|
exports.logger.newLine();
|
|
1934
1885
|
exports.logger.section("Next steps:");
|
|
1935
1886
|
exports.logger.log(
|
|
1936
|
-
` 1. Edit schema: ${
|
|
1887
|
+
` 1. Edit schema: ${path8__default.default.relative(process.cwd(), path8__default.default.join(sectionPath, `${sectionName}.schema.ts`))}`
|
|
1937
1888
|
);
|
|
1938
1889
|
if (createTemplate) {
|
|
1939
1890
|
exports.logger.log(
|
|
1940
|
-
` 2. Edit template: ${
|
|
1891
|
+
` 2. Edit template: ${path8__default.default.relative(process.cwd(), path8__default.default.join(sectionPath, `${sectionName}-default.tsx`))}`
|
|
1941
1892
|
);
|
|
1942
1893
|
}
|
|
1943
1894
|
exports.logger.log(
|
|
1944
|
-
` 3. Add to theme manifest: ${
|
|
1895
|
+
` 3. Add to theme manifest: ${path8__default.default.relative(process.cwd(), path8__default.default.join(themePath, "manifest.ts"))}`
|
|
1945
1896
|
);
|
|
1946
1897
|
exports.logger.newLine();
|
|
1947
1898
|
exports.logger.success("Section created successfully!");
|
|
@@ -2089,10 +2040,10 @@ async function createBlockCommand(name, options) {
|
|
|
2089
2040
|
ensureOneXProject();
|
|
2090
2041
|
if (!options.theme) {
|
|
2091
2042
|
const isStandaloneTheme = ["theme.config.ts", "bundle-entry.ts"].some(
|
|
2092
|
-
(f) => fs__default.default.existsSync(
|
|
2043
|
+
(f) => fs__default.default.existsSync(path8__default.default.join(process.cwd(), f))
|
|
2093
2044
|
);
|
|
2094
2045
|
if (isStandaloneTheme) {
|
|
2095
|
-
options.theme =
|
|
2046
|
+
options.theme = path8__default.default.basename(process.cwd());
|
|
2096
2047
|
}
|
|
2097
2048
|
}
|
|
2098
2049
|
const blockName = toKebabCase(name);
|
|
@@ -2167,24 +2118,24 @@ async function createBlockCommand(name, options) {
|
|
|
2167
2118
|
};
|
|
2168
2119
|
exports.logger.startSpinner("Creating block files...");
|
|
2169
2120
|
try {
|
|
2170
|
-
const blockPath = scope === "shared" ?
|
|
2121
|
+
const blockPath = scope === "shared" ? path8__default.default.join(getFeaturesDir(), "blocks", blockName) : path8__default.default.join(getThemesDir(), themeName, "blocks", blockName);
|
|
2171
2122
|
const schemaContent = generateBlockSchema(data);
|
|
2172
2123
|
await writeFile(
|
|
2173
|
-
|
|
2124
|
+
path8__default.default.join(blockPath, `${blockName}.schema.ts`),
|
|
2174
2125
|
schemaContent
|
|
2175
2126
|
);
|
|
2176
2127
|
const componentContent = generateBlockComponent(data);
|
|
2177
|
-
await writeFile(
|
|
2128
|
+
await writeFile(path8__default.default.join(blockPath, `${blockName}.tsx`), componentContent);
|
|
2178
2129
|
const indexContent = generateBlockIndex(data);
|
|
2179
|
-
await writeFile(
|
|
2130
|
+
await writeFile(path8__default.default.join(blockPath, "index.ts"), indexContent);
|
|
2180
2131
|
exports.logger.stopSpinner(true, "Block files created successfully!");
|
|
2181
2132
|
exports.logger.newLine();
|
|
2182
2133
|
exports.logger.section("Next steps:");
|
|
2183
2134
|
exports.logger.log(
|
|
2184
|
-
` 1. Edit schema: ${
|
|
2135
|
+
` 1. Edit schema: ${path8__default.default.relative(process.cwd(), path8__default.default.join(blockPath, `${blockName}.schema.ts`))}`
|
|
2185
2136
|
);
|
|
2186
2137
|
exports.logger.log(
|
|
2187
|
-
` 2. Edit component: ${
|
|
2138
|
+
` 2. Edit component: ${path8__default.default.relative(process.cwd(), path8__default.default.join(blockPath, `${blockName}.tsx`))}`
|
|
2188
2139
|
);
|
|
2189
2140
|
exports.logger.log(
|
|
2190
2141
|
` 3. Register in block registry: src/lib/registry/block-registry.ts`
|
|
@@ -2362,31 +2313,31 @@ async function createComponentCommand(name, options) {
|
|
|
2362
2313
|
};
|
|
2363
2314
|
exports.logger.startSpinner("Creating component files...");
|
|
2364
2315
|
try {
|
|
2365
|
-
const componentPath =
|
|
2316
|
+
const componentPath = path8__default.default.join(
|
|
2366
2317
|
getFeaturesDir(),
|
|
2367
2318
|
"components",
|
|
2368
2319
|
componentName
|
|
2369
2320
|
);
|
|
2370
2321
|
const schemaContent = generateComponentSchema(data);
|
|
2371
2322
|
await writeFile(
|
|
2372
|
-
|
|
2323
|
+
path8__default.default.join(componentPath, `${componentName}.schema.ts`),
|
|
2373
2324
|
schemaContent
|
|
2374
2325
|
);
|
|
2375
2326
|
const componentContent = generateComponent(data);
|
|
2376
2327
|
await writeFile(
|
|
2377
|
-
|
|
2328
|
+
path8__default.default.join(componentPath, `${componentName}.tsx`),
|
|
2378
2329
|
componentContent
|
|
2379
2330
|
);
|
|
2380
2331
|
const indexContent = generateComponentIndex(data);
|
|
2381
|
-
await writeFile(
|
|
2332
|
+
await writeFile(path8__default.default.join(componentPath, "index.ts"), indexContent);
|
|
2382
2333
|
exports.logger.stopSpinner(true, "Component files created successfully!");
|
|
2383
2334
|
exports.logger.newLine();
|
|
2384
2335
|
exports.logger.section("Next steps:");
|
|
2385
2336
|
exports.logger.log(
|
|
2386
|
-
` 1. Edit schema: ${
|
|
2337
|
+
` 1. Edit schema: ${path8__default.default.relative(process.cwd(), path8__default.default.join(componentPath, `${componentName}.schema.ts`))}`
|
|
2387
2338
|
);
|
|
2388
2339
|
exports.logger.log(
|
|
2389
|
-
` 2. Edit component: ${
|
|
2340
|
+
` 2. Edit component: ${path8__default.default.relative(process.cwd(), path8__default.default.join(componentPath, `${componentName}.tsx`))}`
|
|
2390
2341
|
);
|
|
2391
2342
|
exports.logger.log(
|
|
2392
2343
|
` 3. Register in component registry: src/lib/registry/component-registry.ts`
|
|
@@ -2543,13 +2494,13 @@ async function listSections(themeFilter) {
|
|
|
2543
2494
|
return;
|
|
2544
2495
|
}
|
|
2545
2496
|
for (const theme of themes) {
|
|
2546
|
-
const sectionsDir =
|
|
2497
|
+
const sectionsDir = path8__default.default.join(getThemesDir(), theme, "sections");
|
|
2547
2498
|
if (!fs__default.default.existsSync(sectionsDir)) {
|
|
2548
2499
|
continue;
|
|
2549
2500
|
}
|
|
2550
2501
|
const sections = fs__default.default.readdirSync(sectionsDir).filter((name) => {
|
|
2551
|
-
const sectionPath =
|
|
2552
|
-
return fs__default.default.statSync(sectionPath).isDirectory() && fs__default.default.existsSync(
|
|
2502
|
+
const sectionPath = path8__default.default.join(sectionsDir, name);
|
|
2503
|
+
return fs__default.default.statSync(sectionPath).isDirectory() && fs__default.default.existsSync(path8__default.default.join(sectionPath, "index.ts"));
|
|
2553
2504
|
});
|
|
2554
2505
|
if (sections.length > 0) {
|
|
2555
2506
|
exports.logger.log(chalk4__default.default.cyan(`
|
|
@@ -2563,11 +2514,11 @@ async function listSections(themeFilter) {
|
|
|
2563
2514
|
}
|
|
2564
2515
|
async function listBlocks(themeFilter) {
|
|
2565
2516
|
exports.logger.section("\u{1F9F1} Blocks");
|
|
2566
|
-
const sharedBlocksDir =
|
|
2517
|
+
const sharedBlocksDir = path8__default.default.join(getFeaturesDir(), "blocks");
|
|
2567
2518
|
if (fs__default.default.existsSync(sharedBlocksDir)) {
|
|
2568
2519
|
const sharedBlocks = fs__default.default.readdirSync(sharedBlocksDir).filter((name) => {
|
|
2569
|
-
const blockPath =
|
|
2570
|
-
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(
|
|
2520
|
+
const blockPath = path8__default.default.join(sharedBlocksDir, name);
|
|
2521
|
+
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(path8__default.default.join(blockPath, "index.ts"));
|
|
2571
2522
|
});
|
|
2572
2523
|
if (sharedBlocks.length > 0) {
|
|
2573
2524
|
exports.logger.log(chalk4__default.default.cyan("\n Shared:"));
|
|
@@ -2578,13 +2529,13 @@ async function listBlocks(themeFilter) {
|
|
|
2578
2529
|
}
|
|
2579
2530
|
const themes = themeFilter ? [themeFilter] : listThemes();
|
|
2580
2531
|
for (const theme of themes) {
|
|
2581
|
-
const blocksDir =
|
|
2532
|
+
const blocksDir = path8__default.default.join(getThemesDir(), theme, "blocks");
|
|
2582
2533
|
if (!fs__default.default.existsSync(blocksDir)) {
|
|
2583
2534
|
continue;
|
|
2584
2535
|
}
|
|
2585
2536
|
const blocks = fs__default.default.readdirSync(blocksDir).filter((name) => {
|
|
2586
|
-
const blockPath =
|
|
2587
|
-
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(
|
|
2537
|
+
const blockPath = path8__default.default.join(blocksDir, name);
|
|
2538
|
+
return fs__default.default.statSync(blockPath).isDirectory() && fs__default.default.existsSync(path8__default.default.join(blockPath, "index.ts"));
|
|
2588
2539
|
});
|
|
2589
2540
|
if (blocks.length > 0) {
|
|
2590
2541
|
exports.logger.log(chalk4__default.default.cyan(`
|
|
@@ -2598,14 +2549,14 @@ async function listBlocks(themeFilter) {
|
|
|
2598
2549
|
}
|
|
2599
2550
|
async function listComponents() {
|
|
2600
2551
|
exports.logger.section("\u2699\uFE0F Components");
|
|
2601
|
-
const componentsDir =
|
|
2552
|
+
const componentsDir = path8__default.default.join(getFeaturesDir(), "components");
|
|
2602
2553
|
if (!fs__default.default.existsSync(componentsDir)) {
|
|
2603
2554
|
exports.logger.warning("No components directory found");
|
|
2604
2555
|
return;
|
|
2605
2556
|
}
|
|
2606
2557
|
const components = fs__default.default.readdirSync(componentsDir).filter((name) => {
|
|
2607
|
-
const componentPath =
|
|
2608
|
-
return fs__default.default.statSync(componentPath).isDirectory() && fs__default.default.existsSync(
|
|
2558
|
+
const componentPath = path8__default.default.join(componentsDir, name);
|
|
2559
|
+
return fs__default.default.statSync(componentPath).isDirectory() && fs__default.default.existsSync(path8__default.default.join(componentPath, "index.ts"));
|
|
2609
2560
|
});
|
|
2610
2561
|
if (components.length === 0) {
|
|
2611
2562
|
exports.logger.warning("No components found");
|
|
@@ -2626,11 +2577,11 @@ async function listThemesInfo() {
|
|
|
2626
2577
|
}
|
|
2627
2578
|
exports.logger.log("");
|
|
2628
2579
|
for (const theme of themes) {
|
|
2629
|
-
const themeDir =
|
|
2580
|
+
const themeDir = path8__default.default.join(getThemesDir(), theme);
|
|
2630
2581
|
const candidates = ["theme.config.ts", "bundle-entry.ts", "manifest.ts"];
|
|
2631
2582
|
let manifestContent = "";
|
|
2632
2583
|
for (const candidate of candidates) {
|
|
2633
|
-
const candidatePath =
|
|
2584
|
+
const candidatePath = path8__default.default.join(themeDir, candidate);
|
|
2634
2585
|
if (fs__default.default.existsSync(candidatePath)) {
|
|
2635
2586
|
manifestContent = fs__default.default.readFileSync(candidatePath, "utf-8");
|
|
2636
2587
|
break;
|
|
@@ -2659,14 +2610,14 @@ async function buildCommand(options) {
|
|
|
2659
2610
|
if (options.theme) {
|
|
2660
2611
|
themeName = options.theme;
|
|
2661
2612
|
try {
|
|
2662
|
-
const workspaceThemePath =
|
|
2613
|
+
const workspaceThemePath = path8__default.default.join(getThemesDir(), themeName);
|
|
2663
2614
|
if (fs__default.default.existsSync(workspaceThemePath)) {
|
|
2664
2615
|
themePath = workspaceThemePath;
|
|
2665
2616
|
} else {
|
|
2666
|
-
themePath =
|
|
2617
|
+
themePath = path8__default.default.join(process.cwd(), themeName);
|
|
2667
2618
|
}
|
|
2668
2619
|
} catch {
|
|
2669
|
-
themePath =
|
|
2620
|
+
themePath = path8__default.default.join(process.cwd(), themeName);
|
|
2670
2621
|
}
|
|
2671
2622
|
if (!fs__default.default.existsSync(themePath)) {
|
|
2672
2623
|
exports.logger.error(`Theme "${themeName}" not found.`);
|
|
@@ -2677,10 +2628,10 @@ async function buildCommand(options) {
|
|
|
2677
2628
|
"theme.config.ts",
|
|
2678
2629
|
"bundle-entry.ts",
|
|
2679
2630
|
"manifest.ts"
|
|
2680
|
-
].some((f) => fs__default.default.existsSync(
|
|
2631
|
+
].some((f) => fs__default.default.existsSync(path8__default.default.join(process.cwd(), f)));
|
|
2681
2632
|
if (isThemeDir) {
|
|
2682
2633
|
themePath = process.cwd();
|
|
2683
|
-
themeName =
|
|
2634
|
+
themeName = path8__default.default.basename(themePath);
|
|
2684
2635
|
exports.logger.info(`Building current theme: ${themeName}`);
|
|
2685
2636
|
} else {
|
|
2686
2637
|
exports.logger.error(
|
|
@@ -2689,7 +2640,7 @@ async function buildCommand(options) {
|
|
|
2689
2640
|
process.exit(1);
|
|
2690
2641
|
}
|
|
2691
2642
|
}
|
|
2692
|
-
const packageJsonPath =
|
|
2643
|
+
const packageJsonPath = path8__default.default.join(themePath, "package.json");
|
|
2693
2644
|
const hasPkgJson = fs__default.default.existsSync(packageJsonPath);
|
|
2694
2645
|
if (!hasPkgJson) {
|
|
2695
2646
|
exports.logger.warning(
|
|
@@ -2745,9 +2696,9 @@ async function buildCommand(options) {
|
|
|
2745
2696
|
exports.logger.success("\u2713 Theme built successfully!");
|
|
2746
2697
|
exports.logger.newLine();
|
|
2747
2698
|
exports.logger.info(`Theme: ${themeName}`);
|
|
2748
|
-
const distPath =
|
|
2699
|
+
const distPath = path8__default.default.join(themePath, "dist");
|
|
2749
2700
|
if (fs__default.default.existsSync(distPath)) {
|
|
2750
|
-
exports.logger.log(`Output: ${
|
|
2701
|
+
exports.logger.log(`Output: ${path8__default.default.relative(process.cwd(), distPath)}`);
|
|
2751
2702
|
const files = fs__default.default.readdirSync(distPath);
|
|
2752
2703
|
exports.logger.log(`Files: ${files.length}`);
|
|
2753
2704
|
}
|
|
@@ -2755,17 +2706,17 @@ async function buildCommand(options) {
|
|
|
2755
2706
|
}
|
|
2756
2707
|
function runCommand(command, args, cwd) {
|
|
2757
2708
|
return new Promise((resolve) => {
|
|
2758
|
-
const proc =
|
|
2709
|
+
const proc = child_process.spawn(command, args, {
|
|
2759
2710
|
cwd,
|
|
2760
2711
|
stdio: ["pipe", "pipe", "pipe"],
|
|
2761
2712
|
shell: true
|
|
2762
2713
|
});
|
|
2763
2714
|
let stdout = "";
|
|
2764
2715
|
let stderr = "";
|
|
2765
|
-
proc.stdout
|
|
2716
|
+
proc.stdout.on("data", (data) => {
|
|
2766
2717
|
stdout += data.toString();
|
|
2767
2718
|
});
|
|
2768
|
-
proc.stderr
|
|
2719
|
+
proc.stderr.on("data", (data) => {
|
|
2769
2720
|
stderr += data.toString();
|
|
2770
2721
|
});
|
|
2771
2722
|
proc.on("close", (code) => {
|
|
@@ -2835,11 +2786,11 @@ function getBucketName(env) {
|
|
|
2835
2786
|
return environment === "production" ? "theme-s3-bucket" : "theme-s3-bucket";
|
|
2836
2787
|
}
|
|
2837
2788
|
async function findCompiledThemeDir(themeId, version) {
|
|
2838
|
-
const searchPaths = [
|
|
2789
|
+
const searchPaths = [path8__default.default.resolve(process.cwd(), "dist")];
|
|
2839
2790
|
for (const dir of searchPaths) {
|
|
2840
2791
|
if (await fs__default.default.pathExists(dir)) {
|
|
2841
|
-
const hasManifest = await fs__default.default.pathExists(
|
|
2842
|
-
const hasThemeEntry = await fs__default.default.pathExists(
|
|
2792
|
+
const hasManifest = await fs__default.default.pathExists(path8__default.default.join(dir, "manifest.json"));
|
|
2793
|
+
const hasThemeEntry = await fs__default.default.pathExists(path8__default.default.join(dir, "bundle-entry.js")) || await fs__default.default.pathExists(path8__default.default.join(dir, "theme.config.js")) || await fs__default.default.pathExists(path8__default.default.join(dir, "index.js"));
|
|
2843
2794
|
if (hasManifest || hasThemeEntry) {
|
|
2844
2795
|
return dir;
|
|
2845
2796
|
}
|
|
@@ -2848,7 +2799,7 @@ async function findCompiledThemeDir(themeId, version) {
|
|
|
2848
2799
|
return null;
|
|
2849
2800
|
}
|
|
2850
2801
|
async function readManifest() {
|
|
2851
|
-
const manifestTsPath =
|
|
2802
|
+
const manifestTsPath = path8__default.default.resolve(process.cwd(), "manifest.ts");
|
|
2852
2803
|
if (await fs__default.default.pathExists(manifestTsPath)) {
|
|
2853
2804
|
try {
|
|
2854
2805
|
const module = await import(manifestTsPath);
|
|
@@ -2857,7 +2808,7 @@ async function readManifest() {
|
|
|
2857
2808
|
exports.logger.warning("Failed to import manifest.ts, trying package.json");
|
|
2858
2809
|
}
|
|
2859
2810
|
}
|
|
2860
|
-
const packageJsonPath =
|
|
2811
|
+
const packageJsonPath = path8__default.default.resolve(process.cwd(), "package.json");
|
|
2861
2812
|
if (await fs__default.default.pathExists(packageJsonPath)) {
|
|
2862
2813
|
const pkg = await fs__default.default.readJson(packageJsonPath);
|
|
2863
2814
|
return {
|
|
@@ -2891,13 +2842,13 @@ async function findSourceDir(themeId, explicitDir) {
|
|
|
2891
2842
|
}
|
|
2892
2843
|
const searchPaths = [
|
|
2893
2844
|
process.cwd(),
|
|
2894
|
-
|
|
2895
|
-
|
|
2845
|
+
path8__default.default.resolve(process.cwd(), `../../themes/${themeId}`),
|
|
2846
|
+
path8__default.default.resolve(process.cwd(), `../themes/${themeId}`)
|
|
2896
2847
|
];
|
|
2897
2848
|
const markers = ["theme.config.ts", "bundle-entry.ts"];
|
|
2898
2849
|
for (const dir of searchPaths) {
|
|
2899
2850
|
for (const marker of markers) {
|
|
2900
|
-
if (await fs__default.default.pathExists(
|
|
2851
|
+
if (await fs__default.default.pathExists(path8__default.default.join(dir, marker))) {
|
|
2901
2852
|
return dir;
|
|
2902
2853
|
}
|
|
2903
2854
|
}
|
|
@@ -2949,7 +2900,7 @@ async function uploadCommand(options) {
|
|
|
2949
2900
|
spinner.succeed(`Found compiled theme at: ${compiledDir}`);
|
|
2950
2901
|
spinner.start("Creating bundle.zip...");
|
|
2951
2902
|
const tmpDir = os__default.default.tmpdir();
|
|
2952
|
-
const bundleZipPath =
|
|
2903
|
+
const bundleZipPath = path8__default.default.join(tmpDir, `${themeId}-${version}-bundle.zip`);
|
|
2953
2904
|
await createZipFromDir(compiledDir, bundleZipPath);
|
|
2954
2905
|
const bundleZipBuffer = await fs__default.default.readFile(bundleZipPath);
|
|
2955
2906
|
const bundleSizeMB = (bundleZipBuffer.length / 1024 / 1024).toFixed(2);
|
|
@@ -3003,7 +2954,7 @@ async function uploadCommand(options) {
|
|
|
3003
2954
|
if (sourceDir) {
|
|
3004
2955
|
spinner.succeed(`Found source at: ${sourceDir}`);
|
|
3005
2956
|
spinner.start("Creating source.zip...");
|
|
3006
|
-
const sourceZipPath =
|
|
2957
|
+
const sourceZipPath = path8__default.default.join(
|
|
3007
2958
|
tmpDir,
|
|
3008
2959
|
`${themeId}-${version}-source.zip`
|
|
3009
2960
|
);
|
|
@@ -3137,8 +3088,8 @@ async function resolveLatestVersion(s3Client, bucket, themeId) {
|
|
|
3137
3088
|
async function createCompatibilityFiles(outputDir, manifest) {
|
|
3138
3089
|
const entryFile = manifest.output?.entry || "bundle-entry.js";
|
|
3139
3090
|
if (entryFile !== "bundle-entry.js" && entryFile.startsWith("bundle-entry-")) {
|
|
3140
|
-
const hashedPath =
|
|
3141
|
-
const stablePath =
|
|
3091
|
+
const hashedPath = path8__default.default.join(outputDir, entryFile);
|
|
3092
|
+
const stablePath = path8__default.default.join(outputDir, "bundle-entry.js");
|
|
3142
3093
|
if (await fs__default.default.pathExists(hashedPath)) {
|
|
3143
3094
|
await fs__default.default.copy(hashedPath, stablePath);
|
|
3144
3095
|
const mapPath = hashedPath + ".map";
|
|
@@ -3147,13 +3098,13 @@ async function createCompatibilityFiles(outputDir, manifest) {
|
|
|
3147
3098
|
}
|
|
3148
3099
|
}
|
|
3149
3100
|
}
|
|
3150
|
-
const sectionsRegistryPath =
|
|
3101
|
+
const sectionsRegistryPath = path8__default.default.join(outputDir, "sections-registry.js");
|
|
3151
3102
|
const content = `// Re-export all sections from bundle-entry
|
|
3152
3103
|
// This file exists to maintain compatibility with the import path
|
|
3153
3104
|
export * from './bundle-entry.js';
|
|
3154
3105
|
`;
|
|
3155
3106
|
await fs__default.default.writeFile(sectionsRegistryPath, content, "utf-8");
|
|
3156
|
-
const pkgJsonPath =
|
|
3107
|
+
const pkgJsonPath = path8__default.default.join(outputDir, "package.json");
|
|
3157
3108
|
await fs__default.default.writeFile(pkgJsonPath, '{\n "type": "module"\n}\n', "utf-8");
|
|
3158
3109
|
}
|
|
3159
3110
|
function showDownloadFailureHelp(themeId, bucket) {
|
|
@@ -3248,7 +3199,7 @@ async function downloadCommand(options) {
|
|
|
3248
3199
|
zip.extractAllTo(outputDir, true);
|
|
3249
3200
|
const entries = zip.getEntries().filter((e) => !e.isDirectory);
|
|
3250
3201
|
spinner.succeed(`Extracted ${entries.length} files to ${outputDir}`);
|
|
3251
|
-
const manifestPath =
|
|
3202
|
+
const manifestPath = path8__default.default.join(outputDir, "manifest.json");
|
|
3252
3203
|
const manifest = await fs__default.default.readJson(manifestPath);
|
|
3253
3204
|
await createCompatibilityFiles(outputDir, manifest);
|
|
3254
3205
|
console.log();
|
|
@@ -3348,9 +3299,10 @@ async function resolveLatestVersion2(s3Client, bucket, themeId) {
|
|
|
3348
3299
|
}
|
|
3349
3300
|
function runInstall(cwd) {
|
|
3350
3301
|
return new Promise((resolve) => {
|
|
3351
|
-
const proc =
|
|
3302
|
+
const proc = child_process.spawn("pnpm", ["install"], {
|
|
3352
3303
|
cwd,
|
|
3353
|
-
stdio: "inherit"
|
|
3304
|
+
stdio: "inherit",
|
|
3305
|
+
shell: true
|
|
3354
3306
|
});
|
|
3355
3307
|
proc.on("close", (code) => resolve(code === 0));
|
|
3356
3308
|
proc.on("error", () => resolve(false));
|
|
@@ -3381,7 +3333,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3381
3333
|
const oldPrefix = `${oldName}-`;
|
|
3382
3334
|
const newPrefix = `${newName}-`;
|
|
3383
3335
|
const newDisplayName = newName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3384
|
-
const pkgPath =
|
|
3336
|
+
const pkgPath = path8__default.default.join(themeDir, "package.json");
|
|
3385
3337
|
if (await fs__default.default.pathExists(pkgPath)) {
|
|
3386
3338
|
const pkg = await fs__default.default.readJson(pkgPath);
|
|
3387
3339
|
pkg.name = `@onex-themes/${newName}`;
|
|
@@ -3397,7 +3349,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3397
3349
|
}
|
|
3398
3350
|
await fs__default.default.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
3399
3351
|
}
|
|
3400
|
-
const configPath =
|
|
3352
|
+
const configPath = path8__default.default.join(themeDir, "theme.config.ts");
|
|
3401
3353
|
if (await fs__default.default.pathExists(configPath)) {
|
|
3402
3354
|
let content = await fs__default.default.readFile(configPath, "utf-8");
|
|
3403
3355
|
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
@@ -3407,7 +3359,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3407
3359
|
);
|
|
3408
3360
|
await fs__default.default.writeFile(configPath, content);
|
|
3409
3361
|
}
|
|
3410
|
-
const layoutPath =
|
|
3362
|
+
const layoutPath = path8__default.default.join(themeDir, "theme.layout.ts");
|
|
3411
3363
|
if (await fs__default.default.pathExists(layoutPath)) {
|
|
3412
3364
|
let content = await fs__default.default.readFile(layoutPath, "utf-8");
|
|
3413
3365
|
content = content.replace(/id:\s*"[^"]*"/, `id: "${newName}"`);
|
|
@@ -3420,7 +3372,7 @@ async function renameTheme(themeDir, oldName, newName) {
|
|
|
3420
3372
|
const oldDisplayName = oldName.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
3421
3373
|
const tsFiles = await glob.glob("**/*.ts", { cwd: themeDir, nodir: true });
|
|
3422
3374
|
for (const file of tsFiles) {
|
|
3423
|
-
const filePath =
|
|
3375
|
+
const filePath = path8__default.default.join(themeDir, file);
|
|
3424
3376
|
let content = await fs__default.default.readFile(filePath, "utf-8");
|
|
3425
3377
|
const original = content;
|
|
3426
3378
|
content = content.replace(
|
|
@@ -3449,7 +3401,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3449
3401
|
const spinner = ora__default.default("Initializing clone...").start();
|
|
3450
3402
|
try {
|
|
3451
3403
|
const bucket = options.bucket || getBucketName3(options.environment);
|
|
3452
|
-
const outputDir = options.output ||
|
|
3404
|
+
const outputDir = options.output || path8__default.default.resolve(process.cwd(), newName);
|
|
3453
3405
|
const s3Client = getS3Client3();
|
|
3454
3406
|
if (await fs__default.default.pathExists(outputDir)) {
|
|
3455
3407
|
spinner.fail(chalk4__default.default.red(`Directory already exists: ${outputDir}`));
|
|
@@ -3504,7 +3456,7 @@ async function cloneCommand(themeName, options) {
|
|
|
3504
3456
|
spinner.succeed(
|
|
3505
3457
|
`Renamed theme: ${chalk4__default.default.gray(themeName)} \u2192 ${chalk4__default.default.cyan(newName)}`
|
|
3506
3458
|
);
|
|
3507
|
-
const envExamplePath =
|
|
3459
|
+
const envExamplePath = path8__default.default.join(outputDir, ".env.example");
|
|
3508
3460
|
if (!await fs__default.default.pathExists(envExamplePath)) {
|
|
3509
3461
|
await fs__default.default.writeFile(
|
|
3510
3462
|
envExamplePath,
|
|
@@ -3517,18 +3469,32 @@ async function cloneCommand(themeName, options) {
|
|
|
3517
3469
|
].join("\n")
|
|
3518
3470
|
);
|
|
3519
3471
|
}
|
|
3520
|
-
const
|
|
3521
|
-
|
|
3522
|
-
{
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3472
|
+
const mcpJsonPath = path8__default.default.join(outputDir, ".mcp.json");
|
|
3473
|
+
if (await fs__default.default.pathExists(mcpJsonPath)) {
|
|
3474
|
+
const { default: inquirerMod } = await import('inquirer');
|
|
3475
|
+
const { figmaApiKey } = await inquirerMod.prompt([
|
|
3476
|
+
{
|
|
3477
|
+
type: "password",
|
|
3478
|
+
name: "figmaApiKey",
|
|
3479
|
+
message: "Figma API Key (optional, for Figma-to-code MCP \u2014 press Enter to skip):"
|
|
3480
|
+
}
|
|
3481
|
+
]);
|
|
3482
|
+
let mcpContent = await fs__default.default.readFile(mcpJsonPath, "utf-8");
|
|
3483
|
+
if (figmaApiKey) {
|
|
3484
|
+
mcpContent = mcpContent.replace("__FIGMA_API_KEY__", figmaApiKey);
|
|
3485
|
+
} else {
|
|
3486
|
+
try {
|
|
3487
|
+
const mcpJson = JSON.parse(mcpContent);
|
|
3488
|
+
delete mcpJson.mcpServers?.figma;
|
|
3489
|
+
mcpContent = JSON.stringify(mcpJson, null, 2) + "\n";
|
|
3490
|
+
} catch {
|
|
3491
|
+
}
|
|
3526
3492
|
}
|
|
3527
|
-
|
|
3528
|
-
|
|
3493
|
+
await fs__default.default.writeFile(mcpJsonPath, mcpContent, "utf-8");
|
|
3494
|
+
}
|
|
3529
3495
|
if (options.install !== false) {
|
|
3530
3496
|
const hasPkgJson = await fs__default.default.pathExists(
|
|
3531
|
-
|
|
3497
|
+
path8__default.default.join(outputDir, "package.json")
|
|
3532
3498
|
);
|
|
3533
3499
|
if (hasPkgJson) {
|
|
3534
3500
|
spinner.start("Installing dependencies...");
|
|
@@ -3555,10 +3521,9 @@ async function cloneCommand(themeName, options) {
|
|
|
3555
3521
|
console.log(chalk4__default.default.cyan(" Files: ") + chalk4__default.default.white(entries.length));
|
|
3556
3522
|
console.log();
|
|
3557
3523
|
console.log(chalk4__default.default.cyan("Next steps:"));
|
|
3558
|
-
console.log(chalk4__default.default.gray(` cd ${
|
|
3559
|
-
const copyCmd = process.platform === "win32" ? "copy .env.example .env" : "cp .env.example .env";
|
|
3524
|
+
console.log(chalk4__default.default.gray(` cd ${path8__default.default.relative(process.cwd(), outputDir)}`));
|
|
3560
3525
|
console.log(
|
|
3561
|
-
chalk4__default.default.gray(
|
|
3526
|
+
chalk4__default.default.gray(" cp .env.example .env # then add your Company ID")
|
|
3562
3527
|
);
|
|
3563
3528
|
if (options.install === false) {
|
|
3564
3529
|
console.log(chalk4__default.default.gray(" pnpm install"));
|