@zjex/git-workflow 0.0.2 → 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 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.0.2";async function pu(){switch(console.log(l.green(`
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.0.2",
3
+ "version": "0.1.1",
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": "./scripts/publish.sh",
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,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();
@@ -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 ""