@chatbi-v/cli 2.1.0 → 2.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 CHANGED
@@ -8,11 +8,11 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
 
11
- // ../../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
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
- "../../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"() {
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
- return null;
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
- let current = cwd;
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");
@@ -288,7 +290,7 @@ var init_SandboxRenderer = __esm({
288
290
  * @param data 渲染模板所需的变量上下文
289
291
  */
290
292
  static async renderDirectory(srcDir, destDir, data) {
291
- if (!fs3.existsSync(srcDir)) return;
293
+ if (!srcDir || !destDir || !fs3.existsSync(srcDir)) return;
292
294
  const entries = await fs3.readdir(srcDir, { withFileTypes: true });
293
295
  for (const entry of entries) {
294
296
  const srcPath = path5.join(srcDir, entry.name);
@@ -363,6 +365,11 @@ var init_SandboxContext = __esm({
363
365
  */
364
366
  static async inject(projectRoot, version, corePackages, runtimeDeps) {
365
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
+ }
366
373
  const chatbiDir = path6.join(workspaceRoot, SANDBOX_CONFIG.DIRS.CACHE);
367
374
  await fs4.ensureDir(chatbiDir);
368
375
  if (workspaceRoot !== projectRoot) {
@@ -386,6 +393,22 @@ var init_SandboxContext = __esm({
386
393
  } catch (e) {
387
394
  }
388
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) {
389
412
  const versionPath = SandboxPath.getVersionPath(version);
390
413
  const sandboxNodeModules = path6.join(versionPath, "node_modules");
391
414
  const corePaths = {};
@@ -404,7 +427,7 @@ var init_SandboxContext = __esm({
404
427
  }
405
428
  corePaths["@types/*"] = ["./node_modules/@types/*"];
406
429
  corePaths["vite/client"] = ["./node_modules/vite/client.d.ts"];
407
- const baseConfigPath = path6.join(sandboxNodeModules, "@chatbi-v/tsconfig/base.json");
430
+ const baseConfigPath = path6.join(sandboxNodeModules, "@chatbi-v/config/base.json");
408
431
  const tsConfig = {
409
432
  extends: baseConfigPath,
410
433
  compilerOptions: {
@@ -425,22 +448,24 @@ var init_SandboxContext = __esm({
425
448
  const virtualNodeModules = path6.join(chatbiDir, "node_modules");
426
449
  if (fs4.existsSync(sandboxNodeModules)) {
427
450
  try {
428
- await fs4.remove(virtualNodeModules).catch(() => {
429
- });
430
- await fs4.ensureSymlink(sandboxNodeModules, virtualNodeModules, "dir");
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
+ }
431
466
  } catch (e) {
432
467
  }
433
468
  }
434
- const gitignorePath = path6.join(workspaceRoot, ".gitignore");
435
- if (fs4.existsSync(gitignorePath)) {
436
- let content = await fs4.readFile(gitignorePath, "utf-8");
437
- if (!content.includes(SANDBOX_CONFIG.DIRS.CACHE)) {
438
- await fs4.appendFile(gitignorePath, `
439
- # ChatBI
440
- ${SANDBOX_CONFIG.DIRS.CACHE}
441
- `);
442
- }
443
- }
444
469
  }
445
470
  };
446
471
  }
@@ -563,8 +588,7 @@ var init_sandbox = __esm({
563
588
  this.CORE_PACKAGES = [
564
589
  "@chatbi-v/core",
565
590
  "@chatbi-v/mocks",
566
- "@chatbi-v/tsconfig",
567
- "@chatbi-v/tailwind-config",
591
+ "@chatbi-v/config",
568
592
  "@chatbi-v/plugin-theme-manager",
569
593
  "@chatbi-v/plugin-layout-transform",
570
594
  "@chatbi-v/plugin-system-monitor"
@@ -1122,7 +1146,7 @@ ${pc4.gray("Root: ")} ${pc4.white(cwd)}`,
1122
1146
  postcss: {
1123
1147
  plugins: [
1124
1148
  nativeRequire(tailwindPath)({
1125
- presets: [nativeRequire(path10.join(sandboxNodeModules, "@chatbi-v/tailwind-config"))],
1149
+ presets: [nativeRequire(path10.join(sandboxNodeModules, "@chatbi-v/config/tailwind.js"))],
1126
1150
  darkMode: "class",
1127
1151
  content: [
1128
1152
  path10.join(shellDir, "index.html"),
@@ -2008,12 +2032,6 @@ async function add(options) {
2008
2032
  return;
2009
2033
  }
2010
2034
  const spinner = createSpinner(`\u6B63\u5728\u6DFB\u52A0\u65B0\u63D2\u4EF6: ${pc8.bold(name)}...`).start();
2011
- const myCliRoot = await getCliRoot();
2012
- const templateDir = path14.join(myCliRoot, "templates/plugin");
2013
- if (!fs12.existsSync(templateDir)) {
2014
- spinner.fail("\u627E\u4E0D\u5230\u63D2\u4EF6\u6A21\u677F");
2015
- throw new Error(`\u627E\u4E0D\u5230\u63D2\u4EF6\u6A21\u677F: ${templateDir}`);
2016
- }
2017
2035
  const targetDir = pluginDir;
2018
2036
  spinner.text = "\u6B63\u5728\u52A0\u8F7D\u914D\u7F6E...";
2019
2037
  const config = await ConfigManager.loadConfig(cwd);
@@ -2038,6 +2056,21 @@ async function add(options) {
2038
2056
  // Fix: 注入 tsconfigPath,确保 tsconfig.json 能正确 extend
2039
2057
  tsconfigPath: `../../${SANDBOX_CONFIG.DIRS.CACHE}/tsconfig.json`
2040
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
+ }
2041
2074
  spinner.text = "\u6B63\u5728\u751F\u6210\u63D2\u4EF6\u6587\u4EF6...";
2042
2075
  await SandboxRenderer.renderDirectory(templateDir, targetDir, data);
2043
2076
  spinner.succeed(`\u63D2\u4EF6 ${pc8.bold(name)} \u6DFB\u52A0\u6210\u529F\uFF01`);
@@ -2530,7 +2563,7 @@ async function clean(options) {
2530
2563
  // package.json
2531
2564
  var package_default = {
2532
2565
  name: "@chatbi-v/cli",
2533
- version: "2.1.0",
2566
+ version: "2.1.2",
2534
2567
  description: "Standardized CLI tooling for ChatBI Monorepo",
2535
2568
  type: "module",
2536
2569
  main: "dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatbi-v/cli",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "Standardized CLI tooling for ChatBI Monorepo",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -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.1.0",
16
- "@chatbi-v/mocks": "^2.1.0",
17
- "@chatbi-v/cli": "^2.1.0",
15
+ "@chatbi-v/core": "^2.1.2",
16
+ "@chatbi-v/mocks": "^2.1.2",
17
+ "@chatbi-v/cli": "^2.1.2",
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/tsconfig":"^2.1.0",
28
+ "@chatbi-v/config":"^2.1.2",
29
29
  "@types/node": "^25.0.3",
30
30
  "@types/react": "^18.2.43",
31
31
  "@types/react-dom": "^18.2.17",
@@ -1,7 +1,9 @@
1
+ const baseConfig = require('@chatbi-v/config/tailwind');
1
2
  const path = require('path');
2
3
 
3
4
  /** @type {import('tailwindcss').Config} */
4
5
  module.exports = {
6
+ ...baseConfig,
5
7
  darkMode: 'class',
6
8
  content: [
7
9
  path.resolve(__dirname, './index.html'),
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "{{tsconfigPath}}",
2
+ "extends": "@chatbi-v/config/base.json",
3
3
  "compilerOptions": {
4
4
  "target": "ES2020",
5
5
  "useDefineForClassFields": true,
@@ -24,7 +24,8 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "typescript": "^5.0.0",
27
- "@chatbi-v/cli": "^2.1.0",
27
+ "@chatbi-v/config": "^2.1.2",
28
+ "@chatbi-v/cli": "^2.1.2",
28
29
  "@ant-design/icons": "^5.6.1",
29
30
  "@types/react": "^18.3.1",
30
31
  "@types/react-dom": "^18.3.1",
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "./.chatbi/tsconfig.paths.json",
2
+ "extends": "@chatbi-v/config/base.json",
3
3
  "compilerOptions": {
4
4
  "target": "ESNext",
5
5
  "useDefineForClassFields": true,
@@ -21,14 +21,14 @@
21
21
  },
22
22
  "plugin": true,
23
23
  "peerDependencies": {
24
- "@chatbi-v/core": "^2.1.0",
24
+ "@chatbi-v/core": "^2.1.2",
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.1.0",
31
- "@chatbi-v/tsconfig": "^2.1.0",
30
+ "@chatbi-v/core": "^2.1.2",
31
+ "@chatbi-v/config": "^2.1.2",
32
32
  "tsup": "^8.5.1",
33
33
  "vite": "^5.0.0"
34
34
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "{{tsconfigPath}}",
2
+ "extends": "@chatbi-v/config/base.json",
3
3
  "compilerOptions": {
4
4
  "outDir": "./dist",
5
5
  "rootDir": "./src",