@chatbi-v/cli 3.0.0 → 3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatbi-v/cli",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
4
4
  "description": "Standardized CLI tooling for ChatBI Monorepo",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "dependencies": {
28
28
  "boxen": "^8.0.1",
29
29
  "cac": "^6.7.14",
30
- "execa": "^8.0.1",
30
+ "esbuild": "^0.24.0",
31
31
  "fast-glob": "^3.3.3",
32
32
  "figlet": "^1.9.4",
33
33
  "fs-extra": "^11.2.0",
@@ -37,26 +37,31 @@
37
37
  "ora": "^7.0.1",
38
38
  "picocolors": "^1.0.0",
39
39
  "prompts": "^2.4.2",
40
- "vite": "^5.4.11"
40
+ "vite": "^5.4.11",
41
+ "zod": "^3.23.8",
42
+ "@chatbi-v/core": "3.1.1",
43
+ "@chatbi-v/config": "3.1.1"
41
44
  },
42
45
  "devDependencies": {
43
- "tsup": "^8.5.1",
44
- "typescript": "^5.0.0",
45
- "@types/eslint": "^9.6.1",
46
46
  "@types/boxen": "^3.0.5",
47
47
  "@types/figlet": "^1.7.0",
48
48
  "@types/fs-extra": "^11.0.0",
49
49
  "@types/gradient-string": "^1.1.6",
50
50
  "@types/node": "^20.0.0",
51
51
  "@types/prompts": "^2.4.9",
52
- "@vitest/coverage-v8": "1.6.1",
53
- "vitest": "^1.0.0",
52
+ "@types/tmp": "^0.2.6",
54
53
  "eslint": "^9.17.0",
55
- "@chatbi-v/eslint-plugin-theme": "3.0.0"
54
+ "execa": "^8.0.1",
55
+ "tmp-promise": "^3.0.3",
56
+ "tsup": "^8.5.1",
57
+ "typescript": "^5.0.0",
58
+ "vitest": "^1.3.1"
56
59
  },
57
60
  "scripts": {
58
61
  "build": "tsup",
59
62
  "dev": "tsup --watch",
60
- "test": "vitest"
63
+ "test": "vitest run tests/**/*.test.ts --exclude tests/e2e/**",
64
+ "test:e2e": "pnpm build && vitest run tests/e2e/plugin-create.e2e.test.ts tests/e2e/sandbox-isolation.e2e.test.ts",
65
+ "test:all": "pnpm test && pnpm test:e2e"
61
66
  }
62
67
  }
@@ -12,9 +12,6 @@
12
12
  "dependencies": {
13
13
  "@ant-design/icons": "^5.2.6",
14
14
  "@ant-design/x": "^2.1.0",
15
- "@chatbi-v/core": "^3.0.0",
16
- "@chatbi-v/react": "^3.0.0",
17
- "@chatbi-v/mocks": "^3.0.0",
18
15
  "antd": "^5.20.0",
19
16
  "react": "^18.3.1",
20
17
  "react-dom": "^18.3.1",
@@ -22,8 +19,7 @@
22
19
  "zustand": "^5.0.3"
23
20
  },
