@chatbi-v/cli 3.1.1 → 3.1.2
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/index.js +974 -648
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ var init_package = __esm({
|
|
|
27
27
|
"package.json"() {
|
|
28
28
|
package_default = {
|
|
29
29
|
name: "@chatbi-v/cli",
|
|
30
|
-
version: "3.1.
|
|
30
|
+
version: "3.1.2",
|
|
31
31
|
description: "Standardized CLI tooling for ChatBI Monorepo",
|
|
32
32
|
type: "module",
|
|
33
33
|
main: "dist/index.js",
|
|
@@ -290,7 +290,7 @@ import ora from "ora";
|
|
|
290
290
|
import path3 from "path";
|
|
291
291
|
import pc from "picocolors";
|
|
292
292
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
293
|
-
var _require, _filename, _dirname, config, UPDATE_CHECK_INTERVAL, CACHE_DIR, CACHE_FILE, isDebug, setDebugMode,
|
|
293
|
+
var _require, _filename, _dirname, config, UPDATE_CHECK_INTERVAL, CACHE_DIR, CACHE_FILE, isDebug, setDebugMode, logger2, createSpinner, printBox, findPackageRoot, getCliRoot, checkForUpdates, printUpdateNotification;
|
|
294
294
|
var init_utils = __esm({
|
|
295
295
|
"src/utils.ts"() {
|
|
296
296
|
"use strict";
|
|
@@ -307,7 +307,7 @@ var init_utils = __esm({
|
|
|
307
307
|
setDebugMode = (debug) => {
|
|
308
308
|
isDebug = debug;
|
|
309
309
|
};
|
|
310
|
-
|
|
310
|
+
logger2 = {
|
|
311
311
|
info: (msg) => console.log(pc.cyan(`\u2139 ${msg}`)),
|
|
312
312
|
success: (msg) => console.log(pc.green(`\u2714 ${msg}`)),
|
|
313
313
|
warn: (msg) => console.log(pc.yellow(`\u26A0 ${msg}`)),
|
|
@@ -366,15 +366,18 @@ var init_utils = __esm({
|
|
|
366
366
|
getCliRoot = async () => {
|
|
367
367
|
let myCliRoot = "";
|
|
368
368
|
let checkDir = _dirname;
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
369
|
+
try {
|
|
370
|
+
while (checkDir !== path3.parse(checkDir).root) {
|
|
371
|
+
if (fs.existsSync(path3.join(checkDir, "package.json"))) {
|
|
372
|
+
const pkg = await fs.readJson(path3.join(checkDir, "package.json"));
|
|
373
|
+
if (pkg.name === "@chatbi-v/cli") {
|
|
374
|
+
myCliRoot = checkDir;
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
375
377
|
}
|
|
378
|
+
checkDir = path3.dirname(checkDir);
|
|
376
379
|
}
|
|
377
|
-
|
|
380
|
+
} catch {
|
|
378
381
|
}
|
|
379
382
|
if (!myCliRoot) {
|
|
380
383
|
myCliRoot = findPackageRoot("@chatbi-v/cli") || "";
|
|
@@ -385,15 +388,18 @@ var init_utils = __esm({
|
|
|
385
388
|
try {
|
|
386
389
|
await fs.ensureDir(CACHE_DIR);
|
|
387
390
|
let cache = { lastCheck: 0, latestVersion: currentVersion };
|
|
388
|
-
|
|
391
|
+
try {
|
|
389
392
|
cache = await fs.readJson(CACHE_FILE);
|
|
393
|
+
} catch {
|
|
390
394
|
}
|
|
391
395
|
const now = Date.now();
|
|
392
396
|
if (now - cache.lastCheck > UPDATE_CHECK_INTERVAL) {
|
|
393
|
-
const subprocess = execa("npm", ["view", "@chatbi-v/cli", "version"]
|
|
397
|
+
const subprocess = execa("npm", ["view", "@chatbi-v/cli", "version"], {
|
|
398
|
+
reject: false
|
|
399
|
+
});
|
|
394
400
|
subprocess.unref();
|
|
395
401
|
subprocess.then(async ({ stdout }) => {
|
|
396
|
-
const latest = stdout
|
|
402
|
+
const latest = stdout?.trim() || "";
|
|
397
403
|
await fs.writeJson(CACHE_FILE, {
|
|
398
404
|
lastCheck: now,
|
|
399
405
|
latestVersion: latest
|
|
@@ -486,38 +492,35 @@ var init_config2 = __esm({
|
|
|
486
492
|
*/
|
|
487
493
|
static async loadConfig(cwd = process.cwd()) {
|
|
488
494
|
if (!fs2.existsSync(cwd)) {
|
|
489
|
-
|
|
495
|
+
logger2.warn(`\u9879\u76EE\u76EE\u5F55\u4E0D\u5B58\u5728: ${cwd}\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u914D\u7F6E`);
|
|
490
496
|
return {};
|
|
491
497
|
}
|
|
492
498
|
const config4 = {};
|
|
493
499
|
const versionFilePath = path4.join(cwd, SANDBOX_CONFIG.LOCK_FILE);
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
config4.coreVersion = version;
|
|
499
|
-
}
|
|
500
|
-
} catch {
|
|
500
|
+
try {
|
|
501
|
+
const version = (await fs2.readFile(versionFilePath, "utf-8")).trim();
|
|
502
|
+
if (version) {
|
|
503
|
+
config4.coreVersion = version;
|
|
501
504
|
}
|
|
505
|
+
} catch (e) {
|
|
506
|
+
logger2.debug(`\u8BFB\u53D6 .chatbi-version \u5931\u8D25: ${e.message}`);
|
|
502
507
|
}
|
|
503
508
|
const jiti = createJiti(cwd);
|
|
504
509
|
let projectConfig = {};
|
|
505
510
|
for (const file of this.CONFIG_FILES) {
|
|
506
511
|
const configPath = path4.join(cwd, file);
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
projectConfig = await fs2.readJson(configPath);
|
|
516
|
-
}
|
|
517
|
-
break;
|
|
518
|
-
} catch {
|
|
519
|
-
logger.error(`\u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6 ${file} \u5931\u8D25`);
|
|
512
|
+
try {
|
|
513
|
+
if (file.endsWith(".ts") || file.endsWith(".js")) {
|
|
514
|
+
const mod = await jiti.import(configPath, {
|
|
515
|
+
default: true
|
|
516
|
+
});
|
|
517
|
+
projectConfig = mod.default || mod || {};
|
|
518
|
+
} else if (file.endsWith(".json") || file.startsWith(".chatbirc")) {
|
|
519
|
+
projectConfig = await fs2.readJson(configPath);
|
|
520
520
|
}
|
|
521
|
+
break;
|
|
522
|
+
} catch (e) {
|
|
523
|
+
logger2.error(`\u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6 ${file} \u5931\u8D25: ${e.message}`);
|
|
521
524
|
}
|
|
522
525
|
}
|
|
523
526
|
const envConfig = {};
|
|
@@ -571,30 +574,27 @@ var init_config2 = __esm({
|
|
|
571
574
|
const jiti = createJiti(cwd);
|
|
572
575
|
for (const file of TSUP_CONFIG_FILES) {
|
|
573
576
|
const configPath = path4.join(cwd, file);
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
return mod.default || mod || {};
|
|
583
|
-
}
|
|
584
|
-
} catch (e) {
|
|
585
|
-
logger.warn(`\u52A0\u8F7D tsup \u914D\u7F6E\u6587\u4EF6 ${file} \u5931\u8D25: ${e.message}`);
|
|
577
|
+
try {
|
|
578
|
+
if (file.endsWith(".json")) {
|
|
579
|
+
return await fs2.readJson(configPath);
|
|
580
|
+
} else {
|
|
581
|
+
const mod = await jiti.import(configPath, {
|
|
582
|
+
default: true
|
|
583
|
+
});
|
|
584
|
+
return mod.default || mod || {};
|
|
586
585
|
}
|
|
586
|
+
} catch (e) {
|
|
587
|
+
logger2.warn(`\u52A0\u8F7D tsup \u914D\u7F6E\u6587\u4EF6 ${file} \u5931\u8D25: ${e.message}`);
|
|
587
588
|
}
|
|
588
589
|
}
|
|
589
590
|
const pkgPath = path4.join(cwd, "package.json");
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
return pkg.tsup;
|
|
595
|
-
}
|
|
596
|
-
} catch {
|
|
591
|
+
try {
|
|
592
|
+
const pkg = await fs2.readJson(pkgPath);
|
|
593
|
+
if (pkg.tsup) {
|
|
594
|
+
return pkg.tsup;
|
|
597
595
|
}
|
|
596
|
+
} catch (e) {
|
|
597
|
+
logger2.debug(`\u8BFB\u53D6 package.json \u5931\u8D25: ${e.message}`);
|
|
598
598
|
}
|
|
599
599
|
return {};
|
|
600
600
|
}
|
|
@@ -612,6 +612,7 @@ var init_CacheValidator = __esm({
|
|
|
612
612
|
"src/sandbox/CacheValidator.ts"() {
|
|
613
613
|
"use strict";
|
|
614
614
|
init_esm_shims();
|
|
615
|
+
init_utils();
|
|
615
616
|
MANIFEST_FILE = ".sandbox-manifest.json";
|
|
616
617
|
CacheValidator = class {
|
|
617
618
|
constructor(versionPath) {
|
|
@@ -638,7 +639,8 @@ var init_CacheValidator = __esm({
|
|
|
638
639
|
try {
|
|
639
640
|
const content = await fs3.readFile(filePath);
|
|
640
641
|
return `sha256:${crypto.createHash("sha256").update(content).digest("hex")}`;
|
|
641
|
-
} catch {
|
|
642
|
+
} catch (e) {
|
|
643
|
+
logger2.debug(`\u8BA1\u7B97\u6587\u4EF6 Hash \u5931\u8D25: ${e.message}`);
|
|
642
644
|
return "";
|
|
643
645
|
}
|
|
644
646
|
}
|
|
@@ -649,25 +651,26 @@ var init_CacheValidator = __esm({
|
|
|
649
651
|
const packages = {};
|
|
650
652
|
try {
|
|
651
653
|
const nodeModulesPath = this.getNodeModulesPath();
|
|
652
|
-
|
|
654
|
+
let entries;
|
|
655
|
+
try {
|
|
656
|
+
entries = await fs3.readdir(nodeModulesPath, {
|
|
657
|
+
withFileTypes: true
|
|
658
|
+
});
|
|
659
|
+
} catch {
|
|
653
660
|
return "";
|
|
654
661
|
}
|
|
655
|
-
const entries = await fs3.readdir(nodeModulesPath, {
|
|
656
|
-
withFileTypes: true
|
|
657
|
-
});
|
|
658
662
|
for (const entry of entries) {
|
|
659
663
|
if (entry.isDirectory() && !entry.name.startsWith(".")) {
|
|
660
|
-
const
|
|
664
|
+
const pkgJsonPath2 = path5.join(
|
|
661
665
|
nodeModulesPath,
|
|
662
666
|
entry.name,
|
|
663
667
|
"package.json"
|
|
664
668
|
);
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
}
|
|
669
|
+
try {
|
|
670
|
+
const pkg = await fs3.readJson(pkgJsonPath2);
|
|
671
|
+
packages[entry.name] = `${pkg.name}@${pkg.version}`;
|
|
672
|
+
} catch {
|
|
673
|
+
logger2.debug(`\u5FFD\u7565\u65E0\u6548 package.json: ${pkgJsonPath2}`);
|
|
671
674
|
}
|
|
672
675
|
}
|
|
673
676
|
}
|
|
@@ -682,19 +685,30 @@ var init_CacheValidator = __esm({
|
|
|
682
685
|
*/
|
|
683
686
|
async generatePackageIntegrity(pkgPath) {
|
|
684
687
|
try {
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
const content = await fs3.readFile(
|
|
688
|
+
const pkgJsonPath2 = path5.join(pkgPath, "package.json");
|
|
689
|
+
try {
|
|
690
|
+
const content = await fs3.readFile(pkgJsonPath2);
|
|
688
691
|
return `sha256:${crypto.createHash("sha256").update(content).digest("hex")}`;
|
|
692
|
+
} catch {
|
|
693
|
+
logger2.debug(`package.json \u4E0D\u5B58\u5728\uFF0C\u4F7F\u7528\u76EE\u5F55\u5185\u5BB9: ${pkgPath}`);
|
|
694
|
+
}
|
|
695
|
+
let files;
|
|
696
|
+
try {
|
|
697
|
+
files = await fs3.readdir(pkgPath);
|
|
698
|
+
} catch {
|
|
699
|
+
return "";
|
|
689
700
|
}
|
|
690
|
-
const files = await fs3.readdir(pkgPath);
|
|
691
701
|
const combinedHash = crypto.createHash("sha256");
|
|
692
702
|
for (const file of files.slice(0, 10)) {
|
|
693
703
|
const filePath = path5.join(pkgPath, file);
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
704
|
+
try {
|
|
705
|
+
const stats = await fs3.stat(filePath);
|
|
706
|
+
if (stats.isFile()) {
|
|
707
|
+
const content = await fs3.readFile(filePath);
|
|
708
|
+
combinedHash.update(content);
|
|
709
|
+
}
|
|
710
|
+
} catch (e) {
|
|
711
|
+
logger2.debug(`\u5904\u7406\u6587\u4EF6\u5931\u8D25: ${file}: ${e.message}`);
|
|
698
712
|
}
|
|
699
713
|
}
|
|
700
714
|
return `sha256:${combinedHash.digest("hex")}`;
|
|
@@ -710,13 +724,11 @@ var init_CacheValidator = __esm({
|
|
|
710
724
|
return this.manifest;
|
|
711
725
|
}
|
|
712
726
|
const manifestPath = this.getManifestPath();
|
|
713
|
-
if (!fs3.existsSync(manifestPath)) {
|
|
714
|
-
return null;
|
|
715
|
-
}
|
|
716
727
|
try {
|
|
717
728
|
this.manifest = await fs3.readJson(manifestPath);
|
|
718
729
|
return this.manifest;
|
|
719
|
-
} catch {
|
|
730
|
+
} catch (e) {
|
|
731
|
+
logger2.debug(`\u52A0\u8F7D manifest \u5931\u8D25: ${e.message}`);
|
|
720
732
|
return null;
|
|
721
733
|
}
|
|
722
734
|
}
|
|
@@ -887,7 +899,12 @@ var init_CacheValidator = __esm({
|
|
|
887
899
|
const criticalPkgs = Object.keys(manifest.packages);
|
|
888
900
|
for (const pkg of criticalPkgs) {
|
|
889
901
|
const pkgPath = path5.join(this.getNodeModulesPath(), pkg);
|
|
890
|
-
|
|
902
|
+
try {
|
|
903
|
+
const stats = await fs3.stat(pkgPath);
|
|
904
|
+
if (!stats.isDirectory()) {
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
} catch {
|
|
891
908
|
return false;
|
|
892
909
|
}
|
|
893
910
|
}
|
|
@@ -919,8 +936,10 @@ var init_CacheValidator = __esm({
|
|
|
919
936
|
*/
|
|
920
937
|
async clearManifest() {
|
|
921
938
|
const manifestPath = this.getManifestPath();
|
|
922
|
-
|
|
939
|
+
try {
|
|
923
940
|
await fs3.remove(manifestPath);
|
|
941
|
+
} catch (e) {
|
|
942
|
+
logger2.debug(`\u5220\u9664\u7F13\u5B58\u5931\u8D25: ${e.message}`);
|
|
924
943
|
}
|
|
925
944
|
this.manifest = null;
|
|
926
945
|
}
|
|
@@ -996,13 +1015,15 @@ var init_SandboxPath = __esm({
|
|
|
996
1015
|
while (current !== path6.parse(current).root) {
|
|
997
1016
|
const pkgPath = path6.join(current, "package.json");
|
|
998
1017
|
const pnpmWorkspacePath = path6.join(current, "pnpm-workspace.yaml");
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1018
|
+
try {
|
|
1019
|
+
const content = await fs4.readFile(pnpmWorkspacePath, "utf-8");
|
|
1020
|
+
if (content.includes("packages:")) return current;
|
|
1021
|
+
} catch {
|
|
1022
|
+
}
|
|
1023
|
+
try {
|
|
1024
|
+
const pkg = await fs4.readJson(pkgPath);
|
|
1025
|
+
if (pkg.workspaces) return current;
|
|
1026
|
+
} catch {
|
|
1006
1027
|
}
|
|
1007
1028
|
current = path6.dirname(current);
|
|
1008
1029
|
}
|
|
@@ -1161,12 +1182,12 @@ var init_SandboxPlatform = __esm({
|
|
|
1161
1182
|
let result = await attemptStrategy(strategy);
|
|
1162
1183
|
if (!result.success && strategy !== "copy") {
|
|
1163
1184
|
if (verbose) {
|
|
1164
|
-
|
|
1185
|
+
logger2.warn(`[SandboxPlatform] ${strategy} \u7B56\u7565\u5931\u8D25: ${result.error}`);
|
|
1165
1186
|
}
|
|
1166
1187
|
if (strategy === "symlink" && caps.supportsJunctions && type === "dir") {
|
|
1167
1188
|
result = await attemptStrategy("junction");
|
|
1168
1189
|
if (!result.success && verbose) {
|
|
1169
|
-
|
|
1190
|
+
logger2.warn(`[SandboxPlatform] junction \u7B56\u7565\u4E5F\u5931\u8D25: ${result.error}`);
|
|
1170
1191
|
}
|
|
1171
1192
|
}
|
|
1172
1193
|
if (!result.success) {
|
|
@@ -1174,14 +1195,14 @@ var init_SandboxPlatform = __esm({
|
|
|
1174
1195
|
}
|
|
1175
1196
|
}
|
|
1176
1197
|
if (verbose && !result.success) {
|
|
1177
|
-
|
|
1198
|
+
logger2.error(
|
|
1178
1199
|
`[SandboxPlatform] \u65E0\u6CD5\u521B\u5EFA\u865A\u62DF node_modules: ${result.error}`
|
|
1179
1200
|
);
|
|
1180
1201
|
if (result.suggestion) {
|
|
1181
|
-
|
|
1202
|
+
logger2.info(` \u89E3\u51B3\u65B9\u6848: ${result.suggestion}`);
|
|
1182
1203
|
}
|
|
1183
1204
|
} else if (verbose && result.success && result.suggestion) {
|
|
1184
|
-
|
|
1205
|
+
logger2.warn(`[SandboxPlatform] ${result.suggestion}`);
|
|
1185
1206
|
}
|
|
1186
1207
|
return result;
|
|
1187
1208
|
}
|
|
@@ -1261,6 +1282,7 @@ var init_SandboxContext = __esm({
|
|
|
1261
1282
|
"use strict";
|
|
1262
1283
|
init_esm_shims();
|
|
1263
1284
|
init_constants();
|
|
1285
|
+
init_utils();
|
|
1264
1286
|
init_SandboxPath();
|
|
1265
1287
|
init_SandboxPlatform();
|
|
1266
1288
|
SandboxContext = class {
|
|
@@ -1284,8 +1306,10 @@ var init_SandboxContext = __esm({
|
|
|
1284
1306
|
await fs6.ensureDir(chatbiDir);
|
|
1285
1307
|
if (projectRoot !== targetRoot) {
|
|
1286
1308
|
const localChatbiDir = path8.join(projectRoot, SANDBOX_CONFIG.DIRS.CACHE);
|
|
1287
|
-
|
|
1309
|
+
try {
|
|
1288
1310
|
await fs6.remove(localChatbiDir);
|
|
1311
|
+
} catch (e) {
|
|
1312
|
+
logger2.debug(`\u5220\u9664 .chatbi \u5931\u8D25: ${e.message}`);
|
|
1289
1313
|
}
|
|
1290
1314
|
await this.fixTsConfigExtends(projectRoot, targetRoot);
|
|
1291
1315
|
await this.ensureGitignore(targetRoot);
|
|
@@ -1303,11 +1327,13 @@ var init_SandboxContext = __esm({
|
|
|
1303
1327
|
await fs6.ensureDir(vscodeDir);
|
|
1304
1328
|
const settingsPath = path8.join(vscodeDir, "settings.json");
|
|
1305
1329
|
let settings = {};
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1330
|
+
try {
|
|
1331
|
+
const loaded = await fs6.readJson(settingsPath);
|
|
1332
|
+
if (loaded && typeof loaded === "object") {
|
|
1333
|
+
settings = loaded;
|
|
1310
1334
|
}
|
|
1335
|
+
} catch (e) {
|
|
1336
|
+
logger2.debug(`\u52A0\u8F7D settings.json \u5931\u8D25: ${e.message}`);
|
|
1311
1337
|
}
|
|
1312
1338
|
const sandboxPath = SandboxPath.getVersionPath(version);
|
|
1313
1339
|
const tsdkPath = path8.join(sandboxPath, "node_modules/typescript/lib");
|
|
@@ -1321,30 +1347,33 @@ var init_SandboxContext = __esm({
|
|
|
1321
1347
|
*/
|
|
1322
1348
|
static async fixTsConfigExtends(projectRoot, workspaceRoot) {
|
|
1323
1349
|
const tsConfigPath = path8.join(projectRoot, "tsconfig.json");
|
|
1324
|
-
|
|
1350
|
+
let tsConfig;
|
|
1325
1351
|
try {
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
await fs6.writeJson(tsConfigPath, tsConfig, { spaces: 2 });
|
|
1342
|
-
}
|
|
1343
|
-
} else {
|
|
1344
|
-
tsConfig.extends = extendsTarget;
|
|
1352
|
+
tsConfig = await fs6.readJson(tsConfigPath);
|
|
1353
|
+
} catch (e) {
|
|
1354
|
+
logger2.debug(`\u52A0\u8F7D tsconfig.json \u5931\u8D25: ${e.message}`);
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
if (!tsConfig || typeof tsConfig !== "object") return;
|
|
1358
|
+
let extendsTarget = path8.relative(
|
|
1359
|
+
projectRoot,
|
|
1360
|
+
path8.join(workspaceRoot, ".chatbi/tsconfig.json")
|
|
1361
|
+
);
|
|
1362
|
+
if (!extendsTarget.startsWith(".")) extendsTarget = `./${extendsTarget}`;
|
|
1363
|
+
const hasExtend = (p) => p.includes(".chatbi/tsconfig.json") || p.includes(".chatbi/tsconfig.paths.json");
|
|
1364
|
+
if (Array.isArray(tsConfig.extends)) {
|
|
1365
|
+
if (!tsConfig.extends.some((p) => hasExtend(p))) {
|
|
1366
|
+
tsConfig.extends.push(extendsTarget);
|
|
1345
1367
|
await fs6.writeJson(tsConfigPath, tsConfig, { spaces: 2 });
|
|
1346
1368
|
}
|
|
1347
|
-
}
|
|
1369
|
+
} else if (typeof tsConfig.extends === "string") {
|
|
1370
|
+
if (!hasExtend(tsConfig.extends)) {
|
|
1371
|
+
tsConfig.extends = [tsConfig.extends, extendsTarget];
|
|
1372
|
+
await fs6.writeJson(tsConfigPath, tsConfig, { spaces: 2 });
|
|
1373
|
+
}
|
|
1374
|
+
} else {
|
|
1375
|
+
tsConfig.extends = extendsTarget;
|
|
1376
|
+
await fs6.writeJson(tsConfigPath, tsConfig, { spaces: 2 });
|
|
1348
1377
|
}
|
|
1349
1378
|
}
|
|
1350
1379
|
/**
|
|
@@ -1352,17 +1381,20 @@ var init_SandboxContext = __esm({
|
|
|
1352
1381
|
*/
|
|
1353
1382
|
static async ensureGitignore(root) {
|
|
1354
1383
|
const gitignorePath = path8.join(root, ".gitignore");
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1384
|
+
let content = "";
|
|
1385
|
+
try {
|
|
1386
|
+
content = await fs6.readFile(gitignorePath, "utf-8");
|
|
1387
|
+
} catch (e) {
|
|
1388
|
+
logger2.debug(`\u52A0\u8F7D .gitignore \u5931\u8D25: ${e.message}`);
|
|
1389
|
+
}
|
|
1390
|
+
if (typeof content === "string" && !content.includes(SANDBOX_CONFIG.DIRS.CACHE)) {
|
|
1391
|
+
await fs6.appendFile(
|
|
1392
|
+
gitignorePath,
|
|
1393
|
+
`
|
|
1361
1394
|
# ChatBI
|
|
1362
1395
|
${SANDBOX_CONFIG.DIRS.CACHE}
|
|
1363
1396
|
`
|
|
1364
|
-
|
|
1365
|
-
}
|
|
1397
|
+
);
|
|
1366
1398
|
}
|
|
1367
1399
|
}
|
|
1368
1400
|
/**
|
|
@@ -1394,27 +1426,27 @@ ${SANDBOX_CONFIG.DIRS.CACHE}
|
|
|
1394
1426
|
sandboxNodeModules,
|
|
1395
1427
|
"@chatbi-v/config/base.json"
|
|
1396
1428
|
);
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
// 但这里主要用于沙箱环境的类型解析,"@/*" 的映射可能需要在具体项目的 tsconfig 中覆盖
|
|
1413
|
-
"@/*": ["./src/*"]
|
|
1414
|
-
// "*": ["./node_modules/*"] // 已经在上面添加了 corePaths['*']
|
|
1429
|
+
let tsConfig;
|
|
1430
|
+
try {
|
|
1431
|
+
await fs6.readJson(baseConfigPath);
|
|
1432
|
+
tsConfig = {
|
|
1433
|
+
extends: baseConfigPath,
|
|
1434
|
+
compilerOptions: {
|
|
1435
|
+
baseUrl: ".",
|
|
1436
|
+
moduleResolution: "bundler",
|
|
1437
|
+
skipLibCheck: true,
|
|
1438
|
+
typeRoots: ["./node_modules/@types", "./node_modules"],
|
|
1439
|
+
preserveSymlinks: true,
|
|
1440
|
+
paths: {
|
|
1441
|
+
...corePaths,
|
|
1442
|
+
"@/*": ["./src/*"]
|
|
1443
|
+
}
|
|
1415
1444
|
}
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1445
|
+
};
|
|
1446
|
+
} catch (e) {
|
|
1447
|
+
logger2.debug(`base.json \u52A0\u8F7D\u5931\u8D25\uFF0C\u4F7F\u7528\u964D\u7EA7\u914D\u7F6E: ${e.message}`);
|
|
1448
|
+
tsConfig = this.getDefaultTsConfig(corePaths);
|
|
1449
|
+
}
|
|
1418
1450
|
await fs6.writeJson(path8.join(chatbiDir, "tsconfig.json"), tsConfig, {
|
|
1419
1451
|
spaces: 2
|
|
1420
1452
|
});
|
|
@@ -1424,7 +1456,8 @@ ${SANDBOX_CONFIG.DIRS.CACHE}
|
|
|
1424
1456
|
{ spaces: 2 }
|
|
1425
1457
|
);
|
|
1426
1458
|
const virtualNodeModules = path8.join(chatbiDir, "node_modules");
|
|
1427
|
-
|
|
1459
|
+
try {
|
|
1460
|
+
await fs6.access(sandboxNodeModules);
|
|
1428
1461
|
const result = await SandboxPlatform.safeSymlink({
|
|
1429
1462
|
source: sandboxNodeModules,
|
|
1430
1463
|
target: virtualNodeModules,
|
|
@@ -1437,8 +1470,28 @@ ${SANDBOX_CONFIG.DIRS.CACHE}
|
|
|
1437
1470
|
\u5EFA\u8BAE: ${result.suggestion || "\u8FD0\u884C chatbi sandbox update --force \u91CD\u5EFA\u6C99\u7BB1"}`
|
|
1438
1471
|
);
|
|
1439
1472
|
}
|
|
1473
|
+
} catch (e) {
|
|
1474
|
+
logger2.debug(`sandboxNodeModules \u4E0D\u5B58\u5728: ${e.message}`);
|
|
1440
1475
|
}
|
|
1441
1476
|
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Bug-6 Fix: 生成默认 tsconfig 配置(当 base.json 不可用时)
|
|
1479
|
+
*/
|
|
1480
|
+
static getDefaultTsConfig(corePaths) {
|
|
1481
|
+
return {
|
|
1482
|
+
compilerOptions: {
|
|
1483
|
+
baseUrl: ".",
|
|
1484
|
+
moduleResolution: "bundler",
|
|
1485
|
+
skipLibCheck: true,
|
|
1486
|
+
typeRoots: ["./node_modules/@types", "./node_modules"],
|
|
1487
|
+
preserveSymlinks: true,
|
|
1488
|
+
paths: {
|
|
1489
|
+
...corePaths,
|
|
1490
|
+
"@/*": ["./src/*"]
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1442
1495
|
};
|
|
1443
1496
|
}
|
|
1444
1497
|
});
|
|
@@ -1470,43 +1523,56 @@ var init_WorkspaceResolver = __esm({
|
|
|
1470
1523
|
reject: false
|
|
1471
1524
|
}
|
|
1472
1525
|
);
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1526
|
+
if (!stdout || typeof stdout !== "string" || stdout.trim() === "") {
|
|
1527
|
+
logger2.warn("pnpm \u89E3\u6790\u8FD4\u56DE\u7A7A\u7ED3\u679C\uFF0C\u5C1D\u8BD5\u964D\u7EA7\u65B9\u6848...");
|
|
1528
|
+
} else {
|
|
1529
|
+
try {
|
|
1530
|
+
const pnpmPackages = JSON.parse(stdout);
|
|
1531
|
+
if (Array.isArray(pnpmPackages)) {
|
|
1532
|
+
for (const pkg of pnpmPackages) {
|
|
1533
|
+
if (pkg.name && pkg.path) {
|
|
1534
|
+
packages[pkg.name] = pkg.path;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
if (Object.keys(packages).length > 0) {
|
|
1538
|
+
return packages;
|
|
1479
1539
|
}
|
|
1480
1540
|
}
|
|
1481
|
-
|
|
1482
|
-
return packages;
|
|
1483
|
-
}
|
|
1541
|
+
} catch {
|
|
1484
1542
|
}
|
|
1485
|
-
} catch {
|
|
1486
1543
|
}
|
|
1487
1544
|
} catch (e) {
|
|
1488
|
-
|
|
1545
|
+
logger2.warn(`pnpm \u89E3\u6790\u5931\u8D25: ${e.message}\uFF0C\u5C1D\u8BD5\u964D\u7EA7\u65B9\u6848...`);
|
|
1489
1546
|
}
|
|
1547
|
+
let patterns = ["packages/*"];
|
|
1548
|
+
const workspaceYamlPath = path9.join(workspaceRoot, "pnpm-workspace.yaml");
|
|
1549
|
+
let foundWorkspaceYaml = false;
|
|
1490
1550
|
try {
|
|
1491
|
-
const
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
const
|
|
1496
|
-
if (
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1551
|
+
const content = await fs7.readFile(workspaceYamlPath, "utf-8");
|
|
1552
|
+
foundWorkspaceYaml = true;
|
|
1553
|
+
const match = content.match(/packages:\s*([\s\S]*?)(?:\n\S|$)/);
|
|
1554
|
+
if (match && match[1]) {
|
|
1555
|
+
const lines = match[1].split("\n").map((l) => l.trim()).filter((l) => l.startsWith("-")).map((l) => l.replace(/^-\s*['"]?|['"]?$/g, ""));
|
|
1556
|
+
if (lines.length > 0) patterns = lines;
|
|
1557
|
+
}
|
|
1558
|
+
} catch (e) {
|
|
1559
|
+
logger2.debug(`\u8BFB\u53D6 workspace.yaml \u5931\u8D25: ${e.message}`);
|
|
1560
|
+
}
|
|
1561
|
+
if (!foundWorkspaceYaml) {
|
|
1562
|
+
const pkgJsonPath2 = path9.join(workspaceRoot, "package.json");
|
|
1563
|
+
try {
|
|
1564
|
+
const pkg = await fs7.readJson(pkgJsonPath2);
|
|
1565
|
+
if (Array.isArray(pkg.workspaces)) {
|
|
1566
|
+
patterns = pkg.workspaces;
|
|
1507
1567
|
}
|
|
1568
|
+
} catch (e) {
|
|
1569
|
+
logger2.debug(
|
|
1570
|
+
`\u8BFB\u53D6 package.json \u5931\u8D25: ${pkgJsonPath2}: ${e.message}`
|
|
1571
|
+
);
|
|
1508
1572
|
}
|
|
1509
|
-
|
|
1573
|
+
}
|
|
1574
|
+
const globPatterns = patterns.map((p) => path9.join(p, "package.json"));
|
|
1575
|
+
try {
|
|
1510
1576
|
const { default: fg3 } = await import("fast-glob");
|
|
1511
1577
|
const pkgJsonFiles = await fg3(globPatterns, {
|
|
1512
1578
|
cwd: workspaceRoot,
|
|
@@ -1519,11 +1585,12 @@ var init_WorkspaceResolver = __esm({
|
|
|
1519
1585
|
if (pkg.name) {
|
|
1520
1586
|
packages[pkg.name] = path9.dirname(file);
|
|
1521
1587
|
}
|
|
1522
|
-
} catch {
|
|
1588
|
+
} catch (e) {
|
|
1589
|
+
logger2.debug(`\u626B\u63CF\u5305\u5931\u8D25: ${file}: ${e.message}`);
|
|
1523
1590
|
}
|
|
1524
1591
|
}
|
|
1525
1592
|
} catch (e) {
|
|
1526
|
-
|
|
1593
|
+
logger2.warn(`\u5DE5\u4F5C\u533A\u626B\u63CF\u5931\u8D25: ${e.message}`);
|
|
1527
1594
|
}
|
|
1528
1595
|
return packages;
|
|
1529
1596
|
}
|
|
@@ -1582,12 +1649,31 @@ var init_SandboxPkgManager = __esm({
|
|
|
1582
1649
|
try {
|
|
1583
1650
|
const stats = await fs8.lstat(targetLinkPath).catch(() => null);
|
|
1584
1651
|
if (stats) await fs8.remove(targetLinkPath);
|
|
1585
|
-
} catch {
|
|
1652
|
+
} catch (e) {
|
|
1653
|
+
logger2.debug(
|
|
1654
|
+
`\u521B\u5EFA\u8F6F\u94FE\u63A5\u5931\u8D25: ${targetLinkPath}: ${e.message}`
|
|
1655
|
+
);
|
|
1656
|
+
}
|
|
1657
|
+
try {
|
|
1658
|
+
await fs8.symlink(pkgPath, targetLinkPath, "dir");
|
|
1659
|
+
} catch (e) {
|
|
1660
|
+
console.warn(
|
|
1661
|
+
pc4.yellow(
|
|
1662
|
+
` \u26A0\uFE0F \u521B\u5EFA\u8F6F\u94FE\u63A5\u5931\u8D25: ${targetLinkPath} -> ${pkgPath}: ${e.message}`
|
|
1663
|
+
)
|
|
1664
|
+
);
|
|
1586
1665
|
}
|
|
1587
|
-
await fs8.symlink(pkgPath, targetLinkPath, "dir");
|
|
1588
1666
|
}
|
|
1589
1667
|
const sandboxPkgJsonPath = path10.join(versionPath, "package.json");
|
|
1590
|
-
|
|
1668
|
+
let sandboxPkgJson;
|
|
1669
|
+
try {
|
|
1670
|
+
sandboxPkgJson = await fs8.readJson(sandboxPkgJsonPath);
|
|
1671
|
+
} catch (e) {
|
|
1672
|
+
console.warn(
|
|
1673
|
+
pc4.yellow(` \u26A0\uFE0F \u8BFB\u53D6\u6C99\u7BB1 package.json \u5931\u8D25: ${e.message}`)
|
|
1674
|
+
);
|
|
1675
|
+
return false;
|
|
1676
|
+
}
|
|
1591
1677
|
const sections = ["dependencies", "devDependencies"];
|
|
1592
1678
|
let modified = false;
|
|
1593
1679
|
for (const section of sections) {
|
|
@@ -1609,26 +1695,28 @@ var init_SandboxPkgManager = __esm({
|
|
|
1609
1695
|
await fs8.writeJson(sandboxPkgJsonPath, sandboxPkgJson, { spaces: 2 });
|
|
1610
1696
|
}
|
|
1611
1697
|
const shellPkgJsonPath = path10.join(versionPath, "shell", "package.json");
|
|
1612
|
-
|
|
1613
|
-
const
|
|
1698
|
+
try {
|
|
1699
|
+
const shellPkgJson2 = await fs8.readJson(shellPkgJsonPath);
|
|
1614
1700
|
let shellModified = false;
|
|
1615
1701
|
const allPackagesToLink = { ...localPackages };
|
|
1616
1702
|
if (allLocalPackages["@chatbi-v/cli"]) {
|
|
1617
1703
|
allPackagesToLink["@chatbi-v/cli"] = allLocalPackages["@chatbi-v/cli"];
|
|
1618
1704
|
}
|
|
1619
1705
|
for (const section of sections) {
|
|
1620
|
-
if (
|
|
1706
|
+
if (shellPkgJson2[section]) {
|
|
1621
1707
|
for (const [name, pkgPath] of Object.entries(allPackagesToLink)) {
|
|
1622
|
-
if (
|
|
1623
|
-
|
|
1708
|
+
if (shellPkgJson2[section][name]) {
|
|
1709
|
+
shellPkgJson2[section][name] = `link:${pkgPath}`;
|
|
1624
1710
|
shellModified = true;
|
|
1625
1711
|
}
|
|
1626
1712
|
}
|
|
1627
1713
|
}
|
|
1628
1714
|
}
|
|
1629
1715
|
if (shellModified) {
|
|
1630
|
-
await fs8.writeJson(shellPkgJsonPath,
|
|
1716
|
+
await fs8.writeJson(shellPkgJsonPath, shellPkgJson2, { spaces: 2 });
|
|
1631
1717
|
}
|
|
1718
|
+
} catch {
|
|
1719
|
+
logger2.debug(`shell package.json \u4E0D\u5B58\u5728: ${shellPkgJson}`);
|
|
1632
1720
|
}
|
|
1633
1721
|
return true;
|
|
1634
1722
|
} catch (e) {
|
|
@@ -1762,11 +1850,12 @@ var init_SandboxRenderer = __esm({
|
|
|
1762
1850
|
}
|
|
1763
1851
|
}
|
|
1764
1852
|
}
|
|
1765
|
-
|
|
1853
|
+
try {
|
|
1766
1854
|
const existingContent = await fs9.readFile(destPath, "utf-8");
|
|
1767
1855
|
if (existingContent === outputContent) {
|
|
1768
1856
|
return;
|
|
1769
1857
|
}
|
|
1858
|
+
} catch {
|
|
1770
1859
|
}
|
|
1771
1860
|
await fs9.outputFile(destPath, outputContent);
|
|
1772
1861
|
}
|
|
@@ -1818,8 +1907,10 @@ var init_sandbox = __esm({
|
|
|
1818
1907
|
/** 清理指定版本的沙箱物理文件 */
|
|
1819
1908
|
static async cleanVersion(version) {
|
|
1820
1909
|
const versionPath = this.getVersionPath(version);
|
|
1821
|
-
|
|
1910
|
+
try {
|
|
1822
1911
|
await fs10.remove(versionPath);
|
|
1912
|
+
} catch (e) {
|
|
1913
|
+
logger2.debug(`\u6E05\u7406\u7248\u672C\u76EE\u5F55\u5931\u8D25: ${e.message}`);
|
|
1823
1914
|
}
|
|
1824
1915
|
}
|
|
1825
1916
|
/**
|
|
@@ -1868,23 +1959,24 @@ var init_sandbox = __esm({
|
|
|
1868
1959
|
for (const dir of distDirs) {
|
|
1869
1960
|
const stats = await fs10.lstat(dir).catch(() => null);
|
|
1870
1961
|
if (stats) {
|
|
1871
|
-
|
|
1872
|
-
path12.join(path12.dirname(dir), "package.json")
|
|
1873
|
-
);
|
|
1874
|
-
if (hasPkg) {
|
|
1962
|
+
try {
|
|
1963
|
+
await fs10.access(path12.join(path12.dirname(dir), "package.json"));
|
|
1875
1964
|
targetDirs.push(dir);
|
|
1965
|
+
} catch {
|
|
1876
1966
|
}
|
|
1877
1967
|
}
|
|
1878
1968
|
}
|
|
1879
1969
|
const globalRoot = this.getRoot();
|
|
1880
|
-
|
|
1970
|
+
try {
|
|
1971
|
+
await fs10.access(globalRoot);
|
|
1881
1972
|
targetDirs.push(globalRoot);
|
|
1973
|
+
} catch {
|
|
1882
1974
|
}
|
|
1883
1975
|
}
|
|
1884
1976
|
if (dryRun) {
|
|
1885
1977
|
spinner.stop();
|
|
1886
1978
|
if (targetDirs.length === 0) {
|
|
1887
|
-
|
|
1979
|
+
logger2.info(pc5.green("\u2728 \u6CA1\u6709\u53D1\u73B0\u9700\u8981\u6E05\u7406\u7684\u7F13\u5B58\u76EE\u5F55"));
|
|
1888
1980
|
} else {
|
|
1889
1981
|
printBox(
|
|
1890
1982
|
`${pc5.yellow("\u5373\u5C06\u6E05\u7406\u4EE5\u4E0B\u76EE\u5F55\uFF1A")}
|
|
@@ -1919,8 +2011,10 @@ var init_sandbox = __esm({
|
|
|
1919
2011
|
return versionPath;
|
|
1920
2012
|
}
|
|
1921
2013
|
}
|
|
1922
|
-
|
|
2014
|
+
try {
|
|
1923
2015
|
await fs10.remove(path12.join(versionPath, "node_modules"));
|
|
2016
|
+
} catch (e) {
|
|
2017
|
+
logger2.debug(`\u5220\u9664 node_modules \u5931\u8D25: ${e.message}`);
|
|
1924
2018
|
}
|
|
1925
2019
|
await fs10.ensureDir(versionPath);
|
|
1926
2020
|
const spinner = createSpinner(
|
|
@@ -1962,7 +2056,7 @@ var init_sandbox = __esm({
|
|
|
1962
2056
|
spinner.warn(
|
|
1963
2057
|
pc5.yellow(`\u6C99\u7BB1\u521D\u59CB\u5316\u53D1\u751F\u7F51\u7EDC/\u7248\u672C\u9519\u8BEF (\u6D4B\u8BD5\u73AF\u5883\u5DF2\u5FFD\u7565)`)
|
|
1964
2058
|
);
|
|
1965
|
-
|
|
2059
|
+
logger2.warn(`\u5FFD\u7565\u7684\u5B89\u88C5\u9519\u8BEF: ${installErr.message.split("\n")[0]}`);
|
|
1966
2060
|
} else {
|
|
1967
2061
|
throw installErr;
|
|
1968
2062
|
}
|
|
@@ -1982,37 +2076,51 @@ var init_sandbox = __esm({
|
|
|
1982
2076
|
static async ensureShell(version, force = false) {
|
|
1983
2077
|
const versionPath = this.getVersionPath(version);
|
|
1984
2078
|
const shellDestDir = path12.join(versionPath, "shell");
|
|
1985
|
-
if (!force
|
|
1986
|
-
|
|
2079
|
+
if (!force) {
|
|
2080
|
+
try {
|
|
2081
|
+
await fs10.access(path12.join(shellDestDir, "tsconfig.paths.json"));
|
|
2082
|
+
return shellDestDir;
|
|
2083
|
+
} catch (e) {
|
|
2084
|
+
logger2.debug(`globalRoot \u68C0\u67E5: ${e.message}`);
|
|
2085
|
+
}
|
|
1987
2086
|
}
|
|
1988
2087
|
const cliRoot = await getCliRoot();
|
|
1989
|
-
|
|
1990
|
-
|
|
2088
|
+
let cliVersion = "0.0.0";
|
|
2089
|
+
try {
|
|
2090
|
+
const cliPkg = await fs10.readJson(path12.join(cliRoot, "package.json"));
|
|
2091
|
+
cliVersion = cliPkg.version;
|
|
2092
|
+
} catch {
|
|
2093
|
+
logger2.warn(`\u65E0\u6CD5\u8BFB\u53D6 CLI \u7248\u672C\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u503C: ${cliVersion}`);
|
|
2094
|
+
}
|
|
1991
2095
|
const shellTemplateDir = path12.join(cliRoot, "templates/app");
|
|
1992
|
-
|
|
1993
|
-
await fs10.
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
cliVersion,
|
|
1998
|
-
theme: DEFAULT_CONFIG.THEME,
|
|
1999
|
-
isShell: true,
|
|
2000
|
-
isBusiness: true,
|
|
2001
|
-
tsconfigPath: "./tsconfig.paths.json"
|
|
2002
|
-
};
|
|
2003
|
-
await SandboxRenderer.renderDirectory(
|
|
2004
|
-
shellTemplateDir,
|
|
2005
|
-
shellDestDir,
|
|
2006
|
-
templateData
|
|
2007
|
-
);
|
|
2008
|
-
await fs10.writeJson(
|
|
2009
|
-
path12.join(shellDestDir, "tsconfig.paths.json"),
|
|
2010
|
-
{
|
|
2011
|
-
compilerOptions: { baseUrl: ".", paths: { "@/*": ["./src/*"] } }
|
|
2012
|
-
},
|
|
2013
|
-
{ spaces: 2 }
|
|
2014
|
-
);
|
|
2096
|
+
try {
|
|
2097
|
+
await fs10.access(shellTemplateDir);
|
|
2098
|
+
} catch {
|
|
2099
|
+
logger2.warn(`Shell \u6A21\u677F\u76EE\u5F55\u4E0D\u5B58\u5728: ${shellTemplateDir}`);
|
|
2100
|
+
return shellDestDir;
|
|
2015
2101
|
}
|
|
2102
|
+
await fs10.remove(shellDestDir);
|
|
2103
|
+
const templateData = {
|
|
2104
|
+
name: "chatbi-shell",
|
|
2105
|
+
version,
|
|
2106
|
+
cliVersion,
|
|
2107
|
+
theme: DEFAULT_CONFIG.THEME,
|
|
2108
|
+
isShell: true,
|
|
2109
|
+
isBusiness: true,
|
|
2110
|
+
tsconfigPath: "./tsconfig.paths.json"
|
|
2111
|
+
};
|
|
2112
|
+
await SandboxRenderer.renderDirectory(
|
|
2113
|
+
shellTemplateDir,
|
|
2114
|
+
shellDestDir,
|
|
2115
|
+
templateData
|
|
2116
|
+
);
|
|
2117
|
+
await fs10.writeJson(
|
|
2118
|
+
path12.join(shellDestDir, "tsconfig.paths.json"),
|
|
2119
|
+
{
|
|
2120
|
+
compilerOptions: { baseUrl: ".", paths: { "@/*": ["./src/*"] } }
|
|
2121
|
+
},
|
|
2122
|
+
{ spaces: 2 }
|
|
2123
|
+
);
|
|
2016
2124
|
return shellDestDir;
|
|
2017
2125
|
}
|
|
2018
2126
|
/** 注入项目虚拟上下文 */
|
|
@@ -2032,7 +2140,14 @@ var init_sandbox = __esm({
|
|
|
2032
2140
|
this.CORE_PACKAGES.map((pkg) => {
|
|
2033
2141
|
const packageRoot = path12.join(sandboxNodeModules, pkg);
|
|
2034
2142
|
const sourceRoot = path12.join(packageRoot, "src");
|
|
2035
|
-
|
|
2143
|
+
try {
|
|
2144
|
+
const stats = fs10.statSync(sourceRoot);
|
|
2145
|
+
if (stats.isDirectory()) {
|
|
2146
|
+
return [pkg, sourceRoot];
|
|
2147
|
+
}
|
|
2148
|
+
} catch {
|
|
2149
|
+
}
|
|
2150
|
+
return [pkg, packageRoot];
|
|
2036
2151
|
})
|
|
2037
2152
|
);
|
|
2038
2153
|
}
|
|
@@ -2041,8 +2156,15 @@ var init_sandbox = __esm({
|
|
|
2041
2156
|
const versionRoot = this.getVersionRoot();
|
|
2042
2157
|
const currentLink = path12.join(versionRoot, SANDBOX_CONFIG.DIRS.CURRENT);
|
|
2043
2158
|
const targetPath = this.getVersionPath(version);
|
|
2044
|
-
|
|
2045
|
-
|
|
2159
|
+
try {
|
|
2160
|
+
await fs10.access(targetPath);
|
|
2161
|
+
} catch {
|
|
2162
|
+
throw new Error(`\u7248\u672C ${version} \u4E0D\u5B58\u5728`);
|
|
2163
|
+
}
|
|
2164
|
+
try {
|
|
2165
|
+
await fs10.remove(currentLink);
|
|
2166
|
+
} catch {
|
|
2167
|
+
}
|
|
2046
2168
|
await fs10.ensureSymlink(targetPath, currentLink, "dir");
|
|
2047
2169
|
}
|
|
2048
2170
|
/** 解析版本号 */
|
|
@@ -2052,8 +2174,10 @@ var init_sandbox = __esm({
|
|
|
2052
2174
|
this.getVersionRoot(),
|
|
2053
2175
|
SANDBOX_CONFIG.DIRS.CURRENT
|
|
2054
2176
|
);
|
|
2055
|
-
|
|
2056
|
-
|
|
2177
|
+
try {
|
|
2178
|
+
const realPath = await fs10.readlink(currentLink);
|
|
2179
|
+
return path12.basename(realPath);
|
|
2180
|
+
} catch {
|
|
2057
2181
|
}
|
|
2058
2182
|
const versions = await this.listVersions();
|
|
2059
2183
|
return versions[0] || "1.0.0";
|
|
@@ -2063,9 +2187,12 @@ var init_sandbox = __esm({
|
|
|
2063
2187
|
/** 列出所有已安装版本 */
|
|
2064
2188
|
static async listVersions() {
|
|
2065
2189
|
const versionRoot = this.getVersionRoot();
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2190
|
+
try {
|
|
2191
|
+
const dirs = await fs10.readdir(versionRoot);
|
|
2192
|
+
return dirs.filter((d) => d !== SANDBOX_CONFIG.DIRS.CURRENT && !d.startsWith(".")).sort().reverse();
|
|
2193
|
+
} catch {
|
|
2194
|
+
return [];
|
|
2195
|
+
}
|
|
2069
2196
|
}
|
|
2070
2197
|
/** 可视化展示沙箱状态 */
|
|
2071
2198
|
static async visualizeStatus(cwd) {
|
|
@@ -2105,7 +2232,7 @@ var init_corekit = __esm({
|
|
|
2105
2232
|
CoreKit = class {
|
|
2106
2233
|
static async getWorkspacePatterns(rootDir) {
|
|
2107
2234
|
const workspaceYamlPath = path13.join(rootDir, "pnpm-workspace.yaml");
|
|
2108
|
-
|
|
2235
|
+
try {
|
|
2109
2236
|
const content = await fs11.readFile(workspaceYamlPath, "utf-8");
|
|
2110
2237
|
const match = content.match(/packages:\s*([\s\S]*?)(?:\n\S|$)/);
|
|
2111
2238
|
if (match && match[1]) {
|
|
@@ -2114,17 +2241,18 @@ var init_corekit = __esm({
|
|
|
2114
2241
|
return patterns;
|
|
2115
2242
|
}
|
|
2116
2243
|
}
|
|
2244
|
+
} catch {
|
|
2117
2245
|
}
|
|
2118
2246
|
const pkgPath = path13.join(rootDir, "package.json");
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2247
|
+
try {
|
|
2248
|
+
const pkg = await fs11.readJson(pkgPath);
|
|
2249
|
+
if (Array.isArray(pkg.workspaces)) {
|
|
2250
|
+
return pkg.workspaces;
|
|
2251
|
+
}
|
|
2252
|
+
if (Array.isArray(pkg.workspaces?.packages)) {
|
|
2253
|
+
return pkg.workspaces.packages;
|
|
2254
|
+
}
|
|
2255
|
+
} catch {
|
|
2128
2256
|
}
|
|
2129
2257
|
return [];
|
|
2130
2258
|
}
|
|
@@ -2138,21 +2266,39 @@ var init_corekit = __esm({
|
|
|
2138
2266
|
}
|
|
2139
2267
|
static async getPluginPackagesDir(rootDir) {
|
|
2140
2268
|
const pluginPatterns = await this.getPluginWorkspacePatterns(rootDir);
|
|
2141
|
-
const
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2269
|
+
const sortedPatterns = [
|
|
2270
|
+
...pluginPatterns.filter(
|
|
2271
|
+
(pattern) => pattern.startsWith("packages/plugins/")
|
|
2272
|
+
),
|
|
2273
|
+
...pluginPatterns.filter((pattern) => pattern.startsWith("plugins/")),
|
|
2274
|
+
...pluginPatterns.filter(
|
|
2275
|
+
(pattern) => !pattern.startsWith("packages/plugins/") && !pattern.startsWith("plugins/")
|
|
2276
|
+
)
|
|
2277
|
+
];
|
|
2278
|
+
for (const pattern of sortedPatterns) {
|
|
2279
|
+
const dir = path13.resolve(rootDir, pattern.replace(/\/\*$/, ""));
|
|
2280
|
+
if (fs11.existsSync(dir)) {
|
|
2281
|
+
return dir;
|
|
2282
|
+
}
|
|
2146
2283
|
}
|
|
2147
|
-
return
|
|
2284
|
+
return null;
|
|
2148
2285
|
}
|
|
2149
2286
|
static async getAppPackagesDir(rootDir) {
|
|
2150
2287
|
const appPatterns = await this.getAppWorkspacePatterns(rootDir);
|
|
2151
|
-
const
|
|
2152
|
-
|
|
2153
|
-
|
|
2288
|
+
const sortedPatterns = [
|
|
2289
|
+
...appPatterns.filter((pattern) => pattern.startsWith("packages/apps/")),
|
|
2290
|
+
...appPatterns.filter((pattern) => pattern.startsWith("apps/")),
|
|
2291
|
+
...appPatterns.filter(
|
|
2292
|
+
(pattern) => !pattern.startsWith("packages/apps/") && !pattern.startsWith("apps/")
|
|
2293
|
+
)
|
|
2294
|
+
];
|
|
2295
|
+
for (const pattern of sortedPatterns) {
|
|
2296
|
+
const dir = path13.resolve(rootDir, pattern.replace(/\/\*$/, ""));
|
|
2297
|
+
if (fs11.existsSync(dir)) {
|
|
2298
|
+
return dir;
|
|
2299
|
+
}
|
|
2154
2300
|
}
|
|
2155
|
-
return
|
|
2301
|
+
return null;
|
|
2156
2302
|
}
|
|
2157
2303
|
static async resolvePluginDirectory(rootDir, pluginName) {
|
|
2158
2304
|
const plugins = await this.discoverPlugins(rootDir);
|
|
@@ -2203,19 +2349,15 @@ var init_corekit = __esm({
|
|
|
2203
2349
|
try {
|
|
2204
2350
|
const cliRoot = await getCliRoot();
|
|
2205
2351
|
const cliVersionFile = path13.join(cliRoot, ".chatbi-version");
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
if (version) return version;
|
|
2209
|
-
}
|
|
2352
|
+
const version = (await fs11.readFile(cliVersionFile, "utf-8")).trim();
|
|
2353
|
+
if (version) return version;
|
|
2210
2354
|
} catch {
|
|
2211
2355
|
}
|
|
2212
2356
|
const currentLinkPath = path13.join(Sandbox.getVersionRoot(), "current");
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
} catch {
|
|
2218
|
-
}
|
|
2357
|
+
try {
|
|
2358
|
+
const realPath = await fs11.realpath(currentLinkPath);
|
|
2359
|
+
return path13.basename(realPath);
|
|
2360
|
+
} catch {
|
|
2219
2361
|
}
|
|
2220
2362
|
const versions = await this.listVersions();
|
|
2221
2363
|
return versions[0] || "latest";
|
|
@@ -2302,7 +2444,7 @@ ${pc6.gray("Root: ")} ${pc6.white(cwd)}`,
|
|
|
2302
2444
|
static async startMonorepoDevServer(rootDir, version, customPort) {
|
|
2303
2445
|
const appsDir = await this.getAppPackagesDir(rootDir) || path13.join(rootDir, "apps");
|
|
2304
2446
|
if (!fs11.existsSync(appsDir)) {
|
|
2305
|
-
|
|
2447
|
+
logger2.warn(
|
|
2306
2448
|
`\u5F53\u524D Monorepo \u4E0B\u672A\u627E\u5230\u5E94\u7528\u76EE\u5F55: ${path13.relative(rootDir, appsDir) || "apps"}`
|
|
2307
2449
|
);
|
|
2308
2450
|
return;
|
|
@@ -2316,7 +2458,7 @@ ${pc6.gray("Root: ")} ${pc6.white(cwd)}`,
|
|
|
2316
2458
|
path: path13.dirname(pkgPath)
|
|
2317
2459
|
}));
|
|
2318
2460
|
if (apps.length === 0) {
|
|
2319
|
-
|
|
2461
|
+
logger2.info("\u5F53\u524D Monorepo \u4E0B\u672A\u627E\u5230\u4EFB\u4F55\u5E94\u7528 (apps/)");
|
|
2320
2462
|
return;
|
|
2321
2463
|
}
|
|
2322
2464
|
const { default: prompts7 } = await import("prompts");
|
|
@@ -2331,7 +2473,7 @@ ${pc6.gray("Root: ")} ${pc6.white(cwd)}`,
|
|
|
2331
2473
|
initial: 0
|
|
2332
2474
|
});
|
|
2333
2475
|
if (!response.appPath) {
|
|
2334
|
-
|
|
2476
|
+
logger2.info("\u5DF2\u53D6\u6D88");
|
|
2335
2477
|
return;
|
|
2336
2478
|
}
|
|
2337
2479
|
await this.startAppDevServer(response.appPath, version, customPort, true);
|
|
@@ -2340,7 +2482,7 @@ ${pc6.gray("Root: ")} ${pc6.white(cwd)}`,
|
|
|
2340
2482
|
* 启动插件开发服务器 (Hosted Mode)
|
|
2341
2483
|
*/
|
|
2342
2484
|
static async startPluginDevServer(pluginDir, version, customPort) {
|
|
2343
|
-
|
|
2485
|
+
logger2.info("\u6B63\u5728\u542F\u52A8\u6258\u7BA1\u5F0F Shell...");
|
|
2344
2486
|
const shellPort = customPort || 5173;
|
|
2345
2487
|
const sandboxRoot = Sandbox.getRoot();
|
|
2346
2488
|
const versionPath = Sandbox.getVersionPath(version);
|
|
@@ -2353,6 +2495,12 @@ ${pc6.gray("Root: ")} ${pc6.white(cwd)}`,
|
|
|
2353
2495
|
if (!fs11.existsSync(pluginEntry)) {
|
|
2354
2496
|
pluginEntry = path13.join(pluginDir, "src/index.ts");
|
|
2355
2497
|
}
|
|
2498
|
+
if (!fs11.existsSync(pluginEntry)) {
|
|
2499
|
+
throw new Error(
|
|
2500
|
+
`\u63D2\u4EF6\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${pluginDir}/src/index.{ts,tsx}
|
|
2501
|
+
\u8BF7\u786E\u4FDD\u63D2\u4EF6\u76EE\u5F55\u5305\u542B src/index.ts \u6216 src/index.tsx`
|
|
2502
|
+
);
|
|
2503
|
+
}
|
|
2356
2504
|
const define = {
|
|
2357
2505
|
"process.env.CHATBI_PLUGIN_PATH": JSON.stringify(pluginDir)
|
|
2358
2506
|
};
|
|
@@ -2418,14 +2566,14 @@ ${pc6.white("Local: ")} ${pc6.cyan(pc6.underline(localUrl))}`,
|
|
|
2418
2566
|
"Shell Success"
|
|
2419
2567
|
);
|
|
2420
2568
|
} catch (e) {
|
|
2421
|
-
|
|
2569
|
+
logger2.error("Shell \u670D\u52A1\u5668\u542F\u52A8\u5931\u8D25", e);
|
|
2422
2570
|
}
|
|
2423
2571
|
}
|
|
2424
2572
|
/**
|
|
2425
2573
|
* 启动应用开发服务器 (Integrated Mode)
|
|
2426
2574
|
*/
|
|
2427
2575
|
static async startAppDevServer(appDir, version, customPort, isMonorepo = false) {
|
|
2428
|
-
|
|
2576
|
+
logger2.info("\u6B63\u5728\u542F\u52A8\u5E94\u7528...");
|
|
2429
2577
|
const versionPath = Sandbox.getVersionPath(version);
|
|
2430
2578
|
const sandboxNodeModules = path13.join(versionPath, "node_modules");
|
|
2431
2579
|
const cliRoot = await getCliRoot();
|
|
@@ -2444,7 +2592,7 @@ ${pc6.white("Local: ")} ${pc6.cyan(pc6.underline(localUrl))}`,
|
|
|
2444
2592
|
void 0,
|
|
2445
2593
|
appDir
|
|
2446
2594
|
).catch((e) => {
|
|
2447
|
-
|
|
2595
|
+
logger2.warn(`\u52A0\u8F7D vite.config.ts \u5931\u8D25: ${e.message}`);
|
|
2448
2596
|
return null;
|
|
2449
2597
|
});
|
|
2450
2598
|
}
|
|
@@ -2497,7 +2645,7 @@ ${pc6.white("Local: ")} ${pc6.cyan(pc6.underline(localUrl))}`,
|
|
|
2497
2645
|
"App Success"
|
|
2498
2646
|
);
|
|
2499
2647
|
} catch (e) {
|
|
2500
|
-
|
|
2648
|
+
logger2.error("\u5E94\u7528\u542F\u52A8\u5931\u8D25", e);
|
|
2501
2649
|
}
|
|
2502
2650
|
}
|
|
2503
2651
|
};
|
|
@@ -2533,11 +2681,13 @@ import pc7 from "picocolors";
|
|
|
2533
2681
|
async function build(options) {
|
|
2534
2682
|
const cwd = process.cwd();
|
|
2535
2683
|
const pkgPath = path14.join(cwd, "package.json");
|
|
2536
|
-
|
|
2537
|
-
|
|
2684
|
+
let pkg = {};
|
|
2685
|
+
try {
|
|
2686
|
+
pkg = await fs12.readJson(pkgPath);
|
|
2687
|
+
} catch {
|
|
2688
|
+
logger2.error(`\u5728 ${cwd} \u4E2D\u672A\u627E\u5230\u6216\u65E0\u6CD5\u8BFB\u53D6 package.json`);
|
|
2538
2689
|
return;
|
|
2539
2690
|
}
|
|
2540
|
-
const pkg = await fs12.readJson(pkgPath);
|
|
2541
2691
|
if (options.force) {
|
|
2542
2692
|
const spinnerClean = createSpinner("\u6B63\u5728\u6E05\u7406\u7F13\u5B58\u73AF\u5883...").start();
|
|
2543
2693
|
try {
|
|
@@ -2545,11 +2695,11 @@ async function build(options) {
|
|
|
2545
2695
|
spinnerClean.succeed("\u7F13\u5B58\u73AF\u5883\u6E05\u7406\u5B8C\u6210");
|
|
2546
2696
|
} catch {
|
|
2547
2697
|
spinnerClean.fail("\u7F13\u5B58\u6E05\u7406\u5931\u8D25");
|
|
2548
|
-
|
|
2698
|
+
logger2.error("\u6E05\u7406\u8FC7\u7A0B\u4E2D\u53D1\u751F\u9519\u8BEF");
|
|
2549
2699
|
}
|
|
2550
2700
|
}
|
|
2551
2701
|
const version = await CoreKit.resolveVersion(cwd);
|
|
2552
|
-
|
|
2702
|
+
logger2.info(
|
|
2553
2703
|
`\u6B63\u5728\u6784\u5EFA\u9879\u76EE: ${pc7.bold(pkg.name || "unnamed")} (\u5185\u6838\u7248\u672C: ${version})
|
|
2554
2704
|
`
|
|
2555
2705
|
);
|
|
@@ -2582,28 +2732,41 @@ async function build(options) {
|
|
|
2582
2732
|
if (pkg.scripts && pkg.scripts.build && !process.env.CHATBI_CLI_INTERNAL) {
|
|
2583
2733
|
const buildScript = pkg.scripts.build;
|
|
2584
2734
|
if (!buildScript.includes("chatbi-cli build") && !buildScript.includes("chatbi build")) {
|
|
2585
|
-
|
|
2735
|
+
logger2.info(
|
|
2586
2736
|
`\u68C0\u6D4B\u5230\u81EA\u5B9A\u4E49 build \u811A\u672C\uFF0C\u6B63\u5728\u6267\u884C: ${pc7.cyan("npm run build")}`
|
|
2587
2737
|
);
|
|
2588
2738
|
const args = ["run", "build"];
|
|
2589
2739
|
if (options.watch) {
|
|
2590
2740
|
args.push("--", "--watch");
|
|
2591
2741
|
}
|
|
2592
|
-
await execa4("npm", args, {
|
|
2742
|
+
const npmResult = await execa4("npm", args, {
|
|
2593
2743
|
stdio: "inherit",
|
|
2594
|
-
env: { ...process.env, CHATBI_CLI_INTERNAL: "true" }
|
|
2744
|
+
env: { ...process.env, CHATBI_CLI_INTERNAL: "true" },
|
|
2745
|
+
reject: false
|
|
2595
2746
|
});
|
|
2747
|
+
if (npmResult.failed) {
|
|
2748
|
+
logger2.error(`npm run build \u6267\u884C\u5931\u8D25: exitCode=${npmResult.exitCode}`);
|
|
2749
|
+
return;
|
|
2750
|
+
}
|
|
2596
2751
|
return;
|
|
2597
2752
|
}
|
|
2598
2753
|
}
|
|
2599
2754
|
const mode = await CoreKit.detectMode(cwd);
|
|
2600
2755
|
if (mode === "monorepo") {
|
|
2601
|
-
|
|
2602
|
-
await execa4("pnpm", ["-r", "build"], {
|
|
2756
|
+
logger2.info("\u68C0\u6D4B\u5230 Monorepo \u9879\u76EE\uFF0C\u6B63\u5728\u9012\u5F52\u6784\u5EFA\u5B50\u5305...");
|
|
2757
|
+
const pnpmResult = await execa4("pnpm", ["-r", "build"], {
|
|
2758
|
+
stdio: "inherit",
|
|
2759
|
+
cwd,
|
|
2760
|
+
reject: false
|
|
2761
|
+
});
|
|
2762
|
+
if (pnpmResult.failed) {
|
|
2763
|
+
logger2.error(`pnpm -r build \u6267\u884C\u5931\u8D25: exitCode=${pnpmResult.exitCode}`);
|
|
2764
|
+
return;
|
|
2765
|
+
}
|
|
2603
2766
|
return;
|
|
2604
2767
|
}
|
|
2605
2768
|
if (mode === "app") {
|
|
2606
|
-
|
|
2769
|
+
logger2.info("\u6B63\u5728\u6784\u5EFA\u5E94\u7528 (Vite)...");
|
|
2607
2770
|
const { build: viteBuild } = await import("vite");
|
|
2608
2771
|
const coreAlias = Sandbox.getCoreAlias(version);
|
|
2609
2772
|
await viteBuild({
|
|
@@ -2637,22 +2800,30 @@ async function build(options) {
|
|
|
2637
2800
|
}
|
|
2638
2801
|
const { build: tsupBuild } = await import("tsup");
|
|
2639
2802
|
let entry = ["src/index.ts"];
|
|
2640
|
-
|
|
2803
|
+
const tsxPath = path14.join(cwd, "src/index.tsx");
|
|
2804
|
+
const tsPath = path14.join(cwd, "src/index.ts");
|
|
2805
|
+
try {
|
|
2806
|
+
await fs12.access(tsxPath);
|
|
2641
2807
|
entry = ["src/index.tsx"];
|
|
2642
|
-
}
|
|
2643
|
-
|
|
2644
|
-
|
|
2808
|
+
} catch {
|
|
2809
|
+
try {
|
|
2810
|
+
await fs12.access(tsPath);
|
|
2811
|
+
} catch {
|
|
2812
|
+
logger2.error("\u672A\u627E\u5230\u5165\u53E3\u6587\u4EF6\u3002\u671F\u671B src/index.ts \u6216 src/index.tsx");
|
|
2813
|
+
return;
|
|
2814
|
+
}
|
|
2645
2815
|
}
|
|
2646
2816
|
const isPlugin = mode === "plugin";
|
|
2647
2817
|
const userConfig = await ConfigManager.loadTsupConfig(cwd);
|
|
2648
2818
|
if (Object.keys(userConfig).length > 0) {
|
|
2649
|
-
|
|
2819
|
+
logger2.info(`\u5DF2\u52A0\u8F7D\u672C\u5730\u6784\u5EFA\u914D\u7F6E`);
|
|
2650
2820
|
}
|
|
2651
2821
|
if (!options.watch) {
|
|
2652
2822
|
await fs12.remove(path14.join(cwd, "dist"));
|
|
2653
2823
|
const tsbuildinfo = path14.join(cwd, "tsconfig.tsbuildinfo");
|
|
2654
|
-
|
|
2824
|
+
try {
|
|
2655
2825
|
await fs12.remove(tsbuildinfo);
|
|
2826
|
+
} catch {
|
|
2656
2827
|
}
|
|
2657
2828
|
}
|
|
2658
2829
|
if (isPlugin) {
|
|
@@ -2755,22 +2926,46 @@ async function build(options) {
|
|
|
2755
2926
|
} else if (fs12.existsSync(sandboxTsc)) {
|
|
2756
2927
|
tscBin = sandboxTsc;
|
|
2757
2928
|
} else {
|
|
2929
|
+
let dtsFailed = false;
|
|
2758
2930
|
if (fs12.existsSync(path14.join(cwd, "pnpm-lock.yaml"))) {
|
|
2759
|
-
await execa4(
|
|
2760
|
-
|
|
2931
|
+
const pnpmResult = await execa4(
|
|
2932
|
+
"pnpm",
|
|
2933
|
+
["exec", "tsc", "--build", "tsconfig.json"],
|
|
2934
|
+
{ reject: false }
|
|
2935
|
+
);
|
|
2936
|
+
if (pnpmResult.failed) {
|
|
2937
|
+
dtsFailed = true;
|
|
2938
|
+
logger2.error(
|
|
2939
|
+
`pnpm exec tsc \u6267\u884C\u5931\u8D25: exitCode=${pnpmResult.exitCode}`
|
|
2940
|
+
);
|
|
2941
|
+
} else {
|
|
2942
|
+
dtsSpinner.succeed("\u7C7B\u578B\u5B9A\u4E49\u751F\u6210\u5B8C\u6210");
|
|
2943
|
+
}
|
|
2761
2944
|
} else {
|
|
2762
|
-
await execa4(
|
|
2763
|
-
"
|
|
2764
|
-
"typescript",
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2945
|
+
const npxResult = await execa4(
|
|
2946
|
+
"npx",
|
|
2947
|
+
["-p", "typescript", "tsc", "--build", "tsconfig.json"],
|
|
2948
|
+
{ reject: false }
|
|
2949
|
+
);
|
|
2950
|
+
if (npxResult.failed) {
|
|
2951
|
+
dtsFailed = true;
|
|
2952
|
+
logger2.error(`npx tsc \u6267\u884C\u5931\u8D25: exitCode=${npxResult.exitCode}`);
|
|
2953
|
+
} else {
|
|
2954
|
+
dtsSpinner.succeed("\u7C7B\u578B\u5B9A\u4E49\u751F\u6210\u5B8C\u6210");
|
|
2955
|
+
}
|
|
2956
|
+
}
|
|
2957
|
+
if (dtsFailed) {
|
|
2958
|
+
throw new Error("DTS generation failed");
|
|
2770
2959
|
}
|
|
2771
2960
|
}
|
|
2772
2961
|
if (tscBin !== "tsc") {
|
|
2773
|
-
await execa4(tscBin, ["--build", "tsconfig.json"]
|
|
2962
|
+
const tscResult = await execa4(tscBin, ["--build", "tsconfig.json"], {
|
|
2963
|
+
reject: false
|
|
2964
|
+
});
|
|
2965
|
+
if (tscResult.failed) {
|
|
2966
|
+
dtsSpinner.warn(`\u7C7B\u578B\u751F\u6210\u5931\u8D25: exitCode=${tscResult.exitCode}`);
|
|
2967
|
+
throw new Error("DTS generation failed");
|
|
2968
|
+
}
|
|
2774
2969
|
dtsSpinner.succeed("\u7C7B\u578B\u5B9A\u4E49\u751F\u6210\u5B8C\u6210");
|
|
2775
2970
|
}
|
|
2776
2971
|
} catch {
|
|
@@ -2802,6 +2997,10 @@ import { execa as execa5 } from "execa";
|
|
|
2802
2997
|
import path15 from "path";
|
|
2803
2998
|
import pc8 from "picocolors";
|
|
2804
2999
|
async function fetch(version, options = {}) {
|
|
3000
|
+
if (!version || typeof version !== "string" || version.trim() === "") {
|
|
3001
|
+
logger2.error("\u7248\u672C\u53F7\u4E0D\u80FD\u4E3A\u7A7A\u6216\u65E0\u6548");
|
|
3002
|
+
return;
|
|
3003
|
+
}
|
|
2805
3004
|
const fetchSpinner = createSpinner(
|
|
2806
3005
|
`\u6B63\u5728\u83B7\u53D6\u5185\u6838\u7248\u672C ${pc8.cyan(version)}...`
|
|
2807
3006
|
).start();
|
|
@@ -2811,13 +3010,24 @@ async function fetch(version, options = {}) {
|
|
|
2811
3010
|
const packSpinner = createSpinner("\u6B63\u5728\u6253\u5305\u79BB\u7EBF\u8D44\u6E90...").start();
|
|
2812
3011
|
const tgzName = `chatbi-core-${version}.tgz`;
|
|
2813
3012
|
const tgzPath = path15.resolve(process.cwd(), tgzName);
|
|
2814
|
-
await execa5(
|
|
2815
|
-
"
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
3013
|
+
const { failed, exitCode, stderr } = await execa5(
|
|
3014
|
+
"tar",
|
|
3015
|
+
[
|
|
3016
|
+
"-czf",
|
|
3017
|
+
tgzPath,
|
|
3018
|
+
"-C",
|
|
3019
|
+
path15.dirname(versionPath),
|
|
3020
|
+
path15.basename(versionPath)
|
|
3021
|
+
],
|
|
3022
|
+
{ reject: false }
|
|
3023
|
+
);
|
|
3024
|
+
if (failed) {
|
|
3025
|
+
packSpinner.fail(
|
|
3026
|
+
`\u79BB\u7EBF\u8D44\u6E90\u6253\u5305\u5931\u8D25: exitCode=${exitCode}, stderr=${stderr || "unknown"}`
|
|
3027
|
+
);
|
|
3028
|
+
logger2.error(`tar \u547D\u4EE4\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u786E\u4FDD\u7CFB\u7EDF\u5DF2\u5B89\u88C5 tar`);
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
2821
3031
|
packSpinner.succeed("\u79BB\u7EBF\u8D44\u6E90\u6253\u5305\u5B8C\u6210");
|
|
2822
3032
|
printBox(
|
|
2823
3033
|
`${pc8.green(pc8.bold("\u2728 \u79BB\u7EBF\u5305\u5DF2\u751F\u6210!"))}
|
|
@@ -2827,7 +3037,7 @@ ${pc8.white("\u5B89\u88C5\u547D\u4EE4: ")} ${pc8.gray(`chatbi install ${tgzName}
|
|
|
2827
3037
|
"Pack Success"
|
|
2828
3038
|
);
|
|
2829
3039
|
} else {
|
|
2830
|
-
|
|
3040
|
+
logger2.success(`\u5185\u6838\u7248\u672C ${pc8.cyan(version)} \u5DF2\u51C6\u5907\u5C31\u7EEA\u3002`);
|
|
2831
3041
|
}
|
|
2832
3042
|
}
|
|
2833
3043
|
var init_fetch = __esm({
|
|
@@ -2849,36 +3059,56 @@ import fs13 from "fs-extra";
|
|
|
2849
3059
|
import path16 from "path";
|
|
2850
3060
|
import pc9 from "picocolors";
|
|
2851
3061
|
async function install(target) {
|
|
2852
|
-
if (target.endsWith(".tgz")
|
|
2853
|
-
|
|
2854
|
-
`\u6B63\u5728\u5B89\u88C5\u672C\u5730\u79BB\u7EBF\u5305: ${pc9.bold(target)}...`
|
|
2855
|
-
).start();
|
|
3062
|
+
if (target.endsWith(".tgz")) {
|
|
3063
|
+
let fileAccessible = false;
|
|
2856
3064
|
try {
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
}
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
3065
|
+
await fs13.access(target);
|
|
3066
|
+
fileAccessible = true;
|
|
3067
|
+
} catch {
|
|
3068
|
+
}
|
|
3069
|
+
if (!fileAccessible) {
|
|
3070
|
+
logger.error(`\u672C\u5730\u6587\u4EF6\u4E0D\u5B58\u5728\u6216\u4E0D\u53EF\u8BBF\u95EE: ${target}`);
|
|
3071
|
+
} else {
|
|
3072
|
+
const spinner = createSpinner(
|
|
3073
|
+
`\u6B63\u5728\u5B89\u88C5\u672C\u5730\u79BB\u7EBF\u5305: ${pc9.bold(target)}...`
|
|
3074
|
+
).start();
|
|
3075
|
+
try {
|
|
3076
|
+
const tgzPath = path16.resolve(target);
|
|
3077
|
+
const match = path16.basename(target).match(/chatbi-core-(.+)\.tgz/);
|
|
3078
|
+
let version = "unknown";
|
|
3079
|
+
if (match) {
|
|
3080
|
+
version = match[1];
|
|
3081
|
+
}
|
|
3082
|
+
if (version === "unknown") {
|
|
3083
|
+
spinner.warn("\u65E0\u6CD5\u4ECE\u6587\u4EF6\u540D\u8BC6\u522B\u7248\u672C\uFF0C\u5C06\u4F7F\u7528\u5F53\u524D\u65F6\u95F4\u6233\u4F5C\u4E3A\u7248\u672C\u53F7");
|
|
3084
|
+
version = `local-${Date.now()}`;
|
|
3085
|
+
}
|
|
3086
|
+
const versionRoot = Sandbox.getVersionRoot();
|
|
3087
|
+
await fs13.ensureDir(versionRoot);
|
|
3088
|
+
spinner.text = "\u6B63\u5728\u89E3\u538B\u6587\u4EF6...";
|
|
3089
|
+
const { failed, exitCode, stderr } = await execa6(
|
|
3090
|
+
"tar",
|
|
3091
|
+
["-xzf", tgzPath, "-C", versionRoot],
|
|
3092
|
+
{ reject: false }
|
|
3093
|
+
);
|
|
3094
|
+
if (failed) {
|
|
3095
|
+
spinner.fail(`\u89E3\u538B\u5931\u8D25: exitCode=${exitCode}`);
|
|
3096
|
+
logger.error(`tar \u547D\u4EE4\u6267\u884C\u5931\u8D25: ${stderr || tgzPath}`);
|
|
3097
|
+
throw new Error(`Failed to extract ${tgzPath}: exitCode=${exitCode}`);
|
|
3098
|
+
}
|
|
3099
|
+
spinner.succeed(`\u672C\u5730\u5305\u5DF2\u5B89\u88C5\u81F3\u6C99\u7BB1: ${version}`);
|
|
3100
|
+
spinner.text = "\u6B63\u5728\u51C6\u5907\u5185\u6838\u73AF\u5883...";
|
|
3101
|
+
await Sandbox.prepare(version);
|
|
3102
|
+
spinner.succeed("\u5185\u6838\u73AF\u5883\u5C31\u7EEA");
|
|
3103
|
+
printBox(
|
|
3104
|
+
pc9.green(pc9.bold("\u2728 \u672C\u5730\u5185\u6838\u5B89\u88C5\u6210\u529F!")) + "\n\n" + pc9.white("\u7248\u672C: ") + pc9.cyan(version) + "\n" + pc9.white("\u8DEF\u5F84: ") + pc9.gray(Sandbox.getVersionPath(version)),
|
|
3105
|
+
"Install Success"
|
|
3106
|
+
);
|
|
3107
|
+
return;
|
|
3108
|
+
} catch (e) {
|
|
3109
|
+
spinner.fail("\u5B89\u88C5\u5931\u8D25");
|
|
3110
|
+
throw e;
|
|
3111
|
+
}
|
|
2882
3112
|
}
|
|
2883
3113
|
} else {
|
|
2884
3114
|
const { fetch: fetch2 } = await Promise.resolve().then(() => (init_fetch(), fetch_exports));
|
|
@@ -2981,11 +3211,13 @@ import pc10 from "picocolors";
|
|
|
2981
3211
|
async function sync(options = {}) {
|
|
2982
3212
|
const cwd = options.cwd || process.cwd();
|
|
2983
3213
|
const pkgPath = path17.join(cwd, "package.json");
|
|
2984
|
-
|
|
2985
|
-
|
|
3214
|
+
let pkg = {};
|
|
3215
|
+
try {
|
|
3216
|
+
pkg = await fs14.readJson(pkgPath);
|
|
3217
|
+
} catch {
|
|
3218
|
+
logger2.error("\u672A\u627E\u5230 package.json\u3002\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u8FD0\u884C\u3002");
|
|
2986
3219
|
return;
|
|
2987
3220
|
}
|
|
2988
|
-
const pkg = await fs14.readJson(pkgPath);
|
|
2989
3221
|
let version = options.version;
|
|
2990
3222
|
if (!version) {
|
|
2991
3223
|
version = await CoreKit.resolveVersion(cwd);
|
|
@@ -3152,7 +3384,7 @@ async function init(options) {
|
|
|
3152
3384
|
],
|
|
3153
3385
|
{
|
|
3154
3386
|
onCancel: () => {
|
|
3155
|
-
|
|
3387
|
+
logger2.warn("\u5DF2\u53D6\u6D88\u521D\u59CB\u5316");
|
|
3156
3388
|
process.exit(0);
|
|
3157
3389
|
}
|
|
3158
3390
|
}
|
|
@@ -3167,7 +3399,14 @@ async function init(options) {
|
|
|
3167
3399
|
const isPluginIncluded = finalIncludePlugin;
|
|
3168
3400
|
const rootDir = cwd || process.cwd();
|
|
3169
3401
|
const targetDir = path18.resolve(rootDir, name);
|
|
3170
|
-
|
|
3402
|
+
let targetDirExists = false;
|
|
3403
|
+
try {
|
|
3404
|
+
const stats = await fs15.stat(targetDir);
|
|
3405
|
+
targetDirExists = stats.isDirectory();
|
|
3406
|
+
} catch {
|
|
3407
|
+
targetDirExists = false;
|
|
3408
|
+
}
|
|
3409
|
+
if (targetDirExists) {
|
|
3171
3410
|
if (force) {
|
|
3172
3411
|
await fs15.remove(targetDir);
|
|
3173
3412
|
} else {
|
|
@@ -3190,7 +3429,7 @@ async function init(options) {
|
|
|
3190
3429
|
]
|
|
3191
3430
|
});
|
|
3192
3431
|
if (action === "cancel" || !action) {
|
|
3193
|
-
|
|
3432
|
+
logger2.warn("\u5DF2\u53D6\u6D88\u521D\u59CB\u5316");
|
|
3194
3433
|
return;
|
|
3195
3434
|
}
|
|
3196
3435
|
if (action === "overwrite") {
|
|
@@ -3201,20 +3440,25 @@ async function init(options) {
|
|
|
3201
3440
|
initial: false
|
|
3202
3441
|
});
|
|
3203
3442
|
if (!confirm) {
|
|
3204
|
-
|
|
3443
|
+
logger2.warn("\u5DF2\u53D6\u6D88\u8986\u76D6");
|
|
3205
3444
|
return;
|
|
3206
3445
|
}
|
|
3207
3446
|
await fs15.remove(targetDir);
|
|
3208
3447
|
}
|
|
3209
3448
|
}
|
|
3210
3449
|
}
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3450
|
+
logger2.info(`\u6B63\u5728\u521D\u59CB\u5316\u9879\u76EE: ${pc11.bold(name)}...`);
|
|
3451
|
+
logger2.info(pc11.gray(`\u7C7B\u578B: ${projectType} | \u4E3B\u9898: ${theme || "N/A"}`));
|
|
3452
|
+
logger2.info("");
|
|
3214
3453
|
try {
|
|
3215
3454
|
const myCliRoot = await getCliRoot();
|
|
3216
|
-
|
|
3217
|
-
|
|
3455
|
+
let cliVersion = "0.0.0";
|
|
3456
|
+
try {
|
|
3457
|
+
const cliPkg = await fs15.readJson(path18.join(myCliRoot, "package.json"));
|
|
3458
|
+
cliVersion = cliPkg.version;
|
|
3459
|
+
} catch {
|
|
3460
|
+
logger2.warn(`\u65E0\u6CD5\u8BFB\u53D6 CLI \u7248\u672C\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u503C: ${cliVersion}`);
|
|
3461
|
+
}
|
|
3218
3462
|
const config4 = { coreSource: "npm" };
|
|
3219
3463
|
const kernelVersionFile = path18.join(myCliRoot, SANDBOX_CONFIG.LOCK_FILE);
|
|
3220
3464
|
if (fs15.existsSync(kernelVersionFile)) {
|
|
@@ -3301,11 +3545,11 @@ async function init(options) {
|
|
|
3301
3545
|
);
|
|
3302
3546
|
}
|
|
3303
3547
|
spinner.succeed(pc11.green(`\u9879\u76EE ${name} \u521D\u59CB\u5316\u5B8C\u6210\uFF01`));
|
|
3304
|
-
|
|
3305
|
-
|
|
3548
|
+
logger2.info("");
|
|
3549
|
+
logger2.info(pc11.cyan("\u6B63\u5728\u521D\u59CB\u5316\u5185\u6838\u73AF\u5883..."));
|
|
3306
3550
|
const projectCwd = targetDir;
|
|
3307
3551
|
await sync({ force: true, cwd: projectCwd });
|
|
3308
|
-
|
|
3552
|
+
logger2.info("");
|
|
3309
3553
|
printBox(
|
|
3310
3554
|
`${pc11.green("\u{1F389} \u9879\u76EE\u51C6\u5907\u5C31\u7EEA\uFF01")}
|
|
3311
3555
|
|
|
@@ -3314,7 +3558,7 @@ chatbi dev`,
|
|
|
3314
3558
|
"Happy Coding"
|
|
3315
3559
|
);
|
|
3316
3560
|
} catch (e) {
|
|
3317
|
-
|
|
3561
|
+
logger2.error(`\u521D\u59CB\u5316\u5931\u8D25: ${e.message}`);
|
|
3318
3562
|
}
|
|
3319
3563
|
}
|
|
3320
3564
|
var init_init = __esm({
|
|
@@ -3344,14 +3588,20 @@ async function add(options) {
|
|
|
3344
3588
|
const cwd = process.cwd();
|
|
3345
3589
|
const pkgPath = path19.join(cwd, "package.json");
|
|
3346
3590
|
if (!fs16.existsSync(pkgPath)) {
|
|
3347
|
-
|
|
3591
|
+
logger2.error("\u672A\u627E\u5230 package.json\u3002\u8BF7\u5728 ChatBI-V \u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u8FD0\u884C\u6B64\u547D\u4EE4\u3002");
|
|
3592
|
+
return;
|
|
3593
|
+
}
|
|
3594
|
+
let pkg = {};
|
|
3595
|
+
try {
|
|
3596
|
+
pkg = await fs16.readJson(pkgPath);
|
|
3597
|
+
} catch {
|
|
3598
|
+
logger2.error(`\u8BFB\u53D6 package.json \u5931\u8D25: ${pkgPath}`);
|
|
3348
3599
|
return;
|
|
3349
3600
|
}
|
|
3350
|
-
const pkg = await fs16.readJson(pkgPath);
|
|
3351
3601
|
const pluginPackagesDir = await CoreKit.getPluginPackagesDir(cwd);
|
|
3352
3602
|
const isMonorepo = Boolean(pluginPackagesDir);
|
|
3353
3603
|
if (!isMonorepo) {
|
|
3354
|
-
|
|
3604
|
+
logger2.error(
|
|
3355
3605
|
"\u5F53\u524D\u4E0D\u662F Monorepo \u9879\u76EE\uFF0C\u65E0\u6CD5\u6DFB\u52A0\u63D2\u4EF6 (\u8BF7\u5728\u5305\u542B\u63D2\u4EF6\u5DE5\u4F5C\u7A7A\u95F4\u7684\u9879\u76EE\u4E2D\u8FD0\u884C)"
|
|
3356
3606
|
);
|
|
3357
3607
|
process.exit(1);
|
|
@@ -3398,7 +3648,7 @@ async function add(options) {
|
|
|
3398
3648
|
],
|
|
3399
3649
|
{
|
|
3400
3650
|
onCancel: () => {
|
|
3401
|
-
|
|
3651
|
+
logger2.warn("\u5DF2\u53D6\u6D88\u6DFB\u52A0\u63D2\u4EF6");
|
|
3402
3652
|
process.exit(0);
|
|
3403
3653
|
}
|
|
3404
3654
|
}
|
|
@@ -3413,9 +3663,11 @@ async function add(options) {
|
|
|
3413
3663
|
}
|
|
3414
3664
|
const folderName = cleanName.startsWith("plugin-") ? cleanName : `plugin-${cleanName}`;
|
|
3415
3665
|
const pluginDir = path19.resolve(pluginPackagesDir, folderName);
|
|
3416
|
-
|
|
3417
|
-
|
|
3666
|
+
try {
|
|
3667
|
+
await fs16.access(pluginDir);
|
|
3668
|
+
logger2.error(`\u63D2\u4EF6\u76EE\u5F55 ${folderName} \u5DF2\u5B58\u5728\u3002`);
|
|
3418
3669
|
return;
|
|
3670
|
+
} catch {
|
|
3419
3671
|
}
|
|
3420
3672
|
const spinner = createSpinner(`\u6B63\u5728\u6DFB\u52A0\u65B0\u63D2\u4EF6: ${pc12.bold(name)}...`).start();
|
|
3421
3673
|
const targetDir = pluginDir;
|
|
@@ -3451,8 +3703,8 @@ async function add(options) {
|
|
|
3451
3703
|
}
|
|
3452
3704
|
if (process.env.NODE_ENV === "test") {
|
|
3453
3705
|
spinner.succeed(`\u63D2\u4EF6 ${pc12.bold(name)} \u6DFB\u52A0\u6210\u529F\uFF01`);
|
|
3454
|
-
|
|
3455
|
-
|
|
3706
|
+
logger2.success(`\u63D2\u4EF6 ${pc12.bold(name)} \u6DFB\u52A0\u6210\u529F\uFF01`);
|
|
3707
|
+
logger2.success("\u2728 \u63D2\u4EF6\u521B\u5EFA\u6210\u529F!");
|
|
3456
3708
|
return;
|
|
3457
3709
|
}
|
|
3458
3710
|
if (!templateDir || !fs16.existsSync(templateDir)) {
|
|
@@ -4033,58 +4285,72 @@ import fs18 from "fs-extra";
|
|
|
4033
4285
|
import path21 from "path";
|
|
4034
4286
|
import pc14 from "picocolors";
|
|
4035
4287
|
async function doctor(options = {}) {
|
|
4036
|
-
|
|
4288
|
+
logger2.info("\u6B63\u5728\u8BCA\u65AD\u9879\u76EE\u5065\u5EB7\u72B6\u51B5...\n");
|
|
4037
4289
|
const cwd = process.cwd();
|
|
4038
4290
|
let hasIssues = false;
|
|
4039
4291
|
const issues = [];
|
|
4040
|
-
|
|
4292
|
+
logger2.info(pc14.bold("Step 1: \u68C0\u67E5\u57FA\u7840\u73AF\u5883..."));
|
|
4041
4293
|
const nodeVersion = process.version;
|
|
4042
4294
|
if (parseInt(nodeVersion.slice(1).split(".")[0]) < 18) {
|
|
4043
|
-
|
|
4295
|
+
logger2.error(`Node.js \u7248\u672C\u592A\u4F4E: ${nodeVersion} (\u8981\u6C42 >=18)`);
|
|
4044
4296
|
hasIssues = true;
|
|
4045
4297
|
issues.push(`Node.js \u7248\u672C\u8FC7\u4F4E (${nodeVersion})`);
|
|
4046
4298
|
} else {
|
|
4047
|
-
|
|
4299
|
+
logger2.success(`Node.js \u7248\u672C: ${nodeVersion}`);
|
|
4048
4300
|
}
|
|
4049
4301
|
try {
|
|
4050
4302
|
const { execa: execa8 } = await import("execa");
|
|
4051
|
-
const { stdout: pnpmVer } = await execa8("pnpm", ["-v"]
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4303
|
+
const { failed, stdout: pnpmVer } = await execa8("pnpm", ["-v"], {
|
|
4304
|
+
reject: false
|
|
4305
|
+
});
|
|
4306
|
+
if (failed) {
|
|
4307
|
+
logger2.warn("\u672A\u68C0\u6D4B\u5230 pnpm\uFF0C\u5EFA\u8BAE\u5B89\u88C5\u4EE5\u83B7\u5F97\u6700\u4F73\u4F53\u9A8C");
|
|
4308
|
+
} else {
|
|
4309
|
+
logger2.success(`pnpm \u7248\u672C: ${pnpmVer}`);
|
|
4310
|
+
}
|
|
4311
|
+
} catch (e) {
|
|
4312
|
+
logger2.warn(
|
|
4313
|
+
`\u672A\u68C0\u6D4B\u5230 pnpm\uFF0C\u5EFA\u8BAE\u5B89\u88C5\u4EE5\u83B7\u5F97\u6700\u4F73\u4F53\u9A8C: ${e.message}`
|
|
4314
|
+
);
|
|
4055
4315
|
}
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4316
|
+
try {
|
|
4317
|
+
const gitDirPath = path21.join(cwd, ".git");
|
|
4318
|
+
await fs18.access(gitDirPath);
|
|
4319
|
+
const { execa: execa8 } = await import("execa");
|
|
4320
|
+
const { failed, stdout } = await execa8("git", ["status", "--porcelain"], {
|
|
4321
|
+
cwd,
|
|
4322
|
+
reject: false
|
|
4323
|
+
});
|
|
4324
|
+
if (failed) {
|
|
4325
|
+
logger2.warn("Git \u4E0D\u53EF\u7528\u6216\u5DE5\u4F5C\u533A\u635F\u574F");
|
|
4326
|
+
} else if (stdout.trim()) {
|
|
4327
|
+
logger2.warn("Git \u5DE5\u4F5C\u533A\u4E0D\u5E72\u51C0\uFF0C\u5EFA\u8BAE\u5728\u63D0\u4EA4\u540E\u8FDB\u884C\u64CD\u4F5C");
|
|
4328
|
+
} else {
|
|
4329
|
+
logger2.success("Git \u5DE5\u4F5C\u533A\u5E72\u51C0");
|
|
4066
4330
|
}
|
|
4331
|
+
} catch (e) {
|
|
4332
|
+
logger2.debug(`Git \u68C0\u67E5\u8DF3\u8FC7: ${e.message}`);
|
|
4067
4333
|
}
|
|
4068
|
-
|
|
4334
|
+
logger2.info(pc14.bold("\nStep 2: \u68C0\u67E5\u5185\u6838\u6C99\u7BB1\u73AF\u5883..."));
|
|
4069
4335
|
const version = await CoreKit.resolveVersion(cwd);
|
|
4070
4336
|
const versionPath = Sandbox.getVersionPath(version);
|
|
4071
4337
|
if (!fs18.existsSync(versionPath)) {
|
|
4072
|
-
|
|
4073
|
-
|
|
4338
|
+
logger2.error(`\u5185\u6838\u6C99\u7BB1\u7248\u672C ${version} \u5C1A\u672A\u5B89\u88C5`);
|
|
4339
|
+
logger2.info(
|
|
4074
4340
|
pc14.gray(` \u5EFA\u8BAE\u8FD0\u884C 'chatbi sync' \u6216 'chatbi use ${version}' \u8FDB\u884C\u5B89\u88C5\u3002`)
|
|
4075
4341
|
);
|
|
4076
4342
|
hasIssues = true;
|
|
4077
4343
|
issues.push(`\u5185\u6838\u6C99\u7BB1\u672A\u5B89\u88C5 (${version})`);
|
|
4078
4344
|
} else {
|
|
4079
|
-
|
|
4345
|
+
logger2.success(`\u5185\u6838\u6C99\u7BB1\u5C31\u7EEA (\u7248\u672C: ${version})`);
|
|
4080
4346
|
const sandboxNm = path21.join(versionPath, "node_modules");
|
|
4081
4347
|
if (!fs18.existsSync(sandboxNm)) {
|
|
4082
|
-
|
|
4348
|
+
logger2.warn("\u6C99\u7BB1\u4F9D\u8D56\u672A\u5B89\u88C5\uFF0C\u5C06\u5BFC\u81F4\u6784\u5EFA\u5931\u8D25");
|
|
4083
4349
|
hasIssues = true;
|
|
4084
4350
|
issues.push("\u6C99\u7BB1\u4F9D\u8D56\u7F3A\u5931");
|
|
4085
4351
|
}
|
|
4086
4352
|
}
|
|
4087
|
-
|
|
4353
|
+
logger2.info(pc14.bold("\nStep 2.5: \u6DF1\u5EA6\u6C99\u7BB1\u8BCA\u65AD..."));
|
|
4088
4354
|
try {
|
|
4089
4355
|
const sandboxDiagnostics = new SandboxDiagnostics(version, cwd);
|
|
4090
4356
|
const diagResult = await sandboxDiagnostics.runAllDiagnostics();
|
|
@@ -4093,48 +4359,48 @@ async function doctor(options = {}) {
|
|
|
4093
4359
|
(i) => i.severity === "warning"
|
|
4094
4360
|
);
|
|
4095
4361
|
if (diagResult.passed) {
|
|
4096
|
-
|
|
4362
|
+
logger2.success("\u6C99\u7BB1\u6DF1\u5EA6\u8BCA\u65AD\u901A\u8FC7");
|
|
4097
4363
|
} else {
|
|
4098
|
-
|
|
4364
|
+
logger2.warn(`\u6C99\u7BB1\u6DF1\u5EA6\u8BCA\u65AD\u53D1\u73B0\u95EE\u9898 ${diagResult.errorCount} \u4E2A`);
|
|
4099
4365
|
for (const item of errorItems.slice(0, 3)) {
|
|
4100
|
-
|
|
4366
|
+
logger2.error(` \u2022 ${item.title}`);
|
|
4101
4367
|
issues.push(`\u6C99\u7BB1: ${item.title}`);
|
|
4102
4368
|
}
|
|
4103
4369
|
if (errorItems.length > 3) {
|
|
4104
|
-
|
|
4105
|
-
|
|
4370
|
+
logger2.info(pc14.gray(` ... \u8FD8\u6709 ${errorItems.length - 3} \u4E2A\u95EE\u9898`));
|
|
4371
|
+
logger2.info(pc14.gray(` \u8FD0\u884C 'chatbi sandbox diagnose' \u67E5\u770B\u8BE6\u7EC6\u4FE1\u606F`));
|
|
4106
4372
|
}
|
|
4107
4373
|
}
|
|
4108
4374
|
for (const item of warningItems.slice(0, 2)) {
|
|
4109
|
-
|
|
4375
|
+
logger2.warn(` \u2022 ${item.title}`);
|
|
4110
4376
|
}
|
|
4111
4377
|
if (warningItems.length > 2) {
|
|
4112
|
-
|
|
4378
|
+
logger2.info(pc14.gray(` ... \u8FD8\u6709 ${warningItems.length - 2} \u4E2A\u8B66\u544A`));
|
|
4113
4379
|
}
|
|
4114
4380
|
} catch (e) {
|
|
4115
|
-
|
|
4381
|
+
logger2.warn(`\u6C99\u7BB1\u6DF1\u5EA6\u8BCA\u65AD\u5931\u8D25: ${e.message}`);
|
|
4116
4382
|
}
|
|
4117
|
-
|
|
4383
|
+
logger2.info(pc14.bold("\nStep 3: \u68C0\u67E5\u865A\u62DF\u4F9D\u8D56\u6620\u5C04..."));
|
|
4118
4384
|
const workspaceRoot = await SandboxPath.getWorkspaceRoot(cwd);
|
|
4119
4385
|
const chatbiDir = path21.join(workspaceRoot, ".chatbi");
|
|
4120
4386
|
const isMonorepoSub = cwd !== workspaceRoot;
|
|
4121
4387
|
if (isMonorepoSub) {
|
|
4122
|
-
|
|
4388
|
+
logger2.info(
|
|
4123
4389
|
pc14.gray(`\u5F53\u524D\u4F4D\u4E8E\u5B50\u5305\uFF0C\u68C0\u67E5 Monorepo \u6839\u76EE\u5F55\u914D\u7F6E: ${workspaceRoot}`)
|
|
4124
4390
|
);
|
|
4125
4391
|
}
|
|
4126
4392
|
if (!fs18.existsSync(chatbiDir)) {
|
|
4127
|
-
|
|
4393
|
+
logger2.warn("\u672A\u53D1\u73B0\u865A\u62DF\u4F9D\u8D56\u914D\u7F6E (.chatbi \u76EE\u5F55)");
|
|
4128
4394
|
hasIssues = true;
|
|
4129
4395
|
issues.push("\u7F3A\u5931 .chatbi \u76EE\u5F55");
|
|
4130
4396
|
} else {
|
|
4131
4397
|
const pathsJson = path21.join(chatbiDir, "tsconfig.paths.json");
|
|
4132
4398
|
if (!fs18.existsSync(pathsJson)) {
|
|
4133
|
-
|
|
4399
|
+
logger2.warn("\u865A\u62DF\u4F9D\u8D56\u914D\u7F6E\u6587\u4EF6\u4E0D\u5B8C\u6574");
|
|
4134
4400
|
hasIssues = true;
|
|
4135
4401
|
issues.push("\u865A\u62DF\u4F9D\u8D56\u914D\u7F6E\u4E0D\u5B8C\u6574");
|
|
4136
4402
|
} else {
|
|
4137
|
-
|
|
4403
|
+
logger2.success("\u865A\u62DF\u4F9D\u8D56\u914D\u7F6E\u5DF2\u751F\u6210");
|
|
4138
4404
|
}
|
|
4139
4405
|
}
|
|
4140
4406
|
const tsConfigPath = path21.join(cwd, "tsconfig.json");
|
|
@@ -4163,15 +4429,17 @@ async function doctor(options = {}) {
|
|
|
4163
4429
|
);
|
|
4164
4430
|
}
|
|
4165
4431
|
if (!hasExtend) {
|
|
4166
|
-
|
|
4432
|
+
logger2.warn("tsconfig.json \u672A\u7EE7\u627F\u865A\u62DF\u4F9D\u8D56\u914D\u7F6E");
|
|
4167
4433
|
hasIssues = true;
|
|
4168
4434
|
issues.push("tsconfig.json \u914D\u7F6E\u7F3A\u5931");
|
|
4169
4435
|
missingTsExtend = true;
|
|
4170
4436
|
} else {
|
|
4171
|
-
|
|
4437
|
+
logger2.success("tsconfig.json \u914D\u7F6E\u6B63\u5E38");
|
|
4172
4438
|
}
|
|
4173
|
-
} catch {
|
|
4174
|
-
|
|
4439
|
+
} catch (e) {
|
|
4440
|
+
logger2.error(
|
|
4441
|
+
`\u89E3\u6790 tsconfig.json \u5931\u8D25 (${tsConfigPath}): ${e.message}`
|
|
4442
|
+
);
|
|
4175
4443
|
}
|
|
4176
4444
|
}
|
|
4177
4445
|
const viteConfigPath = path21.join(cwd, "vite.config.ts");
|
|
@@ -4180,7 +4448,7 @@ async function doctor(options = {}) {
|
|
|
4180
4448
|
if (!content.includes("vite.alias.json") && !content.includes("CoreKit")) {
|
|
4181
4449
|
}
|
|
4182
4450
|
}
|
|
4183
|
-
|
|
4451
|
+
logger2.info(pc14.bold("\nStep 4: \u626B\u63CF\u4EE3\u7801\u89C4\u5219..."));
|
|
4184
4452
|
const rules = [
|
|
4185
4453
|
{
|
|
4186
4454
|
id: "plugin-lifecycle-init",
|
|
@@ -4261,6 +4529,10 @@ ${pc14.cyan("\u5EFA\u8BAE\u6839\u636E\u63D0\u793A\u8FDB\u884C\u4FEE\u590D")}`,
|
|
|
4261
4529
|
).start();
|
|
4262
4530
|
try {
|
|
4263
4531
|
const tsConfig = await fs18.readJson(tsConfigPath);
|
|
4532
|
+
if (!tsConfig || typeof tsConfig !== "object") {
|
|
4533
|
+
logger2.warn("tsconfig.json \u683C\u5F0F\u65E0\u6548");
|
|
4534
|
+
return;
|
|
4535
|
+
}
|
|
4264
4536
|
let extendsTarget = "./.chatbi/tsconfig.json";
|
|
4265
4537
|
if (isMonorepoSub) {
|
|
4266
4538
|
extendsTarget = path21.relative(
|
|
@@ -4312,9 +4584,9 @@ async function ls() {
|
|
|
4312
4584
|
const versions = await CoreKit.listVersions();
|
|
4313
4585
|
const currentVersion = await CoreKit.resolveVersion(process.cwd());
|
|
4314
4586
|
const globalCurrentVersion = await CoreKit.resolveVersion();
|
|
4315
|
-
|
|
4587
|
+
logger2.info("\u5DF2\u5B89\u88C5\u7684\u5185\u6838\u6C99\u7BB1\u7248\u672C:");
|
|
4316
4588
|
if (versions.length === 0) {
|
|
4317
|
-
|
|
4589
|
+
logger2.warn("\u5C1A\u672A\u5B89\u88C5\u4EFB\u4F55\u7248\u672C\uFF0C\u8BF7\u8FD0\u884C chatbi sync \u8FDB\u884C\u5B89\u88C5\u3002");
|
|
4318
4590
|
} else {
|
|
4319
4591
|
const list = versions.map((v) => {
|
|
4320
4592
|
const isGlobalCurrent = v === globalCurrentVersion;
|
|
@@ -4360,19 +4632,23 @@ __export(use_exports, {
|
|
|
4360
4632
|
import fs19 from "fs-extra";
|
|
4361
4633
|
import path22 from "path";
|
|
4362
4634
|
async function use(version, options = {}) {
|
|
4635
|
+
if (!version || typeof version !== "string" || version.trim() === "") {
|
|
4636
|
+
logger2.error("\u7248\u672C\u53F7\u4E0D\u80FD\u4E3A\u7A7A\u6216\u65E0\u6548");
|
|
4637
|
+
return;
|
|
4638
|
+
}
|
|
4363
4639
|
const versions = await CoreKit.listVersions();
|
|
4364
4640
|
if (!versions.includes(version)) {
|
|
4365
|
-
|
|
4641
|
+
logger2.warn(`\u7248\u672C ${version} \u5C1A\u672A\u5B89\u88C5\uFF0C\u6B63\u5728\u5C1D\u8BD5\u5B89\u88C5...`);
|
|
4366
4642
|
await Sandbox.prepare(version);
|
|
4367
4643
|
}
|
|
4368
4644
|
if (options.global) {
|
|
4369
4645
|
await Sandbox.useVersion(version);
|
|
4370
|
-
|
|
4646
|
+
logger2.success(`\u5DF2\u5207\u6362\u5168\u5C40\u5185\u6838\u7248\u672C\u81F3: ${version}`);
|
|
4371
4647
|
} else {
|
|
4372
4648
|
const cwd = process.cwd();
|
|
4373
4649
|
const versionFilePath = path22.join(cwd, ".chatbi-version");
|
|
4374
4650
|
await fs19.writeFile(versionFilePath, version, "utf-8");
|
|
4375
|
-
|
|
4651
|
+
logger2.success(`\u5DF2\u5207\u6362\u5F53\u524D\u9879\u76EE\u5185\u6838\u7248\u672C\u4E3A: ${version}`);
|
|
4376
4652
|
}
|
|
4377
4653
|
await sync({ version, force: false });
|
|
4378
4654
|
}
|
|
@@ -4401,8 +4677,10 @@ async function gl(options) {
|
|
|
4401
4677
|
const { type: initialType, prompt: initialPrompt } = options;
|
|
4402
4678
|
const cwd = process.cwd();
|
|
4403
4679
|
const pkgPath = path23.join(cwd, "package.json");
|
|
4404
|
-
|
|
4405
|
-
|
|
4680
|
+
try {
|
|
4681
|
+
await fs20.readJson(pkgPath);
|
|
4682
|
+
} catch {
|
|
4683
|
+
logger2.error("\u672A\u627E\u5230 package.json\u3002\u8BF7\u5728 ChatBI-V \u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u8FD0\u884C\u6B64\u547D\u4EE4\u3002");
|
|
4406
4684
|
return;
|
|
4407
4685
|
}
|
|
4408
4686
|
const response = await prompts3(
|
|
@@ -4448,7 +4726,7 @@ async function gl(options) {
|
|
|
4448
4726
|
],
|
|
4449
4727
|
{
|
|
4450
4728
|
onCancel: () => {
|
|
4451
|
-
|
|
4729
|
+
logger2.warn("\u5DF2\u53D6\u6D88 AI \u751F\u6210");
|
|
4452
4730
|
process.exit(0);
|
|
4453
4731
|
}
|
|
4454
4732
|
}
|
|
@@ -4456,10 +4734,10 @@ async function gl(options) {
|
|
|
4456
4734
|
const genType = initialType || response.genType;
|
|
4457
4735
|
const userPrompt = initialPrompt || response.userPrompt;
|
|
4458
4736
|
if (!userPrompt && genType !== "chat") {
|
|
4459
|
-
|
|
4737
|
+
logger2.error("\u9700\u6C42\u63CF\u8FF0\u4E0D\u80FD\u4E3A\u7A7A\u3002");
|
|
4460
4738
|
return;
|
|
4461
4739
|
}
|
|
4462
|
-
|
|
4740
|
+
logger2.info(`\u6B63\u5728\u547C\u53EB AI \u5F15\u64CE [\u6A21\u5F0F: ${pc16.bold(genType)}]...`);
|
|
4463
4741
|
const toolsContext = `
|
|
4464
4742
|
[Available Tools & Capabilities]
|
|
4465
4743
|
- Tool: plugin -> For creating new feature modules. Requires: name, type (business|system).
|
|
@@ -4503,57 +4781,63 @@ If not, use the SLOT_REQUIRED format.`.trim();
|
|
|
4503
4781
|
let retry = true;
|
|
4504
4782
|
while (retry) {
|
|
4505
4783
|
spinner.start();
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4784
|
+
const { stdout, failed, exitCode, stderr } = await execa7(
|
|
4785
|
+
"gemini",
|
|
4786
|
+
[geminiCmd, currentPrompt],
|
|
4787
|
+
{
|
|
4788
|
+
stdio: "pipe",
|
|
4789
|
+
reject: false
|
|
4790
|
+
}
|
|
4791
|
+
);
|
|
4792
|
+
if (failed) {
|
|
4510
4793
|
spinner.stop();
|
|
4511
|
-
if (
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4794
|
+
if (exitCode === "ENOENT" || exitCode === 127 || exitCode === "ENOENT") {
|
|
4795
|
+
logger2.error("\u672A\u5728\u7CFB\u7EDF\u4E2D\u627E\u5230 `gemini-cli` \u547D\u4EE4\u3002");
|
|
4796
|
+
logger2.info(
|
|
4797
|
+
pc16.yellow("\u8BF7\u786E\u4FDD\u5DF2\u5B89\u88C5 gemini-cli \u5E76\u5C06\u5176\u6DFB\u52A0\u5230\u7CFB\u7EDF PATH \u4E2D\u3002")
|
|
4798
|
+
);
|
|
4799
|
+
} else {
|
|
4800
|
+
logger2.error(
|
|
4801
|
+
`AI \u751F\u6210\u8FC7\u7A0B\u4E2D\u51FA\u9519: exitCode=${exitCode}, stderr=${stderr || stdout}`
|
|
4802
|
+
);
|
|
4803
|
+
}
|
|
4804
|
+
return;
|
|
4805
|
+
}
|
|
4806
|
+
spinner.stop();
|
|
4807
|
+
if (stdout.includes("SLOT_REQUIRED:")) {
|
|
4808
|
+
const slots = [];
|
|
4809
|
+
const lines = stdout.split("\n");
|
|
4810
|
+
for (const line of lines) {
|
|
4811
|
+
if (line.includes("SLOT_REQUIRED:")) {
|
|
4812
|
+
const match = line.match(/SLOT_REQUIRED:\s*([^|]+)\|\s*(.+)/);
|
|
4813
|
+
if (match) {
|
|
4814
|
+
slots.push({
|
|
4815
|
+
type: "text",
|
|
4816
|
+
name: match[1].trim(),
|
|
4817
|
+
message: match[2].trim()
|
|
4818
|
+
});
|
|
4524
4819
|
}
|
|
4525
4820
|
}
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4821
|
+
}
|
|
4822
|
+
if (slots.length > 0) {
|
|
4823
|
+
logger2.info(pc16.yellow("\n\u{1F4DD} AI \u9700\u8981\u66F4\u591A\u4FE1\u606F\u4EE5\u7EE7\u7EED:"));
|
|
4824
|
+
const answers = await prompts3(slots, {
|
|
4825
|
+
onCancel: () => process.exit(0)
|
|
4826
|
+
});
|
|
4827
|
+
const answerContext = Object.entries(answers).map(([k, v]) => `[${k}]: ${v}`).join("\n");
|
|
4828
|
+
currentPrompt += `
|
|
4533
4829
|
|
|
4534
4830
|
[User Answers]:
|
|
4535
4831
|
${answerContext}
|
|
4536
4832
|
|
|
4537
4833
|
Please proceed with generation based on these answers.`;
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
}
|
|
4541
|
-
}
|
|
4542
|
-
logger.info("\n" + stdout);
|
|
4543
|
-
retry = false;
|
|
4544
|
-
logger.success(`AI \u547D\u4EE4 [gemini ${geminiCmd}] \u6267\u884C\u5B8C\u6BD5!`);
|
|
4545
|
-
} catch (error) {
|
|
4546
|
-
spinner.stop();
|
|
4547
|
-
if (error.code === "ENOENT") {
|
|
4548
|
-
logger.error("\u672A\u5728\u7CFB\u7EDF\u4E2D\u627E\u5230 `gemini-cli` \u547D\u4EE4\u3002");
|
|
4549
|
-
logger.info(
|
|
4550
|
-
pc16.yellow("\u8BF7\u786E\u4FDD\u5DF2\u5B89\u88C5 gemini-cli \u5E76\u5C06\u5176\u6DFB\u52A0\u5230\u7CFB\u7EDF PATH \u4E2D\u3002")
|
|
4551
|
-
);
|
|
4552
|
-
} else {
|
|
4553
|
-
logger.error(`AI \u751F\u6210\u8FC7\u7A0B\u4E2D\u51FA\u9519: ${error.message}`);
|
|
4834
|
+
logger2.info("\u6B63\u5728\u6839\u636E\u60A8\u7684\u53CD\u9988\u91CD\u65B0\u547C\u53EB AI...");
|
|
4835
|
+
continue;
|
|
4554
4836
|
}
|
|
4555
|
-
throw error;
|
|
4556
4837
|
}
|
|
4838
|
+
logger2.info("\n" + stdout);
|
|
4839
|
+
retry = false;
|
|
4840
|
+
logger2.success(`AI \u547D\u4EE4 [gemini ${geminiCmd}] \u6267\u884C\u5B8C\u6BD5!`);
|
|
4557
4841
|
}
|
|
4558
4842
|
}
|
|
4559
4843
|
var init_gl = __esm({
|
|
@@ -4576,7 +4860,7 @@ async function discover() {
|
|
|
4576
4860
|
const plugins = await CoreKit.discoverPlugins(cwd);
|
|
4577
4861
|
if (plugins.length === 0) {
|
|
4578
4862
|
spinner.warn("\u672A\u53D1\u73B0\u4EFB\u4F55\u63D2\u4EF6");
|
|
4579
|
-
|
|
4863
|
+
logger2.info(
|
|
4580
4864
|
pc17.gray("\u8BF7\u786E\u4FDD\u63D2\u4EF6\u5DF2\u88AB\u5DE5\u4F5C\u533A\u914D\u7F6E\u5305\u542B\uFF0C\u4E14\u76EE\u5F55\u4E2D\u5B58\u5728 package.json\u3002")
|
|
4581
4865
|
);
|
|
4582
4866
|
} else {
|
|
@@ -4623,7 +4907,7 @@ async function clean(options) {
|
|
|
4623
4907
|
// 深度清理默认选否,普通清理默认选是
|
|
4624
4908
|
});
|
|
4625
4909
|
if (!confirm) {
|
|
4626
|
-
|
|
4910
|
+
logger2.warn("\u5DF2\u53D6\u6D88\u6E05\u7406");
|
|
4627
4911
|
return;
|
|
4628
4912
|
}
|
|
4629
4913
|
}
|
|
@@ -4648,7 +4932,7 @@ import os3 from "os";
|
|
|
4648
4932
|
import path24 from "path";
|
|
4649
4933
|
import pc18 from "picocolors";
|
|
4650
4934
|
async function bench() {
|
|
4651
|
-
|
|
4935
|
+
logger2.info("\u6B63\u5728\u542F\u52A8 CLI \u6027\u80FD\u57FA\u51C6\u6D4B\u8BD5...");
|
|
4652
4936
|
const results = [];
|
|
4653
4937
|
const tmpDir = path24.join(os3.tmpdir(), `chatbi-bench-${Date.now()}`);
|
|
4654
4938
|
await fs21.ensureDir(tmpDir);
|
|
@@ -4728,14 +5012,14 @@ import { loadESLint } from "eslint";
|
|
|
4728
5012
|
import fs22 from "fs-extra";
|
|
4729
5013
|
import path25 from "path";
|
|
4730
5014
|
async function lintTheme(options) {
|
|
4731
|
-
const projectRoot = findProjectRoot(process.cwd());
|
|
5015
|
+
const projectRoot = await findProjectRoot(process.cwd());
|
|
4732
5016
|
const cwd = projectRoot;
|
|
4733
5017
|
const target = options.target || ".";
|
|
4734
5018
|
const files = [path25.isAbsolute(target) ? target : path25.resolve(cwd, target)];
|
|
4735
5019
|
if (options.debug) {
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
5020
|
+
logger2.info("Starting Theme Lint...");
|
|
5021
|
+
logger2.info(`Target: ${target}`);
|
|
5022
|
+
logger2.info(`Options: ${JSON.stringify(options)}`);
|
|
4739
5023
|
}
|
|
4740
5024
|
try {
|
|
4741
5025
|
const ESLint = await loadESLint({ useFlatConfig: true });
|
|
@@ -4762,11 +5046,11 @@ async function lintTheme(options) {
|
|
|
4762
5046
|
}
|
|
4763
5047
|
]
|
|
4764
5048
|
});
|
|
4765
|
-
|
|
5049
|
+
logger2.info(`Scanning files in ${target} for theme violations...`);
|
|
4766
5050
|
const results = await eslint.lintFiles(files);
|
|
4767
5051
|
if (options.fix) {
|
|
4768
5052
|
await ESLint.outputFixes(results);
|
|
4769
|
-
|
|
5053
|
+
logger2.success("Auto-fixes applied where possible.");
|
|
4770
5054
|
}
|
|
4771
5055
|
const themeRuleIds = [
|
|
4772
5056
|
"@chatbi-v/theme/no-hardcoded-colors",
|
|
@@ -4799,7 +5083,7 @@ async function lintTheme(options) {
|
|
|
4799
5083
|
if (options.output) {
|
|
4800
5084
|
await fs22.ensureDir(path25.dirname(options.output));
|
|
4801
5085
|
await fs22.outputFile(options.output, resultText);
|
|
4802
|
-
|
|
5086
|
+
logger2.success(`Report generated at ${options.output}`);
|
|
4803
5087
|
} else {
|
|
4804
5088
|
console.log(resultText);
|
|
4805
5089
|
}
|
|
@@ -4812,17 +5096,17 @@ async function lintTheme(options) {
|
|
|
4812
5096
|
0
|
|
4813
5097
|
);
|
|
4814
5098
|
if (errorCount > 0) {
|
|
4815
|
-
|
|
5099
|
+
logger2.error(
|
|
4816
5100
|
`Lint failed with ${errorCount} errors and ${warningCount} warnings.`
|
|
4817
5101
|
);
|
|
4818
5102
|
process.exit(1);
|
|
4819
5103
|
} else if (warningCount > 0) {
|
|
4820
|
-
|
|
5104
|
+
logger2.warn(`Lint finished with ${warningCount} warnings.`);
|
|
4821
5105
|
} else {
|
|
4822
|
-
|
|
5106
|
+
logger2.success("Theme lint passed!");
|
|
4823
5107
|
}
|
|
4824
5108
|
} catch (error) {
|
|
4825
|
-
|
|
5109
|
+
logger2.error("An error occurred during linting:", error);
|
|
4826
5110
|
process.exit(1);
|
|
4827
5111
|
}
|
|
4828
5112
|
}
|
|
@@ -4835,7 +5119,7 @@ var init_lint_theme = __esm({
|
|
|
4835
5119
|
importThemePlugin = async () => {
|
|
4836
5120
|
try {
|
|
4837
5121
|
const { createRequire: createRequire3 } = await import("module");
|
|
4838
|
-
const projectRoot = findProjectRoot(process.cwd());
|
|
5122
|
+
const projectRoot = await findProjectRoot(process.cwd());
|
|
4839
5123
|
const pluginPath = path25.resolve(
|
|
4840
5124
|
projectRoot,
|
|
4841
5125
|
"node_modules/@chatbi-v/eslint-plugin-theme"
|
|
@@ -4843,15 +5127,23 @@ var init_lint_theme = __esm({
|
|
|
4843
5127
|
const require2 = createRequire3(import.meta.url);
|
|
4844
5128
|
return require2(pluginPath);
|
|
4845
5129
|
} catch (e) {
|
|
4846
|
-
|
|
5130
|
+
logger2.error("Failed to load @chatbi-v/eslint-plugin-theme", e);
|
|
4847
5131
|
throw e;
|
|
4848
5132
|
}
|
|
4849
5133
|
};
|
|
4850
|
-
findProjectRoot = (startDir) => {
|
|
5134
|
+
findProjectRoot = async (startDir) => {
|
|
4851
5135
|
let current = startDir;
|
|
4852
5136
|
while (current !== path25.dirname(current)) {
|
|
4853
|
-
|
|
5137
|
+
const pkgJsonPath2 = path25.join(current, "package.json");
|
|
5138
|
+
const workspaceYamlPath = path25.join(current, "pnpm-workspace.yaml");
|
|
5139
|
+
try {
|
|
5140
|
+
await Promise.all([
|
|
5141
|
+
fs22.readFile(pkgJsonPath2, "utf-8"),
|
|
5142
|
+
fs22.readFile(workspaceYamlPath, "utf-8")
|
|
5143
|
+
]);
|
|
4854
5144
|
return current;
|
|
5145
|
+
} catch (e) {
|
|
5146
|
+
logger2.debug(`\u67E5\u627E\u9879\u76EE\u6839\u76EE\u5F55\u5931\u8D25: ${e.message}`);
|
|
4855
5147
|
}
|
|
4856
5148
|
current = path25.dirname(current);
|
|
4857
5149
|
}
|
|
@@ -4937,9 +5229,9 @@ async function pluginCreate(options) {
|
|
|
4937
5229
|
data = PluginCreateSchema.parse(validated);
|
|
4938
5230
|
} catch (error) {
|
|
4939
5231
|
if (error instanceof z2.ZodError) {
|
|
4940
|
-
|
|
5232
|
+
logger2.error(`\u9A8C\u8BC1\u5931\u8D25: ${formatZodError(error)}`);
|
|
4941
5233
|
} else {
|
|
4942
|
-
|
|
5234
|
+
logger2.error(`\u9A8C\u8BC1\u5931\u8D25: ${error.message}`);
|
|
4943
5235
|
}
|
|
4944
5236
|
return;
|
|
4945
5237
|
}
|
|
@@ -4947,9 +5239,8 @@ async function pluginCreate(options) {
|
|
|
4947
5239
|
let cliVersion = "3.1.0";
|
|
4948
5240
|
try {
|
|
4949
5241
|
const pkgPath = path26.join(__dirname, "../../../../package.json");
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
}
|
|
5242
|
+
const pkgContent = fs23.readJsonSync(pkgPath);
|
|
5243
|
+
cliVersion = pkgContent.version || cliVersion;
|
|
4953
5244
|
} catch {
|
|
4954
5245
|
}
|
|
4955
5246
|
const pluginData = {
|
|
@@ -4976,21 +5267,21 @@ async function pluginCreate(options) {
|
|
|
4976
5267
|
}
|
|
4977
5268
|
if (fs23.existsSync(targetDir)) {
|
|
4978
5269
|
if (force) {
|
|
4979
|
-
|
|
5270
|
+
logger2.info("\u5F3A\u5236\u8986\u76D6\u6A21\u5F0F\uFF0C\u6E05\u7406\u76EE\u6807\u76EE\u5F55...");
|
|
4980
5271
|
fs23.removeSync(targetDir);
|
|
4981
5272
|
} else {
|
|
4982
5273
|
throw new Error(`\u76EE\u6807\u76EE\u5F55\u5DF2\u5B58\u5728: ${targetDir}`);
|
|
4983
5274
|
}
|
|
4984
5275
|
}
|
|
4985
|
-
|
|
5276
|
+
logger2.info(`
|
|
4986
5277
|
${pc19.bold("\u63D2\u4EF6\u521B\u5EFA\u9884\u89C8")}`);
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
5278
|
+
logger2.info(`\u540D\u79F0: ${pc19.cyan(pluginData.name)}`);
|
|
5279
|
+
logger2.info(`\u6A21\u677F: ${pc19.yellow(templateMeta.name)}`);
|
|
5280
|
+
logger2.info(`TypeScript: ${pc19.yellow(pluginData.typescript ? "\u662F" : "\u5426")}`);
|
|
4990
5281
|
const files = await listGeneratedFiles();
|
|
4991
|
-
|
|
5282
|
+
logger2.info(`
|
|
4992
5283
|
${pc19.bold("\u5C06\u521B\u5EFA\u4EE5\u4E0B\u6587\u4EF6:")}`);
|
|
4993
|
-
files.forEach((f) =>
|
|
5284
|
+
files.forEach((f) => logger2.info(` ${pc19.green("+")} ${f}`));
|
|
4994
5285
|
let confirmed = true;
|
|
4995
5286
|
if (process.stdout.isTTY) {
|
|
4996
5287
|
const response = await prompts5(
|
|
@@ -5017,7 +5308,9 @@ ${pc19.bold("\u5C06\u521B\u5EFA\u4EE5\u4E0B\u6587\u4EF6:")}`);
|
|
|
5017
5308
|
"templates/plugin",
|
|
5018
5309
|
templateMeta.dir || ""
|
|
5019
5310
|
);
|
|
5020
|
-
|
|
5311
|
+
try {
|
|
5312
|
+
await fs23.access(targetTemplateDir);
|
|
5313
|
+
} catch {
|
|
5021
5314
|
throw new Error(`\u6A21\u677F\u76EE\u5F55\u4E0D\u5B58\u5728: ${targetTemplateDir}`);
|
|
5022
5315
|
}
|
|
5023
5316
|
await fs23.ensureDir(targetDir);
|
|
@@ -5041,9 +5334,9 @@ ${pc19.bold("\u5C06\u521B\u5EFA\u4EE5\u4E0B\u6587\u4EF6:")}`);
|
|
|
5041
5334
|
force: true,
|
|
5042
5335
|
silent: true
|
|
5043
5336
|
});
|
|
5044
|
-
|
|
5337
|
+
logger2.success(`
|
|
5045
5338
|
\u63D2\u4EF6 ${pc19.green(pluginData.name)} \u521B\u5EFA\u6210\u529F!`);
|
|
5046
|
-
|
|
5339
|
+
logger2.info(
|
|
5047
5340
|
`\u8BF7\u8FD0\u884C ${pc19.cyan(`cd ${path26.relative(process.cwd(), targetDir)}`)} \u5F00\u59CB\u5F00\u53D1`
|
|
5048
5341
|
);
|
|
5049
5342
|
}
|
|
@@ -5082,7 +5375,11 @@ async function readPluginManifestFile(pluginRoot) {
|
|
|
5082
5375
|
if (!manifestPath) {
|
|
5083
5376
|
return null;
|
|
5084
5377
|
}
|
|
5085
|
-
|
|
5378
|
+
try {
|
|
5379
|
+
return await fs24.readJson(manifestPath);
|
|
5380
|
+
} catch {
|
|
5381
|
+
return null;
|
|
5382
|
+
}
|
|
5086
5383
|
}
|
|
5087
5384
|
async function writePluginManifestFile(pluginRoot, manifest) {
|
|
5088
5385
|
const manifestPath = await findPluginManifestPath(pluginRoot) || path27.join(pluginRoot, "src", "plugin.json");
|
|
@@ -5119,7 +5416,7 @@ async function pluginBuild(options = {}) {
|
|
|
5119
5416
|
const pkgPath = path28.join(cwd, "package.json");
|
|
5120
5417
|
if (!fs25.existsSync(pkgPath)) {
|
|
5121
5418
|
spinner.fail("\u672A\u627E\u5230 package.json");
|
|
5122
|
-
|
|
5419
|
+
logger2.error("\u8BF7\u5728\u63D2\u4EF6\u76EE\u5F55\u4E2D\u8FD0\u884C\u6B64\u547D\u4EE4");
|
|
5123
5420
|
return;
|
|
5124
5421
|
}
|
|
5125
5422
|
const pkg = await fs25.readJson(pkgPath);
|
|
@@ -5129,7 +5426,7 @@ async function pluginBuild(options = {}) {
|
|
|
5129
5426
|
entry = "src/index.tsx";
|
|
5130
5427
|
} else if (!fs25.existsSync(path28.join(cwd, "src/index.ts"))) {
|
|
5131
5428
|
spinner.fail("\u672A\u627E\u5230\u5165\u53E3\u6587\u4EF6");
|
|
5132
|
-
|
|
5429
|
+
logger2.error("\u671F\u671B src/index.ts \u6216 src/index.tsx");
|
|
5133
5430
|
return;
|
|
5134
5431
|
}
|
|
5135
5432
|
const pluginJsonPath = await findPluginManifestPath(cwd);
|
|
@@ -5178,7 +5475,7 @@ async function pluginBuild(options = {}) {
|
|
|
5178
5475
|
esmSpinner.succeed("ESM \u683C\u5F0F\u6784\u5EFA\u5B8C\u6210");
|
|
5179
5476
|
} catch (e) {
|
|
5180
5477
|
esmSpinner.fail("ESM \u683C\u5F0F\u6784\u5EFA\u5931\u8D25");
|
|
5181
|
-
|
|
5478
|
+
logger2.error(`\u6784\u5EFA\u5931\u8D25: ${e.message}`);
|
|
5182
5479
|
return;
|
|
5183
5480
|
}
|
|
5184
5481
|
const iifeSpinner = createSpinner("\u6B63\u5728\u6784\u5EFA IIFE \u683C\u5F0F...").start();
|
|
@@ -5213,7 +5510,7 @@ async function pluginBuild(options = {}) {
|
|
|
5213
5510
|
iifeSpinner.succeed("IIFE \u683C\u5F0F\u6784\u5EFA\u5B8C\u6210");
|
|
5214
5511
|
} catch (e) {
|
|
5215
5512
|
iifeSpinner.fail("IIFE \u683C\u5F0F\u6784\u5EFA\u5931\u8D25");
|
|
5216
|
-
|
|
5513
|
+
logger2.error(`\u6784\u5EFA\u5931\u8D25: ${e.message}`);
|
|
5217
5514
|
return;
|
|
5218
5515
|
}
|
|
5219
5516
|
const distDir = path28.join(cwd, "dist");
|
|
@@ -5226,7 +5523,7 @@ async function pluginBuild(options = {}) {
|
|
|
5226
5523
|
);
|
|
5227
5524
|
}
|
|
5228
5525
|
if (watch) {
|
|
5229
|
-
|
|
5526
|
+
logger2.info(pc20.gray("\u76D1\u542C\u6A21\u5F0F\u5DF2\u5F00\u542F\uFF0C\u6309 Ctrl+C \u505C\u6B62..."));
|
|
5230
5527
|
}
|
|
5231
5528
|
}
|
|
5232
5529
|
var init_build2 = __esm({
|
|
@@ -5289,25 +5586,25 @@ async function pluginDelete(name, options) {
|
|
|
5289
5586
|
const workspaceRoot = await SandboxPath.getWorkspaceRoot(process.cwd());
|
|
5290
5587
|
const pluginDir = await CoreKit.resolvePluginDirectory(workspaceRoot, name);
|
|
5291
5588
|
if (!pluginDir || !fs26.existsSync(pluginDir)) {
|
|
5292
|
-
|
|
5589
|
+
logger2.error(`\u63D2\u4EF6 ${name} \u4E0D\u5B58\u5728`);
|
|
5293
5590
|
return;
|
|
5294
5591
|
}
|
|
5295
5592
|
const manifest = await readPluginManifest(pluginDir);
|
|
5296
5593
|
if (!manifest) {
|
|
5297
|
-
|
|
5594
|
+
logger2.error(`\u65E0\u6CD5\u8BFB\u53D6\u63D2\u4EF6 ${name} \u7684\u5143\u6570\u636E\uFF0C\u8BF7\u68C0\u67E5 plugin.json \u662F\u5426\u5B58\u5728`);
|
|
5298
5595
|
return;
|
|
5299
5596
|
}
|
|
5300
5597
|
const pluginType = manifest.type || "business";
|
|
5301
5598
|
const pluginId = manifest.id || name;
|
|
5302
5599
|
if (isSystemPlugin(pluginType)) {
|
|
5303
|
-
|
|
5304
|
-
|
|
5600
|
+
logger2.error(`\u65E0\u6CD5\u5220\u9664\u7CFB\u7EDF\u63D2\u4EF6 ${name} (type=${pluginType})`);
|
|
5601
|
+
logger2.info("\u7CFB\u7EDF\u63D2\u4EF6\u53D7\u5230\u4FDD\u62A4\uFF0C\u65E0\u6CD5\u5220\u9664");
|
|
5305
5602
|
return;
|
|
5306
5603
|
}
|
|
5307
5604
|
const dependents = await findDependentPlugins(pluginId);
|
|
5308
5605
|
if (dependents.length > 0) {
|
|
5309
|
-
|
|
5310
|
-
|
|
5606
|
+
logger2.warn(`\u4EE5\u4E0B\u63D2\u4EF6\u4F9D\u8D56\u6B64\u63D2\u4EF6: ${dependents.join(", ")}`);
|
|
5607
|
+
logger2.info("\u5220\u9664\u524D\u8BF7\u786E\u4FDD\u8FD9\u4E9B\u63D2\u4EF6\u5DF2\u66F4\u65B0\u6216\u79FB\u9664\u76F8\u5173\u4F9D\u8D56");
|
|
5311
5608
|
}
|
|
5312
5609
|
if (!options.force) {
|
|
5313
5610
|
const { confirm } = await prompts6(
|
|
@@ -5319,24 +5616,24 @@ async function pluginDelete(name, options) {
|
|
|
5319
5616
|
},
|
|
5320
5617
|
{
|
|
5321
5618
|
onCancel: () => {
|
|
5322
|
-
|
|
5619
|
+
logger2.info("\u5DF2\u53D6\u6D88\u5220\u9664");
|
|
5323
5620
|
return;
|
|
5324
5621
|
}
|
|
5325
5622
|
}
|
|
5326
5623
|
);
|
|
5327
5624
|
if (!confirm) {
|
|
5328
|
-
|
|
5625
|
+
logger2.info("\u5DF2\u53D6\u6D88\u5220\u9664");
|
|
5329
5626
|
return;
|
|
5330
5627
|
}
|
|
5331
5628
|
}
|
|
5332
5629
|
try {
|
|
5333
5630
|
await fs26.remove(pluginDir);
|
|
5334
5631
|
} catch (err) {
|
|
5335
|
-
|
|
5632
|
+
logger2.error(`\u5220\u9664\u63D2\u4EF6 ${name} \u5931\u8D25`, err);
|
|
5336
5633
|
return;
|
|
5337
5634
|
}
|
|
5338
|
-
|
|
5339
|
-
|
|
5635
|
+
logger2.success(`\u63D2\u4EF6 ${name} \u5DF2\u5220\u9664`);
|
|
5636
|
+
logger2.info(`\u5DF2\u79FB\u9664: ${path29.relative(workspaceRoot, pluginDir)}`);
|
|
5340
5637
|
}
|
|
5341
5638
|
var init_delete = __esm({
|
|
5342
5639
|
"src/commands/plugin/delete.ts"() {
|
|
@@ -5367,14 +5664,15 @@ async function pluginValidate(options = {}) {
|
|
|
5367
5664
|
};
|
|
5368
5665
|
const spinner = createSpinner("\u6B63\u5728\u9A8C\u8BC1\u63D2\u4EF6\u914D\u7F6E...").start();
|
|
5369
5666
|
const pkgPath = path30.join(cwd, "package.json");
|
|
5370
|
-
|
|
5371
|
-
|
|
5667
|
+
let pkg = {};
|
|
5668
|
+
try {
|
|
5669
|
+
pkg = await fs27.readJson(pkgPath);
|
|
5670
|
+
} catch {
|
|
5671
|
+
spinner.fail("\u672A\u627E\u5230\u6216\u65E0\u6CD5\u8BFB\u53D6 package.json");
|
|
5372
5672
|
result.valid = false;
|
|
5373
|
-
result.errors.push("\u672A\u627E\u5230 package.json");
|
|
5673
|
+
result.errors.push("\u672A\u627E\u5230\u6216\u65E0\u6CD5\u8BFB\u53D6 package.json");
|
|
5374
5674
|
return result;
|
|
5375
5675
|
}
|
|
5376
|
-
spinner.text = "\u6B63\u5728\u8BFB\u53D6\u63D2\u4EF6\u914D\u7F6E...";
|
|
5377
|
-
const pkg = await fs27.readJson(pkgPath);
|
|
5378
5676
|
const pluginJsonPath = await findPluginManifestPath(cwd);
|
|
5379
5677
|
if (!pluginJsonPath) {
|
|
5380
5678
|
spinner.fail("\u672A\u627E\u5230 src/plugin.json");
|
|
@@ -5398,14 +5696,15 @@ async function pluginValidate(options = {}) {
|
|
|
5398
5696
|
fixSpinner.succeed("\u5DF2\u521B\u5EFA src/plugin.json");
|
|
5399
5697
|
result.errors = result.errors.filter((e) => !e.includes("plugin.json"));
|
|
5400
5698
|
} catch (e) {
|
|
5401
|
-
fixSpinner.fail(
|
|
5699
|
+
fixSpinner.fail(`\u521B\u5EFA\u5931\u8D25: ${e.message}`);
|
|
5402
5700
|
}
|
|
5403
5701
|
}
|
|
5404
5702
|
return result;
|
|
5405
5703
|
}
|
|
5406
5704
|
spinner.text = "\u6B63\u5728\u9A8C\u8BC1 Manifest \u683C\u5F0F...";
|
|
5705
|
+
let pluginJson;
|
|
5407
5706
|
try {
|
|
5408
|
-
|
|
5707
|
+
pluginJson = await fs27.readJson(pluginJsonPath);
|
|
5409
5708
|
const validation = validateManifest(pluginJson);
|
|
5410
5709
|
if (!validation.valid || !validation.data) {
|
|
5411
5710
|
spinner.fail("Manifest \u683C\u5F0F\u9A8C\u8BC1\u5931\u8D25");
|
|
@@ -5417,7 +5716,9 @@ async function pluginValidate(options = {}) {
|
|
|
5417
5716
|
}
|
|
5418
5717
|
if (typeof validation.data.entry === "string") {
|
|
5419
5718
|
const entryPath = path30.join(cwd, validation.data.entry);
|
|
5420
|
-
|
|
5719
|
+
try {
|
|
5720
|
+
await fs27.access(entryPath);
|
|
5721
|
+
} catch {
|
|
5421
5722
|
spinner.fail(`\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${validation.data.entry}`);
|
|
5422
5723
|
result.valid = false;
|
|
5423
5724
|
result.errors.push(`\u5165\u53E3\u6587\u4EF6\u4E0D\u5B58\u5728: ${validation.data.entry}`);
|
|
@@ -5438,7 +5739,9 @@ async function pluginValidate(options = {}) {
|
|
|
5438
5739
|
continue;
|
|
5439
5740
|
}
|
|
5440
5741
|
const depPath = path30.join(nodeModulesPath, dep);
|
|
5441
|
-
|
|
5742
|
+
try {
|
|
5743
|
+
await fs27.access(depPath);
|
|
5744
|
+
} catch {
|
|
5442
5745
|
result.warnings.push(`\u4F9D\u8D56\u672A\u5B89\u88C5: ${dep}@${version}`);
|
|
5443
5746
|
}
|
|
5444
5747
|
}
|
|
@@ -5477,7 +5780,7 @@ __export(publish_exports, {
|
|
|
5477
5780
|
pluginPublish: () => pluginPublish
|
|
5478
5781
|
});
|
|
5479
5782
|
async function pluginPublish(options) {
|
|
5480
|
-
|
|
5783
|
+
logger2.warn("\u63D2\u4EF6\u53D1\u5E03\u529F\u80FD\u6B63\u5728\u5F00\u53D1\u4E2D...");
|
|
5481
5784
|
}
|
|
5482
5785
|
var init_publish = __esm({
|
|
5483
5786
|
"src/commands/plugin/publish.ts"() {
|
|
@@ -5530,7 +5833,7 @@ async function pluginList(options = {}) {
|
|
|
5530
5833
|
const discoveredPlugins = await CoreKit.discoverPlugins(cwd);
|
|
5531
5834
|
if (discoveredPlugins.length === 0) {
|
|
5532
5835
|
spinner.warn("\u672A\u53D1\u73B0\u4EFB\u4F55\u63D2\u4EF6");
|
|
5533
|
-
|
|
5836
|
+
logger2.info(
|
|
5534
5837
|
pc22.gray("\u8BF7\u786E\u4FDD\u63D2\u4EF6\u5DF2\u88AB\u5DE5\u4F5C\u533A\u914D\u7F6E\u5305\u542B\uFF0C\u4E14\u76EE\u5F55\u4E2D\u5B58\u5728 package.json\u3002")
|
|
5535
5838
|
);
|
|
5536
5839
|
return;
|
|
@@ -5634,7 +5937,7 @@ async function resolveVersion(pluginName, pluginDir, version) {
|
|
|
5634
5937
|
throw new Error(`\u65E0\u6CD5\u8BFB\u53D6\u63D2\u4EF6 ${pluginName} \u7684 package.json`);
|
|
5635
5938
|
}
|
|
5636
5939
|
if (satisfiesVersion(packageJson.version, version)) {
|
|
5637
|
-
|
|
5940
|
+
logger2.info(
|
|
5638
5941
|
`\u63D2\u4EF6 ${pluginName} \u5F53\u524D\u7248\u672C ${packageJson.version} \u5DF2\u6EE1\u8DB3\u8303\u56F4 ${version}`
|
|
5639
5942
|
);
|
|
5640
5943
|
return packageJson.version;
|
|
@@ -5703,43 +6006,43 @@ function checkVersionCompatibility(current, target, compatibility) {
|
|
|
5703
6006
|
return { compatible: true, severity: finalSeverity };
|
|
5704
6007
|
}
|
|
5705
6008
|
function showDryRunPreview(pluginName, currentVersion, targetVersion, compatibility, manifest) {
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
6009
|
+
logger2.info("=".repeat(50));
|
|
6010
|
+
logger2.info(`\u63D2\u4EF6 ${pluginName} \u66F4\u65B0\u9884\u89C8 (dry-run)`);
|
|
6011
|
+
logger2.info("=".repeat(50));
|
|
6012
|
+
logger2.info(`\u5F53\u524D\u7248\u672C: ${currentVersion}`);
|
|
6013
|
+
logger2.info(`\u76EE\u6807\u7248\u672C: ${targetVersion}`);
|
|
6014
|
+
logger2.info("");
|
|
6015
|
+
logger2.info("\u517C\u5BB9\u6027\u68C0\u67E5:");
|
|
5713
6016
|
if (compatibility.compatible) {
|
|
5714
|
-
|
|
6017
|
+
logger2.success(` \u2713 \u517C\u5BB9 (severity: ${compatibility.severity})`);
|
|
5715
6018
|
} else {
|
|
5716
|
-
|
|
6019
|
+
logger2.error(` \u2717 \u4E0D\u517C\u5BB9: ${compatibility.reason}`);
|
|
5717
6020
|
}
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
6021
|
+
logger2.info("");
|
|
6022
|
+
logger2.info("\u5C06\u8981\u66F4\u65B0\u7684\u5B57\u6BB5:");
|
|
6023
|
+
logger2.info(` - version: ${currentVersion} \u2192 ${targetVersion}`);
|
|
5721
6024
|
if (manifest.compatibility) {
|
|
5722
|
-
|
|
6025
|
+
logger2.info(` - compatibility: ${JSON.stringify(manifest.compatibility)}`);
|
|
5723
6026
|
}
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
6027
|
+
logger2.info("");
|
|
6028
|
+
logger2.info("\u6CE8\u610F: \u8FD9\u662F\u9884\u89C8\u6A21\u5F0F\uFF0C\u672A\u6267\u884C\u5B9E\u9645\u66F4\u65B0");
|
|
6029
|
+
logger2.info("=".repeat(50));
|
|
5727
6030
|
}
|
|
5728
6031
|
async function pluginUpdate(name, options = {}) {
|
|
5729
6032
|
const workspaceRoot = await SandboxPath.getWorkspaceRoot(process.cwd());
|
|
5730
6033
|
const pluginDir = await CoreKit.resolvePluginDirectory(workspaceRoot, name);
|
|
5731
6034
|
if (!pluginDir || !fs29.existsSync(pluginDir)) {
|
|
5732
|
-
|
|
6035
|
+
logger2.error(`\u63D2\u4EF6 ${name} \u4E0D\u5B58\u5728`);
|
|
5733
6036
|
return;
|
|
5734
6037
|
}
|
|
5735
6038
|
const manifest = await readPluginManifest3(pluginDir);
|
|
5736
6039
|
if (!manifest) {
|
|
5737
|
-
|
|
6040
|
+
logger2.error(`\u65E0\u6CD5\u8BFB\u53D6\u63D2\u4EF6 ${name} \u7684\u5143\u6570\u636E\uFF0C\u8BF7\u68C0\u67E5 plugin.json \u662F\u5426\u5B58\u5728`);
|
|
5738
6041
|
return;
|
|
5739
6042
|
}
|
|
5740
6043
|
const packageJson = await readPluginPackageJson(pluginDir);
|
|
5741
6044
|
if (!packageJson) {
|
|
5742
|
-
|
|
6045
|
+
logger2.error(`\u65E0\u6CD5\u8BFB\u53D6\u63D2\u4EF6 ${name} \u7684 package.json`);
|
|
5743
6046
|
return;
|
|
5744
6047
|
}
|
|
5745
6048
|
const currentVersion = packageJson.version;
|
|
@@ -5747,11 +6050,11 @@ async function pluginUpdate(name, options = {}) {
|
|
|
5747
6050
|
try {
|
|
5748
6051
|
targetVersion = await resolveVersion(name, pluginDir, options.version);
|
|
5749
6052
|
} catch (err) {
|
|
5750
|
-
|
|
6053
|
+
logger2.error(err.message);
|
|
5751
6054
|
return;
|
|
5752
6055
|
}
|
|
5753
6056
|
if (targetVersion === currentVersion) {
|
|
5754
|
-
|
|
6057
|
+
logger2.info(`\u63D2\u4EF6 ${name} \u5DF2\u662F\u6700\u65B0\u7248\u672C ${currentVersion}`);
|
|
5755
6058
|
return;
|
|
5756
6059
|
}
|
|
5757
6060
|
if (!options.force) {
|
|
@@ -5761,17 +6064,17 @@ async function pluginUpdate(name, options = {}) {
|
|
|
5761
6064
|
manifest.compatibility
|
|
5762
6065
|
);
|
|
5763
6066
|
if (!compatibility.compatible) {
|
|
5764
|
-
|
|
5765
|
-
|
|
6067
|
+
logger2.error(`\u66F4\u65B0\u5931\u8D25: ${compatibility.reason}`);
|
|
6068
|
+
logger2.info("\u4F7F\u7528 --force \u53EF\u7ED5\u8FC7\u517C\u5BB9\u6027\u68C0\u67E5 (\u53EF\u80FD\u5B58\u5728\u98CE\u9669)");
|
|
5766
6069
|
return;
|
|
5767
6070
|
}
|
|
5768
6071
|
if (compatibility.severity === "major") {
|
|
5769
|
-
|
|
6072
|
+
logger2.warn(
|
|
5770
6073
|
`\u8B66\u544A: \u6B64\u66F4\u65B0\u5305\u542B\u7834\u574F\u6027\u53D8\u66F4 (severity: ${compatibility.severity})`
|
|
5771
6074
|
);
|
|
5772
6075
|
}
|
|
5773
6076
|
} else {
|
|
5774
|
-
|
|
6077
|
+
logger2.warn("\u5F3A\u5236\u6A21\u5F0F: \u8DF3\u8FC7\u517C\u5BB9\u6027\u68C0\u67E5");
|
|
5775
6078
|
}
|
|
5776
6079
|
if (options.dryRun) {
|
|
5777
6080
|
const compatibility = checkVersionCompatibility(
|
|
@@ -5795,13 +6098,13 @@ async function pluginUpdate(name, options = {}) {
|
|
|
5795
6098
|
try {
|
|
5796
6099
|
await writePluginManifestFile(pluginDir, updatedManifest);
|
|
5797
6100
|
} catch (err) {
|
|
5798
|
-
|
|
6101
|
+
logger2.error(`\u66F4\u65B0\u63D2\u4EF6 ${name} \u5931\u8D25`, err);
|
|
5799
6102
|
return;
|
|
5800
6103
|
}
|
|
5801
|
-
|
|
5802
|
-
|
|
6104
|
+
logger2.success(`\u63D2\u4EF6 ${name} \u5DF2\u66F4\u65B0`);
|
|
6105
|
+
logger2.info(` ${currentVersion} \u2192 ${targetVersion}`);
|
|
5803
6106
|
if (manifest.compatibility) {
|
|
5804
|
-
|
|
6107
|
+
logger2.info(` \u517C\u5BB9\u6027\u8981\u6C42: ${JSON.stringify(manifest.compatibility)}`);
|
|
5805
6108
|
}
|
|
5806
6109
|
}
|
|
5807
6110
|
var init_update = __esm({
|
|
@@ -5827,8 +6130,12 @@ async function themeCreate(options) {
|
|
|
5827
6130
|
const { name, base = "standard", css = false } = options;
|
|
5828
6131
|
const targetDir = path33.join(process.cwd(), "themes", name);
|
|
5829
6132
|
const baseTheme = BASE_THEMES[base];
|
|
5830
|
-
|
|
5831
|
-
|
|
6133
|
+
if (!baseTheme) {
|
|
6134
|
+
logger2.error(`\u65E0\u6548\u7684\u57FA\u7840\u4E3B\u9898: ${base}\uFF0C\u53EF\u9009\u503C: standard, nebula, glass`);
|
|
6135
|
+
return;
|
|
6136
|
+
}
|
|
6137
|
+
logger2.info(`\u6B63\u5728\u521B\u5EFA\u4E3B\u9898: ${pc23.cyan(name)}`);
|
|
6138
|
+
logger2.info(`\u57FA\u7840\u4E3B\u9898: ${pc23.yellow(baseTheme.name)}`);
|
|
5832
6139
|
await fs30.ensureDir(targetDir);
|
|
5833
6140
|
if (css) {
|
|
5834
6141
|
const cssContent = `:root {
|
|
@@ -5868,7 +6175,7 @@ async function themeCreate(options) {
|
|
|
5868
6175
|
await fs30.writeJson(path33.join(targetDir, "theme.json"), themeJson, {
|
|
5869
6176
|
spaces: 2
|
|
5870
6177
|
});
|
|
5871
|
-
|
|
6178
|
+
logger2.success(`\u4E3B\u9898 ${pc23.green(name)} \u521B\u5EFA\u6210\u529F!`);
|
|
5872
6179
|
}
|
|
5873
6180
|
var BASE_THEMES;
|
|
5874
6181
|
var init_create2 = __esm({
|
|
@@ -5908,13 +6215,24 @@ async function scaffold(options) {
|
|
|
5908
6215
|
typescript = true,
|
|
5909
6216
|
theme = "standard"
|
|
5910
6217
|
} = options;
|
|
6218
|
+
if (name.includes("..") || path34.isAbsolute(name)) {
|
|
6219
|
+
logger2.error(`\u65E0\u6548\u7684\u9879\u76EE\u540D\u79F0: ${name}\uFF0C\u4E0D\u80FD\u5305\u542B\u8DEF\u5F84\u904D\u5386\u5E8F\u5217\u6216\u7EDD\u5BF9\u8DEF\u5F84`);
|
|
6220
|
+
return;
|
|
6221
|
+
}
|
|
5911
6222
|
const targetDir = path34.join(process.cwd(), name);
|
|
5912
|
-
|
|
5913
|
-
|
|
6223
|
+
try {
|
|
6224
|
+
await fs31.access(targetDir);
|
|
6225
|
+
logger2.error(`\u76EE\u5F55 ${name} \u5DF2\u5B58\u5728`);
|
|
6226
|
+
return;
|
|
6227
|
+
} catch {
|
|
6228
|
+
}
|
|
6229
|
+
const templateMeta = TEMPLATES2[template];
|
|
6230
|
+
if (!templateMeta) {
|
|
6231
|
+
logger2.error(`\u65E0\u6548\u7684\u6A21\u677F\u7C7B\u578B: ${template}\uFF0C\u53EF\u9009\u503C: full, minimal, empty`);
|
|
5914
6232
|
return;
|
|
5915
6233
|
}
|
|
5916
|
-
|
|
5917
|
-
|
|
6234
|
+
logger2.info(`\u6B63\u5728\u521B\u5EFA\u9879\u76EE: ${pc24.cyan(name)}`);
|
|
6235
|
+
logger2.info(`\u6A21\u677F: ${pc24.yellow(templateMeta.name)}`);
|
|
5918
6236
|
await fs31.ensureDir(targetDir);
|
|
5919
6237
|
const packageJson = {
|
|
5920
6238
|
name,
|
|
@@ -5955,8 +6273,8 @@ export default defineConfig({
|
|
|
5955
6273
|
`;
|
|
5956
6274
|
await fs31.writeFile(path34.join(targetDir, "vite.config.ts"), viteConfig);
|
|
5957
6275
|
}
|
|
5958
|
-
|
|
5959
|
-
|
|
6276
|
+
logger2.success(`\u9879\u76EE ${pc24.green(name)} \u521B\u5EFA\u6210\u529F!`);
|
|
6277
|
+
logger2.info(`\u8BF7\u8FD0\u884C ${pc24.cyan(`cd ${name} && pnpm install`)} \u5B89\u88C5\u4F9D\u8D56`);
|
|
5960
6278
|
}
|
|
5961
6279
|
var TEMPLATES2;
|
|
5962
6280
|
var init_scaffold = __esm({
|
|
@@ -5990,33 +6308,33 @@ import { execSync } from "child_process";
|
|
|
5990
6308
|
import pc25 from "picocolors";
|
|
5991
6309
|
async function upgrade(targetVersion) {
|
|
5992
6310
|
const currentVersion = package_default.version;
|
|
5993
|
-
|
|
6311
|
+
logger2.info(`\u5F53\u524D\u7248\u672C: ${pc25.cyan(currentVersion)}`);
|
|
5994
6312
|
if (targetVersion) {
|
|
5995
|
-
|
|
6313
|
+
logger2.info(`\u6B63\u5728\u5347\u7EA7\u5230\u7248\u672C: ${pc25.yellow(targetVersion)}`);
|
|
5996
6314
|
try {
|
|
5997
6315
|
execSync(`pnpm add -g @chatbi-v/cli@${targetVersion}`, {
|
|
5998
6316
|
stdio: "inherit"
|
|
5999
6317
|
});
|
|
6000
|
-
|
|
6318
|
+
logger2.success("\u5347\u7EA7\u6210\u529F!");
|
|
6001
6319
|
} catch (error) {
|
|
6002
|
-
|
|
6320
|
+
logger2.error("\u5347\u7EA7\u5931\u8D25", error);
|
|
6003
6321
|
}
|
|
6004
6322
|
} else {
|
|
6005
|
-
|
|
6323
|
+
logger2.info("\u6B63\u5728\u68C0\u67E5\u6700\u65B0\u7248\u672C...");
|
|
6006
6324
|
try {
|
|
6007
6325
|
const latestVersion = execSync("npm view @chatbi-v/cli version", {
|
|
6008
6326
|
encoding: "utf-8"
|
|
6009
6327
|
}).trim();
|
|
6010
6328
|
if (latestVersion > currentVersion) {
|
|
6011
|
-
|
|
6012
|
-
|
|
6329
|
+
logger2.info(`\u6700\u65B0\u7248\u672C: ${pc25.green(latestVersion)}`);
|
|
6330
|
+
logger2.info(
|
|
6013
6331
|
`\u8BF7\u8FD0\u884C ${pc25.cyan(`pnpm add -g @chatbi-v/cli@${latestVersion}`)} \u5347\u7EA7`
|
|
6014
6332
|
);
|
|
6015
6333
|
} else {
|
|
6016
|
-
|
|
6334
|
+
logger2.success("\u5F53\u524D\u5DF2\u662F\u6700\u65B0\u7248\u672C!");
|
|
6017
6335
|
}
|
|
6018
6336
|
} catch {
|
|
6019
|
-
|
|
6337
|
+
logger2.warn("\u65E0\u6CD5\u68C0\u67E5\u6700\u65B0\u7248\u672C");
|
|
6020
6338
|
}
|
|
6021
6339
|
}
|
|
6022
6340
|
}
|
|
@@ -6042,16 +6360,22 @@ async function devtoolsTypes(options) {
|
|
|
6042
6360
|
const { input = "src/plugin.json", output, type = "full" } = options;
|
|
6043
6361
|
const inputPath = path35.resolve(process.cwd(), input);
|
|
6044
6362
|
if (!fs32.existsSync(inputPath)) {
|
|
6045
|
-
|
|
6363
|
+
logger2.error(`\u627E\u4E0D\u5230 plugin.json \u6587\u4EF6: ${inputPath}`);
|
|
6046
6364
|
return;
|
|
6047
6365
|
}
|
|
6048
|
-
|
|
6366
|
+
logger2.info(`\u8BFB\u53D6\u63D2\u4EF6\u6E05\u5355: ${pc26.cyan(inputPath)}`);
|
|
6049
6367
|
try {
|
|
6050
|
-
|
|
6368
|
+
let pluginJson;
|
|
6369
|
+
try {
|
|
6370
|
+
pluginJson = await fs32.readJson(inputPath);
|
|
6371
|
+
} catch {
|
|
6372
|
+
logger2.error(`\u8BFB\u53D6 plugin.json \u5931\u8D25: ${inputPath}`);
|
|
6373
|
+
return;
|
|
6374
|
+
}
|
|
6051
6375
|
const validation = validateManifest2(pluginJson);
|
|
6052
6376
|
if (!validation.valid || !validation.data) {
|
|
6053
6377
|
validation.errors?.forEach((error) => {
|
|
6054
|
-
|
|
6378
|
+
logger2.error(`[${error.path.join(".")}] ${error.message}`);
|
|
6055
6379
|
});
|
|
6056
6380
|
return;
|
|
6057
6381
|
}
|
|
@@ -6061,12 +6385,12 @@ async function devtoolsTypes(options) {
|
|
|
6061
6385
|
const outputPath = path35.resolve(process.cwd(), output);
|
|
6062
6386
|
await fs32.ensureDir(path35.dirname(outputPath));
|
|
6063
6387
|
await fs32.writeFile(outputPath, typeCode, "utf-8");
|
|
6064
|
-
|
|
6388
|
+
logger2.success(`\u7C7B\u578B\u5B9A\u4E49\u5DF2\u751F\u6210: ${pc26.green(outputPath)}`);
|
|
6065
6389
|
} else {
|
|
6066
6390
|
console.log(typeCode);
|
|
6067
6391
|
}
|
|
6068
6392
|
} catch (error) {
|
|
6069
|
-
|
|
6393
|
+
logger2.error("\u751F\u6210\u7C7B\u578B\u5B9A\u4E49\u5931\u8D25", error);
|
|
6070
6394
|
}
|
|
6071
6395
|
}
|
|
6072
6396
|
function generateTypeDefinition(manifest, type) {
|
|
@@ -6197,17 +6521,17 @@ __export(diagnose_exports, {
|
|
|
6197
6521
|
import pc27 from "picocolors";
|
|
6198
6522
|
async function diagnose(options = {}) {
|
|
6199
6523
|
const cwd = process.cwd();
|
|
6200
|
-
|
|
6524
|
+
logger2.info("\u6B63\u5728\u6267\u884C\u6C99\u7BB1\u8BCA\u65AD...\n");
|
|
6201
6525
|
try {
|
|
6202
6526
|
const version = await Sandbox.resolveVersion("current");
|
|
6203
|
-
|
|
6527
|
+
logger2.info(`\u5F53\u524D\u5185\u6838\u7248\u672C: ${pc27.cyan(version)}
|
|
6204
6528
|
`);
|
|
6205
6529
|
const diagnostics = new SandboxDiagnostics(version, cwd);
|
|
6206
6530
|
const result = await diagnostics.runAllDiagnostics();
|
|
6207
|
-
|
|
6531
|
+
logger2.info(SandboxDiagnostics.formatResults(result));
|
|
6208
6532
|
const fixableIssues = SandboxDiagnostics.getFixableIssues(result);
|
|
6209
6533
|
if (fixableIssues.length > 0) {
|
|
6210
|
-
|
|
6534
|
+
logger2.info("");
|
|
6211
6535
|
const suggestions = fixableIssues.map(
|
|
6212
6536
|
(issue) => ` ${pc27.red("\u2022")} ${pc27.bold(issue.title)}
|
|
6213
6537
|
${pc27.gray(issue.description)}
|
|
@@ -6221,23 +6545,23 @@ ${suggestions}`,
|
|
|
6221
6545
|
);
|
|
6222
6546
|
}
|
|
6223
6547
|
if (options.fix && fixableIssues.length > 0) {
|
|
6224
|
-
|
|
6548
|
+
logger2.info(pc27.bold("\n\u6B63\u5728\u6267\u884C\u81EA\u52A8\u4FEE\u590D...\n"));
|
|
6225
6549
|
const { sync: sync2 } = await Promise.resolve().then(() => (init_sync(), sync_exports));
|
|
6226
6550
|
for (const issue of fixableIssues) {
|
|
6227
6551
|
if (issue.fixCommand?.startsWith("chatbi sync")) {
|
|
6228
|
-
|
|
6552
|
+
logger2.info(`${pc27.cyan("\u2192")} \u6267\u884C: ${issue.fixCommand}`);
|
|
6229
6553
|
try {
|
|
6230
6554
|
await sync2({ force: true });
|
|
6231
|
-
|
|
6555
|
+
logger2.success(`\u4FEE\u590D\u5B8C\u6210: ${issue.title}`);
|
|
6232
6556
|
} catch (e) {
|
|
6233
|
-
|
|
6557
|
+
logger2.error(`\u4FEE\u590D\u5931\u8D25: ${e.message}`);
|
|
6234
6558
|
}
|
|
6235
6559
|
}
|
|
6236
6560
|
}
|
|
6237
6561
|
}
|
|
6238
6562
|
return result;
|
|
6239
6563
|
} catch (e) {
|
|
6240
|
-
|
|
6564
|
+
logger2.error(`\u8BCA\u65AD\u5931\u8D25: ${e.message}`);
|
|
6241
6565
|
throw e;
|
|
6242
6566
|
}
|
|
6243
6567
|
}
|
|
@@ -6263,19 +6587,19 @@ import pc28 from "picocolors";
|
|
|
6263
6587
|
async function update(options = {}) {
|
|
6264
6588
|
const { force = true, clean: clean2 = false, version } = options;
|
|
6265
6589
|
const cwd = process.cwd();
|
|
6266
|
-
|
|
6590
|
+
logger2.info(pc28.bold("\u6C99\u7BB1\u66F4\u65B0\u5DE5\u5177\n"));
|
|
6267
6591
|
try {
|
|
6268
6592
|
const targetVersion = version || await Sandbox.resolveVersion("latest");
|
|
6269
|
-
|
|
6593
|
+
logger2.info(`\u76EE\u6807\u7248\u672C: ${pc28.cyan(targetVersion)}`);
|
|
6270
6594
|
const currentVersion = await Sandbox.resolveVersion("current");
|
|
6271
6595
|
if (currentVersion !== targetVersion) {
|
|
6272
|
-
|
|
6596
|
+
logger2.info(
|
|
6273
6597
|
`\u5F53\u524D\u7248\u672C: ${pc28.yellow(currentVersion)} \u2192 ${pc28.cyan(targetVersion)}`
|
|
6274
6598
|
);
|
|
6275
6599
|
} else {
|
|
6276
|
-
|
|
6600
|
+
logger2.info(`\u5F53\u524D\u7248\u672C: ${pc28.green(currentVersion)} (\u5DF2\u662F\u6700\u65B0)`);
|
|
6277
6601
|
}
|
|
6278
|
-
|
|
6602
|
+
logger2.info("");
|
|
6279
6603
|
if (clean2) {
|
|
6280
6604
|
const spinner2 = createSpinner("\u6B63\u5728\u6E05\u7406\u65E7\u7248\u672C...").start();
|
|
6281
6605
|
try {
|
|
@@ -6284,7 +6608,7 @@ async function update(options = {}) {
|
|
|
6284
6608
|
} catch (e) {
|
|
6285
6609
|
spinner2.fail(`\u6E05\u7406\u5931\u8D25: ${e.message}`);
|
|
6286
6610
|
}
|
|
6287
|
-
|
|
6611
|
+
logger2.info("");
|
|
6288
6612
|
}
|
|
6289
6613
|
const spinner = createSpinner(`\u6B63\u5728\u66F4\u65B0\u6C99\u7BB1\u5230 ${targetVersion}...`).start();
|
|
6290
6614
|
try {
|
|
@@ -6294,22 +6618,22 @@ async function update(options = {}) {
|
|
|
6294
6618
|
spinner.fail(`\u6C99\u7BB1\u66F4\u65B0\u5931\u8D25: ${e.message}`);
|
|
6295
6619
|
throw e;
|
|
6296
6620
|
}
|
|
6297
|
-
|
|
6298
|
-
|
|
6621
|
+
logger2.info("");
|
|
6622
|
+
logger2.info(pc28.bold("\u9A8C\u8BC1\u5B89\u88C5...\n"));
|
|
6299
6623
|
const diagnostics = new (await Promise.resolve().then(() => (init_SandboxDiagnostics(), SandboxDiagnostics_exports))).SandboxDiagnostics(targetVersion, cwd);
|
|
6300
6624
|
const result = await diagnostics.runAllDiagnostics();
|
|
6301
6625
|
if (result.passed) {
|
|
6302
|
-
|
|
6626
|
+
logger2.success("\u5B89\u88C5\u9A8C\u8BC1\u901A\u8FC7");
|
|
6303
6627
|
} else {
|
|
6304
|
-
|
|
6628
|
+
logger2.warn(
|
|
6305
6629
|
`\u5B89\u88C5\u9A8C\u8BC1\u53D1\u73B0\u95EE\u9898 ${result.errorCount} \u4E2A\uFF0C\u5EFA\u8BAE\u8FD0\u884C ${pc28.cyan("chatbi sandbox diagnose")} \u67E5\u770B\u8BE6\u60C5`
|
|
6306
6630
|
);
|
|
6307
6631
|
}
|
|
6308
|
-
|
|
6309
|
-
|
|
6632
|
+
logger2.info("");
|
|
6633
|
+
logger2.success(pc28.green("\u2728 \u6C99\u7BB1\u66F4\u65B0\u5B8C\u6210\uFF01"));
|
|
6310
6634
|
return { version: targetVersion, success: true };
|
|
6311
6635
|
} catch (e) {
|
|
6312
|
-
|
|
6636
|
+
logger2.error(`\u66F4\u65B0\u5931\u8D25: ${e.message}`);
|
|
6313
6637
|
throw e;
|
|
6314
6638
|
}
|
|
6315
6639
|
}
|
|
@@ -6333,6 +6657,7 @@ var init_ModuleResolver = __esm({
|
|
|
6333
6657
|
"src/sandbox/ModuleResolver.ts"() {
|
|
6334
6658
|
"use strict";
|
|
6335
6659
|
init_esm_shims();
|
|
6660
|
+
init_utils();
|
|
6336
6661
|
init_SandboxPath();
|
|
6337
6662
|
ModuleResolver = class {
|
|
6338
6663
|
projectRoot;
|
|
@@ -6367,15 +6692,14 @@ var init_ModuleResolver = __esm({
|
|
|
6367
6692
|
".chatbi",
|
|
6368
6693
|
"resolution.json"
|
|
6369
6694
|
);
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
this.config
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
}
|
|
6695
|
+
try {
|
|
6696
|
+
const config4 = fs33.readJsonSync(resolutionPath);
|
|
6697
|
+
this.config = {
|
|
6698
|
+
...this.config,
|
|
6699
|
+
...config4
|
|
6700
|
+
};
|
|
6701
|
+
} catch (e) {
|
|
6702
|
+
logger2.debug(`\u52A0\u8F7D resolution.json \u5931\u8D25: ${e.message}`);
|
|
6379
6703
|
}
|
|
6380
6704
|
}
|
|
6381
6705
|
/**
|
|
@@ -6387,12 +6711,13 @@ var init_ModuleResolver = __esm({
|
|
|
6387
6711
|
const pkgPath = path36.join(this.sandboxNodeModules, name);
|
|
6388
6712
|
let actualVersion = overrideVersion;
|
|
6389
6713
|
try {
|
|
6390
|
-
const
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6714
|
+
const pkgJsonPath2 = path36.join(pkgPath, "package.json");
|
|
6715
|
+
const pkg = await fs33.readJson(pkgJsonPath2);
|
|
6716
|
+
actualVersion = pkg.version || overrideVersion;
|
|
6717
|
+
} catch (e) {
|
|
6718
|
+
logger2.debug(
|
|
6719
|
+
`\u8BFB\u53D6 package.json \u5931\u8D25: ${pkgJsonPath}: ${e.message}`
|
|
6720
|
+
);
|
|
6396
6721
|
}
|
|
6397
6722
|
return {
|
|
6398
6723
|
name,
|
|
@@ -6470,12 +6795,9 @@ var init_ModuleResolver = __esm({
|
|
|
6470
6795
|
*/
|
|
6471
6796
|
async checkInLocation(name, nodeModulesPath, source) {
|
|
6472
6797
|
const pkgPath = path36.join(nodeModulesPath, name);
|
|
6473
|
-
const
|
|
6474
|
-
if (!fs33.existsSync(pkgJsonPath)) {
|
|
6475
|
-
return null;
|
|
6476
|
-
}
|
|
6798
|
+
const pkgJsonPath2 = path36.join(pkgPath, "package.json");
|
|
6477
6799
|
try {
|
|
6478
|
-
const pkg = await fs33.readJson(
|
|
6800
|
+
const pkg = await fs33.readJson(pkgJsonPath2);
|
|
6479
6801
|
return {
|
|
6480
6802
|
name,
|
|
6481
6803
|
version: pkg.version || "unknown",
|
|
@@ -6483,7 +6805,8 @@ var init_ModuleResolver = __esm({
|
|
|
6483
6805
|
source,
|
|
6484
6806
|
isConflicted: false
|
|
6485
6807
|
};
|
|
6486
|
-
} catch {
|
|
6808
|
+
} catch (e) {
|
|
6809
|
+
logger2.debug(`\u68C0\u67E5\u5305\u4F4D\u7F6E\u5931\u8D25: ${name}: ${e.message}`);
|
|
6487
6810
|
return null;
|
|
6488
6811
|
}
|
|
6489
6812
|
}
|
|
@@ -6530,15 +6853,13 @@ var init_ModuleResolver = __esm({
|
|
|
6530
6853
|
* 列出 node_modules 中的包
|
|
6531
6854
|
*/
|
|
6532
6855
|
async listPackages(nodeModulesPath) {
|
|
6533
|
-
if (!fs33.existsSync(nodeModulesPath)) {
|
|
6534
|
-
return [];
|
|
6535
|
-
}
|
|
6536
6856
|
try {
|
|
6537
6857
|
const entries = await fs33.readdir(nodeModulesPath, {
|
|
6538
6858
|
withFileTypes: true
|
|
6539
6859
|
});
|
|
6540
6860
|
return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name);
|
|
6541
|
-
} catch {
|
|
6861
|
+
} catch (e) {
|
|
6862
|
+
logger2.debug(`\u5217\u51FA\u5305\u5931\u8D25: ${nodeModulesPath}: ${e.message}`);
|
|
6542
6863
|
return [];
|
|
6543
6864
|
}
|
|
6544
6865
|
}
|
|
@@ -6550,8 +6871,13 @@ var init_ModuleResolver = __esm({
|
|
|
6550
6871
|
if (!result.path) {
|
|
6551
6872
|
return false;
|
|
6552
6873
|
}
|
|
6553
|
-
const
|
|
6554
|
-
|
|
6874
|
+
const pkgJsonPath2 = path36.join(result.path, "package.json");
|
|
6875
|
+
try {
|
|
6876
|
+
const stats = fs33.statSync(pkgJsonPath2);
|
|
6877
|
+
return stats.isFile();
|
|
6878
|
+
} catch {
|
|
6879
|
+
return false;
|
|
6880
|
+
}
|
|
6555
6881
|
}
|
|
6556
6882
|
/**
|
|
6557
6883
|
* 格式化解析结果
|
|
@@ -6583,12 +6909,12 @@ __export(resolve_exports, {
|
|
|
6583
6909
|
import pc30 from "picocolors";
|
|
6584
6910
|
async function resolve(packageName, options = {}) {
|
|
6585
6911
|
if (!packageName) {
|
|
6586
|
-
|
|
6587
|
-
|
|
6912
|
+
logger2.error("\u8BF7\u6307\u5B9A\u8981\u89E3\u6790\u7684\u5305\u540D");
|
|
6913
|
+
logger2.info("\u7528\u6CD5: chatbi sandbox resolve <pkg>");
|
|
6588
6914
|
return;
|
|
6589
6915
|
}
|
|
6590
6916
|
const cwd = process.cwd();
|
|
6591
|
-
|
|
6917
|
+
logger2.info(`\u6B63\u5728\u89E3\u6790\u5305: ${pc30.cyan(packageName)}
|
|
6592
6918
|
`);
|
|
6593
6919
|
try {
|
|
6594
6920
|
const version = await Sandbox.resolveVersion("current");
|
|
@@ -6605,54 +6931,54 @@ async function resolve(packageName, options = {}) {
|
|
|
6605
6931
|
unknown: pc30.gray
|
|
6606
6932
|
};
|
|
6607
6933
|
const colorFn = sourceColors[result.source] || pc30.gray;
|
|
6608
|
-
|
|
6934
|
+
logger2.info(
|
|
6609
6935
|
"\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"
|
|
6610
6936
|
);
|
|
6611
|
-
|
|
6937
|
+
logger2.info(
|
|
6612
6938
|
"\u2551 Package Resolution \u2551"
|
|
6613
6939
|
);
|
|
6614
|
-
|
|
6940
|
+
logger2.info(
|
|
6615
6941
|
"\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563"
|
|
6616
6942
|
);
|
|
6617
|
-
|
|
6618
|
-
|
|
6943
|
+
logger2.info(`\u2551 \u5305\u540D: ${pc30.cyan(result.name.padEnd(52))}\u2551`);
|
|
6944
|
+
logger2.info(
|
|
6619
6945
|
`\u2551 \u7248\u672C: ${(result.version ? pc30.green(result.version) : pc30.red("\u672A\u627E\u5230")).padEnd(52)}\u2551`
|
|
6620
6946
|
);
|
|
6621
|
-
|
|
6622
|
-
|
|
6947
|
+
logger2.info(`\u2551 \u6765\u6E90: ${colorFn(result.source.padEnd(52))}\u2551`);
|
|
6948
|
+
logger2.info(
|
|
6623
6949
|
"\u2551 \u2551"
|
|
6624
6950
|
);
|
|
6625
|
-
|
|
6951
|
+
logger2.info(`\u2551 \u8DEF\u5F84:`);
|
|
6626
6952
|
const pathLines = wrapText(result.path || "\u672A\u627E\u5230", 56);
|
|
6627
6953
|
for (const line of pathLines) {
|
|
6628
|
-
|
|
6954
|
+
logger2.info(`\u2551 ${pc30.gray(line.padEnd(56))}\u2551`);
|
|
6629
6955
|
}
|
|
6630
|
-
|
|
6956
|
+
logger2.info(
|
|
6631
6957
|
"\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563"
|
|
6632
6958
|
);
|
|
6633
6959
|
if (result.isConflicted) {
|
|
6634
|
-
|
|
6635
|
-
|
|
6960
|
+
logger2.info(`\u2551 ${pc30.yellow("\u26A0\uFE0F \u5B58\u5728\u51B2\u7A81").padEnd(57)}\u2551`);
|
|
6961
|
+
logger2.info(
|
|
6636
6962
|
"\u2551 \u2551"
|
|
6637
6963
|
);
|
|
6638
6964
|
if (result.conflictDescription) {
|
|
6639
6965
|
const descLines = wrapText(result.conflictDescription, 56);
|
|
6640
6966
|
for (const line of descLines) {
|
|
6641
|
-
|
|
6967
|
+
logger2.info(`\u2551 ${line.padEnd(57)}\u2551`);
|
|
6642
6968
|
}
|
|
6643
6969
|
}
|
|
6644
6970
|
} else {
|
|
6645
|
-
|
|
6971
|
+
logger2.info(`\u2551 ${pc30.green("\u2713 \u65E0\u51B2\u7A81").padEnd(57)}\u2551`);
|
|
6646
6972
|
}
|
|
6647
|
-
|
|
6973
|
+
logger2.info(
|
|
6648
6974
|
"\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"
|
|
6649
6975
|
);
|
|
6650
6976
|
if (options.conflicts) {
|
|
6651
|
-
|
|
6652
|
-
|
|
6977
|
+
logger2.info("");
|
|
6978
|
+
logger2.info(pc30.bold("\u68C0\u6D4B\u6240\u6709\u5305\u51B2\u7A81...\n"));
|
|
6653
6979
|
const conflicts = await resolver.detectConflicts();
|
|
6654
6980
|
if (conflicts.length === 0) {
|
|
6655
|
-
|
|
6981
|
+
logger2.success("\u672A\u68C0\u6D4B\u5230\u7248\u672C\u51B2\u7A81");
|
|
6656
6982
|
} else {
|
|
6657
6983
|
printBox(
|
|
6658
6984
|
conflicts.map(
|
|
@@ -6664,7 +6990,7 @@ async function resolve(packageName, options = {}) {
|
|
|
6664
6990
|
}
|
|
6665
6991
|
return result;
|
|
6666
6992
|
} catch (e) {
|
|
6667
|
-
|
|
6993
|
+
logger2.error(`\u89E3\u6790\u5931\u8D25: ${e.message}`);
|
|
6668
6994
|
throw e;
|
|
6669
6995
|
}
|
|
6670
6996
|
}
|
|
@@ -6714,8 +7040,8 @@ import pc31 from "picocolors";
|
|
|
6714
7040
|
var cli = cac("chatbi-cli");
|
|
6715
7041
|
var showHeader = () => {
|
|
6716
7042
|
const title = figlet.textSync("ChatBI-V CLI", { font: "Standard" });
|
|
6717
|
-
|
|
6718
|
-
|
|
7043
|
+
logger2.info(gradient.pastel.multiline(title));
|
|
7044
|
+
logger2.info(
|
|
6719
7045
|
boxen2(pc31.cyan(`ChatBI-V \u7EDF\u4E00\u5F00\u53D1\u5DE5\u5177 v${package_default.version}`), {
|
|
6720
7046
|
padding: 0,
|
|
6721
7047
|
margin: { top: 1, bottom: 1 },
|
|
@@ -6732,13 +7058,13 @@ var wrapAction = (action, commandName) => {
|
|
|
6732
7058
|
const options = args[args.length - 1];
|
|
6733
7059
|
if (options && options.debug) {
|
|
6734
7060
|
setDebugMode(true);
|
|
6735
|
-
|
|
7061
|
+
logger2.debug("Debug mode enabled");
|
|
6736
7062
|
}
|
|
6737
7063
|
showHeader();
|
|
6738
7064
|
try {
|
|
6739
7065
|
await action(...args);
|
|
6740
7066
|
} catch (e) {
|
|
6741
|
-
|
|
7067
|
+
logger2.error(`${commandName} \u6267\u884C\u5931\u8D25`, e);
|
|
6742
7068
|
process.exit(1);
|
|
6743
7069
|
} finally {
|
|
6744
7070
|
const latestVersion = await updateCheckPromise;
|
|
@@ -6802,7 +7128,7 @@ cli.command("update [targetVersion]", "\u66F4\u65B0\u5185\u6838\u7248\u672C").al
|
|
|
6802
7128
|
wrapAction(async (targetVersion) => {
|
|
6803
7129
|
const { sync: sync2 } = await Promise.resolve().then(() => (init_sync(), sync_exports));
|
|
6804
7130
|
await sync2({ version: targetVersion, force: true });
|
|
6805
|
-
|
|
7131
|
+
logger2.success("\u66F4\u65B0\u5B8C\u6210\uFF01");
|
|
6806
7132
|
}, "update")
|
|
6807
7133
|
);
|
|
6808
7134
|
cli.command("sync", "\u540C\u6B65\u5185\u6838\u4F9D\u8D56\u4E0E\u89C4\u8303").alias("s").option("-v, --core-version <version>", "\u6307\u5B9A\u5185\u6838\u7248\u672C").option("-f, --force", "\u5F3A\u5236\u91CD\u65B0\u521D\u59CB\u5316\u5185\u6838\u6C99\u7BB1").option("--clean", "\u6E05\u7406\u5E76\u91CD\u7F6E\u6C99\u7BB1").action(
|
|
@@ -6810,7 +7136,7 @@ cli.command("sync", "\u540C\u6B65\u5185\u6838\u4F9D\u8D56\u4E0E\u89C4\u8303").al
|
|
|
6810
7136
|
const { sync: sync2 } = await Promise.resolve().then(() => (init_sync(), sync_exports));
|
|
6811
7137
|
const { doctor: doctor2 } = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
6812
7138
|
await sync2({ ...options, version: options.coreVersion });
|
|
6813
|
-
|
|
7139
|
+
logger2.info("");
|
|
6814
7140
|
await doctor2({ fix: false });
|
|
6815
7141
|
}, "sync")
|
|
6816
7142
|
);
|
|
@@ -6962,14 +7288,14 @@ cli.command("devtools types", "\u4ECE plugin.json \u751F\u6210 TypeScript \u7C7B
|
|
|
6962
7288
|
}, "devtools types")
|
|
6963
7289
|
);
|
|
6964
7290
|
cli.command("sandbox", "\u6C99\u7BB1\u7BA1\u7406\u547D\u4EE4").action(() => {
|
|
6965
|
-
|
|
7291
|
+
logger2.warn(
|
|
6966
7292
|
"\u8BF7\u4F7F\u7528 sandbox \u5B50\u547D\u4EE4: sandbox-diagnose, sandbox-update, sandbox-resolve"
|
|
6967
7293
|
);
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
7294
|
+
logger2.info("\u7528\u6CD5: chatbi <\u5B50\u547D\u4EE4>");
|
|
7295
|
+
logger2.info("\u5B50\u547D\u4EE4:");
|
|
7296
|
+
logger2.info(" sandbox-diagnose - \u8BCA\u65AD\u6C99\u7BB1\u95EE\u9898");
|
|
7297
|
+
logger2.info(" sandbox-update - \u66F4\u65B0\u6C99\u7BB1");
|
|
7298
|
+
logger2.info(" sandbox-resolve - \u89E3\u6790\u5305\u7248\u672C");
|
|
6973
7299
|
});
|
|
6974
7300
|
cli.command("sandbox-diagnose", "\u8BCA\u65AD\u6C99\u7BB1\u73AF\u5883\u95EE\u9898\u5E76\u63D0\u4F9B\u4FEE\u590D\u5EFA\u8BAE").option("--fix", "\u81EA\u52A8\u4FEE\u590D\u53D1\u73B0\u7684\u95EE\u9898").option("--verbose", "\u663E\u793A\u8BE6\u7EC6\u4FE1\u606F").action(
|
|
6975
7301
|
wrapAction(async (options) => {
|