@sokeai/cli 1.0.3 → 1.0.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/push.sh +117 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sokeai/cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "授客AI官方CLI工具 - 支持AI Agent Skills",
5
5
  "bin": {
6
6
  "soke-cli": "scripts/run.js"
package/scripts/push.sh CHANGED
@@ -9,6 +9,7 @@ set -e # 遇到错误立即退出
9
9
  RED='\033[0;31m'
10
10
  GREEN='\033[0;32m'
11
11
  YELLOW='\033[1;33m'
12
+ BLUE='\033[0;34m'
12
13
  NC='\033[0m' # No Color
13
14
 
14
15
  # 打印带颜色的信息
@@ -24,6 +25,47 @@ print_error() {
24
25
  echo -e "${RED}[错误]${NC} $1"
25
26
  }
26
27
 
28
+ print_highlight() {
29
+ echo -e "${BLUE}[提示]${NC} $1"
30
+ }
31
+
32
+ # 获取 package.json 中的当前版本号
33
+ get_current_version() {
34
+ if [[ ! -f "package.json" ]]; then
35
+ print_error "未找到 package.json 文件"
36
+ exit 1
37
+ fi
38
+
39
+ # 使用 grep 和 sed 提取版本号
40
+ version=$(grep '"version"' package.json | sed -E 's/.*"version": "([^"]+)".*/\1/')
41
+ echo "$version"
42
+ }
43
+
44
+ # 更新 package.json 中的版本号
45
+ update_version() {
46
+ local new_version=$1
47
+
48
+ if [[ "$OSTYPE" == "darwin"* ]]; then
49
+ # macOS 使用 BSD sed
50
+ sed -i '' "s/\"version\": \".*\"/\"version\": \"$new_version\"/" package.json
51
+ else
52
+ # Linux 使用 GNU sed
53
+ sed -i "s/\"version\": \".*\"/\"version\": \"$new_version\"/" package.json
54
+ fi
55
+
56
+ print_info "已更新 package.json 版本号为: ${GREEN}${new_version}${NC}"
57
+ }
58
+
59
+ # 验证版本号格式(简单的语义化版本检查)
60
+ validate_version() {
61
+ local version=$1
62
+ if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
63
+ print_error "版本号格式不正确,应为 x.y.z 格式(如 1.0.4)"
64
+ return 1
65
+ fi
66
+ return 0
67
+ }
68
+
27
69
  # 获取当前分支名
28
70
  CURRENT_BRANCH=$(git branch --show-current)
29
71
 
@@ -38,6 +80,51 @@ if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
38
80
  exit 0
39
81
  fi
40
82
 
83
+ # 询问是否作为新版本发布
84
+ echo ""
85
+ read -p "本次改动是否作为新版本发布?(y/n): " is_release
86
+
87
+ IS_RELEASE=false
88
+ NEW_VERSION=""
89
+
90
+ if [[ "$is_release" == "y" || "$is_release" == "Y" ]]; then
91
+ IS_RELEASE=true
92
+
93
+ # 获取当前版本号
94
+ CURRENT_VERSION=$(get_current_version)
95
+ print_highlight "当前版本号: ${BLUE}${CURRENT_VERSION}${NC}"
96
+
97
+ # 提示输入新版本号
98
+ while true; do
99
+ echo ""
100
+ read -p "请输入新版本号 (格式: x.y.z): " NEW_VERSION
101
+
102
+ if [[ -z "$NEW_VERSION" ]]; then
103
+ print_error "版本号不能为空"
104
+ continue
105
+ fi
106
+
107
+ if validate_version "$NEW_VERSION"; then
108
+ if [[ "$NEW_VERSION" == "$CURRENT_VERSION" ]]; then
109
+ print_warning "新版本号与当前版本号相同,是否继续?(y/n)"
110
+ read -p "> " continue_same
111
+ if [[ "$continue_same" == "y" || "$continue_same" == "Y" ]]; then
112
+ break
113
+ fi
114
+ else
115
+ break
116
+ fi
117
+ fi
118
+ done
119
+
120
+ # 更新 package.json 中的版本号
121
+ update_version "$NEW_VERSION"
122
+
123
+ # 将 package.json 的改动加入暂存区
124
+ git add package.json
125
+ print_info "已将 package.json 版本更新加入暂存区"
126
+ fi
127
+
41
128
  # 执行 git add .
42
129
  print_info "正在暂存所有更改..."
43
130
  git add .
@@ -50,11 +137,22 @@ fi
50
137
 
51
138
  # 提示输入 commit 信息
52
139
  echo ""
53
- read -p "请输入 commit 信息: " commit_info
54
-
55
- if [[ -z "$commit_info" ]]; then
56
- print_error "commit 信息不能为空"
57
- exit 1
140
+ if [[ "$IS_RELEASE" == true ]]; then
141
+ # 如果是版本发布,提供默认的 commit 信息
142
+ DEFAULT_COMMIT="chore: release v${NEW_VERSION}"
143
+ print_highlight "建议的 commit 信息: ${BLUE}${DEFAULT_COMMIT}${NC}"
144
+ read -p "请输入 commit 信息 (直接回车使用建议信息): " commit_info
145
+
146
+ if [[ -z "$commit_info" ]]; then
147
+ commit_info="$DEFAULT_COMMIT"
148
+ fi
149
+ else
150
+ read -p "请输入 commit 信息: " commit_info
151
+
152
+ if [[ -z "$commit_info" ]]; then
153
+ print_error "commit 信息不能为空"
154
+ exit 1
155
+ fi
58
156
  fi
59
157
 
60
158
  # 执行 commit
@@ -102,6 +200,20 @@ echo ""
102
200
  print_info "推送摘要:"
103
201
  echo " - 功能分支: ${FEATURE_BRANCH}"
104
202
  echo " - Commit 信息: ${commit_info}"
203
+
204
+ if [[ "$IS_RELEASE" == true ]]; then
205
+ echo " - 🎉 版本发布: ${GREEN}v${NEW_VERSION}${NC}"
206
+ fi
207
+
105
208
  echo " - Aliyun (origin): master 分支已更新"
106
209
  echo " - GitHub (github): master 和 main 分支已更新"
210
+
211
+ if [[ "$IS_RELEASE" == true ]]; then
212
+ echo ""
213
+ print_highlight "📦 下一步操作:"
214
+ echo " 1. 编译二进制文件: make build"
215
+ echo " 2. 发布到 NPM: npm publish"
216
+ echo " 3. 创建 GitHub Release (可选)"
217
+ fi
218
+
107
219
  echo ""