@chatbi-v/cli 2.0.2 → 2.0.4
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/bin/chatbi-cli.js +1 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2464 -188
- package/package.json +6 -3
- package/templates/app/package.json.hbs +5 -2
- package/templates/plugin/package.json.hbs +5 -5
- package/templates/plugin/tsconfig.json.hbs +1 -1
- package/dist/bench-ACSHVGHE.mjs +0 -77
- package/dist/build-UB4D3WNI.mjs +0 -11
- package/dist/chunk-4OD6C56P.mjs +0 -89
- package/dist/chunk-7A54IJI5.mjs +0 -6368
- package/dist/chunk-LJFX6MNO.mjs +0 -255
- package/dist/chunk-SBGVKO4C.mjs +0 -2255
- package/dist/chunk-TX5M36S5.mjs +0 -55
- package/dist/chunk-V7IEPMC4.mjs +0 -52
- package/dist/chunk-WCPZB47I.mjs +0 -262
- package/dist/chunk-WIVHOK75.mjs +0 -5292
- package/dist/chunk-Y24V4GQG.mjs +0 -9577
- package/dist/commands/add.js +0 -182
- package/dist/commands/bench.js +0 -100
- package/dist/commands/build.js +0 -290
- package/dist/commands/dev.js +0 -8
- package/dist/commands/discover.js +0 -25
- package/dist/commands/doctor.js +0 -231
- package/dist/commands/fetch.js +0 -41
- package/dist/commands/gl.js +0 -151
- package/dist/commands/init.js +0 -253
- package/dist/commands/install.js +0 -85
- package/dist/commands/ls.js +0 -46
- package/dist/commands/sync.js +0 -78
- package/dist/commands/use.js +0 -31
- package/dist/config.js +0 -70
- package/dist/corekit.js +0 -370
- package/dist/execa-METROS6Z.mjs +0 -17
- package/dist/fetch-7X2UFWIV.mjs +0 -10
- package/dist/index.cjs +0 -27278
- package/dist/index.mjs +0 -2769
- package/dist/init-QFRFYEA5.mjs +0 -12
- package/dist/sandbox.js +0 -522
- package/dist/sync-7HPKGVFY.mjs +0 -11
- package/dist/utils.js +0 -99
package/dist/commands/init.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.init = init;
|
|
7
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
10
|
-
const handlebars_1 = __importDefault(require("handlebars"));
|
|
11
|
-
const prompts_1 = __importDefault(require("prompts"));
|
|
12
|
-
const utils_1 = require("../utils");
|
|
13
|
-
const sync_1 = require("./sync");
|
|
14
|
-
// ... (shims remain the same)
|
|
15
|
-
const _require = require;
|
|
16
|
-
const _filename = __filename;
|
|
17
|
-
const _dirname = __dirname;
|
|
18
|
-
async function init(options) {
|
|
19
|
-
let { name, template, pluginType = 'business', theme = 'standard', projectType, includeApp, includePlugin } = options;
|
|
20
|
-
// 1. 交互式获取信息
|
|
21
|
-
const response = await (0, prompts_1.default)([
|
|
22
|
-
// ... (prompts remain the same)
|
|
23
|
-
{
|
|
24
|
-
type: name ? null : 'text',
|
|
25
|
-
name: 'projectName',
|
|
26
|
-
message: '请输入项目名称:',
|
|
27
|
-
initial: 'my-chatbi-workspace',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
type: projectType ? null : 'select',
|
|
31
|
-
name: 'projectType',
|
|
32
|
-
message: '请选择项目类型:',
|
|
33
|
-
choices: [
|
|
34
|
-
{ title: 'Monorepo Workspace (完整工作空间)', value: 'monorepo', description: '包含 Apps 和 Plugins 的多包管理结构' },
|
|
35
|
-
{ title: 'Host App (独立宿主应用)', value: 'app', description: '独立的 ChatBI 应用框架' },
|
|
36
|
-
{ title: 'Plugin (独立插件)', value: 'plugin', description: '独立的业务或系统插件' },
|
|
37
|
-
],
|
|
38
|
-
initial: 0,
|
|
39
|
-
},
|
|
40
|
-
// Monorepo specific questions
|
|
41
|
-
{
|
|
42
|
-
type: (prev) => (projectType === 'monorepo' || prev === 'monorepo') && includeApp === undefined ? 'confirm' : null,
|
|
43
|
-
name: 'includeApp',
|
|
44
|
-
message: '是否初始化默认 Host App?',
|
|
45
|
-
initial: true
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
type: (prev) => (projectType === 'monorepo' || prev === 'monorepo') && includePlugin === undefined ? 'confirm' : null,
|
|
49
|
-
name: 'includePlugin',
|
|
50
|
-
message: '是否初始化示例 Plugin?',
|
|
51
|
-
initial: true
|
|
52
|
-
},
|
|
53
|
-
// Plugin specific questions
|
|
54
|
-
{
|
|
55
|
-
type: (prev, values) => ((projectType === 'plugin' || values.projectType === 'plugin') || (includePlugin || values.includePlugin)) && !pluginType ? 'select' : null,
|
|
56
|
-
name: 'pluginType',
|
|
57
|
-
message: '请选择插件类型:',
|
|
58
|
-
choices: [
|
|
59
|
-
{ title: 'Business (业务插件)', value: 'business', description: '侧重于业务逻辑和 UI 展示' },
|
|
60
|
-
{ title: 'System (系统插件)', value: 'system', description: '侧重于系统能力和底层扩展' },
|
|
61
|
-
],
|
|
62
|
-
initial: 0,
|
|
63
|
-
},
|
|
64
|
-
// Theme selection (for App)
|
|
65
|
-
{
|
|
66
|
-
type: (prev, values) => ((projectType === 'app' || values.projectType === 'app') || (includeApp || values.includeApp)) && !theme ? 'select' : null,
|
|
67
|
-
name: 'theme',
|
|
68
|
-
message: '请选择应用默认主题:',
|
|
69
|
-
choices: [
|
|
70
|
-
{ title: 'Standard (经典蓝)', value: 'standard' },
|
|
71
|
-
{ title: 'Nebula (星云紫)', value: 'nebula' },
|
|
72
|
-
{ title: 'Glass (毛玻璃)', value: 'glass' },
|
|
73
|
-
],
|
|
74
|
-
initial: 0,
|
|
75
|
-
}
|
|
76
|
-
], {
|
|
77
|
-
onCancel: () => {
|
|
78
|
-
utils_1.logger.warn('已取消初始化');
|
|
79
|
-
process.exit(0);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
name = name || response.projectName;
|
|
83
|
-
projectType = projectType || response.projectType || 'monorepo';
|
|
84
|
-
pluginType = pluginType || response.pluginType || pluginType;
|
|
85
|
-
theme = theme || response.theme || theme;
|
|
86
|
-
const finalIncludeApp = includeApp !== undefined ? includeApp : (response.includeApp !== undefined ? response.includeApp : true);
|
|
87
|
-
const finalIncludePlugin = includePlugin !== undefined ? includePlugin : (response.includePlugin !== undefined ? response.includePlugin : true);
|
|
88
|
-
const isAppIncluded = finalIncludeApp;
|
|
89
|
-
const isPluginIncluded = finalIncludePlugin;
|
|
90
|
-
const rootDir = process.cwd();
|
|
91
|
-
const targetDir = path_1.default.resolve(rootDir, name);
|
|
92
|
-
if (fs_extra_1.default.existsSync(targetDir)) {
|
|
93
|
-
utils_1.logger.error(`目录 ${name} 已存在。`);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
utils_1.logger.info(`正在初始化项目: ${picocolors_1.default.bold(name)}...`);
|
|
97
|
-
utils_1.logger.info(picocolors_1.default.gray(`类型: ${projectType} | 主题: ${theme || 'N/A'}`));
|
|
98
|
-
console.log('');
|
|
99
|
-
try {
|
|
100
|
-
const myCliRoot = await (0, utils_1.getCliRoot)();
|
|
101
|
-
const cliPkg = await fs_extra_1.default.readJson(path_1.default.join(myCliRoot, 'package.json'));
|
|
102
|
-
const cliVersion = cliPkg.version;
|
|
103
|
-
// 获取内核版本 (用于模板依赖)
|
|
104
|
-
let kernelVersion = cliVersion;
|
|
105
|
-
const kernelVersionFile = path_1.default.join(myCliRoot, '.chatbi-version');
|
|
106
|
-
if (fs_extra_1.default.existsSync(kernelVersionFile)) {
|
|
107
|
-
kernelVersion = (await fs_extra_1.default.readFile(kernelVersionFile, 'utf-8')).trim();
|
|
108
|
-
}
|
|
109
|
-
// Helper to render a template to a destination
|
|
110
|
-
const renderTemplate = async (templateName, destDir, extraData = {}) => {
|
|
111
|
-
const srcDir = path_1.default.join(myCliRoot, 'templates', templateName);
|
|
112
|
-
if (!fs_extra_1.default.existsSync(srcDir)) {
|
|
113
|
-
throw new Error(`找不到模板: ${templateName},请检查路径 ${srcDir} 是否正确。`);
|
|
114
|
-
}
|
|
115
|
-
await fs_extra_1.default.ensureDir(destDir);
|
|
116
|
-
const templateData = {
|
|
117
|
-
name: path_1.default.basename(destDir),
|
|
118
|
-
projectName: name, // Original project name from CLI argument
|
|
119
|
-
projectTitle: name.split('-').map(s => s.charAt(0).toUpperCase() + s.slice(1)).join(' '),
|
|
120
|
-
projectVersion: '0.1.0',
|
|
121
|
-
version: kernelVersion, // 使用内核版本作为依赖版本
|
|
122
|
-
cliVersion, // CLI 自身版本
|
|
123
|
-
pluginType,
|
|
124
|
-
theme,
|
|
125
|
-
isNebula: theme === 'nebula',
|
|
126
|
-
isGlass: theme === 'glass',
|
|
127
|
-
isBusiness: pluginType === 'business',
|
|
128
|
-
isApp: projectType === 'app' || isAppIncluded,
|
|
129
|
-
// Zero Dependency Mode: No explicit core path needed in package.json
|
|
130
|
-
// tsconfig extends the virtual paths config
|
|
131
|
-
tsconfigPath: projectType === 'monorepo' ? '../../.chatbi/tsconfig.json' : './.chatbi/tsconfig.json',
|
|
132
|
-
...extraData
|
|
133
|
-
};
|
|
134
|
-
const processFiles = async (currentSrc, currentDest) => {
|
|
135
|
-
const files = await fs_extra_1.default.readdir(currentSrc);
|
|
136
|
-
for (const file of files) {
|
|
137
|
-
if (file === '.DS_Store')
|
|
138
|
-
continue;
|
|
139
|
-
const srcPath = path_1.default.join(currentSrc, file);
|
|
140
|
-
const stats = await fs_extra_1.default.stat(srcPath);
|
|
141
|
-
if (stats.isDirectory()) {
|
|
142
|
-
const destPath = path_1.default.join(currentDest, file);
|
|
143
|
-
await fs_extra_1.default.ensureDir(destPath);
|
|
144
|
-
await processFiles(srcPath, destPath);
|
|
145
|
-
}
|
|
146
|
-
else if (file.endsWith('.hbs')) {
|
|
147
|
-
// Handle template files
|
|
148
|
-
const content = await fs_extra_1.default.readFile(srcPath, 'utf-8');
|
|
149
|
-
let result = content;
|
|
150
|
-
// 启发式判断:包含 {{ 即视为 Handlebars 模板
|
|
151
|
-
const hasHandlebarsVars = content.includes('{{');
|
|
152
|
-
if (hasHandlebarsVars) {
|
|
153
|
-
try {
|
|
154
|
-
// 针对可能包含 React {{ }} 的文件,做一个简单的预处理
|
|
155
|
-
// 只有当 {{ 后面紧跟着 Handlebars 关键字或变量名时,才保留;否则转义
|
|
156
|
-
const safeContent = content.replace(/\{\{(?!\s*([#/]?(?:if|else|each|with|unless|name|version|projectName|projectTitle|projectVersion|cliVersion|tsconfigPath|theme|isNebula|isGlass|isBusiness|isApp|isShell|pluginName|pluginPackageName|pluginVersion|pluginDisplayName|pluginDescription|pluginClassName|pluginPath|pluginFolderName|pluginType|pluginId|className))\b)/g, '\\{{');
|
|
157
|
-
const templateFn = handlebars_1.default.compile(safeContent);
|
|
158
|
-
result = templateFn(templateData);
|
|
159
|
-
}
|
|
160
|
-
catch (e) {
|
|
161
|
-
// 编译失败则降级为简单替换
|
|
162
|
-
result = content;
|
|
163
|
-
for (const [key, val] of Object.entries(templateData)) {
|
|
164
|
-
const regex = new RegExp(`\\{\\{\\s*${key}\\s*\\}\\}`, 'g');
|
|
165
|
-
result = result.replace(regex, String(val));
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
// Remove .hbs extension for the output file
|
|
170
|
-
const destPath = path_1.default.join(currentDest, file.replace(/\.hbs$/, ''));
|
|
171
|
-
await fs_extra_1.default.outputFile(destPath, result);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
// Copy raw files
|
|
175
|
-
const destPath = path_1.default.join(currentDest, file);
|
|
176
|
-
await fs_extra_1.default.copy(srcPath, destPath);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
await processFiles(srcDir, destDir);
|
|
181
|
-
};
|
|
182
|
-
const spinner = (0, utils_1.createSpinner)('正在生成项目结构...').start();
|
|
183
|
-
// 1. Render Root Structure
|
|
184
|
-
if (projectType === 'monorepo') {
|
|
185
|
-
spinner.text = '正在生成 Monorepo 骨架...';
|
|
186
|
-
await renderTemplate('monorepo', targetDir, { name });
|
|
187
|
-
if (isAppIncluded) {
|
|
188
|
-
spinner.text = '正在生成 Host App...';
|
|
189
|
-
const appDir = path_1.default.join(targetDir, 'apps', 'main'); // Default to 'main' app
|
|
190
|
-
await renderTemplate('app', appDir, { name: '@chatbi-v/main' });
|
|
191
|
-
}
|
|
192
|
-
if (isPluginIncluded) {
|
|
193
|
-
spinner.text = '正在生成 Demo Plugin...';
|
|
194
|
-
const pluginDir = path_1.default.join(targetDir, 'plugins', 'plugin-demo');
|
|
195
|
-
await renderTemplate('plugin', pluginDir, {
|
|
196
|
-
name: '@chatbi-v/plugin-demo',
|
|
197
|
-
pluginId: 'demo',
|
|
198
|
-
pluginName: 'demo',
|
|
199
|
-
pluginPackageName: '@chatbi-v/plugin-demo',
|
|
200
|
-
pluginVersion: '0.1.0',
|
|
201
|
-
pluginDisplayName: '示例插件',
|
|
202
|
-
pluginDescription: '这是一个初始化的示例插件',
|
|
203
|
-
pluginClassName: 'DemoPlugin',
|
|
204
|
-
pluginPath: 'plugin-demo',
|
|
205
|
-
pluginFolderName: 'plugin-demo',
|
|
206
|
-
className: 'DemoPlugin'
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else if (projectType === 'app') {
|
|
211
|
-
spinner.text = '正在生成独立应用...';
|
|
212
|
-
await renderTemplate('app', targetDir, { name });
|
|
213
|
-
}
|
|
214
|
-
else if (projectType === 'plugin') {
|
|
215
|
-
spinner.text = '正在生成独立插件...';
|
|
216
|
-
await renderTemplate('plugin', targetDir, {
|
|
217
|
-
name: `@chatbi-v/plugin-${name}`,
|
|
218
|
-
pluginId: name,
|
|
219
|
-
pluginName: name,
|
|
220
|
-
pluginPackageName: `@chatbi-v/plugin-${name}`,
|
|
221
|
-
pluginVersion: '0.1.0',
|
|
222
|
-
pluginDisplayName: name,
|
|
223
|
-
pluginDescription: 'A ChatBI-V Plugin',
|
|
224
|
-
pluginClassName: name.split('-').map(s => s.charAt(0).toUpperCase() + s.slice(1)).join(''),
|
|
225
|
-
pluginPath: name,
|
|
226
|
-
pluginFolderName: name,
|
|
227
|
-
className: name.split('-').map(s => s.charAt(0).toUpperCase() + s.slice(1)).join('')
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
spinner.succeed('项目结构生成完成');
|
|
231
|
-
// 2. Sync Dependencies (Monorepo 模式下仅在根目录同步一次即可)
|
|
232
|
-
const syncSpinner = (0, utils_1.createSpinner)('正在同步内核依赖...').start();
|
|
233
|
-
// 统一在根目录生成虚拟环境,子包通过 tsconfig extends 继承
|
|
234
|
-
await (0, sync_1.sync)({ cwd: targetDir, silent: true });
|
|
235
|
-
syncSpinner.succeed('内核依赖同步完成');
|
|
236
|
-
// 3. Create CLI Config
|
|
237
|
-
const configSpinner = (0, utils_1.createSpinner)('正在生成项目配置...').start();
|
|
238
|
-
const cliConfig = {
|
|
239
|
-
coreVersion: kernelVersion
|
|
240
|
-
};
|
|
241
|
-
await fs_extra_1.default.writeJson(path_1.default.join(targetDir, 'chatbi.config.json'), cliConfig, { spaces: 2 });
|
|
242
|
-
configSpinner.succeed('项目配置生成完成');
|
|
243
|
-
(0, utils_1.printBox)(`${picocolors_1.default.green(picocolors_1.default.bold('✨ 项目已成功创建!'))}\n\n` +
|
|
244
|
-
`${picocolors_1.default.white('接下来你可以:')}\n` +
|
|
245
|
-
`${picocolors_1.default.cyan(` cd ${name}`)}\n` +
|
|
246
|
-
`${picocolors_1.default.cyan(' pnpm install')}\n` +
|
|
247
|
-
`${picocolors_1.default.cyan(' pnpm dev')}`, 'Success');
|
|
248
|
-
}
|
|
249
|
-
catch (error) {
|
|
250
|
-
utils_1.logger.error('初始化失败', error);
|
|
251
|
-
throw error;
|
|
252
|
-
}
|
|
253
|
-
}
|
package/dist/commands/install.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.install = install;
|
|
40
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
41
|
-
const path_1 = __importDefault(require("path"));
|
|
42
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
43
|
-
const sandbox_1 = require("../sandbox");
|
|
44
|
-
const execa_1 = require("execa");
|
|
45
|
-
const utils_1 = require("../utils");
|
|
46
|
-
async function install(target) {
|
|
47
|
-
// 1. 检查是否是本地文件 (tgz)
|
|
48
|
-
if (target.endsWith('.tgz') && fs_extra_1.default.existsSync(target)) {
|
|
49
|
-
const spinner = (0, utils_1.createSpinner)(`正在安装本地离线包: ${picocolors_1.default.bold(target)}...`).start();
|
|
50
|
-
try {
|
|
51
|
-
const tgzPath = path_1.default.resolve(target);
|
|
52
|
-
const match = path_1.default.basename(target).match(/chatbi-core-(.+)\.tgz/);
|
|
53
|
-
let version = 'unknown';
|
|
54
|
-
if (match) {
|
|
55
|
-
version = match[1];
|
|
56
|
-
}
|
|
57
|
-
if (version === 'unknown') {
|
|
58
|
-
spinner.warn('无法从文件名识别版本,将使用当前时间戳作为版本号');
|
|
59
|
-
version = `local-${Date.now()}`;
|
|
60
|
-
}
|
|
61
|
-
const versionRoot = sandbox_1.Sandbox.getVersionRoot();
|
|
62
|
-
await fs_extra_1.default.ensureDir(versionRoot);
|
|
63
|
-
// 解压
|
|
64
|
-
spinner.text = '正在解压文件...';
|
|
65
|
-
await (0, execa_1.execa)('tar', ['-xzf', tgzPath, '-C', versionRoot]);
|
|
66
|
-
spinner.succeed(`本地包已安装至沙箱: ${version}`);
|
|
67
|
-
// 自动切换到该版本
|
|
68
|
-
spinner.text = '正在准备内核环境...';
|
|
69
|
-
await sandbox_1.Sandbox.prepare(version);
|
|
70
|
-
spinner.succeed('内核环境就绪');
|
|
71
|
-
(0, utils_1.printBox)(picocolors_1.default.green(picocolors_1.default.bold('✨ 本地内核安装成功!')) + '\n\n' +
|
|
72
|
-
picocolors_1.default.white('版本: ') + picocolors_1.default.cyan(version) + '\n' +
|
|
73
|
-
picocolors_1.default.white('路径: ') + picocolors_1.default.gray(sandbox_1.Sandbox.getVersionPath(version)), 'Install Success');
|
|
74
|
-
}
|
|
75
|
-
catch (e) {
|
|
76
|
-
spinner.fail('安装失败');
|
|
77
|
-
throw e;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
// 如果不是文件,假设是版本号,走普通 fetch 流程
|
|
82
|
-
const { fetch } = await Promise.resolve().then(() => __importStar(require('./fetch')));
|
|
83
|
-
await fetch(target);
|
|
84
|
-
}
|
|
85
|
-
}
|
package/dist/commands/ls.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ls = ls;
|
|
7
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
8
|
-
const corekit_1 = require("../corekit");
|
|
9
|
-
const sandbox_1 = require("../sandbox");
|
|
10
|
-
const utils_1 = require("../utils");
|
|
11
|
-
async function ls() {
|
|
12
|
-
const versions = await corekit_1.CoreKit.listVersions();
|
|
13
|
-
const currentVersion = await corekit_1.CoreKit.resolveVersion(process.cwd());
|
|
14
|
-
const globalCurrentVersion = await corekit_1.CoreKit.resolveVersion();
|
|
15
|
-
utils_1.logger.info('已安装的内核沙箱版本:');
|
|
16
|
-
if (versions.length === 0) {
|
|
17
|
-
utils_1.logger.warn('尚未安装任何版本,请运行 chatbi sync 进行安装。');
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
const list = versions.map(v => {
|
|
21
|
-
const isGlobalCurrent = v === globalCurrentVersion;
|
|
22
|
-
const isProjectCurrent = v === currentVersion;
|
|
23
|
-
let prefix = ' ';
|
|
24
|
-
if (isProjectCurrent) {
|
|
25
|
-
prefix = picocolors_1.default.green(' *');
|
|
26
|
-
}
|
|
27
|
-
else if (isGlobalCurrent) {
|
|
28
|
-
prefix = picocolors_1.default.blue(' >');
|
|
29
|
-
}
|
|
30
|
-
let suffix = '';
|
|
31
|
-
if (isProjectCurrent && isGlobalCurrent) {
|
|
32
|
-
suffix = picocolors_1.default.gray(' (当前项目 & 全局)');
|
|
33
|
-
}
|
|
34
|
-
else if (isProjectCurrent) {
|
|
35
|
-
suffix = picocolors_1.default.gray(' (当前项目)');
|
|
36
|
-
}
|
|
37
|
-
else if (isGlobalCurrent) {
|
|
38
|
-
suffix = picocolors_1.default.gray(' (全局)');
|
|
39
|
-
}
|
|
40
|
-
return `${prefix} ${picocolors_1.default.white(v)}${suffix}`;
|
|
41
|
-
}).join('\n');
|
|
42
|
-
(0, utils_1.printBox)(list + picocolors_1.default.gray('\n\n提示: * 当前项目使用, > 全局默认使用'), 'Kernel Versions');
|
|
43
|
-
}
|
|
44
|
-
// 展示当前项目的可视化面板
|
|
45
|
-
await sandbox_1.Sandbox.visualizeStatus(process.cwd());
|
|
46
|
-
}
|
package/dist/commands/sync.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.sync = sync;
|
|
7
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
10
|
-
const utils_1 = require("../utils");
|
|
11
|
-
const sandbox_1 = require("../sandbox");
|
|
12
|
-
const corekit_1 = require("../corekit");
|
|
13
|
-
async function sync(options = {}) {
|
|
14
|
-
const cwd = options.cwd || process.cwd();
|
|
15
|
-
const pkgPath = path_1.default.join(cwd, 'package.json');
|
|
16
|
-
if (!fs_extra_1.default.existsSync(pkgPath)) {
|
|
17
|
-
utils_1.logger.error('未找到 package.json。请在项目根目录下运行。');
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const pkg = await fs_extra_1.default.readJson(pkgPath);
|
|
21
|
-
// 优先序:options.version > .chatbi-version > projectConfig.coreVersion > CLI 版本
|
|
22
|
-
let version = options.version;
|
|
23
|
-
if (!version) {
|
|
24
|
-
version = await corekit_1.CoreKit.resolveVersion(cwd);
|
|
25
|
-
}
|
|
26
|
-
// 0. 如果开启了 clean,先清理沙箱
|
|
27
|
-
if (options.clean) {
|
|
28
|
-
const cleanSpinner = (0, utils_1.createSpinner)(`正在清理沙箱版本 ${version}...`).start();
|
|
29
|
-
await sandbox_1.Sandbox.cleanVersion(version);
|
|
30
|
-
cleanSpinner.succeed(`沙箱版本 ${version} 已清理`);
|
|
31
|
-
}
|
|
32
|
-
const mainSpinner = (0, utils_1.createSpinner)(`正在同步内核依赖 (版本: ${version})...`).start();
|
|
33
|
-
// 1. 准备环境 (虚拟化沙箱)
|
|
34
|
-
mainSpinner.text = '正在同步沙箱内核...';
|
|
35
|
-
await sandbox_1.Sandbox.prepare(version, options.force);
|
|
36
|
-
mainSpinner.text = '正在生成虚拟上下文...';
|
|
37
|
-
// 如果是显式指定的版本,且项目之前没有版本文件,或者版本不同,则写入版本文件
|
|
38
|
-
if (options.version) {
|
|
39
|
-
const versionFilePath = path_1.default.join(cwd, '.chatbi-version');
|
|
40
|
-
await fs_extra_1.default.writeFile(versionFilePath, version, 'utf-8');
|
|
41
|
-
}
|
|
42
|
-
// 生成虚拟依赖环境 (tsconfig 映射等)
|
|
43
|
-
await sandbox_1.Sandbox.injectContext(cwd, version);
|
|
44
|
-
// 2. 更新 package.json 依赖
|
|
45
|
-
let modified = false;
|
|
46
|
-
const deps = pkg.dependencies || {};
|
|
47
|
-
const devDeps = pkg.devDependencies || {};
|
|
48
|
-
// 检查并清理旧的显式依赖 (实现零依赖)
|
|
49
|
-
const isVirtualMode = true;
|
|
50
|
-
if (isVirtualMode) {
|
|
51
|
-
for (const pkgName of sandbox_1.Sandbox.CORE_PACKAGES) {
|
|
52
|
-
// 移除所有核心包依赖,实现真正的零显式依赖
|
|
53
|
-
if (deps[pkgName]) {
|
|
54
|
-
delete deps[pkgName];
|
|
55
|
-
modified = true;
|
|
56
|
-
}
|
|
57
|
-
if (devDeps[pkgName]) {
|
|
58
|
-
delete devDeps[pkgName];
|
|
59
|
-
modified = true;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (modified) {
|
|
64
|
-
pkg.dependencies = deps;
|
|
65
|
-
pkg.devDependencies = devDeps;
|
|
66
|
-
await fs_extra_1.default.writeJson(pkgPath, pkg, { spaces: 2 });
|
|
67
|
-
mainSpinner.succeed('内核同步完成 (依赖已优化)');
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
mainSpinner.succeed('内核同步完成');
|
|
71
|
-
}
|
|
72
|
-
if (!options.silent) {
|
|
73
|
-
(0, utils_1.printBox)(`${picocolors_1.default.green(picocolors_1.default.bold('✨ 内核同步成功!'))}\n\n` +
|
|
74
|
-
`${picocolors_1.default.white('当前版本: ')} ${picocolors_1.default.cyan(version)}\n` +
|
|
75
|
-
`${picocolors_1.default.white('沙箱路径: ')} ${picocolors_1.default.gray(sandbox_1.Sandbox.getVersionPath(version))}\n\n` +
|
|
76
|
-
`${picocolors_1.default.white('提示: ')} 项目现在通过虚拟别名引用核心包,无需显式安装依赖。`, 'Sync Success');
|
|
77
|
-
}
|
|
78
|
-
}
|
package/dist/commands/use.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.use = use;
|
|
7
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const sandbox_1 = require("../sandbox");
|
|
10
|
-
const corekit_1 = require("../corekit");
|
|
11
|
-
const sync_1 = require("./sync");
|
|
12
|
-
const utils_1 = require("../utils");
|
|
13
|
-
async function use(version, options = {}) {
|
|
14
|
-
const versions = await corekit_1.CoreKit.listVersions();
|
|
15
|
-
if (!versions.includes(version)) {
|
|
16
|
-
utils_1.logger.warn(`版本 ${version} 尚未安装,正在尝试安装...`);
|
|
17
|
-
await sandbox_1.Sandbox.prepare(version);
|
|
18
|
-
}
|
|
19
|
-
if (options.global) {
|
|
20
|
-
await sandbox_1.Sandbox.useVersion(version);
|
|
21
|
-
utils_1.logger.success(`已切换全局内核版本至: ${version}`);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
const cwd = process.cwd();
|
|
25
|
-
const versionFilePath = path_1.default.join(cwd, '.chatbi-version');
|
|
26
|
-
await fs_extra_1.default.writeFile(versionFilePath, version, 'utf-8');
|
|
27
|
-
utils_1.logger.success(`已切换当前项目内核版本为: ${version}`);
|
|
28
|
-
}
|
|
29
|
-
// 自动运行一次同步,确保项目虚拟环境更新
|
|
30
|
-
await (0, sync_1.sync)({ version, force: false });
|
|
31
|
-
}
|
package/dist/config.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ConfigManager = void 0;
|
|
7
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const jiti_1 = require("jiti");
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
|
-
/**
|
|
12
|
-
* 配置管理器
|
|
13
|
-
* 负责读取和合并项目配置
|
|
14
|
-
*/
|
|
15
|
-
class ConfigManager {
|
|
16
|
-
/**
|
|
17
|
-
* 加载项目配置
|
|
18
|
-
* @param cwd 项目根目录
|
|
19
|
-
*/
|
|
20
|
-
static async loadConfig(cwd = process.cwd()) {
|
|
21
|
-
const config = {};
|
|
22
|
-
// 1. 优先检查 .chatbi-version 文件 (最轻量的版本锁定方式)
|
|
23
|
-
const versionFilePath = path_1.default.join(cwd, '.chatbi-version');
|
|
24
|
-
if (fs_extra_1.default.existsSync(versionFilePath)) {
|
|
25
|
-
try {
|
|
26
|
-
const version = (await fs_extra_1.default.readFile(versionFilePath, 'utf-8')).trim();
|
|
27
|
-
if (version) {
|
|
28
|
-
config.coreVersion = version;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
// ignore
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// 2. 检查标准配置文件
|
|
36
|
-
const jiti = (0, jiti_1.createJiti)(cwd);
|
|
37
|
-
for (const file of this.CONFIG_FILES) {
|
|
38
|
-
const configPath = path_1.default.join(cwd, file);
|
|
39
|
-
if (fs_extra_1.default.existsSync(configPath)) {
|
|
40
|
-
try {
|
|
41
|
-
let projectConfig = {};
|
|
42
|
-
if (file.endsWith('.ts') || file.endsWith('.js')) {
|
|
43
|
-
const mod = await jiti.import(configPath, { default: true });
|
|
44
|
-
projectConfig = mod.default || mod || {};
|
|
45
|
-
}
|
|
46
|
-
else if (file.endsWith('.json') || file.startsWith('.chatbirc')) {
|
|
47
|
-
projectConfig = await fs_extra_1.default.readJson(configPath);
|
|
48
|
-
}
|
|
49
|
-
// 合并配置,.chatbi-version 优先级最高 (如果已经读取到了就跳过)
|
|
50
|
-
return {
|
|
51
|
-
...projectConfig,
|
|
52
|
-
...config
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
utils_1.logger.error(`读取配置文件 ${file} 失败`, e);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return config;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.ConfigManager = ConfigManager;
|
|
64
|
-
ConfigManager.CONFIG_FILES = [
|
|
65
|
-
'chatbi.config.ts',
|
|
66
|
-
'chatbi.config.js',
|
|
67
|
-
'chatbi.config.json',
|
|
68
|
-
'.chatbirc',
|
|
69
|
-
'.chatbirc.json'
|
|
70
|
-
];
|