@chatbi-v/cli 1.0.10 → 1.0.11
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 +277 -378
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -4660,7 +4660,7 @@ var require_lib = __commonJS({
|
|
|
4660
4660
|
});
|
|
4661
4661
|
|
|
4662
4662
|
// src/utils.ts
|
|
4663
|
-
var import_path2, import_module, import_url, import_fs_extra2, import_meta, _require, _filename, _dirname, findPackageRoot, getCliRoot;
|
|
4663
|
+
var import_path2, import_module, import_url, import_fs_extra2, import_child_process, import_meta, _require, _filename, _dirname, workspacePackagesCache, getWorkspacePackages, findPackageRoot, getCliRoot;
|
|
4664
4664
|
var init_utils2 = __esm({
|
|
4665
4665
|
"src/utils.ts"() {
|
|
4666
4666
|
"use strict";
|
|
@@ -4668,20 +4668,30 @@ var init_utils2 = __esm({
|
|
|
4668
4668
|
import_module = require("module");
|
|
4669
4669
|
import_url = require("url");
|
|
4670
4670
|
import_fs_extra2 = __toESM(require_lib());
|
|
4671
|
+
import_child_process = require("child_process");
|
|
4671
4672
|
import_meta = {};
|
|
4672
4673
|
_require = typeof require !== "undefined" ? require : (0, import_module.createRequire)(import_meta.url);
|
|
4673
4674
|
_filename = typeof __filename !== "undefined" ? __filename : (0, import_url.fileURLToPath)(import_meta.url);
|
|
4674
4675
|
_dirname = typeof __dirname !== "undefined" ? __dirname : import_path2.default.dirname(_filename);
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4676
|
+
workspacePackagesCache = null;
|
|
4677
|
+
getWorkspacePackages = () => {
|
|
4678
|
+
if (workspacePackagesCache) return workspacePackagesCache;
|
|
4679
|
+
try {
|
|
4680
|
+
const output = (0, import_child_process.execSync)("pnpm m ls --depth -1 --json", { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
4681
|
+
const packages = JSON.parse(output);
|
|
4682
|
+
workspacePackagesCache = {};
|
|
4683
|
+
for (const pkg of packages) {
|
|
4684
|
+
workspacePackagesCache[pkg.name] = pkg.path;
|
|
4685
|
+
}
|
|
4686
|
+
return workspacePackagesCache;
|
|
4687
|
+
} catch (e) {
|
|
4688
|
+
return {};
|
|
4681
4689
|
}
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4690
|
+
};
|
|
4691
|
+
findPackageRoot = (pkgName) => {
|
|
4692
|
+
const workspacePkgs = getWorkspacePackages();
|
|
4693
|
+
if (workspacePkgs[pkgName]) {
|
|
4694
|
+
return workspacePkgs[pkgName];
|
|
4685
4695
|
}
|
|
4686
4696
|
try {
|
|
4687
4697
|
const pkgPath = _require.resolve(`${pkgName}/package.json`);
|
|
@@ -4718,6 +4728,262 @@ var init_utils2 = __esm({
|
|
|
4718
4728
|
}
|
|
4719
4729
|
});
|
|
4720
4730
|
|
|
4731
|
+
// src/sandbox.ts
|
|
4732
|
+
var import_fs_extra3, import_path3, import_os, import_picocolors2, Sandbox;
|
|
4733
|
+
var init_sandbox = __esm({
|
|
4734
|
+
"src/sandbox.ts"() {
|
|
4735
|
+
"use strict";
|
|
4736
|
+
import_fs_extra3 = __toESM(require_lib());
|
|
4737
|
+
import_path3 = __toESM(require("path"));
|
|
4738
|
+
import_os = __toESM(require("os"));
|
|
4739
|
+
import_picocolors2 = __toESM(require_picocolors());
|
|
4740
|
+
init_utils2();
|
|
4741
|
+
Sandbox = class {
|
|
4742
|
+
static BASE_DIR = import_path3.default.join(import_os.default.homedir(), ".chatbi-v-core");
|
|
4743
|
+
/**
|
|
4744
|
+
* 获取沙箱根目录
|
|
4745
|
+
*/
|
|
4746
|
+
static getRoot() {
|
|
4747
|
+
return this.BASE_DIR;
|
|
4748
|
+
}
|
|
4749
|
+
/**
|
|
4750
|
+
* 获取特定版本的内核路径
|
|
4751
|
+
*/
|
|
4752
|
+
static getVersionPath(version) {
|
|
4753
|
+
return import_path3.default.join(this.BASE_DIR, "versions", version);
|
|
4754
|
+
}
|
|
4755
|
+
/**
|
|
4756
|
+
* 确保沙箱目录存在
|
|
4757
|
+
*/
|
|
4758
|
+
static async ensureDir() {
|
|
4759
|
+
await import_fs_extra3.default.ensureDir(this.BASE_DIR);
|
|
4760
|
+
await import_fs_extra3.default.ensureDir(import_path3.default.join(this.BASE_DIR, "versions"));
|
|
4761
|
+
}
|
|
4762
|
+
/**
|
|
4763
|
+
* 将 Shell 模板同步到沙箱
|
|
4764
|
+
*/
|
|
4765
|
+
static async syncShellToSandbox(version, force = false) {
|
|
4766
|
+
const versionPath = this.getVersionPath(version);
|
|
4767
|
+
await import_fs_extra3.default.ensureDir(versionPath);
|
|
4768
|
+
const cliRoot = await getCliRoot();
|
|
4769
|
+
const shellTemplateDir = import_path3.default.join(cliRoot, "templates", "app");
|
|
4770
|
+
const shellDestDir = import_path3.default.join(versionPath, "shell");
|
|
4771
|
+
if (import_fs_extra3.default.existsSync(shellTemplateDir) && (!import_fs_extra3.default.existsSync(shellDestDir) || force)) {
|
|
4772
|
+
await import_fs_extra3.default.remove(shellDestDir);
|
|
4773
|
+
await import_fs_extra3.default.copy(shellTemplateDir, shellDestDir);
|
|
4774
|
+
}
|
|
4775
|
+
}
|
|
4776
|
+
/**
|
|
4777
|
+
* 将内核代码同步到沙箱
|
|
4778
|
+
* @param version 版本号
|
|
4779
|
+
* @param force 是否强制覆盖
|
|
4780
|
+
*/
|
|
4781
|
+
static async syncCoreToSandbox(version, force = false) {
|
|
4782
|
+
const versionPath = this.getVersionPath(version);
|
|
4783
|
+
if (import_fs_extra3.default.existsSync(versionPath) && !force) {
|
|
4784
|
+
await this.syncShellToSandbox(version, force);
|
|
4785
|
+
return versionPath;
|
|
4786
|
+
}
|
|
4787
|
+
await import_fs_extra3.default.ensureDir(versionPath);
|
|
4788
|
+
console.log(import_picocolors2.default.cyan(`\u{1F4E6} \u6B63\u5728\u6784\u5EFA\u5185\u6838\u6C99\u7BB1 ${version} (\u6765\u6E90: local)...`));
|
|
4789
|
+
const workspacePkgs = getWorkspacePackages();
|
|
4790
|
+
const corePackages = [
|
|
4791
|
+
"@chatbi-v/core",
|
|
4792
|
+
"@chatbi-v/mocks",
|
|
4793
|
+
"@chatbi-v/tsconfig",
|
|
4794
|
+
"@chatbi-v/tailwind-config",
|
|
4795
|
+
"@chatbi-v/plugin-theme-manager",
|
|
4796
|
+
"@chatbi-v/plugin-layout-transform",
|
|
4797
|
+
"@chatbi-v/plugin-system-monitor"
|
|
4798
|
+
];
|
|
4799
|
+
const rootPkgJson = {
|
|
4800
|
+
name: `chatbi-sandbox-${version}`,
|
|
4801
|
+
private: true,
|
|
4802
|
+
dependencies: {},
|
|
4803
|
+
devDependencies: {
|
|
4804
|
+
"tailwindcss": "^3.4.1",
|
|
4805
|
+
"autoprefixer": "^10.4.17",
|
|
4806
|
+
"postcss": "^8.4.35",
|
|
4807
|
+
"vite": "^5.0.8",
|
|
4808
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
4809
|
+
"typescript": "^5.3.3"
|
|
4810
|
+
}
|
|
4811
|
+
};
|
|
4812
|
+
for (const pkgName of corePackages) {
|
|
4813
|
+
if (workspacePkgs[pkgName]) {
|
|
4814
|
+
rootPkgJson.dependencies[pkgName] = `link:${workspacePkgs[pkgName]}`;
|
|
4815
|
+
} else {
|
|
4816
|
+
console.warn(import_picocolors2.default.yellow(` ! \u8B66\u544A: \u5DE5\u4F5C\u533A\u4E2D\u672A\u627E\u5230 ${pkgName}\uFF0C\u5C06\u5C1D\u8BD5\u4ECE npm \u5B89\u88C5`));
|
|
4817
|
+
rootPkgJson.dependencies[pkgName] = "*";
|
|
4818
|
+
}
|
|
4819
|
+
}
|
|
4820
|
+
await import_fs_extra3.default.writeJson(import_path3.default.join(versionPath, "package.json"), rootPkgJson, { spaces: 2 });
|
|
4821
|
+
await import_fs_extra3.default.writeFile(import_path3.default.join(versionPath, ".npmrc"), "shamefully-hoist=true\nauto-install-peers=true\n");
|
|
4822
|
+
await this.syncShellToSandbox(version, force);
|
|
4823
|
+
console.log(import_picocolors2.default.green(`\u2705 \u5185\u6838\u6C99\u7BB1 ${version} \u5DF2\u5C31\u7EEA: ${versionPath}`));
|
|
4824
|
+
return versionPath;
|
|
4825
|
+
}
|
|
4826
|
+
/**
|
|
4827
|
+
* 将项目链接到沙箱内核
|
|
4828
|
+
* @param projectRoot 项目根目录
|
|
4829
|
+
* @param version 内核版本
|
|
4830
|
+
*/
|
|
4831
|
+
static async linkProject(projectRoot, version) {
|
|
4832
|
+
const chatbiLink = import_path3.default.join(projectRoot, ".chatbi");
|
|
4833
|
+
const versionPath = this.getVersionPath(version);
|
|
4834
|
+
if (!import_fs_extra3.default.existsSync(versionPath)) {
|
|
4835
|
+
await this.syncCoreToSandbox(version);
|
|
4836
|
+
}
|
|
4837
|
+
if (import_fs_extra3.default.existsSync(chatbiLink)) {
|
|
4838
|
+
const stats = await import_fs_extra3.default.lstat(chatbiLink);
|
|
4839
|
+
if (stats.isSymbolicLink() || stats.isDirectory()) {
|
|
4840
|
+
await import_fs_extra3.default.remove(chatbiLink);
|
|
4841
|
+
}
|
|
4842
|
+
}
|
|
4843
|
+
try {
|
|
4844
|
+
console.log(import_picocolors2.default.blue(`\u{1F4CB} \u6B63\u5728\u590D\u5236\u6C99\u7BB1\u5185\u6838\u5230\u672C\u5730: .chatbi -> ${versionPath}`));
|
|
4845
|
+
await import_fs_extra3.default.copy(versionPath, chatbiLink);
|
|
4846
|
+
} catch (e) {
|
|
4847
|
+
console.error(import_picocolors2.default.red(`\u274C \u590D\u5236\u6C99\u7BB1\u5931\u8D25:`), e);
|
|
4848
|
+
}
|
|
4849
|
+
await this.ensureGitignore(projectRoot);
|
|
4850
|
+
}
|
|
4851
|
+
/**
|
|
4852
|
+
* 确保项目拥有虚拟依赖环境
|
|
4853
|
+
* 生成 .chatbi/tsconfig.paths.json 供项目继承
|
|
4854
|
+
*/
|
|
4855
|
+
static async ensureVirtualContext(projectRoot, version) {
|
|
4856
|
+
const chatbiDir = import_path3.default.join(projectRoot, ".chatbi");
|
|
4857
|
+
await import_fs_extra3.default.ensureDir(chatbiDir);
|
|
4858
|
+
const versionPath = this.getVersionPath(version);
|
|
4859
|
+
const sandboxNodeModules = import_path3.default.join(versionPath, "node_modules");
|
|
4860
|
+
const paths = {
|
|
4861
|
+
"@chatbi-v/core": [import_path3.default.join(sandboxNodeModules, "@chatbi-v/core")],
|
|
4862
|
+
"@chatbi-v/core/*": [import_path3.default.join(sandboxNodeModules, "@chatbi-v/core/*")],
|
|
4863
|
+
"@chatbi-v/mocks": [import_path3.default.join(sandboxNodeModules, "@chatbi-v/mocks")],
|
|
4864
|
+
"@chatbi-v/plugin-theme-manager": [import_path3.default.join(sandboxNodeModules, "@chatbi-v/plugin-theme-manager")],
|
|
4865
|
+
"@chatbi-v/plugin-system-monitor": [import_path3.default.join(sandboxNodeModules, "@chatbi-v/plugin-system-monitor")]
|
|
4866
|
+
};
|
|
4867
|
+
const tsConfigPaths = {
|
|
4868
|
+
compilerOptions: {
|
|
4869
|
+
target: "ESNext",
|
|
4870
|
+
useDefineForClassFields: true,
|
|
4871
|
+
lib: ["DOM", "DOM.Iterable", "ESNext"],
|
|
4872
|
+
allowJs: false,
|
|
4873
|
+
skipLibCheck: true,
|
|
4874
|
+
esModuleInterop: true,
|
|
4875
|
+
allowSyntheticDefaultImports: true,
|
|
4876
|
+
strict: true,
|
|
4877
|
+
forceConsistentCasingInFileNames: true,
|
|
4878
|
+
module: "ESNext",
|
|
4879
|
+
moduleResolution: "bundler",
|
|
4880
|
+
resolveJsonModule: true,
|
|
4881
|
+
isolatedModules: true,
|
|
4882
|
+
noEmit: true,
|
|
4883
|
+
jsx: "react-jsx",
|
|
4884
|
+
baseUrl: ".",
|
|
4885
|
+
paths
|
|
4886
|
+
}
|
|
4887
|
+
};
|
|
4888
|
+
await import_fs_extra3.default.writeJson(import_path3.default.join(chatbiDir, "tsconfig.paths.json"), tsConfigPaths, { spaces: 2 });
|
|
4889
|
+
const coreDtsPath = import_path3.default.join(sandboxNodeModules, "@chatbi-v/core/dist/index.d.ts");
|
|
4890
|
+
const dtsContent = `/// <reference types="${coreDtsPath}" />
|
|
4891
|
+
`;
|
|
4892
|
+
await import_fs_extra3.default.writeFile(import_path3.default.join(chatbiDir, "env.d.ts"), dtsContent);
|
|
4893
|
+
await this.ensureGitignore(projectRoot);
|
|
4894
|
+
}
|
|
4895
|
+
/**
|
|
4896
|
+
* 获取核心库的 Vite Alias 配置
|
|
4897
|
+
*/
|
|
4898
|
+
static getCoreAlias(version) {
|
|
4899
|
+
const versionPath = this.getVersionPath(version);
|
|
4900
|
+
const sandboxNodeModules = import_path3.default.join(versionPath, "node_modules");
|
|
4901
|
+
return {
|
|
4902
|
+
"@chatbi-v/core": import_path3.default.join(sandboxNodeModules, "@chatbi-v/core"),
|
|
4903
|
+
"@chatbi-v/mocks": import_path3.default.join(sandboxNodeModules, "@chatbi-v/mocks"),
|
|
4904
|
+
"@chatbi-v/plugin-theme-manager": import_path3.default.join(sandboxNodeModules, "@chatbi-v/plugin-theme-manager"),
|
|
4905
|
+
"@chatbi-v/plugin-system-monitor": import_path3.default.join(sandboxNodeModules, "@chatbi-v/plugin-system-monitor")
|
|
4906
|
+
};
|
|
4907
|
+
}
|
|
4908
|
+
/**
|
|
4909
|
+
* 清理特定版本的沙箱
|
|
4910
|
+
* @param version 版本号
|
|
4911
|
+
*/
|
|
4912
|
+
static async cleanVersion(version) {
|
|
4913
|
+
const versionPath = this.getVersionPath(version);
|
|
4914
|
+
console.log(import_picocolors2.default.gray(` \u5220\u9664\u6C99\u7BB1\u76EE\u5F55: ${versionPath}`));
|
|
4915
|
+
await import_fs_extra3.default.remove(versionPath);
|
|
4916
|
+
}
|
|
4917
|
+
/**
|
|
4918
|
+
* 确保 .chatbi 被 git 忽略
|
|
4919
|
+
*/
|
|
4920
|
+
static async ensureGitignore(projectRoot) {
|
|
4921
|
+
const gitignorePath = import_path3.default.join(projectRoot, ".gitignore");
|
|
4922
|
+
if (import_fs_extra3.default.existsSync(gitignorePath)) {
|
|
4923
|
+
let content = await import_fs_extra3.default.readFile(gitignorePath, "utf-8");
|
|
4924
|
+
let modified = false;
|
|
4925
|
+
if (!content.includes(".chatbi")) {
|
|
4926
|
+
content += "\n\n# ChatBI Sandbox\n.chatbi\n";
|
|
4927
|
+
modified = true;
|
|
4928
|
+
}
|
|
4929
|
+
if (!content.includes(".chatbi-runtime")) {
|
|
4930
|
+
content += ".chatbi-runtime\n";
|
|
4931
|
+
modified = true;
|
|
4932
|
+
}
|
|
4933
|
+
if (modified) {
|
|
4934
|
+
await import_fs_extra3.default.writeFile(gitignorePath, content);
|
|
4935
|
+
}
|
|
4936
|
+
}
|
|
4937
|
+
}
|
|
4938
|
+
};
|
|
4939
|
+
}
|
|
4940
|
+
});
|
|
4941
|
+
|
|
4942
|
+
// src/config.ts
|
|
4943
|
+
var import_fs_extra4, import_path4, import_picocolors3, import_jiti, ConfigManager;
|
|
4944
|
+
var init_config = __esm({
|
|
4945
|
+
"src/config.ts"() {
|
|
4946
|
+
"use strict";
|
|
4947
|
+
import_fs_extra4 = __toESM(require_lib());
|
|
4948
|
+
import_path4 = __toESM(require("path"));
|
|
4949
|
+
import_picocolors3 = __toESM(require_picocolors());
|
|
4950
|
+
import_jiti = require("jiti");
|
|
4951
|
+
ConfigManager = class {
|
|
4952
|
+
static CONFIG_FILES = [
|
|
4953
|
+
"chatbi.config.ts",
|
|
4954
|
+
"chatbi.config.js",
|
|
4955
|
+
"chatbi.config.json",
|
|
4956
|
+
".chatbirc",
|
|
4957
|
+
".chatbirc.json"
|
|
4958
|
+
];
|
|
4959
|
+
/**
|
|
4960
|
+
* 加载项目配置
|
|
4961
|
+
* @param cwd 项目根目录
|
|
4962
|
+
*/
|
|
4963
|
+
static async loadConfig(cwd = process.cwd()) {
|
|
4964
|
+
const jiti = (0, import_jiti.createJiti)(cwd);
|
|
4965
|
+
for (const file of this.CONFIG_FILES) {
|
|
4966
|
+
const configPath = import_path4.default.join(cwd, file);
|
|
4967
|
+
if (import_fs_extra4.default.existsSync(configPath)) {
|
|
4968
|
+
try {
|
|
4969
|
+
if (file.endsWith(".ts") || file.endsWith(".js")) {
|
|
4970
|
+
const mod = await jiti.import(configPath, { default: true });
|
|
4971
|
+
return mod.default || mod || {};
|
|
4972
|
+
}
|
|
4973
|
+
if (file.endsWith(".json") || file.startsWith(".chatbirc")) {
|
|
4974
|
+
return await import_fs_extra4.default.readJson(configPath);
|
|
4975
|
+
}
|
|
4976
|
+
} catch (e) {
|
|
4977
|
+
console.error(import_picocolors3.default.red(`\u274C \u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6 ${file} \u5931\u8D25:`), e);
|
|
4978
|
+
}
|
|
4979
|
+
}
|
|
4980
|
+
}
|
|
4981
|
+
return {};
|
|
4982
|
+
}
|
|
4983
|
+
};
|
|
4984
|
+
}
|
|
4985
|
+
});
|
|
4986
|
+
|
|
4721
4987
|
// ../../../node_modules/.pnpm/handlebars@4.7.8/node_modules/handlebars/dist/cjs/handlebars/utils.js
|
|
4722
4988
|
var require_utils3 = __commonJS({
|
|
4723
4989
|
"../../../node_modules/.pnpm/handlebars@4.7.8/node_modules/handlebars/dist/cjs/handlebars/utils.js"(exports2) {
|
|
@@ -10566,373 +10832,6 @@ var require_lib2 = __commonJS({
|
|
|
10566
10832
|
}
|
|
10567
10833
|
});
|
|
10568
10834
|
|
|
10569
|
-
// src/sandbox.ts
|
|
10570
|
-
var import_fs_extra3, import_path3, import_os, import_picocolors2, Sandbox;
|
|
10571
|
-
var init_sandbox = __esm({
|
|
10572
|
-
"src/sandbox.ts"() {
|
|
10573
|
-
"use strict";
|
|
10574
|
-
import_fs_extra3 = __toESM(require_lib());
|
|
10575
|
-
import_path3 = __toESM(require("path"));
|
|
10576
|
-
import_os = __toESM(require("os"));
|
|
10577
|
-
import_picocolors2 = __toESM(require_picocolors());
|
|
10578
|
-
init_utils2();
|
|
10579
|
-
Sandbox = class {
|
|
10580
|
-
static BASE_DIR = import_path3.default.join(import_os.default.homedir(), ".chatbi-v-core");
|
|
10581
|
-
/**
|
|
10582
|
-
* 获取沙箱根目录
|
|
10583
|
-
*/
|
|
10584
|
-
static getRoot() {
|
|
10585
|
-
return this.BASE_DIR;
|
|
10586
|
-
}
|
|
10587
|
-
/**
|
|
10588
|
-
* 获取特定版本的内核路径
|
|
10589
|
-
*/
|
|
10590
|
-
static getVersionPath(version) {
|
|
10591
|
-
return import_path3.default.join(this.BASE_DIR, "versions", version);
|
|
10592
|
-
}
|
|
10593
|
-
/**
|
|
10594
|
-
* 确保沙箱目录存在
|
|
10595
|
-
*/
|
|
10596
|
-
static async ensureDir() {
|
|
10597
|
-
await import_fs_extra3.default.ensureDir(this.BASE_DIR);
|
|
10598
|
-
await import_fs_extra3.default.ensureDir(import_path3.default.join(this.BASE_DIR, "versions"));
|
|
10599
|
-
}
|
|
10600
|
-
/**
|
|
10601
|
-
* 将 Shell 模板同步到沙箱
|
|
10602
|
-
*/
|
|
10603
|
-
static async syncShellToSandbox(version, force = false) {
|
|
10604
|
-
const versionPath = this.getVersionPath(version);
|
|
10605
|
-
await import_fs_extra3.default.ensureDir(versionPath);
|
|
10606
|
-
const cliRoot = await getCliRoot();
|
|
10607
|
-
const shellTemplateDir = import_path3.default.join(cliRoot, "templates", "app");
|
|
10608
|
-
const shellDestDir = import_path3.default.join(versionPath, "shell");
|
|
10609
|
-
if (import_fs_extra3.default.existsSync(shellTemplateDir) && (!import_fs_extra3.default.existsSync(shellDestDir) || force)) {
|
|
10610
|
-
await import_fs_extra3.default.remove(shellDestDir);
|
|
10611
|
-
await import_fs_extra3.default.copy(shellTemplateDir, shellDestDir);
|
|
10612
|
-
const templateData = {
|
|
10613
|
-
name: "chatbi-shell-runtime",
|
|
10614
|
-
projectName: "chatbi-shell",
|
|
10615
|
-
isApp: true,
|
|
10616
|
-
theme: "standard",
|
|
10617
|
-
isNebula: false,
|
|
10618
|
-
isGlass: false,
|
|
10619
|
-
corePath: "file:../core"
|
|
10620
|
-
};
|
|
10621
|
-
const processFiles = async (dir) => {
|
|
10622
|
-
const files = await import_fs_extra3.default.readdir(dir);
|
|
10623
|
-
for (const file of files) {
|
|
10624
|
-
const filePath = import_path3.default.join(dir, file);
|
|
10625
|
-
const stats = await import_fs_extra3.default.stat(filePath);
|
|
10626
|
-
if (stats.isDirectory()) {
|
|
10627
|
-
await processFiles(filePath);
|
|
10628
|
-
} else if (file.endsWith(".hbs")) {
|
|
10629
|
-
const content = await import_fs_extra3.default.readFile(filePath, "utf-8");
|
|
10630
|
-
let result = content;
|
|
10631
|
-
if (content.includes("{{")) {
|
|
10632
|
-
const Handlebars3 = (await Promise.resolve().then(() => __toESM(require_lib2()))).default;
|
|
10633
|
-
try {
|
|
10634
|
-
const template = Handlebars3.compile(content);
|
|
10635
|
-
result = template(templateData);
|
|
10636
|
-
} catch (e) {
|
|
10637
|
-
}
|
|
10638
|
-
}
|
|
10639
|
-
await import_fs_extra3.default.writeFile(filePath.replace(/\.hbs$/, ""), result);
|
|
10640
|
-
await import_fs_extra3.default.remove(filePath);
|
|
10641
|
-
}
|
|
10642
|
-
}
|
|
10643
|
-
};
|
|
10644
|
-
await processFiles(shellDestDir);
|
|
10645
|
-
const pkgJsonPath = import_path3.default.join(shellDestDir, "package.json");
|
|
10646
|
-
if (import_fs_extra3.default.existsSync(pkgJsonPath)) {
|
|
10647
|
-
const pkgJson = await import_fs_extra3.default.readJson(pkgJsonPath);
|
|
10648
|
-
const fixPath = (deps = {}) => {
|
|
10649
|
-
for (const key in deps) {
|
|
10650
|
-
if (deps[key].startsWith("file:.chatbi/")) {
|
|
10651
|
-
deps[key] = deps[key].replace("file:.chatbi/", "file:../");
|
|
10652
|
-
}
|
|
10653
|
-
}
|
|
10654
|
-
};
|
|
10655
|
-
fixPath(pkgJson.dependencies);
|
|
10656
|
-
fixPath(pkgJson.devDependencies);
|
|
10657
|
-
await import_fs_extra3.default.writeJson(pkgJsonPath, pkgJson, { spaces: 2 });
|
|
10658
|
-
}
|
|
10659
|
-
await import_fs_extra3.default.writeFile(import_path3.default.join(shellDestDir, ".needs-install"), "true");
|
|
10660
|
-
}
|
|
10661
|
-
}
|
|
10662
|
-
/**
|
|
10663
|
-
* 将内核代码同步到沙箱
|
|
10664
|
-
* @param version 版本号
|
|
10665
|
-
* @param force 是否强制覆盖
|
|
10666
|
-
*/
|
|
10667
|
-
static async syncCoreToSandbox(version, force = false) {
|
|
10668
|
-
const versionPath = this.getVersionPath(version);
|
|
10669
|
-
if (import_fs_extra3.default.existsSync(versionPath) && !force) {
|
|
10670
|
-
await this.syncShellToSandbox(version, force);
|
|
10671
|
-
return versionPath;
|
|
10672
|
-
}
|
|
10673
|
-
await import_fs_extra3.default.ensureDir(versionPath);
|
|
10674
|
-
console.log(import_picocolors2.default.cyan(`\u{1F4E6} \u6B63\u5728\u540C\u6B65\u5185\u6838\u7248\u672C ${version} \u5230\u6C99\u7BB1...`));
|
|
10675
|
-
const packagesToSync = [
|
|
10676
|
-
{ name: "@chatbi-v/core", dest: "core" },
|
|
10677
|
-
{ name: "@chatbi-v/mocks", dest: "mocks" },
|
|
10678
|
-
{ name: "@chatbi-v/tsconfig", dest: "tsconfig" },
|
|
10679
|
-
{ name: "@chatbi-v/tailwind-config", dest: "tailwind-config" },
|
|
10680
|
-
{ name: "@chatbi-v/plugin-theme-manager", dest: "plugin-theme-manager" },
|
|
10681
|
-
{ name: "@chatbi-v/plugin-layout-transform", dest: "plugin-layout-transform" },
|
|
10682
|
-
{ name: "@chatbi-v/plugin-system-monitor", dest: "plugin-system-monitor" }
|
|
10683
|
-
];
|
|
10684
|
-
const cliRoot = await getCliRoot();
|
|
10685
|
-
for (const p of packagesToSync) {
|
|
10686
|
-
try {
|
|
10687
|
-
const pkgRoot = findPackageRoot(p.name);
|
|
10688
|
-
const targetDir = import_path3.default.join(versionPath, p.dest);
|
|
10689
|
-
await import_fs_extra3.default.remove(targetDir);
|
|
10690
|
-
await import_fs_extra3.default.ensureDir(targetDir);
|
|
10691
|
-
if (p.name.includes("tsconfig")) {
|
|
10692
|
-
await import_fs_extra3.default.copy(pkgRoot, targetDir, {
|
|
10693
|
-
filter: (src) => !src.includes("node_modules")
|
|
10694
|
-
});
|
|
10695
|
-
} else {
|
|
10696
|
-
const distPath = import_path3.default.join(pkgRoot, "dist");
|
|
10697
|
-
if (import_fs_extra3.default.existsSync(distPath)) {
|
|
10698
|
-
await import_fs_extra3.default.copy(distPath, import_path3.default.join(targetDir, "dist"));
|
|
10699
|
-
} else {
|
|
10700
|
-
const indexPath = import_path3.default.join(pkgRoot, "index.js");
|
|
10701
|
-
if (import_fs_extra3.default.existsSync(indexPath)) await import_fs_extra3.default.copy(indexPath, import_path3.default.join(targetDir, "index.js"));
|
|
10702
|
-
const indexTsPath = import_path3.default.join(pkgRoot, "index.ts");
|
|
10703
|
-
if (import_fs_extra3.default.existsSync(indexTsPath)) await import_fs_extra3.default.copy(indexTsPath, import_path3.default.join(targetDir, "index.ts"));
|
|
10704
|
-
}
|
|
10705
|
-
const pkgJsonPath = import_path3.default.join(pkgRoot, "package.json");
|
|
10706
|
-
const pkgJson = await import_fs_extra3.default.readJson(pkgJsonPath);
|
|
10707
|
-
const processDeps = (deps = {}) => {
|
|
10708
|
-
for (const [name, depVersion] of Object.entries(deps)) {
|
|
10709
|
-
if (depVersion.startsWith("workspace:")) {
|
|
10710
|
-
const targetPkg = packagesToSync.find((tp) => tp.name === name);
|
|
10711
|
-
if (targetPkg) {
|
|
10712
|
-
const relPath = import_path3.default.relative(targetDir, import_path3.default.join(versionPath, targetPkg.dest));
|
|
10713
|
-
deps[name] = `file:${relPath}`;
|
|
10714
|
-
}
|
|
10715
|
-
}
|
|
10716
|
-
}
|
|
10717
|
-
};
|
|
10718
|
-
const processPeerDeps = (deps = {}) => {
|
|
10719
|
-
for (const name of Object.keys(deps)) {
|
|
10720
|
-
if (name === "@chatbi-v/core" || name.startsWith("@chatbi-v/plugin-")) {
|
|
10721
|
-
deps[name] = "*";
|
|
10722
|
-
}
|
|
10723
|
-
if (name === "@chatbi-v/cli") {
|
|
10724
|
-
delete deps[name];
|
|
10725
|
-
}
|
|
10726
|
-
}
|
|
10727
|
-
};
|
|
10728
|
-
processDeps(pkgJson.dependencies);
|
|
10729
|
-
processPeerDeps(pkgJson.peerDependencies);
|
|
10730
|
-
processDeps(pkgJson.devDependencies);
|
|
10731
|
-
if (pkgJson.devDependencies && pkgJson.devDependencies["@chatbi-v/cli"]) {
|
|
10732
|
-
delete pkgJson.devDependencies["@chatbi-v/cli"];
|
|
10733
|
-
}
|
|
10734
|
-
if (p.name === "@chatbi-v/core") {
|
|
10735
|
-
if (pkgJson.dependencies) {
|
|
10736
|
-
}
|
|
10737
|
-
}
|
|
10738
|
-
await import_fs_extra3.default.writeJson(import_path3.default.join(targetDir, "package.json"), pkgJson, { spaces: 2 });
|
|
10739
|
-
}
|
|
10740
|
-
} catch (e) {
|
|
10741
|
-
console.warn(import_picocolors2.default.yellow(` ! \u65E0\u6CD5\u540C\u6B65 ${p.name}: ${e instanceof Error ? e.message : String(e)}`));
|
|
10742
|
-
}
|
|
10743
|
-
}
|
|
10744
|
-
await this.syncShellToSandbox(version, force);
|
|
10745
|
-
await import_fs_extra3.default.writeFile(import_path3.default.join(versionPath, "pnpm-workspace.yaml"), 'packages:\n - "*"\n');
|
|
10746
|
-
const rootPkgJson = {
|
|
10747
|
-
name: "chatbi-sandbox-root",
|
|
10748
|
-
private: true,
|
|
10749
|
-
devDependencies: {
|
|
10750
|
-
"tailwindcss": "^3.4.1",
|
|
10751
|
-
"autoprefixer": "^10.4.17",
|
|
10752
|
-
"postcss": "^8.4.35",
|
|
10753
|
-
"vite": "^5.0.8",
|
|
10754
|
-
"@vitejs/plugin-react": "^4.2.1",
|
|
10755
|
-
"typescript": "^5.3.3"
|
|
10756
|
-
}
|
|
10757
|
-
};
|
|
10758
|
-
await import_fs_extra3.default.writeJson(import_path3.default.join(versionPath, "package.json"), rootPkgJson, { spaces: 2 });
|
|
10759
|
-
await import_fs_extra3.default.writeFile(import_path3.default.join(versionPath, ".npmrc"), "shamefully-hoist=true\nauto-install-peers=true\n");
|
|
10760
|
-
const sandboxNodeModules = import_path3.default.join(versionPath, "node_modules");
|
|
10761
|
-
await import_fs_extra3.default.ensureDir(sandboxNodeModules);
|
|
10762
|
-
const scopeDir = import_path3.default.join(sandboxNodeModules, "@chatbi-v");
|
|
10763
|
-
await import_fs_extra3.default.ensureDir(scopeDir);
|
|
10764
|
-
for (const p of packagesToSync) {
|
|
10765
|
-
const targetLink = import_path3.default.join(sandboxNodeModules, p.name);
|
|
10766
|
-
const sourceDir = import_path3.default.join(versionPath, p.dest);
|
|
10767
|
-
if (!import_fs_extra3.default.existsSync(targetLink)) {
|
|
10768
|
-
try {
|
|
10769
|
-
await import_fs_extra3.default.ensureSymlink(sourceDir, targetLink);
|
|
10770
|
-
} catch (e) {
|
|
10771
|
-
}
|
|
10772
|
-
}
|
|
10773
|
-
}
|
|
10774
|
-
console.log(import_picocolors2.default.green(`\u2705 \u5185\u6838\u7248\u672C ${version} \u5DF2\u5C31\u7EEA: ${versionPath}`));
|
|
10775
|
-
return versionPath;
|
|
10776
|
-
}
|
|
10777
|
-
/**
|
|
10778
|
-
* 将项目链接到沙箱内核
|
|
10779
|
-
* @param projectRoot 项目根目录
|
|
10780
|
-
* @param version 内核版本
|
|
10781
|
-
*/
|
|
10782
|
-
static async linkProject(projectRoot, version) {
|
|
10783
|
-
const chatbiLink = import_path3.default.join(projectRoot, ".chatbi");
|
|
10784
|
-
const versionPath = this.getVersionPath(version);
|
|
10785
|
-
if (!import_fs_extra3.default.existsSync(versionPath)) {
|
|
10786
|
-
await this.syncCoreToSandbox(version);
|
|
10787
|
-
}
|
|
10788
|
-
if (import_fs_extra3.default.existsSync(chatbiLink)) {
|
|
10789
|
-
const stats = await import_fs_extra3.default.lstat(chatbiLink);
|
|
10790
|
-
if (stats.isSymbolicLink() || stats.isDirectory()) {
|
|
10791
|
-
await import_fs_extra3.default.remove(chatbiLink);
|
|
10792
|
-
}
|
|
10793
|
-
}
|
|
10794
|
-
try {
|
|
10795
|
-
console.log(import_picocolors2.default.blue(`\u{1F4CB} \u6B63\u5728\u590D\u5236\u6C99\u7BB1\u5185\u6838\u5230\u672C\u5730: .chatbi -> ${versionPath}`));
|
|
10796
|
-
await import_fs_extra3.default.copy(versionPath, chatbiLink);
|
|
10797
|
-
} catch (e) {
|
|
10798
|
-
console.error(import_picocolors2.default.red(`\u274C \u590D\u5236\u6C99\u7BB1\u5931\u8D25:`), e);
|
|
10799
|
-
}
|
|
10800
|
-
await this.ensureGitignore(projectRoot);
|
|
10801
|
-
}
|
|
10802
|
-
/**
|
|
10803
|
-
* 确保项目拥有虚拟依赖环境
|
|
10804
|
-
* 生成 .chatbi/tsconfig.paths.json 供项目继承
|
|
10805
|
-
*/
|
|
10806
|
-
static async ensureVirtualContext(projectRoot, version) {
|
|
10807
|
-
const chatbiDir = import_path3.default.join(projectRoot, ".chatbi");
|
|
10808
|
-
await import_fs_extra3.default.ensureDir(chatbiDir);
|
|
10809
|
-
const versionPath = this.getVersionPath(version);
|
|
10810
|
-
const paths = {
|
|
10811
|
-
"@chatbi-v/core": [import_path3.default.join(versionPath, "core")],
|
|
10812
|
-
"@chatbi-v/core/*": [import_path3.default.join(versionPath, "core/*")],
|
|
10813
|
-
// 可以在此添加其他核心库的映射
|
|
10814
|
-
"@chatbi-v/mocks": [import_path3.default.join(versionPath, "mocks")],
|
|
10815
|
-
"@chatbi-v/plugin-theme-manager": [import_path3.default.join(versionPath, "plugin-theme-manager")],
|
|
10816
|
-
"@chatbi-v/plugin-system-monitor": [import_path3.default.join(versionPath, "plugin-system-monitor")]
|
|
10817
|
-
};
|
|
10818
|
-
const tsConfigPaths = {
|
|
10819
|
-
compilerOptions: {
|
|
10820
|
-
target: "ESNext",
|
|
10821
|
-
useDefineForClassFields: true,
|
|
10822
|
-
lib: ["DOM", "DOM.Iterable", "ESNext"],
|
|
10823
|
-
allowJs: false,
|
|
10824
|
-
skipLibCheck: true,
|
|
10825
|
-
esModuleInterop: true,
|
|
10826
|
-
allowSyntheticDefaultImports: true,
|
|
10827
|
-
strict: true,
|
|
10828
|
-
forceConsistentCasingInFileNames: true,
|
|
10829
|
-
module: "ESNext",
|
|
10830
|
-
moduleResolution: "bundler",
|
|
10831
|
-
resolveJsonModule: true,
|
|
10832
|
-
isolatedModules: true,
|
|
10833
|
-
noEmit: true,
|
|
10834
|
-
jsx: "react-jsx",
|
|
10835
|
-
baseUrl: ".",
|
|
10836
|
-
paths
|
|
10837
|
-
}
|
|
10838
|
-
};
|
|
10839
|
-
await import_fs_extra3.default.writeJson(import_path3.default.join(chatbiDir, "tsconfig.paths.json"), tsConfigPaths, { spaces: 2 });
|
|
10840
|
-
const dtsContent = `/// <reference types="${import_path3.default.join(versionPath, "core/dist/index.d.ts")}" />
|
|
10841
|
-
`;
|
|
10842
|
-
await import_fs_extra3.default.writeFile(import_path3.default.join(chatbiDir, "env.d.ts"), dtsContent);
|
|
10843
|
-
await this.ensureGitignore(projectRoot);
|
|
10844
|
-
}
|
|
10845
|
-
/**
|
|
10846
|
-
* 获取核心库的 Vite Alias 配置
|
|
10847
|
-
*/
|
|
10848
|
-
static getCoreAlias(version) {
|
|
10849
|
-
const versionPath = this.getVersionPath(version);
|
|
10850
|
-
return {
|
|
10851
|
-
"@chatbi-v/core": import_path3.default.join(versionPath, "core"),
|
|
10852
|
-
"@chatbi-v/mocks": import_path3.default.join(versionPath, "mocks"),
|
|
10853
|
-
"@chatbi-v/plugin-theme-manager": import_path3.default.join(versionPath, "plugin-theme-manager"),
|
|
10854
|
-
"@chatbi-v/plugin-system-monitor": import_path3.default.join(versionPath, "plugin-system-monitor")
|
|
10855
|
-
};
|
|
10856
|
-
}
|
|
10857
|
-
/**
|
|
10858
|
-
* 清理特定版本的沙箱
|
|
10859
|
-
* @param version 版本号
|
|
10860
|
-
*/
|
|
10861
|
-
static async cleanVersion(version) {
|
|
10862
|
-
const versionPath = this.getVersionPath(version);
|
|
10863
|
-
console.log(import_picocolors2.default.gray(` \u5220\u9664\u6C99\u7BB1\u76EE\u5F55: ${versionPath}`));
|
|
10864
|
-
await import_fs_extra3.default.remove(versionPath);
|
|
10865
|
-
}
|
|
10866
|
-
/**
|
|
10867
|
-
* 确保 .chatbi 被 git 忽略
|
|
10868
|
-
*/
|
|
10869
|
-
static async ensureGitignore(projectRoot) {
|
|
10870
|
-
const gitignorePath = import_path3.default.join(projectRoot, ".gitignore");
|
|
10871
|
-
if (import_fs_extra3.default.existsSync(gitignorePath)) {
|
|
10872
|
-
let content = await import_fs_extra3.default.readFile(gitignorePath, "utf-8");
|
|
10873
|
-
let modified = false;
|
|
10874
|
-
if (!content.includes(".chatbi")) {
|
|
10875
|
-
content += "\n\n# ChatBI Sandbox\n.chatbi\n";
|
|
10876
|
-
modified = true;
|
|
10877
|
-
}
|
|
10878
|
-
if (!content.includes(".chatbi-runtime")) {
|
|
10879
|
-
content += ".chatbi-runtime\n";
|
|
10880
|
-
modified = true;
|
|
10881
|
-
}
|
|
10882
|
-
if (modified) {
|
|
10883
|
-
await import_fs_extra3.default.writeFile(gitignorePath, content);
|
|
10884
|
-
}
|
|
10885
|
-
}
|
|
10886
|
-
}
|
|
10887
|
-
};
|
|
10888
|
-
}
|
|
10889
|
-
});
|
|
10890
|
-
|
|
10891
|
-
// src/config.ts
|
|
10892
|
-
var import_fs_extra4, import_path4, import_picocolors3, import_jiti, ConfigManager;
|
|
10893
|
-
var init_config = __esm({
|
|
10894
|
-
"src/config.ts"() {
|
|
10895
|
-
"use strict";
|
|
10896
|
-
import_fs_extra4 = __toESM(require_lib());
|
|
10897
|
-
import_path4 = __toESM(require("path"));
|
|
10898
|
-
import_picocolors3 = __toESM(require_picocolors());
|
|
10899
|
-
import_jiti = require("jiti");
|
|
10900
|
-
ConfigManager = class {
|
|
10901
|
-
static CONFIG_FILES = [
|
|
10902
|
-
"chatbi.config.ts",
|
|
10903
|
-
"chatbi.config.js",
|
|
10904
|
-
"chatbi.config.json",
|
|
10905
|
-
".chatbirc",
|
|
10906
|
-
".chatbirc.json"
|
|
10907
|
-
];
|
|
10908
|
-
/**
|
|
10909
|
-
* 加载项目配置
|
|
10910
|
-
* @param cwd 项目根目录
|
|
10911
|
-
*/
|
|
10912
|
-
static async loadConfig(cwd = process.cwd()) {
|
|
10913
|
-
const jiti = (0, import_jiti.createJiti)(cwd);
|
|
10914
|
-
for (const file of this.CONFIG_FILES) {
|
|
10915
|
-
const configPath = import_path4.default.join(cwd, file);
|
|
10916
|
-
if (import_fs_extra4.default.existsSync(configPath)) {
|
|
10917
|
-
try {
|
|
10918
|
-
if (file.endsWith(".ts") || file.endsWith(".js")) {
|
|
10919
|
-
const mod = await jiti.import(configPath, { default: true });
|
|
10920
|
-
return mod.default || mod || {};
|
|
10921
|
-
}
|
|
10922
|
-
if (file.endsWith(".json") || file.startsWith(".chatbirc")) {
|
|
10923
|
-
return await import_fs_extra4.default.readJson(configPath);
|
|
10924
|
-
}
|
|
10925
|
-
} catch (e) {
|
|
10926
|
-
console.error(import_picocolors3.default.red(`\u274C \u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6 ${file} \u5931\u8D25:`), e);
|
|
10927
|
-
}
|
|
10928
|
-
}
|
|
10929
|
-
}
|
|
10930
|
-
return {};
|
|
10931
|
-
}
|
|
10932
|
-
};
|
|
10933
|
-
}
|
|
10934
|
-
});
|
|
10935
|
-
|
|
10936
10835
|
// src/commands/sync.ts
|
|
10937
10836
|
var sync_exports = {};
|
|
10938
10837
|
__export(sync_exports, {
|
|
@@ -12663,7 +12562,7 @@ async function discover() {
|
|
|
12663
12562
|
// package.json
|
|
12664
12563
|
var package_default = {
|
|
12665
12564
|
name: "@chatbi-v/cli",
|
|
12666
|
-
version: "1.0.
|
|
12565
|
+
version: "1.0.11",
|
|
12667
12566
|
description: "Standardized CLI tooling for ChatBI Monorepo",
|
|
12668
12567
|
main: "dist/index.js",
|
|
12669
12568
|
bin: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatbi-v/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "Standardized CLI tooling for ChatBI Monorepo",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"tsup": "^8.5.1",
|
|
31
31
|
"typescript": "^5.0.0",
|
|
32
32
|
"vite": "^5.4.21",
|
|
33
|
-
"@chatbi-v/
|
|
33
|
+
"@chatbi-v/mocks": "2.0.0",
|
|
34
34
|
"@chatbi-v/plugin-system-monitor": "2.0.0",
|
|
35
|
-
"@chatbi-v/
|
|
36
|
-
"@chatbi-v/
|
|
35
|
+
"@chatbi-v/core": "2.0.0",
|
|
36
|
+
"@chatbi-v/plugin-theme-manager": "2.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/boxen": "^3.0.5",
|