@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/chunk-LJFX6MNO.mjs
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
sync
|
|
3
|
-
} from "./chunk-4OD6C56P.mjs";
|
|
4
|
-
import {
|
|
5
|
-
require_prompts
|
|
6
|
-
} from "./chunk-WIVHOK75.mjs";
|
|
7
|
-
import {
|
|
8
|
-
require_lib as require_lib2
|
|
9
|
-
} from "./chunk-7A54IJI5.mjs";
|
|
10
|
-
import {
|
|
11
|
-
createSpinner,
|
|
12
|
-
getCliRoot,
|
|
13
|
-
logger,
|
|
14
|
-
printBox,
|
|
15
|
-
require_lib,
|
|
16
|
-
require_picocolors
|
|
17
|
-
} from "./chunk-Y24V4GQG.mjs";
|
|
18
|
-
import {
|
|
19
|
-
__toESM,
|
|
20
|
-
init_esm_shims
|
|
21
|
-
} from "./chunk-TX5M36S5.mjs";
|
|
22
|
-
|
|
23
|
-
// src/commands/init.ts
|
|
24
|
-
init_esm_shims();
|
|
25
|
-
var import_fs_extra = __toESM(require_lib());
|
|
26
|
-
var import_picocolors = __toESM(require_picocolors());
|
|
27
|
-
var import_handlebars = __toESM(require_lib2());
|
|
28
|
-
var import_prompts = __toESM(require_prompts());
|
|
29
|
-
import path from "path";
|
|
30
|
-
async function init(options) {
|
|
31
|
-
let { name, template, pluginType = "business", theme = "standard", projectType, includeApp, includePlugin } = options;
|
|
32
|
-
const response = await (0, import_prompts.default)([
|
|
33
|
-
// ... (prompts remain the same)
|
|
34
|
-
{
|
|
35
|
-
type: name ? null : "text",
|
|
36
|
-
name: "projectName",
|
|
37
|
-
message: "\u8BF7\u8F93\u5165\u9879\u76EE\u540D\u79F0:",
|
|
38
|
-
initial: "my-chatbi-workspace"
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
type: projectType ? null : "select",
|
|
42
|
-
name: "projectType",
|
|
43
|
-
message: "\u8BF7\u9009\u62E9\u9879\u76EE\u7C7B\u578B:",
|
|
44
|
-
choices: [
|
|
45
|
-
{ title: "Monorepo Workspace (\u5B8C\u6574\u5DE5\u4F5C\u7A7A\u95F4)", value: "monorepo", description: "\u5305\u542B Apps \u548C Plugins \u7684\u591A\u5305\u7BA1\u7406\u7ED3\u6784" },
|
|
46
|
-
{ title: "Host App (\u72EC\u7ACB\u5BBF\u4E3B\u5E94\u7528)", value: "app", description: "\u72EC\u7ACB\u7684 ChatBI \u5E94\u7528\u6846\u67B6" },
|
|
47
|
-
{ title: "Plugin (\u72EC\u7ACB\u63D2\u4EF6)", value: "plugin", description: "\u72EC\u7ACB\u7684\u4E1A\u52A1\u6216\u7CFB\u7EDF\u63D2\u4EF6" }
|
|
48
|
-
],
|
|
49
|
-
initial: 0
|
|
50
|
-
},
|
|
51
|
-
// Monorepo specific questions
|
|
52
|
-
{
|
|
53
|
-
type: (prev) => (projectType === "monorepo" || prev === "monorepo") && includeApp === void 0 ? "confirm" : null,
|
|
54
|
-
name: "includeApp",
|
|
55
|
-
message: "\u662F\u5426\u521D\u59CB\u5316\u9ED8\u8BA4 Host App?",
|
|
56
|
-
initial: true
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
type: (prev) => (projectType === "monorepo" || prev === "monorepo") && includePlugin === void 0 ? "confirm" : null,
|
|
60
|
-
name: "includePlugin",
|
|
61
|
-
message: "\u662F\u5426\u521D\u59CB\u5316\u793A\u4F8B Plugin?",
|
|
62
|
-
initial: true
|
|
63
|
-
},
|
|
64
|
-
// Plugin specific questions
|
|
65
|
-
{
|
|
66
|
-
type: (prev, values) => (projectType === "plugin" || values.projectType === "plugin" || (includePlugin || values.includePlugin)) && !pluginType ? "select" : null,
|
|
67
|
-
name: "pluginType",
|
|
68
|
-
message: "\u8BF7\u9009\u62E9\u63D2\u4EF6\u7C7B\u578B:",
|
|
69
|
-
choices: [
|
|
70
|
-
{ title: "Business (\u4E1A\u52A1\u63D2\u4EF6)", value: "business", description: "\u4FA7\u91CD\u4E8E\u4E1A\u52A1\u903B\u8F91\u548C UI \u5C55\u793A" },
|
|
71
|
-
{ title: "System (\u7CFB\u7EDF\u63D2\u4EF6)", value: "system", description: "\u4FA7\u91CD\u4E8E\u7CFB\u7EDF\u80FD\u529B\u548C\u5E95\u5C42\u6269\u5C55" }
|
|
72
|
-
],
|
|
73
|
-
initial: 0
|
|
74
|
-
},
|
|
75
|
-
// Theme selection (for App)
|
|
76
|
-
{
|
|
77
|
-
type: (prev, values) => (projectType === "app" || values.projectType === "app" || (includeApp || values.includeApp)) && !theme ? "select" : null,
|
|
78
|
-
name: "theme",
|
|
79
|
-
message: "\u8BF7\u9009\u62E9\u5E94\u7528\u9ED8\u8BA4\u4E3B\u9898:",
|
|
80
|
-
choices: [
|
|
81
|
-
{ title: "Standard (\u7ECF\u5178\u84DD)", value: "standard" },
|
|
82
|
-
{ title: "Nebula (\u661F\u4E91\u7D2B)", value: "nebula" },
|
|
83
|
-
{ title: "Glass (\u6BDB\u73BB\u7483)", value: "glass" }
|
|
84
|
-
],
|
|
85
|
-
initial: 0
|
|
86
|
-
}
|
|
87
|
-
], {
|
|
88
|
-
onCancel: () => {
|
|
89
|
-
logger.warn("\u5DF2\u53D6\u6D88\u521D\u59CB\u5316");
|
|
90
|
-
process.exit(0);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
name = name || response.projectName;
|
|
94
|
-
projectType = projectType || response.projectType || "monorepo";
|
|
95
|
-
pluginType = pluginType || response.pluginType || pluginType;
|
|
96
|
-
theme = theme || response.theme || theme;
|
|
97
|
-
const finalIncludeApp = includeApp !== void 0 ? includeApp : response.includeApp !== void 0 ? response.includeApp : true;
|
|
98
|
-
const finalIncludePlugin = includePlugin !== void 0 ? includePlugin : response.includePlugin !== void 0 ? response.includePlugin : true;
|
|
99
|
-
const isAppIncluded = finalIncludeApp;
|
|
100
|
-
const isPluginIncluded = finalIncludePlugin;
|
|
101
|
-
const rootDir = process.cwd();
|
|
102
|
-
const targetDir = path.resolve(rootDir, name);
|
|
103
|
-
if (import_fs_extra.default.existsSync(targetDir)) {
|
|
104
|
-
logger.error(`\u76EE\u5F55 ${name} \u5DF2\u5B58\u5728\u3002`);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
logger.info(`\u6B63\u5728\u521D\u59CB\u5316\u9879\u76EE: ${import_picocolors.default.bold(name)}...`);
|
|
108
|
-
logger.info(import_picocolors.default.gray(`\u7C7B\u578B: ${projectType} | \u4E3B\u9898: ${theme || "N/A"}`));
|
|
109
|
-
console.log("");
|
|
110
|
-
try {
|
|
111
|
-
const myCliRoot = await getCliRoot();
|
|
112
|
-
const cliPkg = await import_fs_extra.default.readJson(path.join(myCliRoot, "package.json"));
|
|
113
|
-
const cliVersion = cliPkg.version;
|
|
114
|
-
let kernelVersion = cliVersion;
|
|
115
|
-
const kernelVersionFile = path.join(myCliRoot, ".chatbi-version");
|
|
116
|
-
if (import_fs_extra.default.existsSync(kernelVersionFile)) {
|
|
117
|
-
kernelVersion = (await import_fs_extra.default.readFile(kernelVersionFile, "utf-8")).trim();
|
|
118
|
-
}
|
|
119
|
-
const renderTemplate = async (templateName, destDir, extraData = {}) => {
|
|
120
|
-
const srcDir = path.join(myCliRoot, "templates", templateName);
|
|
121
|
-
if (!import_fs_extra.default.existsSync(srcDir)) {
|
|
122
|
-
throw new Error(`\u627E\u4E0D\u5230\u6A21\u677F: ${templateName}\uFF0C\u8BF7\u68C0\u67E5\u8DEF\u5F84 ${srcDir} \u662F\u5426\u6B63\u786E\u3002`);
|
|
123
|
-
}
|
|
124
|
-
await import_fs_extra.default.ensureDir(destDir);
|
|
125
|
-
const templateData = {
|
|
126
|
-
name: path.basename(destDir),
|
|
127
|
-
projectName: name,
|
|
128
|
-
// Original project name from CLI argument
|
|
129
|
-
projectTitle: name.split("-").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(" "),
|
|
130
|
-
projectVersion: "0.1.0",
|
|
131
|
-
version: kernelVersion,
|
|
132
|
-
// 使用内核版本作为依赖版本
|
|
133
|
-
cliVersion,
|
|
134
|
-
// CLI 自身版本
|
|
135
|
-
pluginType,
|
|
136
|
-
theme,
|
|
137
|
-
isNebula: theme === "nebula",
|
|
138
|
-
isGlass: theme === "glass",
|
|
139
|
-
isBusiness: pluginType === "business",
|
|
140
|
-
isApp: projectType === "app" || isAppIncluded,
|
|
141
|
-
// Zero Dependency Mode: No explicit core path needed in package.json
|
|
142
|
-
// tsconfig extends the virtual paths config
|
|
143
|
-
tsconfigPath: projectType === "monorepo" ? "../../.chatbi/tsconfig.json" : "./.chatbi/tsconfig.json",
|
|
144
|
-
...extraData
|
|
145
|
-
};
|
|
146
|
-
const processFiles = async (currentSrc, currentDest) => {
|
|
147
|
-
const files = await import_fs_extra.default.readdir(currentSrc);
|
|
148
|
-
for (const file of files) {
|
|
149
|
-
if (file === ".DS_Store") continue;
|
|
150
|
-
const srcPath = path.join(currentSrc, file);
|
|
151
|
-
const stats = await import_fs_extra.default.stat(srcPath);
|
|
152
|
-
if (stats.isDirectory()) {
|
|
153
|
-
const destPath = path.join(currentDest, file);
|
|
154
|
-
await import_fs_extra.default.ensureDir(destPath);
|
|
155
|
-
await processFiles(srcPath, destPath);
|
|
156
|
-
} else if (file.endsWith(".hbs")) {
|
|
157
|
-
const content = await import_fs_extra.default.readFile(srcPath, "utf-8");
|
|
158
|
-
let result = content;
|
|
159
|
-
const hasHandlebarsVars = content.includes("{{");
|
|
160
|
-
if (hasHandlebarsVars) {
|
|
161
|
-
try {
|
|
162
|
-
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, "\\{{");
|
|
163
|
-
const templateFn = import_handlebars.default.compile(safeContent);
|
|
164
|
-
result = templateFn(templateData);
|
|
165
|
-
} catch (e) {
|
|
166
|
-
result = content;
|
|
167
|
-
for (const [key, val] of Object.entries(templateData)) {
|
|
168
|
-
const regex = new RegExp(`\\{\\{\\s*${key}\\s*\\}\\}`, "g");
|
|
169
|
-
result = result.replace(regex, String(val));
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
const destPath = path.join(currentDest, file.replace(/\.hbs$/, ""));
|
|
174
|
-
await import_fs_extra.default.outputFile(destPath, result);
|
|
175
|
-
} else {
|
|
176
|
-
const destPath = path.join(currentDest, file);
|
|
177
|
-
await import_fs_extra.default.copy(srcPath, destPath);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
await processFiles(srcDir, destDir);
|
|
182
|
-
};
|
|
183
|
-
const spinner = createSpinner("\u6B63\u5728\u751F\u6210\u9879\u76EE\u7ED3\u6784...").start();
|
|
184
|
-
if (projectType === "monorepo") {
|
|
185
|
-
spinner.text = "\u6B63\u5728\u751F\u6210 Monorepo \u9AA8\u67B6...";
|
|
186
|
-
await renderTemplate("monorepo", targetDir, { name });
|
|
187
|
-
if (isAppIncluded) {
|
|
188
|
-
spinner.text = "\u6B63\u5728\u751F\u6210 Host App...";
|
|
189
|
-
const appDir = path.join(targetDir, "apps", "main");
|
|
190
|
-
await renderTemplate("app", appDir, { name: "@chatbi-v/main" });
|
|
191
|
-
}
|
|
192
|
-
if (isPluginIncluded) {
|
|
193
|
-
spinner.text = "\u6B63\u5728\u751F\u6210 Demo Plugin...";
|
|
194
|
-
const pluginDir = path.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: "\u793A\u4F8B\u63D2\u4EF6",
|
|
202
|
-
pluginDescription: "\u8FD9\u662F\u4E00\u4E2A\u521D\u59CB\u5316\u7684\u793A\u4F8B\u63D2\u4EF6",
|
|
203
|
-
pluginClassName: "DemoPlugin",
|
|
204
|
-
pluginPath: "plugin-demo",
|
|
205
|
-
pluginFolderName: "plugin-demo",
|
|
206
|
-
className: "DemoPlugin"
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
} else if (projectType === "app") {
|
|
210
|
-
spinner.text = "\u6B63\u5728\u751F\u6210\u72EC\u7ACB\u5E94\u7528...";
|
|
211
|
-
await renderTemplate("app", targetDir, { name });
|
|
212
|
-
} else if (projectType === "plugin") {
|
|
213
|
-
spinner.text = "\u6B63\u5728\u751F\u6210\u72EC\u7ACB\u63D2\u4EF6...";
|
|
214
|
-
await renderTemplate("plugin", targetDir, {
|
|
215
|
-
name: `@chatbi-v/plugin-${name}`,
|
|
216
|
-
pluginId: name,
|
|
217
|
-
pluginName: name,
|
|
218
|
-
pluginPackageName: `@chatbi-v/plugin-${name}`,
|
|
219
|
-
pluginVersion: "0.1.0",
|
|
220
|
-
pluginDisplayName: name,
|
|
221
|
-
pluginDescription: "A ChatBI-V Plugin",
|
|
222
|
-
pluginClassName: name.split("-").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(""),
|
|
223
|
-
pluginPath: name,
|
|
224
|
-
pluginFolderName: name,
|
|
225
|
-
className: name.split("-").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("")
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
spinner.succeed("\u9879\u76EE\u7ED3\u6784\u751F\u6210\u5B8C\u6210");
|
|
229
|
-
const syncSpinner = createSpinner("\u6B63\u5728\u540C\u6B65\u5185\u6838\u4F9D\u8D56...").start();
|
|
230
|
-
await sync({ cwd: targetDir, silent: true });
|
|
231
|
-
syncSpinner.succeed("\u5185\u6838\u4F9D\u8D56\u540C\u6B65\u5B8C\u6210");
|
|
232
|
-
const configSpinner = createSpinner("\u6B63\u5728\u751F\u6210\u9879\u76EE\u914D\u7F6E...").start();
|
|
233
|
-
const cliConfig = {
|
|
234
|
-
coreVersion: kernelVersion
|
|
235
|
-
};
|
|
236
|
-
await import_fs_extra.default.writeJson(path.join(targetDir, "chatbi.config.json"), cliConfig, { spaces: 2 });
|
|
237
|
-
configSpinner.succeed("\u9879\u76EE\u914D\u7F6E\u751F\u6210\u5B8C\u6210");
|
|
238
|
-
printBox(
|
|
239
|
-
`${import_picocolors.default.green(import_picocolors.default.bold("\u2728 \u9879\u76EE\u5DF2\u6210\u529F\u521B\u5EFA!"))}
|
|
240
|
-
|
|
241
|
-
${import_picocolors.default.white("\u63A5\u4E0B\u6765\u4F60\u53EF\u4EE5:")}
|
|
242
|
-
${import_picocolors.default.cyan(` cd ${name}`)}
|
|
243
|
-
${import_picocolors.default.cyan(" pnpm install")}
|
|
244
|
-
${import_picocolors.default.cyan(" pnpm dev")}`,
|
|
245
|
-
"Success"
|
|
246
|
-
);
|
|
247
|
-
} catch (error) {
|
|
248
|
-
logger.error("\u521D\u59CB\u5316\u5931\u8D25", error);
|
|
249
|
-
throw error;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export {
|
|
254
|
-
init
|
|
255
|
-
};
|