@sokeai/cli 1.0.2 → 1.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sokeai/cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "授客AI官方CLI工具 - 支持AI Agent Skills",
5
5
  "bin": {
6
6
  "soke-cli": "scripts/run.js"
@@ -0,0 +1,219 @@
1
+ #!/bin/bash
2
+
3
+ # 授客CLI双远程仓库推送脚本
4
+ # 用途:将代码同时推送到 GitHub 和 Aliyun 远程仓库
5
+
6
+ set -e # 遇到错误立即退出
7
+
8
+ # 颜色定义
9
+ RED='\033[0;31m'
10
+ GREEN='\033[0;32m'
11
+ YELLOW='\033[1;33m'
12
+ BLUE='\033[0;34m'
13
+ NC='\033[0m' # No Color
14
+
15
+ # 打印带颜色的信息
16
+ print_info() {
17
+ echo -e "${GREEN}[信息]${NC} $1"
18
+ }
19
+
20
+ print_warning() {
21
+ echo -e "${YELLOW}[警告]${NC} $1"
22
+ }
23
+
24
+ print_error() {
25
+ echo -e "${RED}[错误]${NC} $1"
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
+
69
+ # 获取当前分支名
70
+ CURRENT_BRANCH=$(git branch --show-current)
71
+
72
+ # 显示当前分支并确认
73
+ echo ""
74
+ print_info "当前所在分支: ${GREEN}${CURRENT_BRANCH}${NC}"
75
+ echo ""
76
+ read -p "是否在当前分支提交代码?(y/n): " confirm
77
+
78
+ if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
79
+ print_warning "用户取消操作,脚本退出"
80
+ exit 0
81
+ fi
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
+
128
+ # 执行 git add .
129
+ print_info "正在暂存所有更改..."
130
+ git add .
131
+
132
+ # 检查是否有需要提交的更改
133
+ if git diff --cached --quiet; then
134
+ print_warning "没有需要提交的更改"
135
+ exit 0
136
+ fi
137
+
138
+ # 提示输入 commit 信息
139
+ echo ""
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
156
+ fi
157
+
158
+ # 执行 commit
159
+ print_info "正在提交代码..."
160
+ git commit -m "$commit_info"
161
+
162
+ # 保存当前分支名(用于后续合并)
163
+ FEATURE_BRANCH=$CURRENT_BRANCH
164
+
165
+ # 切换到 master 分支
166
+ print_info "切换到 master 分支..."
167
+ git checkout master
168
+
169
+ # 合并功能分支到 master
170
+ print_info "合并 ${FEATURE_BRANCH} 到 master..."
171
+ git merge $FEATURE_BRANCH
172
+
173
+ # 推送到 origin (Aliyun) 的 master 分支
174
+ print_info "推送到 Aliyun 远程仓库 (origin master)..."
175
+ git push origin master
176
+
177
+ # 推送到 github 的 master 分支
178
+ print_info "推送到 GitHub 远程仓库 (github master)..."
179
+ git push github master
180
+
181
+ # 切换到 main 分支
182
+ print_info "切换到 main 分支..."
183
+ git checkout main
184
+
185
+ # 合并 master 到 main
186
+ print_info "合并 master 到 main..."
187
+ git merge master
188
+
189
+ # 推送到 github 的 main 分支
190
+ print_info "推送到 GitHub 远程仓库 (github main)..."
191
+ git push github main
192
+
193
+ # 切换回原分支
194
+ print_info "切换回原分支 ${FEATURE_BRANCH}..."
195
+ git checkout $FEATURE_BRANCH
196
+
197
+ echo ""
198
+ print_info "✅ 代码推送完成!"
199
+ echo ""
200
+ print_info "推送摘要:"
201
+ echo " - 功能分支: ${FEATURE_BRANCH}"
202
+ echo " - Commit 信息: ${commit_info}"
203
+
204
+ if [[ "$IS_RELEASE" == true ]]; then
205
+ echo " - 🎉 版本发布: ${GREEN}v${NEW_VERSION}${NC}"
206
+ fi
207
+
208
+ echo " - Aliyun (origin): master 分支已更新"
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
+
219
+ echo ""
@@ -199,8 +199,8 @@ main() {
199
199
  echo -e "NPM: ${BLUE}https://www.npmjs.com/package/@sokeai/cli${NC}"
200
200
  echo -e "GitHub: ${BLUE}https://github.com/sokeai/soke-cli/releases/tag/v${VERSION}${NC}"
201
201
  echo ""
202
- echo "用户可以通过以下命令安装:"
203
- echo -e "${YELLOW}npm install -g @sokeai/cli${NC}"
202
+ echo "安装或升级到最新版本:"
203
+ echo -e "${YELLOW}npm install -g @sokeai/cli@latest${NC}"
204
204
  }
205
205
 
206
206
  # 确认发布