24
21
  "devDependencies": {
25
- "@chatbi-v/cli": "^3.0.0",
26
- "@chatbi-v/config":"^3.0.0",
22
+ "@chatbi-v/cli": "^{{cliVersion}}",
27
23
  "@types/node": "^25.0.3",
28
24
  "@types/react": "^18.3.12",
29
25
  "@types/react-dom": "^18.3.1",
@@ -1,6 +1,6 @@
1
1
  import React, { lazy, Suspense, useMemo } from 'react';
2
2
  import { useLocation } from 'react-router-dom';
3
- import { PluginSlot, Slot } from '@chatbi-v/core';
3
+ import { Slot, PluginSlot } from '@chatbi-v/react';
4
4
 
5
5
  import { GlobalSettingsModal } from './components/GlobalSettingsModal';
6
6
  import { ContentSkeleton, NavSkeleton } from './components/LayoutSkeletons';
@@ -15,12 +15,14 @@ export const usePluginLoader = () => {
15
15
  * 将 Vite 扫描到的物理路径转换为内核可识别的规范化 ID
16
16
  * 规范化规则:
17
17
  * 1. @chatbi-plugins/xxx/src/index -> packages/plugins/xxx/src/index
18
- * 2. ../../plugins/xxx/src/index -> packages/plugins/xxx/src/index
18
+ * 2. ../../packages/plugins/xxx/src/index -> packages/plugins/xxx/src/index
19
+ * 3. @chatbi-apps/xxx/src/index -> apps/xxx/src/index
20
+ * 4. ../../apps/xxx/src/index 或 ../../packages/apps/xxx/src/index -> apps/xxx/src/index
19
21
  */
20
22
  const normalizeModulePath = (path: string) => {
21
23
  const mapping = [
22
- { pattern: /^(@chatbi-plugins\/|(\.\.\/)+plugins\/)/, replacement: 'packages/plugins/' },
23
- { pattern: /^(@chatbi-apps\/|(\.\.\/)+apps\/)/, replacement: 'packages/apps/' }
24
+ { pattern: /^(@chatbi-plugins\/|(\.\.\/)+packages\/plugins\/)/, replacement: 'packages/plugins/' },
25
+ { pattern: /^(@chatbi-apps\/|(\.\.\/)+apps\/|(\.\.\/)+packages\/apps\/)/, replacement: 'apps/' }
24
26
  ];
25
27
 
26
28
  for (const { pattern, replacement } of mapping) {
@@ -35,6 +37,8 @@ export const usePluginLoader = () => {
35
37
  const globModules = import.meta.glob<any>([
36
38
  '@chatbi-plugins/*/src/index.{ts,tsx}',
37
39
  '@chatbi-apps/*/src/index.{ts,tsx}',
40
+ '../../../../apps/*/src/index.{ts,tsx}',
41
+ '../../../../packages/apps/*/src/index.{ts,tsx}',
38
42
  ], { eager: false });
39
43
 
40
44
  const normalizedModules: Record<string, () => Promise<any>> = {};
@@ -11,8 +11,9 @@ export default {
11
11
  content: [
12
12
  path.resolve(__dirname, './index.html'),
13
13
  path.resolve(__dirname, './src/**/*.{js,ts,jsx,tsx}'),
14
- path.resolve(__dirname, '../../plugins/*/src/**/*.{js,ts,jsx,tsx}'),
14
+ path.resolve(__dirname, '../../packages/plugins/*/src/**/*.{js,ts,jsx,tsx}'),
15
15
  path.resolve(__dirname, '../../apps/*/src/**/*.{js,ts,jsx,tsx}'),
16
+ path.resolve(__dirname, '../../packages/apps/*/src/**/*.{js,ts,jsx,tsx}'),
16
17
  ],
17
18
  theme: {
18
19
  extend: {
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "@chatbi-v/config/base.json",
2
+ "extends": "{{tsconfigPath}}",
3
3
  "compilerOptions": {
4
4
  "target": "ES2020",
5
5
  "useDefineForClassFields": true,
@@ -17,4 +17,4 @@
17
17
  "jsx": "react-jsx"
18
18
  },
19
19
  "include": ["src"]
20
- }
20
+ }
@@ -6,6 +6,14 @@ import { defineConfig, loadEnv } from 'vite';
6
6
  /**
7
7
  * 动态获取 Workspace 中的包,用于 exclude
8
8
  */
9
+ function getWorkspaceAppsDir() {
10
+ const packagesAppsDir = path.resolve(__dirname, '../../packages/apps');
11
+ if (fs.existsSync(packagesAppsDir)) {
12
+ return packagesAppsDir;
13
+ }
14
+ return path.resolve(__dirname, '../../apps');
15
+ }
16
+
9
17
  function getWorkspacePackages() {
10
18
  try {
11
19
  const pkgPath = path.resolve(__dirname, 'package.json');
@@ -34,8 +42,8 @@ function manualChunks(id: string) {
34
42
  }
35
43
 
36
44
  // 2. ChatBI 插件 (Workspace)
37
- if (id.includes('/plugins/')) {
38
- const matches = id.match(/\/plugins\/([^/]+)\//);
45
+ if (id.includes('/packages/plugins/')) {
46
+ const matches = id.match(/\/packages\/plugins\/([^/]+)\//);
39
47
  if (matches && matches[1]) {
40
48
  const pluginName = matches[1];
41
49
  // 统一分包名称格式为 plugin-{name}
@@ -86,8 +94,8 @@ export default defineConfig(({ mode }) => {
86
94
  resolve: {
87
95
  alias: {
88
96
  '@': path.resolve(__dirname, './src'),
89
- '@chatbi-plugins': path.resolve(__dirname, '../../plugins'),
90
- '@chatbi-apps': path.resolve(__dirname, '../../apps'),
97
+ '@chatbi-plugins': path.resolve(__dirname, '../../packages/plugins'),
98
+ '@chatbi-apps': getWorkspaceAppsDir(),
91
99
  },
92
100
  // 强制统一核心依赖实例
93
101
  dedupe: ['react', 'react-dom', 'antd', '@ant-design/x', '@chatbi-v/core'],
@@ -4,8 +4,9 @@
4
4
 
5
5
  ## 项目结构
6
6
 
7
- - `apps/main`: 宿主应用,用于验证插件功能。
8
- - `plugins/`: 业务插件源码目录。
7
+ - `apps/main`: 默认宿主应用,用于验证插件功能。
8
+ - `packages/apps/*`: 兼容未来扩展的应用工作区目录。
9
+ - `packages/plugins/`: 业务插件源码目录。
9
10
  - `.chatbi/`: 离线 SDK 资源(核心包、标准插件、CLI 工具)。
10
11
 
11
12
  ## 快速开始
@@ -27,4 +28,4 @@
27
28
 
28
29
  ## 插件开发
29
30
 
30
- 参考 `plugins/demo-plugin` 示例。
31
+ 参考 `packages/plugins/demo-plugin` 示例。
@@ -11,13 +11,12 @@
11
11
  },
12
12
  "workspaces": [
13
13
  "apps/*",
14
- "plugins/*",
14
+ "packages/apps/*",
15
+ "packages/plugins/*",
15
16
  "packages/*",
16
17
  "libs/*"
17
18
  ],
18
19
  "dependencies": {
19
- "@chatbi-v/core": "^3.0.0",
20
- "@chatbi-v/mocks": "^3.0.0",
21
20
  "react": "^18.3.1",
22
21
  "react-dom": "^18.3.1",
23
22
  "antd": "^5.29.3",
@@ -28,8 +27,7 @@
28
27
  },
29
28
  "devDependencies": {
30
29
  "typescript": "^5.0.0",
31
- "@chatbi-v/config": "^3.0.0",
32
- "@chatbi-v/cli": "^3.0.0",
30
+ "@chatbi-v/cli": "^{{cliVersion}}",
33
31
  "@ant-design/icons": "^5.6.1",
34
32
  "@types/react": "^18.3.1",
35
33
  "@types/react-dom": "^18.3.1",
@@ -2,8 +2,9 @@
2
2
  packages:
3
3
  # 宿主应用目录
4
4
  - 'apps/*'
5
+ - 'packages/apps/*'
5
6
  # 插件目录
6
- - 'plugins/*'
7
+ - 'packages/plugins/*'
7
8
 
8
9
  # 增量配置:如果添加了核心库或工具库,可在此处包含
9
10
  - 'packages/*'
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "@chatbi-v/config/base.json",
2
+ "extends": "{{tsconfigPath}}",
3
3
  "compilerOptions": {
4
4
  "target": "ESNext",
5
5
  "useDefineForClassFields": true,
@@ -18,9 +18,9 @@
18
18
  "jsx": "react-jsx",
19
19
  "baseUrl": ".",
20
20
  "paths": {
21
- "@chatbi-plugins/*": ["./plugins/*/src"],
22
- "@chatbi-apps/*": ["./apps/*/src"]
21
+ "@chatbi-plugins/*": ["./packages/plugins/*/src"],
22
+ "@chatbi-apps/*": ["./apps/*/src", "./packages/apps/*/src"]
23
23
  }
24
24
  },
25
- "include": ["apps/main/src", "plugins/*/src"]
25
+ "include": ["apps/main/src", "packages/apps/*/src", "packages/plugins/*/src"]
26
26
  }
@@ -5,14 +5,12 @@
5
5
  "files": [
6
6
  "dist"
7
7
  ],
8
- "main": "dist/index.cjs",
8
+ "main": "dist/index.mjs",
9
9
  "module": "dist/index.mjs",
10
- "types": "dist/index.d.ts",
11
10
  "exports": {
12
11
  ".": {
13
- "types": "./dist/index.d.ts",
14
12
  "import": "./dist/index.mjs",
15
- "require": "./dist/index.cjs"
13
+ "default": "./dist/index.mjs"
16
14
  }
17
15
  },
18
16
  "scripts": {
@@ -21,14 +19,13 @@
21
19
  },
22
20
  "plugin": true,
23
21
  "peerDependencies": {
24
- "@chatbi-v/core": "^3.0.0",
22
+ "@ant-design/icons": "^5.0.0",
25
23
  "antd": "^5.20.0",
26
24
  "react": ">=18.0.0",
27
25
  "react-dom": ">=18.0.0"
28
26
  },
29
27
  "devDependencies": {
30
- "@chatbi-v/core": "^3.0.0",
31
- "@chatbi-v/config": "^3.0.0",
28
+ "@chatbi-v/cli": "^{{cliVersion}}",
32
29
  "tsup": "^8.5.1",
33
30
  "vite": "^5.0.0"
34
31
  }
@@ -2,8 +2,10 @@ import { RocketOutlined } from '@ant-design/icons';
2
2
  import { createLogger, definePlugin, type PluginContext, Slot } from '@chatbi-v/core';
3
3
  import React from 'react';
4
4
  import pkg from '../package.json';
5
+ import manifest from './plugin.json';
5
6
 
6
7
  const logger = createLogger('{{pluginName}}');
8
+ const routePath = manifest.routes?.[0]?.path || '/{{pluginPath}}';
7
9
 
8
10
  /**
9
11
  * {{pluginDescription}}
@@ -11,20 +13,21 @@ const logger = createLogger('{{pluginName}}');
11
13
  export const {{pluginClassName}} = definePlugin({
12
14
  /** 插件元数据 */
13
15
  metadata: {
14
- id: pkg.name,
15
- name: '{{pluginDisplayName}}',
16
+ id: manifest.id,
17
+ name: manifest.name,
16
18
  version: pkg.version,
17
- type: '{{pluginType}}', // business | system | renderer
18
- description: '{{pluginDescription}}',
19
+ type: manifest.type,
20
+ description: manifest.description,
21
+ dependencies: manifest.dependencies?.map((dependency) => dependency.id) || [],
19
22
  capabilities: {
20
23
  configurable: true
21
24
  },
22
25
  routes: [
23
26
  {
24
- path: '/{{pluginPath}}',
27
+ path: routePath,
25
28
  component: React.lazy(() => import('./components/MainView')),
26
29
  meta: {
27
- title: '{{pluginDisplayName}}',
30
+ title: manifest.name,
28
31
  icon: 'RocketOutlined'
29
32
  }
30
33
  }
@@ -36,8 +39,8 @@ export const {{pluginClassName}} = definePlugin({
36
39
  order: 10,
37
40
  meta: {
38
41
  icon: <RocketOutlined />,
39
- label: '{{pluginDisplayName}}',
40
- path: '/{{pluginPath}}'
42
+ label: manifest.name,
43
+ path: routePath
41
44
  }
42
45
  }
43
46
  ],
@@ -57,11 +60,11 @@ export const {{pluginClassName}} = definePlugin({
57
60
  },
58
61
 
59
62
  async onLoad(context: PluginContext) {
60
- logger.info('{{pluginDisplayName}} loaded');
63
+ logger.info('{{pluginDisplayName}} 已加载');
61
64
 
62
65
  // [示例] 服务注册 (Service Registry)
63
66
  // 推荐模式:通过服务暴露配置或能力,供其他插件消费
64
- // context.registerService(`${pkg.name}.service`, {
67
+ // context.registerService('service', {
65
68
  // getPublicConfig: () => ({
66
69
  // // 仅暴露允许公开的配置
67
70
  // someConfig: context.storage.get('someConfig')
@@ -73,7 +76,7 @@ export const {{pluginClassName}} = definePlugin({
73
76
 
74
77
  // [示例] 服务消费 (Service Consumption)
75
78
  // 注意:需要在 metadata.dependencies 中声明依赖的插件 ID
76
- // const otherService = context.getService('com.example.other-plugin.service');
79
+ // const otherService = context.getService('chatbi-v.plugin-other.service');
77
80
  // if (otherService) {
78
81
  // otherService.doSomething();
79
82
  // }
@@ -0,0 +1,14 @@
1
+ {
2
+ "id": "{{pluginId}}",
3
+ "version": "{{pluginVersion}}",
4
+ "name": "{{pluginDisplayName}}",
5
+ "entry": "src/index.tsx",
6
+ "type": "{{pluginType}}",
7
+ "description": "{{pluginDescription}}",
8
+ "dependencies": [],
9
+ "routes": [
10
+ {
11
+ "path": "/{{pluginPath}}"
12
+ }
13
+ ]
14
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "@chatbi-v/config/base.json",
2
+ "extends": "{{tsconfigPath}}",
3
3
  "compilerOptions": {
4
4
  "outDir": "./dist",
5
5
  "rootDir": "./src",