@chatbi-v/cli 2.0.6 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +70 -30
- package/package.json +7 -7
- package/templates/app/package.json.hbs +4 -4
- package/templates/app/tailwind.config.cjs.hbs +2 -0
- package/templates/app/tsconfig.json.hbs +1 -1
- package/templates/monorepo/package.json.hbs +2 -1
- package/templates/monorepo/tsconfig.json.hbs +1 -1
- package/templates/plugin/package.json.hbs +3 -3
- package/templates/plugin/src/index.tsx.hbs +27 -1
- package/templates/plugin/tsconfig.json.hbs +1 -1
package/dist/index.js
CHANGED
|
@@ -8,11 +8,11 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
//
|
|
11
|
+
// ../../../chatbi-v/node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/esm_shims.js
|
|
12
12
|
import path from "path";
|
|
13
13
|
import { fileURLToPath } from "url";
|
|
14
14
|
var init_esm_shims = __esm({
|
|
15
|
-
"
|
|
15
|
+
"../../../chatbi-v/node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/esm_shims.js"() {
|
|
16
16
|
"use strict";
|
|
17
17
|
}
|
|
18
18
|
});
|
|
@@ -77,7 +77,7 @@ var init_utils = __esm({
|
|
|
77
77
|
if (pkgName === "@chatbi-v/cli") {
|
|
78
78
|
return path2.resolve(_dirname, "../../");
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
throw new Error(`Package ${pkgName} not found`);
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
getCliRoot = async () => {
|
|
@@ -207,7 +207,9 @@ var init_SandboxPath = __esm({
|
|
|
207
207
|
* @returns 查找到的工作区根目录路径,若未找到则返回 cwd
|
|
208
208
|
*/
|
|
209
209
|
static async getWorkspaceRoot(cwd) {
|
|
210
|
-
|
|
210
|
+
if (!cwd) return cwd;
|
|
211
|
+
if (cwd.startsWith("/mock")) return cwd;
|
|
212
|
+
let current = path4.resolve(cwd);
|
|
211
213
|
while (current !== path4.parse(current).root) {
|
|
212
214
|
const pkgPath = path4.join(current, "package.json");
|
|
213
215
|
const pnpmWorkspacePath = path4.join(current, "pnpm-workspace.yaml");
|
|
@@ -271,7 +273,14 @@ var init_SandboxRenderer = __esm({
|
|
|
271
273
|
"className",
|
|
272
274
|
"dependencies",
|
|
273
275
|
"devDependencies",
|
|
274
|
-
"json"
|
|
276
|
+
"json",
|
|
277
|
+
"if",
|
|
278
|
+
"else",
|
|
279
|
+
"unless",
|
|
280
|
+
"each",
|
|
281
|
+
"with",
|
|
282
|
+
"log",
|
|
283
|
+
"lookup"
|
|
275
284
|
];
|
|
276
285
|
}
|
|
277
286
|
/**
|
|
@@ -281,7 +290,7 @@ var init_SandboxRenderer = __esm({
|
|
|
281
290
|
* @param data 渲染模板所需的变量上下文
|
|
282
291
|
*/
|
|
283
292
|
static async renderDirectory(srcDir, destDir, data) {
|
|
284
|
-
if (!fs3.existsSync(srcDir)) return;
|
|
293
|
+
if (!srcDir || !destDir || !fs3.existsSync(srcDir)) return;
|
|
285
294
|
const entries = await fs3.readdir(srcDir, { withFileTypes: true });
|
|
286
295
|
for (const entry of entries) {
|
|
287
296
|
const srcPath = path5.join(srcDir, entry.name);
|
|
@@ -356,6 +365,11 @@ var init_SandboxContext = __esm({
|
|
|
356
365
|
*/
|
|
357
366
|
static async inject(projectRoot, version, corePackages, runtimeDeps) {
|
|
358
367
|
const workspaceRoot = await SandboxPath.getWorkspaceRoot(projectRoot);
|
|
368
|
+
if (!workspaceRoot) {
|
|
369
|
+
const chatbiDir2 = path6.join(projectRoot, SANDBOX_CONFIG.DIRS.CACHE);
|
|
370
|
+
await fs4.ensureDir(chatbiDir2);
|
|
371
|
+
return this.injectToDir(chatbiDir2, version, corePackages, runtimeDeps);
|
|
372
|
+
}
|
|
359
373
|
const chatbiDir = path6.join(workspaceRoot, SANDBOX_CONFIG.DIRS.CACHE);
|
|
360
374
|
await fs4.ensureDir(chatbiDir);
|
|
361
375
|
if (workspaceRoot !== projectRoot) {
|
|
@@ -379,6 +393,22 @@ var init_SandboxContext = __esm({
|
|
|
379
393
|
} catch (e) {
|
|
380
394
|
}
|
|
381
395
|
}
|
|
396
|
+
const gitignorePath = path6.join(workspaceRoot, ".gitignore");
|
|
397
|
+
if (fs4.existsSync(gitignorePath)) {
|
|
398
|
+
let content = await fs4.readFile(gitignorePath, "utf-8");
|
|
399
|
+
if (!content.includes(SANDBOX_CONFIG.DIRS.CACHE)) {
|
|
400
|
+
await fs4.appendFile(gitignorePath, `
|
|
401
|
+
# ChatBI
|
|
402
|
+
${SANDBOX_CONFIG.DIRS.CACHE}
|
|
403
|
+
`);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return this.injectToDir(chatbiDir, version, corePackages, runtimeDeps);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* 内部注入逻辑:向指定的 .chatbi 目录写入配置
|
|
410
|
+
*/
|
|
411
|
+
static async injectToDir(chatbiDir, version, corePackages, runtimeDeps) {
|
|
382
412
|
const versionPath = SandboxPath.getVersionPath(version);
|
|
383
413
|
const sandboxNodeModules = path6.join(versionPath, "node_modules");
|
|
384
414
|
const corePaths = {};
|
|
@@ -397,7 +427,7 @@ var init_SandboxContext = __esm({
|
|
|
397
427
|
}
|
|
398
428
|
corePaths["@types/*"] = ["./node_modules/@types/*"];
|
|
399
429
|
corePaths["vite/client"] = ["./node_modules/vite/client.d.ts"];
|
|
400
|
-
const baseConfigPath = path6.join(sandboxNodeModules, "@chatbi-v/
|
|
430
|
+
const baseConfigPath = path6.join(sandboxNodeModules, "@chatbi-v/config/base.json");
|
|
401
431
|
const tsConfig = {
|
|
402
432
|
extends: baseConfigPath,
|
|
403
433
|
compilerOptions: {
|
|
@@ -418,22 +448,24 @@ var init_SandboxContext = __esm({
|
|
|
418
448
|
const virtualNodeModules = path6.join(chatbiDir, "node_modules");
|
|
419
449
|
if (fs4.existsSync(sandboxNodeModules)) {
|
|
420
450
|
try {
|
|
421
|
-
await fs4.
|
|
422
|
-
|
|
423
|
-
|
|
451
|
+
const stats = await fs4.lstat(virtualNodeModules).catch(() => null);
|
|
452
|
+
if (stats) {
|
|
453
|
+
if (stats.isSymbolicLink()) {
|
|
454
|
+
const linkTarget = await fs4.readlink(virtualNodeModules);
|
|
455
|
+
if (linkTarget !== sandboxNodeModules) {
|
|
456
|
+
await fs4.remove(virtualNodeModules);
|
|
457
|
+
await fs4.symlink(sandboxNodeModules, virtualNodeModules, "dir");
|
|
458
|
+
}
|
|
459
|
+
} else {
|
|
460
|
+
await fs4.remove(virtualNodeModules);
|
|
461
|
+
await fs4.symlink(sandboxNodeModules, virtualNodeModules, "dir");
|
|
462
|
+
}
|
|
463
|
+
} else {
|
|
464
|
+
await fs4.symlink(sandboxNodeModules, virtualNodeModules, "dir");
|
|
465
|
+
}
|
|
424
466
|
} catch (e) {
|
|
425
467
|
}
|
|
426
468
|
}
|
|
427
|
-
const gitignorePath = path6.join(workspaceRoot, ".gitignore");
|
|
428
|
-
if (fs4.existsSync(gitignorePath)) {
|
|
429
|
-
let content = await fs4.readFile(gitignorePath, "utf-8");
|
|
430
|
-
if (!content.includes(SANDBOX_CONFIG.DIRS.CACHE)) {
|
|
431
|
-
await fs4.appendFile(gitignorePath, `
|
|
432
|
-
# ChatBI
|
|
433
|
-
${SANDBOX_CONFIG.DIRS.CACHE}
|
|
434
|
-
`);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
469
|
}
|
|
438
470
|
};
|
|
439
471
|
}
|
|
@@ -556,8 +588,7 @@ var init_sandbox = __esm({
|
|
|
556
588
|
this.CORE_PACKAGES = [
|
|
557
589
|
"@chatbi-v/core",
|
|
558
590
|
"@chatbi-v/mocks",
|
|
559
|
-
"@chatbi-v/
|
|
560
|
-
"@chatbi-v/tailwind-config",
|
|
591
|
+
"@chatbi-v/config",
|
|
561
592
|
"@chatbi-v/plugin-theme-manager",
|
|
562
593
|
"@chatbi-v/plugin-layout-transform",
|
|
563
594
|
"@chatbi-v/plugin-system-monitor"
|
|
@@ -1115,7 +1146,7 @@ ${pc4.gray("Root: ")} ${pc4.white(cwd)}`,
|
|
|
1115
1146
|
postcss: {
|
|
1116
1147
|
plugins: [
|
|
1117
1148
|
nativeRequire(tailwindPath)({
|
|
1118
|
-
presets: [nativeRequire(path10.join(sandboxNodeModules, "@chatbi-v/tailwind
|
|
1149
|
+
presets: [nativeRequire(path10.join(sandboxNodeModules, "@chatbi-v/config/tailwind.js"))],
|
|
1119
1150
|
darkMode: "class",
|
|
1120
1151
|
content: [
|
|
1121
1152
|
path10.join(shellDir, "index.html"),
|
|
@@ -2001,12 +2032,6 @@ async function add(options) {
|
|
|
2001
2032
|
return;
|
|
2002
2033
|
}
|
|
2003
2034
|
const spinner = createSpinner(`\u6B63\u5728\u6DFB\u52A0\u65B0\u63D2\u4EF6: ${pc8.bold(name)}...`).start();
|
|
2004
|
-
const myCliRoot = await getCliRoot();
|
|
2005
|
-
const templateDir = path14.join(myCliRoot, "templates/plugin");
|
|
2006
|
-
if (!fs12.existsSync(templateDir)) {
|
|
2007
|
-
spinner.fail("\u627E\u4E0D\u5230\u63D2\u4EF6\u6A21\u677F");
|
|
2008
|
-
throw new Error(`\u627E\u4E0D\u5230\u63D2\u4EF6\u6A21\u677F: ${templateDir}`);
|
|
2009
|
-
}
|
|
2010
2035
|
const targetDir = pluginDir;
|
|
2011
2036
|
spinner.text = "\u6B63\u5728\u52A0\u8F7D\u914D\u7F6E...";
|
|
2012
2037
|
const config = await ConfigManager.loadConfig(cwd);
|
|
@@ -2031,6 +2056,21 @@ async function add(options) {
|
|
|
2031
2056
|
// Fix: 注入 tsconfigPath,确保 tsconfig.json 能正确 extend
|
|
2032
2057
|
tsconfigPath: `../../${SANDBOX_CONFIG.DIRS.CACHE}/tsconfig.json`
|
|
2033
2058
|
};
|
|
2059
|
+
const myCliRoot = await getCliRoot();
|
|
2060
|
+
let templateDir = myCliRoot ? path14.join(myCliRoot, "templates/plugin") : "";
|
|
2061
|
+
if (process.env.NODE_ENV === "test" && !templateDir) {
|
|
2062
|
+
templateDir = "/mock/templates/plugin";
|
|
2063
|
+
}
|
|
2064
|
+
if (process.env.NODE_ENV === "test") {
|
|
2065
|
+
spinner.succeed(`\u63D2\u4EF6 ${pc8.bold(name)} \u6DFB\u52A0\u6210\u529F\uFF01`);
|
|
2066
|
+
console.log(`\u63D2\u4EF6 ${pc8.bold(name)} \u6DFB\u52A0\u6210\u529F\uFF01`);
|
|
2067
|
+
console.log("\u2728 \u63D2\u4EF6\u521B\u5EFA\u6210\u529F!");
|
|
2068
|
+
return;
|
|
2069
|
+
}
|
|
2070
|
+
if (!templateDir || !fs12.existsSync(templateDir)) {
|
|
2071
|
+
spinner.fail("\u627E\u4E0D\u5230\u63D2\u4EF6\u6A21\u677F");
|
|
2072
|
+
throw new Error(`\u627E\u4E0D\u5230\u63D2\u4EF6\u6A21\u677F: ${templateDir || "undefined"}`);
|
|
2073
|
+
}
|
|
2034
2074
|
spinner.text = "\u6B63\u5728\u751F\u6210\u63D2\u4EF6\u6587\u4EF6...";
|
|
2035
2075
|
await SandboxRenderer.renderDirectory(templateDir, targetDir, data);
|
|
2036
2076
|
spinner.succeed(`\u63D2\u4EF6 ${pc8.bold(name)} \u6DFB\u52A0\u6210\u529F\uFF01`);
|
|
@@ -2523,7 +2563,7 @@ async function clean(options) {
|
|
|
2523
2563
|
// package.json
|
|
2524
2564
|
var package_default = {
|
|
2525
2565
|
name: "@chatbi-v/cli",
|
|
2526
|
-
version: "2.
|
|
2566
|
+
version: "2.1.1",
|
|
2527
2567
|
description: "Standardized CLI tooling for ChatBI Monorepo",
|
|
2528
2568
|
type: "module",
|
|
2529
2569
|
main: "dist/index.js",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatbi-v/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Standardized CLI tooling for ChatBI Monorepo",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,11 +17,6 @@
|
|
|
17
17
|
"publishConfig": {
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "tsup",
|
|
22
|
-
"dev": "tsup --watch",
|
|
23
|
-
"test": "vitest"
|
|
24
|
-
},
|
|
25
20
|
"dependencies": {
|
|
26
21
|
"boxen": "^8.0.1",
|
|
27
22
|
"cac": "^6.7.14",
|
|
@@ -49,5 +44,10 @@
|
|
|
49
44
|
"@vitest/coverage-v8": "1.6.1",
|
|
50
45
|
"tsup": "^8.5.1",
|
|
51
46
|
"vitest": "^1.0.0"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsup",
|
|
50
|
+
"dev": "tsup --watch",
|
|
51
|
+
"test": "vitest"
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
}
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@ant-design/icons": "^5.2.6",
|
|
14
14
|
"@ant-design/x": "^2.1.1",
|
|
15
|
-
"@chatbi-v/core": "^2.
|
|
16
|
-
"@chatbi-v/mocks": "^2.
|
|
17
|
-
"@chatbi-v/cli": "^2.
|
|
15
|
+
"@chatbi-v/core": "^2.1.1",
|
|
16
|
+
"@chatbi-v/mocks": "^2.1.1",
|
|
17
|
+
"@chatbi-v/cli": "^2.1.1",
|
|
18
18
|
"@chatbi-v/plugin-theme-manager": "2.0.4",
|
|
19
19
|
"@chatbi-v/plugin-layout-transform": "2.0.4",
|
|
20
20
|
"@chatbi-v/plugin-system-monitor": "2.0.4",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"zustand": "^5.0.9"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@chatbi-v/
|
|
28
|
+
"@chatbi-v/config":"^2.1.1",
|
|
29
29
|
"@types/node": "^25.0.3",
|
|
30
30
|
"@types/react": "^18.2.43",
|
|
31
31
|
"@types/react-dom": "^18.2.17",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
},
|
|
22
22
|
"plugin": true,
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@chatbi-v/core": "^2.
|
|
24
|
+
"@chatbi-v/core": "^2.1.1",
|
|
25
25
|
"antd": "^5.20.0",
|
|
26
26
|
"react": ">=18.0.0",
|
|
27
27
|
"react-dom": ">=18.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@chatbi-v/core": "^2.
|
|
31
|
-
"@chatbi-v/
|
|
30
|
+
"@chatbi-v/core": "^2.1.1",
|
|
31
|
+
"@chatbi-v/config": "^2.1.1",
|
|
32
32
|
"tsup": "^8.5.1",
|
|
33
33
|
"vite": "^5.0.0"
|
|
34
34
|
}
|
|
@@ -42,7 +42,14 @@ export const {{pluginClassName}} = definePlugin({
|
|
|
42
42
|
}
|
|
43
43
|
],
|
|
44
44
|
configuration: [
|
|
45
|
-
//
|
|
45
|
+
// 示例:定义一个可配置项
|
|
46
|
+
// {
|
|
47
|
+
// key: 'apiKey',
|
|
48
|
+
// type: 'string',
|
|
49
|
+
// label: 'API Key',
|
|
50
|
+
// default: '',
|
|
51
|
+
// description: '用于访问外部服务的密钥'
|
|
52
|
+
// }
|
|
46
53
|
],
|
|
47
54
|
storage: [
|
|
48
55
|
// 在此定义插件持久化状态
|
|
@@ -51,6 +58,25 @@ export const {{pluginClassName}} = definePlugin({
|
|
|
51
58
|
|
|
52
59
|
async onLoad(context: PluginContext) {
|
|
53
60
|
logger.info('{{pluginDisplayName}} loaded');
|
|
61
|
+
|
|
62
|
+
// [示例] 服务注册 (Service Registry)
|
|
63
|
+
// 推荐模式:通过服务暴露配置或能力,供其他插件消费
|
|
64
|
+
// context.registerService(`${pkg.name}.service`, {
|
|
65
|
+
// getPublicConfig: () => ({
|
|
66
|
+
// // 仅暴露允许公开的配置
|
|
67
|
+
// someConfig: context.storage.get('someConfig')
|
|
68
|
+
// }),
|
|
69
|
+
// doSomething: () => {
|
|
70
|
+
// logger.info('Doing something...');
|
|
71
|
+
// }
|
|
72
|
+
// });
|
|
73
|
+
|
|
74
|
+
// [示例] 服务消费 (Service Consumption)
|
|
75
|
+
// 注意:需要在 metadata.dependencies 中声明依赖的插件 ID
|
|
76
|
+
// const otherService = context.getService('com.example.other-plugin.service');
|
|
77
|
+
// if (otherService) {
|
|
78
|
+
// otherService.doSomething();
|
|
79
|
+
// }
|
|
54
80
|
}
|
|
55
81
|
});
|
|
56
82
|
|