@x-all-in-one/coding-helper 0.4.1 → 0.4.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.
@@ -12,12 +12,14 @@ export declare class MainMenu {
12
12
  * @param handlers.onPlan - 套餐配置回调
13
13
  * @param handlers.onApiKey - API Key 配置回调
14
14
  * @param handlers.onTool - 工具配置回调
15
+ * @param handlers.onSelfUpdate - 自更新回调
15
16
  */
16
17
  show(handlers: {
17
18
  onLanguage: () => Promise<void>;
18
19
  onPlan: () => Promise<void>;
19
20
  onApiKey: () => Promise<void>;
20
21
  onTool: () => Promise<void>;
22
+ onSelfUpdate: () => Promise<void>;
21
23
  }): Promise<void>;
22
24
  /**
23
25
  * 打开官网
@@ -29,6 +29,7 @@ export class MainMenu {
29
29
  * @param handlers.onPlan - 套餐配置回调
30
30
  * @param handlers.onApiKey - API Key 配置回调
31
31
  * @param handlers.onTool - 工具配置回调
32
+ * @param handlers.onSelfUpdate - 自更新回调
32
33
  */
33
34
  async show(handlers) {
34
35
  const cfg = configManager.getConfig();
@@ -53,6 +54,7 @@ export class MainMenu {
53
54
  { name: `> ${i18n.t('wizard.menu_config_api_key')}`, value: 'apikey' },
54
55
  { name: `> ${i18n.t('wizard.menu_config_tool')}`, value: 'tool' },
55
56
  new inquirer.Separator(),
57
+ { name: `> ${i18n.t('wizard.menu_self_update')}`, value: 'self_update' },
56
58
  { name: `> ${i18n.t('wizard.menu_open_website')}`, value: 'website' },
57
59
  { name: `x ${i18n.t('wizard.menu_exit')}`, value: 'exit' },
58
60
  ];
@@ -65,6 +67,7 @@ export class MainMenu {
65
67
  message: i18n.t('wizard.select_operation'),
66
68
  choices,
67
69
  default: defaultChoice,
70
+ pageSize: 10,
68
71
  },
69
72
  ]);
70
73
  if (action === 'exit') {
@@ -83,6 +86,9 @@ export class MainMenu {
83
86
  else if (action === 'tool') {
84
87
  await handlers.onTool();
85
88
  }
89
+ else if (action === 'self_update') {
90
+ await handlers.onSelfUpdate();
91
+ }
86
92
  else if (action === 'website') {
87
93
  await this.openOfficialWebsite();
88
94
  }
@@ -47,6 +47,10 @@ export declare class Wizard {
47
47
  * 加载模型配置到工具
48
48
  */
49
49
  private loadModelConfig;
50
+ /**
51
+ * 自更新 Coding Helper
52
+ */
53
+ selfUpdate(): Promise<void>;
50
54
  /**
51
55
  * 显示主菜单
52
56
  */
@@ -1,4 +1,6 @@
1
+ import { execSync } from 'node:child_process';
1
2
  import chalk from 'chalk';
3
+ import ora from 'ora';
2
4
  import { configManager } from '../config.js';
3
5
  import { i18n } from '../i18n.js';
4
6
  import { toolRegistry } from '../tool-manager.js';
@@ -182,6 +184,26 @@ export class Wizard {
182
184
  async loadModelConfig(toolName) {
183
185
  await toolMenu.loadModelConfig(toolName);
184
186
  }
187
+ /**
188
+ * 自更新 Coding Helper
189
+ */
190
+ async selfUpdate() {
191
+ const spinner = ora({
192
+ text: i18n.t('wizard.self_updating'),
193
+ spinner: 'star2',
194
+ }).start();
195
+ try {
196
+ execSync('npm install -g @x-all-in-one/coding-helper', { stdio: 'pipe' });
197
+ spinner.succeed(chalk.green(i18n.t('wizard.self_updated')));
198
+ console.log(chalk.cyan(`\n${i18n.t('wizard.self_update_restart_hint')}\n`));
199
+ await new Promise(resolve => setTimeout(resolve, 2000));
200
+ process.exit(0);
201
+ }
202
+ catch {
203
+ spinner.fail(chalk.red(i18n.t('wizard.self_update_failed')));
204
+ await new Promise(resolve => setTimeout(resolve, 1500));
205
+ }
206
+ }
185
207
  /**
186
208
  * 显示主菜单
187
209
  */
@@ -191,6 +213,7 @@ export class Wizard {
191
213
  onPlan: () => this.configPlan(),
192
214
  onApiKey: () => this.configApiKey(),
193
215
  onTool: () => this.selectAndConfigureTool(),
216
+ onSelfUpdate: () => this.selfUpdate(),
194
217
  });
195
218
  }
196
219
  /**
@@ -186,6 +186,11 @@
186
186
  "updating_tool": "Updating {{tool}}...",
187
187
  "tool_updated": "{{tool}} updated successfully",
188
188
  "update_failed": "Update failed",
189
+ "menu_self_update": "Update Coding Helper",
190
+ "self_updating": "Updating Coding Helper...",
191
+ "self_updated": "Coding Helper updated successfully",
192
+ "self_update_failed": "Update failed",
193
+ "self_update_restart_hint": "Please run 'chelper' to use the new version",
189
194
  "plugin_submenu": "Plugin",
190
195
  "plugin_menu_title": "Plugin Menu",
191
196
  "plugin_not_installed": "{{plugin}} is not installed",
@@ -186,6 +186,11 @@
186
186
  "updating_tool": "正在更新 {{tool}}...",
187
187
  "tool_updated": "{{tool}} 更新成功",
188
188
  "update_failed": "更新失败",
189
+ "menu_self_update": "更新 Coding Helper",
190
+ "self_updating": "正在更新 Coding Helper...",
191
+ "self_updated": "Coding Helper 更新成功",
192
+ "self_update_failed": "更新失败",
193
+ "self_update_restart_hint": "请运行 'chelper' 以使用新版本",
189
194
  "plugin_submenu": "插件",
190
195
  "plugin_menu_title": "插件菜单",
191
196
  "plugin_not_installed": "{{plugin}} 尚未安装",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@x-all-in-one/coding-helper",
3
3
  "type": "module",
4
- "version": "0.4.1",
4
+ "version": "0.4.2",
5
5
  "description": "X All In One Coding Helper",
6
6
  "author": "X.AIO",
7
7
  "homepage": "https://docs.x-aio.com/zh/docs",