@chatbi-v/cli 2.0.1 → 2.0.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.
Files changed (67) hide show
  1. package/README.md +45 -0
  2. package/dist/bench-ACSHVGHE.mjs +77 -0
  3. package/dist/build-UB4D3WNI.mjs +11 -0
  4. package/dist/chunk-4OD6C56P.mjs +89 -0
  5. package/dist/chunk-7A54IJI5.mjs +6368 -0
  6. package/dist/chunk-LJFX6MNO.mjs +255 -0
  7. package/dist/chunk-SBGVKO4C.mjs +2255 -0
  8. package/dist/chunk-TX5M36S5.mjs +55 -0
  9. package/dist/chunk-V7IEPMC4.mjs +52 -0
  10. package/dist/chunk-WCPZB47I.mjs +262 -0
  11. package/dist/chunk-WIVHOK75.mjs +5292 -0
  12. package/dist/chunk-Y24V4GQG.mjs +9577 -0
  13. package/dist/commands/add.js +182 -0
  14. package/dist/commands/bench.js +100 -0
  15. package/dist/commands/build.js +290 -0
  16. package/dist/commands/dev.js +8 -0
  17. package/dist/commands/discover.js +25 -0
  18. package/dist/commands/doctor.js +231 -0
  19. package/dist/commands/fetch.js +41 -0
  20. package/dist/commands/gl.js +151 -0
  21. package/dist/commands/init.js +253 -0
  22. package/dist/commands/install.js +85 -0
  23. package/dist/commands/ls.js +46 -0
  24. package/dist/commands/sync.js +78 -0
  25. package/dist/commands/use.js +31 -0
  26. package/dist/config.js +70 -0
  27. package/dist/corekit.js +370 -0
  28. package/dist/execa-METROS6Z.mjs +17 -0
  29. package/dist/fetch-7X2UFWIV.mjs +10 -0
  30. package/dist/index.cjs +27278 -0
  31. package/dist/index.js +193 -23981
  32. package/dist/index.mjs +2769 -0
  33. package/dist/init-QFRFYEA5.mjs +12 -0
  34. package/dist/sandbox.js +522 -0
  35. package/dist/sync-7HPKGVFY.mjs +11 -0
  36. package/dist/utils.js +99 -0
  37. package/package.json +4 -3
  38. package/templates/app/.env.hbs +2 -2
  39. package/templates/app/README.md.hbs +29 -11
  40. package/templates/app/chatbi.config.ts.hbs +10 -33
  41. package/templates/app/index.html.hbs +1 -1
  42. package/templates/app/package.json.hbs +12 -14
  43. package/templates/app/postcss.config.cjs.hbs +5 -1
  44. package/templates/app/src/App.tsx.hbs +66 -36
  45. package/templates/app/src/components/GlobalSettingsModal.tsx.hbs +11 -1
  46. package/templates/app/src/hooks/useAppRoutes.ts.hbs +3 -6
  47. package/templates/app/src/hooks/usePluginLoader.ts.hbs +54 -7
  48. package/templates/app/src/hooks/usePluginStateSync.ts.hbs +81 -0
  49. package/templates/app/src/hooks/useThemeSync.ts.hbs +25 -74
  50. package/templates/app/src/layouts/MainContent.tsx.hbs +1 -1
  51. package/templates/app/src/layouts/SidebarNav.tsx.hbs +15 -14
  52. package/templates/app/src/main.tsx.hbs +2 -9
  53. package/templates/app/src/providers/AppProviders.tsx.hbs +2 -0
  54. package/templates/app/src/stores/useSessionStore.ts.hbs +1 -1
  55. package/templates/app/src/stores/useUIStore.ts.hbs +22 -3
  56. package/templates/app/src/vite-env.d.ts.hbs +1 -0
  57. package/templates/app/tailwind.config.cjs.hbs +26 -7
  58. package/templates/app/tsconfig.json.hbs +2 -5
  59. package/templates/app/vite.config.ts.hbs +67 -52
  60. package/templates/monorepo/package.json.hbs +1 -1
  61. package/templates/plugin/README.md.hbs +36 -0
  62. package/templates/plugin/package.json.hbs +26 -21
  63. package/templates/plugin/src/api/index.ts.hbs +3 -0
  64. package/templates/plugin/src/components/MainView.tsx.hbs +12 -0
  65. package/templates/plugin/src/index.tsx.hbs +39 -72
  66. package/templates/plugin/tsconfig.json.hbs +4 -15
  67. package/templates/app/src/services/api/modules/auth.ts.hbs +0 -18
@@ -0,0 +1,255 @@
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
+ };