@zjex/git-workflow 0.2.6 → 0.2.9

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 CHANGED
@@ -1876,11 +1876,11 @@ async function performUpdate(packageName) {
1876
1876
  }).start();
1877
1877
  try {
1878
1878
  try {
1879
- execSync6("npm uninstall -g git-workflow", {
1879
+ execSync6(`npm uninstall -g ${packageName}`, {
1880
1880
  encoding: "utf-8",
1881
1881
  stdio: ["pipe", "pipe", "pipe"]
1882
1882
  });
1883
- spinner.text = "\u5DF2\u5378\u8F7D\u65E7\u7248\u672C\uFF0C\u6B63\u5728\u5B89\u88C5\u65B0\u7248\u672C...";
1883
+ spinner.text = "\u6B63\u5728\u5B89\u88C5\u65B0\u7248\u672C...";
1884
1884
  } catch {
1885
1885
  }
1886
1886
  execSync6(`npm install -g ${packageName}`, {
@@ -1889,17 +1889,31 @@ async function performUpdate(packageName) {
1889
1889
  });
1890
1890
  spinner.succeed(colors.green("\u66F4\u65B0\u6210\u529F\uFF01"));
1891
1891
  console.log("");
1892
- console.log(colors.cyan(" \u63D0\u793A: \u8BF7\u91CD\u65B0\u8FD0\u884C\u547D\u4EE4\u4EE5\u4F7F\u7528\u65B0\u7248\u672C"));
1893
- console.log("");
1892
+ console.log(
1893
+ boxen(
1894
+ [
1895
+ colors.bold("\u2728 \u66F4\u65B0\u5B8C\u6210\uFF01"),
1896
+ "",
1897
+ colors.dim("\u8BF7\u8FD0\u884C\u4EE5\u4E0B\u547D\u4EE4\u5237\u65B0\u5E76\u4F7F\u7528\u65B0\u7248\u672C:"),
1898
+ "",
1899
+ colors.yellow(" hash -r && gw --version"),
1900
+ "",
1901
+ colors.dim("\u6216\u8005\u91CD\u65B0\u6253\u5F00\u7EC8\u7AEF")
1902
+ ].join("\n"),
1903
+ {
1904
+ padding: 1,
1905
+ margin: { top: 0, bottom: 1, left: 2, right: 2 },
1906
+ borderStyle: "round",
1907
+ borderColor: "green",
1908
+ align: "left"
1909
+ }
1910
+ )
1911
+ );
1894
1912
  process.exit(0);
1895
1913
  } catch (error) {
1896
1914
  spinner.fail(colors.red("\u66F4\u65B0\u5931\u8D25"));
1897
1915
  console.log("");
1898
1916
  console.log(colors.dim(" \u4F60\u53EF\u4EE5\u624B\u52A8\u8FD0\u884C\u4EE5\u4E0B\u547D\u4EE4\u66F4\u65B0:"));
1899
- console.log(colors.yellow(" # \u5982\u679C\u4E4B\u524D\u5B89\u88C5\u8FC7\u65E7\u7248\u672C\uFF0C\u5148\u5378\u8F7D:"));
1900
- console.log(colors.cyan(" npm uninstall -g git-workflow"));
1901
- console.log("");
1902
- console.log(colors.yellow(" # \u7136\u540E\u5B89\u88C5\u65B0\u7248\u672C:"));
1903
1917
  console.log(colors.cyan(` npm install -g ${packageName}`));
1904
1918
  console.log("");
1905
1919
  }
@@ -1949,7 +1963,7 @@ process.on("SIGTERM", () => {
1949
1963
  console.log("");
1950
1964
  process.exit(0);
1951
1965
  });
1952
- var version = true ? "0.2.6" : "0.0.0-dev";
1966
+ var version = true ? "0.2.9" : "0.0.0-dev";
1953
1967
  async function mainMenu() {
1954
1968
  await checkForUpdates(version, "@zjex/git-workflow");
1955
1969
  console.log(
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@zjex/git-workflow",
3
- "version": "0.2.6",
4
- "description": "个人常用的 Git 工作流工具,快速创建规范的开发分支和管理 Tag",
3
+ "version": "0.2.9",
4
+ "description": "🚀 极简的 Git 工作流 CLI 工具,让分支管理和版本发布变得轻松愉快",
5
5
  "type": "module",
6
6
  "bin": {
7
- "git-flow": "./dist/index.js",
8
- "gw": "./dist/index.js"
7
+ "git-flow": "dist/index.js",
8
+ "gw": "dist/index.js"
9
9
  },
10
10
  "publishConfig": {
11
11
  "access": "public"
@@ -52,4 +52,4 @@
52
52
  "tsx": "^4.21.0",
53
53
  "typescript": "^5.9.3"
54
54
  }
55
- }
55
+ }
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+
3
+ import boxen from "boxen";
4
+
5
+ const version = process.argv[2];
6
+
7
+ if (!version) {
8
+ console.error("请提供版本号");
9
+ process.exit(1);
10
+ }
11
+
12
+ const message = [
13
+ "\x1b[1m🎉 发布成功!\x1b[0m",
14
+ "",
15
+ `\x1b[36m版本:\x1b[0m \x1b[1mv${version}\x1b[0m`,
16
+ ].join("\n");
17
+
18
+ console.log("");
19
+ console.log(
20
+ boxen(message, {
21
+ padding: { top: 1, bottom: 1, left: 8, right: 8 },
22
+ margin: { top: 0, bottom: 1, left: 0, right: 0 },
23
+ borderStyle: "round",
24
+ borderColor: "green",
25
+ align: "center",
26
+ })
27
+ );
28
+
29
+ console.log(
30
+ "\x1b[2m 🔗 \x1b[0m\x1b[36mGitHub:\x1b[0m \x1b[2m\x1b[4mhttps://github.com/iamzjt-front-end/git-workflow/releases/tag/v" +
31
+ version +
32
+ "\x1b[0m"
33
+ );
34
+ console.log(
35
+ "\x1b[2m 📦 \x1b[0m\x1b[36mnpm:\x1b[0m \x1b[2m\x1b[4mhttps://www.npmjs.com/package/@zjex/git-workflow\x1b[0m"
36
+ );
37
+ console.log("");
@@ -7,67 +7,115 @@ RED='\033[0;31m'
7
7
  GREEN='\033[0;32m'
8
8
  YELLOW='\033[1;33m'
9
9
  CYAN='\033[0;36m'
10
+ BLUE='\033[0;34m'
11
+ DIM='\033[2m'
12
+ BOLD='\033[1m'
10
13
  NC='\033[0m' # No Color
11
14
 
12
15
  # 打印带颜色的消息
13
16
  print_info() {
14
- echo -e "${CYAN}${1}${NC}"
15
- }
16
-
17
- print_success() {
18
- echo -e "${GREEN}✔ ${1}${NC}"
17
+ echo -e "${CYAN}${1}${NC}"
19
18
  }
20
19
 
21
20
  print_error() {
22
21
  echo -e "${RED}✖ ${1}${NC}"
23
22
  }
24
23
 
25
- print_step() {
26
- echo -e "${CYAN}${1}${NC}"
24
+ print_dim() {
25
+ echo -e "${DIM} ${1}${NC}"
26
+ }
27
+
28
+ # 执行步骤(带完成标记,折叠输出)
29
+ run_step() {
30
+ local step_num=$1
31
+ local step_name=$2
32
+ local command=$3
33
+
34
+ echo -ne "${BLUE}[${step_num}/${TOTAL_STEPS}]${NC} ${step_name}... "
35
+
36
+ # 执行命令并捕获输出
37
+ if output=$(eval "$command" 2>&1); then
38
+ echo -e "${GREEN}✅${NC}"
39
+ return 0
40
+ else
41
+ echo -e "${RED}❌${NC}"
42
+ echo ""
43
+ echo -e "${RED}错误详情:${NC}"
44
+ echo "$output"
45
+ return 1
46
+ fi
27
47
  }
28
48
 
29
- # 检查是否在 git 仓库中
30
- if ! git rev-parse --git-dir > /dev/null 2>&1; then
49
+ # 执行步骤(显示输出,用于交互式命令)
50
+ run_step_interactive() {
51
+ local step_num=$1
52
+ local step_name=$2
53
+ local command=$3
54
+
55
+ echo -e "${BLUE}[${step_num}/${TOTAL_STEPS}]${NC} ${step_name}..."
56
+ echo ""
57
+
58
+ if eval "$command"; then
59
+ echo ""
60
+ return 0
61
+ else
62
+ echo -e "${RED} ❌ 失败${NC}"
63
+ return 1
64
+ fi
65
+ }
66
+
67
+ # 总步骤数
68
+ TOTAL_STEPS=11
69
+
70
+ echo ""
71
+ echo -e "${BOLD}🚀 开始发布流程${NC}"
72
+ echo ""
73
+
74
+
75
+ # [1] 检查是否在 git 仓库中
76
+ if ! run_step "1" "检查 Git 仓库" "git rev-parse --git-dir"; then
31
77
  print_error "当前目录不是 git 仓库"
32
78
  exit 1
33
79
  fi
34
80
 
35
- # 检查是否有未提交的更改(发布前的脏工作区)
81
+ # [2] 检查是否有未提交的更改
82
+ echo -ne "${BLUE}[2/${TOTAL_STEPS}]${NC} 检查工作区状态... "
36
83
  if [[ -n $(git status --porcelain) ]]; then
84
+ echo -e "${RED}❌${NC}"
37
85
  echo ""
38
86
  print_error "检测到未提交的更改,请先提交后再发布"
39
87
  echo ""
40
88
  git status --short
41
89
  echo ""
42
- print_info "提示: 可以使用 'gw c' 或 'git add . && git commit' 提交更改"
90
+ print_info "💡 提示: 可以使用 'gw c' 提交更改"
43
91
  exit 1
92
+ else
93
+ echo -e "${GREEN}✅${NC}"
44
94
  fi
45
95
 
46
- # 检查 npm 登录状态
47
- print_step "检查 npm 登录状态..."
96
+ # [3] 检查 npm 登录状态
97
+ echo -ne "${BLUE}[3/${TOTAL_STEPS}]${NC} 检查 npm 登录状态... "
48
98
  if ! npm whoami &> /dev/null; then
99
+ echo -e "${RED}❌${NC}"
49
100
  print_error "未登录 npm,请先执行: npm login"
50
101
  exit 1
51
102
  fi
52
103
  NPM_USER=$(npm whoami)
53
- print_success "已登录 npm (用户: ${NPM_USER})"
104
+ echo -e "${GREEN}✅${NC} ${DIM}(${NPM_USER})${NC}"
54
105
 
55
106
  # 获取当前分支
56
107
  CURRENT_BRANCH=$(git branch --show-current)
57
- print_info "当前分支: ${CURRENT_BRANCH}"
58
108
 
59
- # 拉取最新代码
60
- print_step "拉取最新代码..."
61
- git pull origin "$CURRENT_BRANCH"
62
- print_success "代码已更新"
109
+ # [4] 拉取最新代码
110
+ if ! run_step "4" "拉取最新代码" "git pull origin '$CURRENT_BRANCH'"; then
111
+ exit 1
112
+ fi
63
113
 
64
114
  # 获取当前版本
65
115
  CURRENT_VERSION=$(node -p "require('./package.json').version")
66
- print_info "当前版本: ${CURRENT_VERSION}"
67
116
 
68
- # 交互式选择版本号
69
- print_step "选择新版本号..."
70
- npm run version
117
+ # [5] 交互式选择版本号
118
+ run_step_interactive "5" "选择新版本号" "npm run version"
71
119
 
72
120
  # 获取新版本
73
121
  NEW_VERSION=$(node -p "require('./package.json').version")
@@ -77,44 +125,59 @@ if [[ "$NEW_VERSION" == "$CURRENT_VERSION" ]]; then
77
125
  exit 0
78
126
  fi
79
127
 
80
- print_success "版本号已更新: ${CURRENT_VERSION} → ${NEW_VERSION}"
128
+ # 显示版本升级信息
129
+ echo -e "${GREEN} ✅${NC} ${DIM}(${CURRENT_VERSION} → ${NEW_VERSION})${NC}"
81
130
 
82
- # 构建项目
83
- print_step "构建项目..."
84
- npm run build
85
- print_success "构建完成"
131
+ # [6] 构建项目
132
+ if ! run_step "6" "构建项目" "npm run build"; then
133
+ exit 1
134
+ fi
86
135
 
87
- # 生成 changelog
88
- print_step "生成 CHANGELOG..."
89
- npm run changelog
90
- print_success "CHANGELOG 已更新"
136
+ # [7] 生成 changelog
137
+ if ! run_step "7" "生成 CHANGELOG" "npm run changelog"; then
138
+ exit 1
139
+ fi
91
140
 
92
- # 提交版本更新和 changelog
93
- print_step "提交版本更新..."
94
- git add package.json CHANGELOG.md
95
- git commit -m "🔖 chore(release): 发布 v${NEW_VERSION}"
96
- print_success "版本更新已提交"
141
+ # [8] 提交版本更新和 changelog
142
+ echo -ne "${BLUE}[8/${TOTAL_STEPS}]${NC} 提交版本更新... "
143
+ if output=$(git add package.json CHANGELOG.md && git commit -m "🔖 chore(release): 发布 v${NEW_VERSION}" 2>&1); then
144
+ echo -e "${GREEN}✅${NC} ${DIM}(🔖 chore(release): 发布 v${NEW_VERSION})${NC}"
145
+ else
146
+ echo -e "${RED}❌${NC}"
147
+ echo ""
148
+ echo -e "${RED}错误详情:${NC}"
149
+ echo "$output"
150
+ exit 1
151
+ fi
97
152
 
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 已创建"
153
+ # [9] 创建 tag
154
+ echo -ne "${BLUE}[9/${TOTAL_STEPS}]${NC} 创建 Git Tag... "
155
+ if output=$(git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}" 2>&1); then
156
+ echo -e "${GREEN}✅${NC} ${DIM}(v${NEW_VERSION})${NC}"
157
+ else
158
+ echo -e "${RED}❌${NC}"
159
+ echo ""
160
+ echo -e "${RED}错误详情:${NC}"
161
+ echo "$output"
162
+ exit 1
163
+ fi
102
164
 
103
- # 推送到远程
104
- print_step "推送到远程仓库..."
105
- git push origin "$CURRENT_BRANCH"
106
- git push origin "v${NEW_VERSION}"
107
- print_success "已推送到远程"
165
+ # [10] 推送到远程
166
+ echo -ne "${BLUE}[10/${TOTAL_STEPS}]${NC} 推送到远程仓库... "
167
+ if output=$(git push origin "$CURRENT_BRANCH" && git push origin "v${NEW_VERSION}" 2>&1); then
168
+ echo -e "${GREEN}✅${NC} ${DIM}(${CURRENT_BRANCH}, v${NEW_VERSION})${NC}"
169
+ else
170
+ echo -e "${RED}❌${NC}"
171
+ echo ""
172
+ echo -e "${RED}错误详情:${NC}"
173
+ echo "$output"
174
+ exit 1
175
+ fi
108
176
 
109
- # 发布到 npm
110
- print_step "发布到 npm..."
111
- npm publish
112
- print_success "已发布到 npm"
177
+ # [11] 发布到 npm
178
+ if ! run_step "11" "发布到 npm" "npm publish"; then
179
+ exit 1
180
+ fi
113
181
 
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 ""
182
+ # 成功总结
183
+ node scripts/publish-success.js "${NEW_VERSION}"
@@ -145,18 +145,18 @@ async function performUpdate(packageName: string): Promise<void> {
145
145
  }).start();
146
146
 
147
147
  try {
148
- // 先尝试卸载旧版本(无 scope 的版本)
148
+ // 先卸载当前版本,确保干净安装
149
149
  try {
150
- execSync("npm uninstall -g git-workflow", {
150
+ execSync(`npm uninstall -g ${packageName}`, {
151
151
  encoding: "utf-8",
152
152
  stdio: ["pipe", "pipe", "pipe"],
153
153
  });
154
- spinner.text = "已卸载旧版本,正在安装新版本...";
154
+ spinner.text = "正在安装新版本...";
155
155
  } catch {
156
- // 旧版本不存在,忽略错误
156
+ // 当前版本不存在,忽略错误
157
157
  }
158
158
 
159
- // 执行更新命令
159
+ // 执行安装命令
160
160
  execSync(`npm install -g ${packageName}`, {
161
161
  encoding: "utf-8",
162
162
  stdio: ["pipe", "pipe", "pipe"],
@@ -164,8 +164,26 @@ async function performUpdate(packageName: string): Promise<void> {
164
164
 
165
165
  spinner.succeed(colors.green("更新成功!"));
166
166
  console.log("");
167
- console.log(colors.cyan(" 提示: 请重新运行命令以使用新版本"));
168
- console.log("");
167
+ console.log(
168
+ boxen(
169
+ [
170
+ colors.bold("✨ 更新完成!"),
171
+ "",
172
+ colors.dim("请运行以下命令刷新并使用新版本:"),
173
+ "",
174
+ colors.yellow(" hash -r && gw --version"),
175
+ "",
176
+ colors.dim("或者重新打开终端"),
177
+ ].join("\n"),
178
+ {
179
+ padding: 1,
180
+ margin: { top: 0, bottom: 1, left: 2, right: 2 },
181
+ borderStyle: "round",
182
+ borderColor: "green",
183
+ align: "left",
184
+ }
185
+ )
186
+ );
169
187
 
170
188
  // 更新成功后退出,让用户重新运行
171
189
  process.exit(0);
@@ -173,10 +191,6 @@ async function performUpdate(packageName: string): Promise<void> {
173
191
  spinner.fail(colors.red("更新失败"));
174
192
  console.log("");
175
193
  console.log(colors.dim(" 你可以手动运行以下命令更新:"));
176
- console.log(colors.yellow(" # 如果之前安装过旧版本,先卸载:"));
177
- console.log(colors.cyan(" npm uninstall -g git-workflow"));
178
- console.log("");
179
- console.log(colors.yellow(" # 然后安装新版本:"));
180
194
  console.log(colors.cyan(` npm install -g ${packageName}`));
181
195
  console.log("");
182
196
  }
package/test-box.sh ADDED
@@ -0,0 +1,18 @@
1
+ #!/bin/bash
2
+
3
+ GREEN='\033[0;32m'
4
+ CYAN='\033[0;36m'
5
+ BOLD='\033[1m'
6
+ NC='\033[0m'
7
+
8
+ NEW_VERSION="0.2.8"
9
+
10
+ echo ""
11
+ echo -e "${GREEN}╭──────────────────────────────╮${NC}"
12
+ echo -e "${GREEN}│ │${NC}"
13
+ echo -e "${GREEN}│${NC} ${BOLD}🎉 发布成功!${NC} ${GREEN}│${NC}"
14
+ echo -e "${GREEN}│ │${NC}"
15
+ echo -e "${GREEN}│${NC} ${CYAN}版本:${NC} ${BOLD}v${NEW_VERSION}${NC} ${GREEN}│${NC}"
16
+ echo -e "${GREEN}│ │${NC}"
17
+ echo -e "${GREEN}╰──────────────────────────────╯${NC}"
18
+ echo ""
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+
3
+ BLUE='\033[0;34m'
4
+ GREEN='\033[0;32m'
5
+ CYAN='\033[0;36m'
6
+ DIM='\033[2m'
7
+ BOLD='\033[1m'
8
+ NC='\033[0m'
9
+
10
+ TOTAL_STEPS=11
11
+ NEW_VERSION="0.2.8"
12
+ CURRENT_BRANCH="main"
13
+
14
+ echo ""
15
+ echo -e "${BOLD}🚀 开始发布流程${NC}"
16
+ echo ""
17
+
18
+ echo -e "${BLUE}[1/${TOTAL_STEPS}]${NC} 检查 Git 仓库... ${GREEN}✅${NC}"
19
+ echo -e "${BLUE}[2/${TOTAL_STEPS}]${NC} 检查工作区状态... ${GREEN}✅${NC}"
20
+ echo -e "${BLUE}[3/${TOTAL_STEPS}]${NC} 检查 npm 登录状态... ${GREEN}✅${NC} ${DIM}(zjex)${NC}"
21
+ echo -e "${BLUE}[4/${TOTAL_STEPS}]${NC} 拉取最新代码... ${GREEN}✅${NC}"
22
+ echo -e "${BLUE}[5/${TOTAL_STEPS}]${NC} 选择新版本号... ${GREEN}✅${NC} ${DIM}(0.2.7 → 0.2.8)${NC}"
23
+ echo -e "${BLUE}[6/${TOTAL_STEPS}]${NC} 构建项目... ${GREEN}✅${NC}"
24
+ echo -e "${BLUE}[7/${TOTAL_STEPS}]${NC} 生成 CHANGELOG... ${GREEN}✅${NC}"
25
+ echo -e "${BLUE}[8/${TOTAL_STEPS}]${NC} 提交版本更新... ${GREEN}✅${NC} ${DIM}(🔖 chore(release): 发布 v${NEW_VERSION})${NC}"
26
+ echo -e "${BLUE}[9/${TOTAL_STEPS}]${NC} 创建 Git Tag... ${GREEN}✅${NC} ${DIM}(v${NEW_VERSION})${NC}"
27
+ echo -e "${BLUE}[10/${TOTAL_STEPS}]${NC} 推送到远程仓库... ${GREEN}✅${NC} ${DIM}(${CURRENT_BRANCH}, v${NEW_VERSION})${NC}"
28
+ echo -e "${BLUE}[11/${TOTAL_STEPS}]${NC} 发布到 npm... ${GREEN}✅${NC}"
29
+
30
+ node scripts/publish-success.js "${NEW_VERSION}"