Skip to content

Commit 1848dcf

Browse files
committed
feat: add update command to auto-update eff-u-code
- Add 'fuck-u-code update' command to update to latest version - Check current and latest versions from npm - Auto-install latest version globally - Add translations for en/zh/ru - Add update command to CLI help examples
1 parent 6a59ca3 commit 1848dcf

File tree

8 files changed

+151
-3
lines changed

8 files changed

+151
-3
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ fuck-u-code config set ai.model gpt-4o # Set AI model
9797
fuck-u-code config set ai.apiKey sk-xxx # Set API key
9898
```
9999

100+
### Update
101+
102+
Update eff-u-code to the latest version:
103+
104+
```bash
105+
fuck-u-code update # Update to latest version
106+
```
107+
108+
This will:
109+
- Check current installed version
110+
- Check latest version on npm
111+
- Auto-install the latest version globally
112+
100113
### Uninstall
101114

102115
Remove fuck-u-code and clean up all local files:

README_RU.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ fuck-u-code config set ai.model gpt-4o # Установить модель
9898
fuck-u-code config set ai.apiKey sk-xxx # Установить API-ключ
9999
```
100100

101+
### Обновление
102+
103+
Обновить eff-u-code до последней версии:
104+
105+
```bash
106+
fuck-u-code update # Обновить до последней версии
107+
```
108+
109+
Будет выполнено:
110+
- Проверка текущей установленной версии
111+
- Проверка последней версии на npm
112+
- Автоматическая установка последней версии глобально
113+
101114
### Удаление
102115

103116
Удалить fuck-u-code и очистить все локальные файлы:

