@zjex/git-workflow 0.1.0 → 0.1.1
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/README.md +3 -3
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/scripts/publish.sh +120 -0
- package/scripts/restore-prompt.js +33 -0
- package/scripts/stash-prompt.js +50 -0
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# @zjex/git-workflow
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<img src="https://img.shields.io/npm/v/@zjex/git-workflow.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="npm version">
|
|
5
|
-
<img src="https://img.shields.io/npm/dm/@zjex/git-workflow.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="npm downloads">
|
|
6
|
-
<img src="https://img.shields.io/npm/l/@zjex/git-workflow.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="license">
|
|
4
|
+
<a href="https://www.npmjs.com/package/@zjex/git-workflow"><img src="https://img.shields.io/npm/v/@zjex/git-workflow.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="npm version"></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@zjex/git-workflow"><img src="https://img.shields.io/npm/dm/@zjex/git-workflow.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="npm downloads"></a>
|
|
6
|
+
<a href="https://www.npmjs.com/package/@zjex/git-workflow"><img src="https://img.shields.io/npm/l/@zjex/git-workflow.svg?style=flat&colorA=18181B&colorB=28CF8D" alt="license"></a>
|
|
7
7
|
<img src="https://img.shields.io/badge/node-%3E%3D18-28CF8D?style=flat&colorA=18181B" alt="node version">
|
|
8
8
|
</p>
|
|
9
9
|
|
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.1.
|
|
85
|
+
`}process.on("uncaughtException",e=>{e instanceof z&&process.exit(0),console.error(e),process.exit(1)});var Wt="0.1.1";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.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "个人常用的 Git 工作流工具,快速创建规范的开发分支和管理 Tag",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"version": "node scripts/version.js",
|
|
18
18
|
"release": "./scripts/release.sh",
|
|
19
19
|
"release:dry": "./scripts/release.sh --dry-run",
|
|
20
|
-
"publish:npm": "
|
|
20
|
+
"publish:npm": "./scripts/publish.sh",
|
|
21
21
|
"prepublishOnly": "npm run build",
|
|
22
22
|
"prepare": "husky"
|
|
23
23
|
},
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
print_step() {
|
|
26
|
+
echo -e "${CYAN}▶ ${1}${NC}"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# 检查是否在 git 仓库中
|
|
30
|
+
if ! git rev-parse --git-dir > /dev/null 2>&1; then
|
|
31
|
+
print_error "当前目录不是 git 仓库"
|
|
32
|
+
exit 1
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
# 检查是否有未提交的更改(发布前的脏工作区)
|
|
36
|
+
if [[ -n $(git status --porcelain) ]]; then
|
|
37
|
+
echo ""
|
|
38
|
+
print_error "检测到未提交的更改,请先提交后再发布"
|
|
39
|
+
echo ""
|
|
40
|
+
git status --short
|
|
41
|
+
echo ""
|
|
42
|
+
print_info "提示: 可以使用 'gw c' 或 'git add . && git commit' 提交更改"
|
|
43
|
+
exit 1
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
# 检查 npm 登录状态
|
|
47
|
+
print_step "检查 npm 登录状态..."
|
|
48
|
+
if ! npm whoami &> /dev/null; then
|
|
49
|
+
print_error "未登录 npm,请先执行: npm login"
|
|
50
|
+
exit 1
|
|
51
|
+
fi
|
|
52
|
+
NPM_USER=$(npm whoami)
|
|
53
|
+
print_success "已登录 npm (用户: ${NPM_USER})"
|
|
54
|
+
|
|
55
|
+
# 获取当前分支
|
|
56
|
+
CURRENT_BRANCH=$(git branch --show-current)
|
|
57
|
+
print_info "当前分支: ${CURRENT_BRANCH}"
|
|
58
|
+
|
|
59
|
+
# 拉取最新代码
|
|
60
|
+
print_step "拉取最新代码..."
|
|
61
|
+
git pull origin "$CURRENT_BRANCH"
|
|
62
|
+
print_success "代码已更新"
|
|
63
|
+
|
|
64
|
+
# 获取当前版本
|
|
65
|
+
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
|
66
|
+
print_info "当前版本: ${CURRENT_VERSION}"
|
|
67
|
+
|
|
68
|
+
# 交互式选择版本号
|
|
69
|
+
print_step "选择新版本号..."
|
|
70
|
+
npm run version
|
|
71
|
+
|
|
72
|
+
# 获取新版本
|
|
73
|
+
NEW_VERSION=$(node -p "require('./package.json').version")
|
|
74
|
+
|
|
75
|
+
if [[ "$NEW_VERSION" == "$CURRENT_VERSION" ]]; then
|
|
76
|
+
print_info "版本号未更改,已取消发布"
|
|
77
|
+
exit 0
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
print_success "版本号已更新: ${CURRENT_VERSION} → ${NEW_VERSION}"
|
|
81
|
+
|
|
82
|
+
# 构建项目
|
|
83
|
+
print_step "构建项目..."
|
|
84
|
+
npm run build
|
|
85
|
+
print_success "构建完成"
|
|
86
|
+
|
|
87
|
+
# 生成 changelog
|
|
88
|
+
print_step "生成 CHANGELOG..."
|
|
89
|
+
npm run changelog
|
|
90
|
+
print_success "CHANGELOG 已更新"
|
|
91
|
+
|
|
92
|
+
# 提交版本更新和 changelog
|
|
93
|
+
print_step "提交版本更新..."
|
|
94
|
+
git add package.json CHANGELOG.md
|
|
95
|
+
git commit -m "🔖 chore(release): 发布 v${NEW_VERSION}"
|
|
96
|
+
print_success "版本更新已提交"
|
|
97
|
+
|
|
98
|
+
# 创建 tag
|
|
99
|
+
print_step "创建 tag: v${NEW_VERSION}..."
|
|
100
|
+
git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}"
|
|
101
|
+
print_success "Tag 已创建"
|
|
102
|
+
|
|
103
|
+
# 推送到远程
|
|
104
|
+
print_step "推送到远程仓库..."
|
|
105
|
+
git push origin "$CURRENT_BRANCH"
|
|
106
|
+
git push origin "v${NEW_VERSION}"
|
|
107
|
+
print_success "已推送到远程"
|
|
108
|
+
|
|
109
|
+
# 发布到 npm
|
|
110
|
+
print_step "发布到 npm..."
|
|
111
|
+
npm publish
|
|
112
|
+
print_success "已发布到 npm"
|
|
113
|
+
|
|
114
|
+
echo ""
|
|
115
|
+
print_success "🎉 发布成功!"
|
|
116
|
+
echo ""
|
|
117
|
+
echo "版本: v${NEW_VERSION}"
|
|
118
|
+
echo "GitHub: https://github.com/iamzjt-front-end/git-workflow/releases/tag/v${NEW_VERSION}"
|
|
119
|
+
echo "npm: https://www.npmjs.com/package/@zjex/git-workflow/v/${NEW_VERSION}"
|
|
120
|
+
echo ""
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { confirm } from "@inquirer/prompts";
|
|
4
|
+
|
|
5
|
+
const colors = {
|
|
6
|
+
reset: "\x1b[0m",
|
|
7
|
+
cyan: "\x1b[36m",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
console.log("");
|
|
12
|
+
console.log(`${colors.cyan}ℹ 之前暂存的更改可以恢复${colors.reset}`);
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const answer = await confirm({
|
|
16
|
+
message: "是否恢复暂存的更改? (Ctrl+C 跳过)",
|
|
17
|
+
default: false,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// 输出结果到 stdout
|
|
21
|
+
process.stdout.write((answer ? "yes" : "no") + "\n");
|
|
22
|
+
process.exit(0);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (error.name === "ExitPromptError") {
|
|
25
|
+
// Ctrl+C 被按下,静默退出,默认不恢复
|
|
26
|
+
process.stdout.write("no\n");
|
|
27
|
+
process.exit(0);
|
|
28
|
+
}
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
main();
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { select } from "@inquirer/prompts";
|
|
4
|
+
|
|
5
|
+
const colors = {
|
|
6
|
+
reset: "\x1b[0m",
|
|
7
|
+
cyan: "\x1b[36m",
|
|
8
|
+
yellow: "\x1b[33m",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
console.log("");
|
|
13
|
+
console.log(`${colors.cyan}ℹ 检测到未提交的更改${colors.reset}`);
|
|
14
|
+
console.log("");
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const answer = await select({
|
|
18
|
+
message: "请选择操作 (Ctrl+C 退出):",
|
|
19
|
+
choices: [
|
|
20
|
+
{
|
|
21
|
+
name: "提交这些更改后继续",
|
|
22
|
+
value: "commit",
|
|
23
|
+
description: "先提交当前更改,然后继续发布流程",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "暂存 (stash) 这些更改后继续",
|
|
27
|
+
value: "stash",
|
|
28
|
+
description: "将更改保存到 stash,发布完成后可以恢复",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "取消发布",
|
|
32
|
+
value: "cancel",
|
|
33
|
+
description: "退出发布流程",
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 输出结果到 stdout
|
|
39
|
+
process.stdout.write(answer + "\n");
|
|
40
|
+
process.exit(0);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (error.name === "ExitPromptError") {
|
|
43
|
+
// Ctrl+C 被按下,静默退出
|
|
44
|
+
process.exit(130); // 130 是 Ctrl+C 的标准退出码
|
|
45
|
+
}
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
main();
|