@zjex/git-workflow 0.0.2 → 0.1.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/dist/index.js +1 -1
- package/package.json +4 -3
- package/scripts/version.js +138 -0
- package/scripts/version.sh +133 -0
package/dist/index.js
CHANGED
|
@@ -82,7 +82,7 @@ Commit \u547D\u4EE4:
|
|
|
82
82
|
\u5206\u652F\u547D\u540D\u683C\u5F0F:
|
|
83
83
|
feature/${W}-<Story ID>-<\u63CF\u8FF0>
|
|
84
84
|
hotfix/${W}-<Issue ID>-<\u63CF\u8FF0>
|
|
85
|
-
`}process.on("uncaughtException",e=>{e instanceof z&&process.exit(0),console.error(e),process.exit(1)});var Wt="0.0
|
|
85
|
+
`}process.on("uncaughtException",e=>{e instanceof z&&process.exit(0),console.error(e),process.exit(1)});var Wt="0.1.0";async function pu(){switch(console.log(l.green(`
|
|
86
86
|
\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557
|
|
87
87
|
\u255A\u2550\u2550\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u255A\u2588\u2588\u2557\u2588\u2588\u2554\u255D
|
|
88
88
|
\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557 \u255A\u2588\u2588\u2588\u2554\u255D
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zjex/git-workflow",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "个人常用的 Git 工作流工具,快速创建规范的开发分支和管理 Tag",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
"build": "tsup",
|
|
15
15
|
"dev": "tsx src/index.ts",
|
|
16
16
|
"changelog": "changelogen -o CHANGELOG.md",
|
|
17
|
+
"version": "node scripts/version.js",
|
|
17
18
|
"release": "./scripts/release.sh",
|
|
18
19
|
"release:dry": "./scripts/release.sh --dry-run",
|
|
19
|
-
"publish:npm": "npm run build && npm run changelog && npm publish",
|
|
20
|
+
"publish:npm": "npm run version && npm run build && npm run changelog && npm publish",
|
|
20
21
|
"prepublishOnly": "npm run build",
|
|
21
22
|
"prepare": "husky"
|
|
22
23
|
},
|
|
@@ -50,4 +51,4 @@
|
|
|
50
51
|
"tsx": "^4.21.0",
|
|
51
52
|
"typescript": "^5.9.3"
|
|
52
53
|
}
|
|
53
|
-
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { select, input } from "@inquirer/prompts";
|
|
4
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import { dirname, join } from "path";
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
|
|
11
|
+
// 颜色定义
|
|
12
|
+
const colors = {
|
|
13
|
+
reset: "\x1b[0m",
|
|
14
|
+
green: "\x1b[32m",
|
|
15
|
+
cyan: "\x1b[36m",
|
|
16
|
+
yellow: "\x1b[33m",
|
|
17
|
+
red: "\x1b[31m",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const log = {
|
|
21
|
+
info: (msg) => console.log(`${colors.cyan}ℹ ${msg}${colors.reset}`),
|
|
22
|
+
success: (msg) => console.log(`${colors.green}✔ ${msg}${colors.reset}`),
|
|
23
|
+
error: (msg) => console.log(`${colors.red}✖ ${msg}${colors.reset}`),
|
|
24
|
+
warning: (msg) => console.log(`${colors.yellow}⚠ ${msg}${colors.reset}`),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// 读取 package.json
|
|
28
|
+
const packagePath = join(__dirname, "../package.json");
|
|
29
|
+
const packageJson = JSON.parse(readFileSync(packagePath, "utf-8"));
|
|
30
|
+
const currentVersion = packageJson.version;
|
|
31
|
+
|
|
32
|
+
// 计算下一个版本号
|
|
33
|
+
function calculateNextVersion(current, type) {
|
|
34
|
+
const [major, minor, patch] = current.split(".").map(Number);
|
|
35
|
+
|
|
36
|
+
switch (type) {
|
|
37
|
+
case "patch":
|
|
38
|
+
return `${major}.${minor}.${patch + 1}`;
|
|
39
|
+
case "minor":
|
|
40
|
+
return `${major}.${minor + 1}.0`;
|
|
41
|
+
case "major":
|
|
42
|
+
return `${major + 1}.0.0`;
|
|
43
|
+
default:
|
|
44
|
+
return current;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 验证版本号格式
|
|
49
|
+
function validateVersion(version) {
|
|
50
|
+
const semverRegex =
|
|
51
|
+
/^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$/;
|
|
52
|
+
return semverRegex.test(version);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function main() {
|
|
56
|
+
console.log("");
|
|
57
|
+
log.info(`当前版本: ${colors.cyan}${currentVersion}${colors.reset}`);
|
|
58
|
+
console.log("");
|
|
59
|
+
|
|
60
|
+
const patchVersion = calculateNextVersion(currentVersion, "patch");
|
|
61
|
+
const minorVersion = calculateNextVersion(currentVersion, "minor");
|
|
62
|
+
const majorVersion = calculateNextVersion(currentVersion, "major");
|
|
63
|
+
|
|
64
|
+
const choices = [
|
|
65
|
+
{
|
|
66
|
+
name: `patch ${currentVersion} → ${patchVersion} (bug 修复)`,
|
|
67
|
+
value: { type: "patch", version: patchVersion },
|
|
68
|
+
description: "向后兼容的 bug 修复",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: `minor ${currentVersion} → ${minorVersion} (新功能)`,
|
|
72
|
+
value: { type: "minor", version: minorVersion },
|
|
73
|
+
description: "向后兼容的新功能",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: `major ${currentVersion} → ${majorVersion} (破坏性更新)`,
|
|
77
|
+
value: { type: "major", version: majorVersion },
|
|
78
|
+
description: "不向后兼容的重大更改",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "custom (自定义版本号)",
|
|
82
|
+
value: { type: "custom", version: null },
|
|
83
|
+
description: "输入自定义版本号",
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const answer = await select({
|
|
89
|
+
message: "选择新版本号:",
|
|
90
|
+
choices,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
let newVersion = answer.version;
|
|
94
|
+
|
|
95
|
+
// 如果选择自定义版本号
|
|
96
|
+
if (answer.type === "custom") {
|
|
97
|
+
newVersion = await input({
|
|
98
|
+
message: "请输入版本号:",
|
|
99
|
+
default: currentVersion,
|
|
100
|
+
validate: (value) => {
|
|
101
|
+
if (!value) {
|
|
102
|
+
return "版本号不能为空";
|
|
103
|
+
}
|
|
104
|
+
if (!validateVersion(value)) {
|
|
105
|
+
return "版本号格式无效,请使用语义化版本格式 (如 1.0.0 或 1.0.0-beta.1)";
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 更新 package.json
|
|
113
|
+
console.log("");
|
|
114
|
+
log.info(`正在更新版本号到 ${newVersion}...`);
|
|
115
|
+
|
|
116
|
+
packageJson.version = newVersion;
|
|
117
|
+
writeFileSync(
|
|
118
|
+
packagePath,
|
|
119
|
+
JSON.stringify(packageJson, null, "\t") + "\n",
|
|
120
|
+
"utf-8"
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
log.success(`版本号已更新: ${currentVersion} → ${newVersion}`);
|
|
124
|
+
console.log("");
|
|
125
|
+
|
|
126
|
+
process.exit(0);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (error.name === "ExitPromptError") {
|
|
129
|
+
console.log("");
|
|
130
|
+
log.info("已取消");
|
|
131
|
+
process.exit(0);
|
|
132
|
+
}
|
|
133
|
+
log.error(`发生错误: ${error.message}`);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
main();
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
|
|
5
|
+
# 颜色定义
|
|
6
|
+
RED='\033[0;31m'
|
|
7
|
+
GREEN='\033[0;32m'
|
|
8
|
+
YELLOW='\033[1;33m'
|
|
9
|
+
CYAN='\033[0;36m'
|
|
10
|
+
NC='\033[0m' # No Color
|
|
11
|
+
|
|
12
|
+
# 打印带颜色的消息
|
|
13
|
+
print_info() {
|
|
14
|
+
echo -e "${CYAN}ℹ ${1}${NC}"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
print_success() {
|
|
18
|
+
echo -e "${GREEN}✔ ${1}${NC}"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
print_error() {
|
|
22
|
+
echo -e "${RED}✖ ${1}${NC}"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
# 获取当前版本
|
|
26
|
+
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
|
27
|
+
|
|
28
|
+
# 计算下一个版本号
|
|
29
|
+
calculate_next_version() {
|
|
30
|
+
local current=$1
|
|
31
|
+
local type=$2
|
|
32
|
+
|
|
33
|
+
IFS='.' read -r major minor patch <<< "$current"
|
|
34
|
+
|
|
35
|
+
case $type in
|
|
36
|
+
patch)
|
|
37
|
+
echo "${major}.${minor}.$((patch + 1))"
|
|
38
|
+
;;
|
|
39
|
+
minor)
|
|
40
|
+
echo "${major}.$((minor + 1)).0"
|
|
41
|
+
;;
|
|
42
|
+
major)
|
|
43
|
+
echo "$((major + 1)).0.0"
|
|
44
|
+
;;
|
|
45
|
+
esac
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# 验证版本号格式
|
|
49
|
+
validate_version() {
|
|
50
|
+
if [[ ! $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$ ]]; then
|
|
51
|
+
return 1
|
|
52
|
+
fi
|
|
53
|
+
return 0
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# 显示当前版本
|
|
57
|
+
echo ""
|
|
58
|
+
print_info "当前版本: ${CURRENT_VERSION}"
|
|
59
|
+
echo ""
|
|
60
|
+
|
|
61
|
+
# 计算版本选项
|
|
62
|
+
PATCH_VERSION=$(calculate_next_version "$CURRENT_VERSION" "patch")
|
|
63
|
+
MINOR_VERSION=$(calculate_next_version "$CURRENT_VERSION" "minor")
|
|
64
|
+
MAJOR_VERSION=$(calculate_next_version "$CURRENT_VERSION" "major")
|
|
65
|
+
|
|
66
|
+
# 显示选项
|
|
67
|
+
echo "选择新版本号:"
|
|
68
|
+
echo ""
|
|
69
|
+
echo -e " ${GREEN}1)${NC} patch ${CYAN}${CURRENT_VERSION}${NC} → ${GREEN}${PATCH_VERSION}${NC} (bug 修复)"
|
|
70
|
+
echo -e " ${GREEN}2)${NC} minor ${CYAN}${CURRENT_VERSION}${NC} → ${GREEN}${MINOR_VERSION}${NC} (新功能)"
|
|
71
|
+
echo -e " ${GREEN}3)${NC} major ${CYAN}${CURRENT_VERSION}${NC} → ${GREEN}${MAJOR_VERSION}${NC} (破坏性更新)"
|
|
72
|
+
echo -e " ${GREEN}4)${NC} custom (自定义版本号)"
|
|
73
|
+
echo -e " ${RED}5)${NC} cancel (取消)"
|
|
74
|
+
echo ""
|
|
75
|
+
|
|
76
|
+
# 读取用户选择
|
|
77
|
+
while true; do
|
|
78
|
+
read -p "请选择 (1-5): " -n 1 -r VERSION_TYPE
|
|
79
|
+
echo ""
|
|
80
|
+
|
|
81
|
+
if [[ "$VERSION_TYPE" =~ ^[1-5]$ ]]; then
|
|
82
|
+
break
|
|
83
|
+
else
|
|
84
|
+
print_error "无效的选择,请输入 1-5"
|
|
85
|
+
fi
|
|
86
|
+
done
|
|
87
|
+
|
|
88
|
+
# 处理选择
|
|
89
|
+
case $VERSION_TYPE in
|
|
90
|
+
1)
|
|
91
|
+
NEW_VERSION=$PATCH_VERSION
|
|
92
|
+
;;
|
|
93
|
+
2)
|
|
94
|
+
NEW_VERSION=$MINOR_VERSION
|
|
95
|
+
;;
|
|
96
|
+
3)
|
|
97
|
+
NEW_VERSION=$MAJOR_VERSION
|
|
98
|
+
;;
|
|
99
|
+
4)
|
|
100
|
+
while true; do
|
|
101
|
+
read -p "请输入版本号 (如 1.0.0 或 1.0.0-beta.1): " CUSTOM_VERSION
|
|
102
|
+
|
|
103
|
+
if [[ -z "$CUSTOM_VERSION" ]]; then
|
|
104
|
+
print_error "版本号不能为空"
|
|
105
|
+
continue
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
if ! validate_version "$CUSTOM_VERSION"; then
|
|
109
|
+
print_error "版本号格式无效,请使用语义化版本格式 (如 1.0.0 或 1.0.0-beta.1)"
|
|
110
|
+
continue
|
|
111
|
+
fi
|
|
112
|
+
|
|
113
|
+
NEW_VERSION=$CUSTOM_VERSION
|
|
114
|
+
break
|
|
115
|
+
done
|
|
116
|
+
;;
|
|
117
|
+
5)
|
|
118
|
+
print_info "已取消"
|
|
119
|
+
exit 0
|
|
120
|
+
;;
|
|
121
|
+
esac
|
|
122
|
+
|
|
123
|
+
# 更新版本号
|
|
124
|
+
echo ""
|
|
125
|
+
print_info "正在更新版本号到 ${NEW_VERSION}..."
|
|
126
|
+
|
|
127
|
+
npm version "$NEW_VERSION" --no-git-tag-version > /dev/null 2>&1 || {
|
|
128
|
+
print_error "更新版本号失败"
|
|
129
|
+
exit 1
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
print_success "版本号已更新: ${CURRENT_VERSION} → ${NEW_VERSION}"
|
|
133
|
+
echo ""
|