README_ZH.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ fuck-u-code config set ai.model gpt-4o # 设置 AI 模型
9797
fuck-u-code config set ai.apiKey sk-xxx # 设置 API 密钥
9898
```
9999

100+
### 更新
101+
102+
更新 eff-u-code 到最新版本:
103+
104+
```bash
105+
fuck-u-code update # 更新到最新版本
106+
```
107+
108+
将会执行:
109+
- 检查当前安装的版本
110+
- 检查 npm 上的最新版本
111+
- 自动安装最新版本到全局
112+
100113
### 卸载
101114

102115
移除 fuck-u-code 并清理所有本地文件:

src/cli/commands/update.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Update command - updates eff-u-code to the latest version
3+
*/
4+
5+
import { Command } from 'commander';
6+
import { execSync } from 'node:child_process';
7+
import { t } from '../../i18n/index.js';
8+
import chalk from 'chalk';
9+
10+
interface NpmListOutput {
11+
dependencies?: {
12+
'eff-u-code'?: {
13+
version: string;
14+
};
15+
};
16+
}
17+
18+
export function createUpdateCommand(): Command {
19+
const command = new Command('update');
20+
21+
command
22+
.description(t('cmd_update_description'))
23+
.addHelpText(
24+
'after',
25+
`
26+
${t('cli_examples')}
27+
$ fuck-u-code update # ${t('cmd_update_example')}
28+
`
29+
)
30+
.action(() => {
31+
try {
32+
console.log(chalk.blue('🔄 ' + t('update_checking')));
33+
34+
// Get current version
35+
const currentVersion = execSync('npm list -g eff-u-code --depth=0 --json', {
36+
encoding: 'utf-8',
37+
});
38+
const current = JSON.parse(currentVersion) as NpmListOutput;
39+
const installedVersion = current.dependencies?.['eff-u-code']?.version ?? 'unknown';
40+
41+
// Get latest version from npm
42+
const latestVersionOutput = execSync('npm view eff-u-code version', {
43+
encoding: 'utf-8',
44+
}).trim();
45+
46+
console.log(chalk.gray(`${t('update_current_version')}: ${installedVersion}`));
47+
console.log(chalk.gray(`${t('update_latest_version')}: ${latestVersionOutput}`));
48+
49+
if (installedVersion === latestVersionOutput) {
50+
console.log(chalk.green('✓ ' + t('update_already_latest')));
51+
return;
52+
}
53+
54+
console.log(chalk.yellow('⬆ ' + t('update_updating')));
55+
56+
// Update the package
57+
execSync('npm install -g eff-u-code@latest', {
58+
stdio: 'inherit',
59+
});
60+
61+
console.log(chalk.green('✓ ' + t('update_success')));
62+
console.log(chalk.gray(`${t('update_updated_to')}: ${latestVersionOutput}`));
63+
} catch (error) {
64+
console.error(chalk.red('✗ ' + t('update_failed')));
65+
if (error instanceof Error) {
66+
console.error(chalk.red(error.message));
67+
}
68+
process.exit(1);
69+
}
70+
});
71+
72+
return command;
73+
}

src/cli/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createAIReviewCommand } from './commands/ai-review.js';
88
import { createConfigCommand } from './commands/config.js';
99
import { createMcpInstallCommand } from './commands/mcp-install.js';
1010
import { createUninstallCommand } from './commands/uninstall.js';
11+
import { createUpdateCommand } from './commands/update.js';
1112
import { t, setLocale, type Locale } from '../i18n/index.js';
1213
import { loadLocaleFromConfig } from '../config/index.js';
1314
import { getSupportedLanguageNames } from '../parser/index.js';
@@ -32,6 +33,7 @@ ${t('cli_examples')}
3233
$ fuck-u-code analyze . --locale zh # ${t('cli_example_analyze_locale')}
3334
$ fuck-u-code ai-review . --model gpt-4o # ${t('cli_example_ai_review')}
3435
$ fuck-u-code mcp-install claude # ${t('cli_example_mcp_install')}
36+
$ fuck-u-code update # ${t('cmd_update_example')}
3537
$ fuck-u-code uninstall # ${t('uninstall_example')}
3638
3739
${t('cli_supported_languages')}
@@ -43,6 +45,7 @@ ${t('cli_supported_languages')}
4345
program.addCommand(createAIReviewCommand());
4446
program.addCommand(createConfigCommand());
4547
program.addCommand(createMcpInstallCommand());
48+
program.addCommand(createUpdateCommand());
4649
program.addCommand(createUninstallCommand());
4750

4851
return program;

src/i18n/locales/en.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,5 +371,16 @@
371371
"uninstall_no_cursor": "No MCP entry in Cursor",
372372
"uninstall_removed_npm": "Uninstalled global npm package",
373373
"uninstall_no_npm": "No global npm package found",
374-
"uninstall_complete": "✓ Uninstall complete. Goodbye!"
374+
"uninstall_complete": "✓ Uninstall complete. Goodbye!",
375+
376+
"cmd_update_description": "Update eff-u-code to the latest version",
377+
"cmd_update_example": "Update to latest version",
378+
"update_checking": "Checking for updates...",
379+
"update_current_version": "Current version",
380+
"update_latest_version": "Latest version",
381+
"update_already_latest": "Already on the latest version",
382+
"update_updating": "Updating eff-u-code...",
383+
"update_success": "Update successful!",
384+
"update_updated_to": "Updated to version",
385+
"update_failed": "Update failed"
375386
}

src/i18n/locales/ru.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,5 +371,16 @@
371371
"uninstall_no_cursor": "Запись MCP в Cursor не найдена",
372372
"uninstall_removed_npm": "Удален глобальный npm-пакет",
373373
"uninstall_no_npm": "Глобальный npm-пакет не найден",
374-
"uninstall_complete": "✓ Удаление завершено. До свидания!"
374+
"uninstall_complete": "✓ Удаление завершено. До свидания!",
375+
376+
"cmd_update_description": "Обновить eff-u-code до последней версии",
377+
"cmd_update_example": "Обновить до последней версии",
378+
"update_checking": "Проверка обновлений...",
379+
"update_current_version": "Текущая версия",
380+
"update_latest_version": "Последняя версия",
381+
"update_already_latest": "Уже установлена последняя версия",
382+
"update_updating": "Обновление eff-u-code...",
383+
"update_success": "Обновление успешно!",
384+
"update_updated_to": "Обновлено до версии",
385+
"update_failed": "Обновление не удалось"
375386
}

src/i18n/locales/zh.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,5 +372,16 @@
372372
"uninstall_no_cursor": "Cursor 中无 MCP 配置",
373373
"uninstall_removed_npm": "已卸载全局 npm 包",
374374
"uninstall_no_npm": "未找到全局 npm 包",
375-
"uninstall_complete": "✓ 卸载完成。再见!"
375+
"uninstall_complete": "✓ 卸载完成。再见!",
376+
377+
"cmd_update_description": "更新 eff-u-code 到最新版本",
378+
"cmd_update_example": "更新到最新版本",
379+
"update_checking": "正在检查更新...",
380+
"update_current_version": "当前版本",
381+
"update_latest_version": "最新版本",
382+
"update_already_latest": "已经是最新版本",
383+
"update_updating": "正在更新 eff-u-code...",
384+
"update_success": "更新成功!",
385+
"update_updated_to": "已更新到版本",
386+
"update_failed": "更新失败"
376387
}

0 commit comments

Comments
 (0)