daodou-command 1.1.1 → 1.2.0
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/CHANGELOG.md +95 -0
- package/bin/daodou.js +23 -1
- package/lib/commands/upgrade.js +151 -0
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# 更新日志
|
|
2
|
+
|
|
3
|
+
所有重要的项目更改都将记录在此文件中。
|
|
4
|
+
|
|
5
|
+
格式基于 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.0.0/),
|
|
6
|
+
并且此项目遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
7
|
+
|
|
8
|
+
## [未发布]
|
|
9
|
+
|
|
10
|
+
### 新增
|
|
11
|
+
### 更改
|
|
12
|
+
### 修复
|
|
13
|
+
### 移除
|
|
14
|
+
|
|
15
|
+
## [1.2.0] - 2025-09-16
|
|
16
|
+
|
|
17
|
+
### 新增
|
|
18
|
+
- 添加 `dao upgrade` 命令用于检查和更新工具版本
|
|
19
|
+
- 支持 `--check` 选项仅检查版本不更新
|
|
20
|
+
- 支持 `--force` 选项强制更新
|
|
21
|
+
- 自动从npm获取最新版本信息
|
|
22
|
+
- 智能版本比较和更新提示
|
|
23
|
+
- 主程序自动读取package.json中的版本号,无需手动维护
|
|
24
|
+
|
|
25
|
+
### 更改
|
|
26
|
+
- 将update命令重命名为upgrade,更符合CLI工具命名习惯
|
|
27
|
+
- 优化版本管理流程,减少手动维护工作
|
|
28
|
+
|
|
29
|
+
### 技术改进
|
|
30
|
+
- 改进错误处理和用户反馈
|
|
31
|
+
- 添加彩色输出和加载动画
|
|
32
|
+
- 增强网络超时和错误恢复机制
|
|
33
|
+
|
|
34
|
+
## [1.1.2] - 2025-09-16
|
|
35
|
+
|
|
36
|
+
### 修复
|
|
37
|
+
- 修复主程序版本号显示问题
|
|
38
|
+
- 主程序现在自动读取package.json中的版本号,无需手动维护
|
|
39
|
+
|
|
40
|
+
## [1.1.1] - 2025-09-16
|
|
41
|
+
|
|
42
|
+
### 修复
|
|
43
|
+
- 修复主程序版本号显示问题
|
|
44
|
+
- 主程序现在自动读取package.json中的版本号,无需手动维护
|
|
45
|
+
|
|
46
|
+
## [1.1.0] - 2025-09-16
|
|
47
|
+
|
|
48
|
+
### 新增
|
|
49
|
+
- 在package.json中添加git仓库信息
|
|
50
|
+
- 添加repository字段,指向GitHub仓库
|
|
51
|
+
- 添加bugs字段,指向GitHub issues页面
|
|
52
|
+
- 添加homepage字段,指向项目主页
|
|
53
|
+
|
|
54
|
+
### 更改
|
|
55
|
+
- 版本号从1.0.0升级到1.1.0
|
|
56
|
+
- 更新了npm包信息,现在包含完整的仓库链接
|
|
57
|
+
|
|
58
|
+
## [1.0.0] - 2025-09-16
|
|
59
|
+
|
|
60
|
+
### 新增
|
|
61
|
+
- 初始版本发布
|
|
62
|
+
- 支持自动化构建功能
|
|
63
|
+
- 自动检测Git分支
|
|
64
|
+
- 一键触发Jenkins构建
|
|
65
|
+
- 实时监听构建进度
|
|
66
|
+
- 支持多语言管理功能
|
|
67
|
+
- 多语言文件管理
|
|
68
|
+
- 自动翻译功能(Google Translate API)
|
|
69
|
+
- 多代理轮换绕过API限制
|
|
70
|
+
- 命令行工具基础功能
|
|
71
|
+
- 使用commander.js构建CLI
|
|
72
|
+
- 支持help和version命令
|
|
73
|
+
- 配置文件自动生成和管理
|
|
74
|
+
|
|
75
|
+
### 技术特性
|
|
76
|
+
- 基于Node.js开发
|
|
77
|
+
- 使用simple-git进行Git操作
|
|
78
|
+
- 集成Google Translate API
|
|
79
|
+
- 支持代理轮换
|
|
80
|
+
- 使用Puppeteer进行浏览器自动化
|
|
81
|
+
- 支持JSON5配置文件格式
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 版本说明
|
|
86
|
+
|
|
87
|
+
- **主版本号(MAJOR)**: 当你做了不兼容的API修改
|
|
88
|
+
- **次版本号(MINOR)**: 当你做了向下兼容的功能性新增
|
|
89
|
+
- **修订号(PATCH)**: 当你做了向下兼容的问题修正
|
|
90
|
+
|
|
91
|
+
## 链接
|
|
92
|
+
|
|
93
|
+
- [GitHub仓库](https://github.com/h025/daodou-command)
|
|
94
|
+
- [npm包页面](https://www.npmjs.com/package/daodou-command)
|
|
95
|
+
- [问题反馈](https://github.com/h025/daodou-command/issues)
|
package/bin/daodou.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const { Command } = require('commander');
|
|
4
4
|
const chalk = require('chalk');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const packageJson = require('../package.json');
|
|
5
7
|
const buildCommand = require('../lib/commands/build');
|
|
6
8
|
const langCommand = require('../lib/commands/lang');
|
|
7
9
|
|
|
@@ -11,7 +13,7 @@ const program = new Command();
|
|
|
11
13
|
program
|
|
12
14
|
.name('dao')
|
|
13
15
|
.description('刀豆命令行工具 - 自动化构建和部署')
|
|
14
|
-
.version(
|
|
16
|
+
.version(packageJson.version, '-v, --version');
|
|
15
17
|
|
|
16
18
|
// 添加 build 命令
|
|
17
19
|
program
|
|
@@ -32,6 +34,22 @@ program
|
|
|
32
34
|
}
|
|
33
35
|
});
|
|
34
36
|
|
|
37
|
+
// 添加 upgrade 命令
|
|
38
|
+
program
|
|
39
|
+
.command('upgrade')
|
|
40
|
+
.description('检查并更新daodou-command到最新版本')
|
|
41
|
+
.option('-c, --check', '仅检查是否有新版本,不执行更新')
|
|
42
|
+
.option('-f, --force', '强制更新到最新版本')
|
|
43
|
+
.action(async (options) => {
|
|
44
|
+
try {
|
|
45
|
+
const upgradeCommand = require('../lib/commands/upgrade');
|
|
46
|
+
await upgradeCommand.execute(options);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error(chalk.red('更新失败:'), error.message);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
35
53
|
// 添加 lang 命令
|
|
36
54
|
const langCmd = program
|
|
37
55
|
.command('lang')
|
|
@@ -73,6 +91,10 @@ program.addHelpText('after', `
|
|
|
73
91
|
$ dao build --jenkins-url http://jenkins.example.com
|
|
74
92
|
$ dao build --parameters '{"param1":"value1"}'
|
|
75
93
|
|
|
94
|
+
$ dao upgrade # 检查并更新到最新版本
|
|
95
|
+
$ dao upgrade --check # 仅检查是否有新版本
|
|
96
|
+
$ dao upgrade --force # 强制更新到最新版本
|
|
97
|
+
|
|
76
98
|
$ dao lang add "hello"
|
|
77
99
|
$ dao lang add "hello" "Hello World"
|
|
78
100
|
$ dao lang add "world" --lang en
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
const ora = require('ora');
|
|
4
|
+
const { execSync } = require('child_process');
|
|
5
|
+
const packageJson = require('../../package.json');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 获取npm上的最新版本号
|
|
9
|
+
* @returns {Promise<string>} 最新版本号
|
|
10
|
+
*/
|
|
11
|
+
async function getLatestVersion() {
|
|
12
|
+
try {
|
|
13
|
+
const response = await axios.get(`https://registry.npmjs.org/${packageJson.name}/latest`, {
|
|
14
|
+
timeout: 10000
|
|
15
|
+
});
|
|
16
|
+
return response.data.version;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw new Error(`获取最新版本失败: ${error.message}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 获取当前安装的版本号
|
|
24
|
+
* @returns {string} 当前版本号
|
|
25
|
+
*/
|
|
26
|
+
function getCurrentVersion() {
|
|
27
|
+
return packageJson.version;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 比较版本号
|
|
32
|
+
* @param {string} current 当前版本
|
|
33
|
+
* @param {string} latest 最新版本
|
|
34
|
+
* @returns {boolean} 是否有更新
|
|
35
|
+
*/
|
|
36
|
+
function hasUpdate(current, latest) {
|
|
37
|
+
const currentParts = current.split('.').map(Number);
|
|
38
|
+
const latestParts = latest.split('.').map(Number);
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {
|
|
41
|
+
const currentPart = currentParts[i] || 0;
|
|
42
|
+
const latestPart = latestParts[i] || 0;
|
|
43
|
+
|
|
44
|
+
if (latestPart > currentPart) {
|
|
45
|
+
return true;
|
|
46
|
+
} else if (latestPart < currentPart) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 执行npm更新
|
|
56
|
+
* @param {string} version 要更新的版本
|
|
57
|
+
*/
|
|
58
|
+
function updatePackage(version) {
|
|
59
|
+
try {
|
|
60
|
+
console.log(chalk.blue(`正在更新到版本 ${version}...`));
|
|
61
|
+
execSync(`npm install -g ${packageJson.name}@${version} --force`, {
|
|
62
|
+
stdio: 'inherit',
|
|
63
|
+
timeout: 300000 // 5分钟超时
|
|
64
|
+
});
|
|
65
|
+
console.log(chalk.green(`✅ 成功更新到版本 ${version}`));
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw new Error(`更新失败: ${error.message}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 显示更新信息
|
|
73
|
+
* @param {string} current 当前版本
|
|
74
|
+
* @param {string} latest 最新版本
|
|
75
|
+
* @param {boolean} hasUpdateAvailable 是否有更新
|
|
76
|
+
*/
|
|
77
|
+
function displayUpdateInfo(current, latest, hasUpdateAvailable) {
|
|
78
|
+
console.log(chalk.cyan('📦 daodou-command 版本信息:'));
|
|
79
|
+
console.log(` 当前版本: ${chalk.yellow(current)}`);
|
|
80
|
+
console.log(` 最新版本: ${chalk.yellow(latest)}`);
|
|
81
|
+
|
|
82
|
+
if (hasUpdateAvailable) {
|
|
83
|
+
console.log(chalk.red(' ⚠️ 有新版本可用!'));
|
|
84
|
+
console.log(chalk.gray(' 使用 "dao update" 命令进行更新'));
|
|
85
|
+
} else {
|
|
86
|
+
console.log(chalk.green(' ✅ 已是最新版本'));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 执行更新命令
|
|
92
|
+
* @param {Object} options 命令选项
|
|
93
|
+
*/
|
|
94
|
+
async function execute(options) {
|
|
95
|
+
const spinner = ora('检查更新中...').start();
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
// 获取版本信息
|
|
99
|
+
const currentVersion = getCurrentVersion();
|
|
100
|
+
const latestVersion = await getLatestVersion();
|
|
101
|
+
const hasUpdateAvailable = hasUpdate(currentVersion, latestVersion);
|
|
102
|
+
|
|
103
|
+
spinner.stop();
|
|
104
|
+
|
|
105
|
+
// 显示版本信息
|
|
106
|
+
displayUpdateInfo(currentVersion, latestVersion, hasUpdateAvailable);
|
|
107
|
+
|
|
108
|
+
// 如果只是检查版本,直接返回
|
|
109
|
+
if (options.check) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 如果没有更新且不是强制更新,提示用户
|
|
114
|
+
if (!hasUpdateAvailable && !options.force) {
|
|
115
|
+
console.log(chalk.gray(' 无需更新'));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 如果有更新或强制更新,执行更新
|
|
120
|
+
if (hasUpdateAvailable || options.force) {
|
|
121
|
+
console.log(); // 空行
|
|
122
|
+
|
|
123
|
+
if (options.force && !hasUpdateAvailable) {
|
|
124
|
+
console.log(chalk.yellow('⚠️ 强制更新到当前版本'));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
updatePackage(latestVersion);
|
|
128
|
+
|
|
129
|
+
// 验证更新结果
|
|
130
|
+
console.log(chalk.blue('验证更新结果...'));
|
|
131
|
+
try {
|
|
132
|
+
const { execSync } = require('child_process');
|
|
133
|
+
const newVersion = execSync('dao --version', { encoding: 'utf8' }).trim();
|
|
134
|
+
console.log(chalk.green(`✅ 更新完成!当前版本: ${newVersion}`));
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.log(chalk.yellow('⚠️ 更新完成,但无法验证版本号'));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
} catch (error) {
|
|
141
|
+
spinner.stop();
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module.exports = {
|
|
147
|
+
execute,
|
|
148
|
+
getLatestVersion,
|
|
149
|
+
getCurrentVersion,
|
|
150
|
+
hasUpdate
|
|
151
|
+
};
|