ccman 2.1.3 → 2.1.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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +308 -258
  3. package/README_en.md +444 -0
  4. package/dist/cli.js +213 -33
  5. package/dist/cli.js.map +1 -1
  6. package/dist/config/default-providers.d.ts +34 -0
  7. package/dist/config/default-providers.d.ts.map +1 -0
  8. package/dist/config/default-providers.js +96 -0
  9. package/dist/config/default-providers.js.map +1 -0
  10. package/dist/config/static-env.d.ts +1 -1
  11. package/dist/config/static-env.js +1 -1
  12. package/package.json +24 -3
  13. package/.editorconfig +0 -15
  14. package/.env.development +0 -3
  15. package/.env.production +0 -3
  16. package/.eslintrc.js +0 -28
  17. package/.github/workflows/release.yml +0 -99
  18. package/.prettierrc +0 -10
  19. package/CLAUDE.md +0 -279
  20. package/README_zh.md +0 -394
  21. package/dev-test.sh +0 -40
  22. package/docs/npm-publish-guide.md +0 -71
  23. package/docs/release-guide.md +0 -144
  24. package/docs/scripts-guide.md +0 -221
  25. package/docs/version-management.md +0 -64
  26. package/jest.config.js +0 -22
  27. package/release-temp/README.md +0 -394
  28. package/release-temp/package.json +0 -61
  29. package/scripts/build-env.js +0 -75
  30. package/scripts/modules/check-uncommitted.sh +0 -109
  31. package/scripts/modules/create-tag.sh +0 -279
  32. package/scripts/modules/monitor-release.sh +0 -296
  33. package/scripts/modules/version-bump.sh +0 -262
  34. package/scripts/publish-local.sh +0 -91
  35. package/scripts/quick-release.sh +0 -100
  36. package/scripts/release.sh +0 -430
  37. package/scripts/smart-release-v3.sh +0 -283
  38. package/scripts/smart-release.sh +0 -322
  39. package/src/cli.ts +0 -598
  40. package/src/commands/lang.ts +0 -105
  41. package/src/core/CCMConfigManager.ts +0 -259
  42. package/src/core/ClaudeConfigManager.ts +0 -141
  43. package/src/i18n/LanguageManager.ts +0 -169
  44. package/src/i18n/messages.ts +0 -233
  45. package/src/index.ts +0 -4
  46. package/src/providers/ProviderManager.ts +0 -412
  47. package/src/types/index.ts +0 -101
  48. package/src/utils/env-config.ts +0 -53
  49. package/src/utils/version.ts +0 -16
  50. package/tsconfig.json +0 -25
@@ -1,296 +0,0 @@
1
- #!/bin/bash
2
-
3
- # 脚本4: 发布状态监控模块
4
- # 功能: 监控GitHub Actions、NPM发布、GitHub Release状态
5
-
6
- set -e
7
-
8
- # 颜色定义
9
- GREEN='\033[0;32m'
10
- YELLOW='\033[1;33m'
11
- RED='\033[0;31m'
12
- BLUE='\033[0;34m'
13
- CYAN='\033[0;36m'
14
- NC='\033[0m'
15
-
16
- print_success() { echo -e "${GREEN}✅ $1${NC}"; }
17
- print_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
18
- print_error() { echo -e "${RED}❌ $1${NC}"; }
19
- print_info() { echo -e "${BLUE}ℹ️ $1${NC}"; }
20
- print_check() { echo -e "${CYAN}🔍 $1${NC}"; }
21
-
22
- # 配置
23
- REPO_OWNER="2ue"
24
- REPO_NAME="ccm"
25
- PACKAGE_NAME="ccman"
26
- MAX_WAIT_MINUTES=5
27
- CHECK_INTERVAL=15 # 秒
28
-
29
- # 获取版本信息
30
- get_version_info() {
31
- if [ ! -f "package.json" ]; then
32
- print_error "package.json 未找到"
33
- exit 1
34
- fi
35
-
36
- local version=$(node -p "require('./package.json').version" 2>/dev/null || echo "")
37
- if [ -z "$version" ]; then
38
- print_error "无法读取版本号"
39
- exit 1
40
- fi
41
-
42
- echo "$version"
43
- }
44
-
45
- # 获取最新commit ID
46
- get_latest_commit() {
47
- git rev-parse HEAD 2>/dev/null || echo "unknown"
48
- }
49
-
50
- # 输出监控链接
51
- show_monitoring_links() {
52
- local version=$1
53
- local commit_id=$2
54
- local tag_name="v$version"
55
-
56
- print_info "📊 监控链接:"
57
- echo " 🔗 GitHub Actions: https://github.com/${REPO_OWNER}/${REPO_NAME}/actions"
58
- echo " 🔗 GitHub Actions (Commit): https://github.com/${REPO_OWNER}/${REPO_NAME}/commit/${commit_id}/checks"
59
- echo " 🔗 NPM Package: https://www.npmjs.com/package/${PACKAGE_NAME}"
60
- echo " 🔗 NPM Version: https://www.npmjs.com/package/${PACKAGE_NAME}/v/${version}"
61
- echo " 🔗 GitHub Releases: https://github.com/${REPO_OWNER}/${REPO_NAME}/releases"
62
- echo " 🔗 GitHub Release: https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/tag/${tag_name}"
63
- echo ""
64
- }
65
-
66
- # 检查GitHub Actions状态
67
- check_github_actions() {
68
- local max_attempts=$((MAX_WAIT_MINUTES * 60 / CHECK_INTERVAL))
69
- local attempt=0
70
-
71
- print_check "监控 GitHub Actions 状态..."
72
-
73
- while [ $attempt -lt $max_attempts ]; do
74
- # 检查最新的workflow运行状态
75
- local api_response=$(curl -s "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/actions/runs?per_page=1" 2>/dev/null || echo "")
76
-
77
- if [ -n "$api_response" ] && ! echo "$api_response" | grep -q '"message"'; then
78
- local run_status=$(echo "$api_response" | grep -o '"status":"[^"]*"' | head -1 | cut -d'"' -f4 2>/dev/null || echo "unknown")
79
- local run_conclusion=$(echo "$api_response" | grep -o '"conclusion":"[^"]*"' | head -1 | cut -d'"' -f4 2>/dev/null || echo "null")
80
-
81
- case "$run_status" in
82
- "completed")
83
- echo # 换行
84
- if [ "$run_conclusion" = "success" ]; then
85
- print_success "GitHub Actions 构建成功! ✨"
86
- return 0
87
- else
88
- print_error "GitHub Actions 构建失败: $run_conclusion ❌"
89
- return 1
90
- fi
91
- ;;
92
- "in_progress")
93
- echo -ne "\r${CYAN}🔄 GitHub Actions 运行中... (${attempt}/${max_attempts}) - 状态: $run_status${NC}"
94
- ;;
95
- "queued")
96
- echo -ne "\r${YELLOW}⏳ GitHub Actions 排队中... (${attempt}/${max_attempts})${NC}"
97
- ;;
98
- *)
99
- echo -ne "\r${YELLOW}⏳ 等待 GitHub Actions 启动... (${attempt}/${max_attempts})${NC}"
100
- ;;
101
- esac
102
- else
103
- echo -ne "\r${YELLOW}⏳ 连接 GitHub API... (${attempt}/${max_attempts})${NC}"
104
- fi
105
-
106
- sleep $CHECK_INTERVAL
107
- ((attempt++))
108
- done
109
-
110
- echo # 换行
111
- print_warning "GitHub Actions 检查超时 (${MAX_WAIT_MINUTES}分钟)"
112
- return 2
113
- }
114
-
115
- # 检查NPM包发布状态
116
- check_npm_package() {
117
- local version=$1
118
- local max_attempts=$((MAX_WAIT_MINUTES * 60 / CHECK_INTERVAL))
119
- local attempt=0
120
-
121
- print_check "监控 NPM 包发布状态..."
122
-
123
- while [ $attempt -lt $max_attempts ]; do
124
- # 检查NPM包版本
125
- local npm_response=$(curl -s "https://registry.npmjs.org/${PACKAGE_NAME}" 2>/dev/null || echo "")
126
-
127
- if [ -n "$npm_response" ]; then
128
- # 检查是否包含目标版本
129
- if echo "$npm_response" | grep -q "\"$version\""; then
130
- print_success "NPM 包 v$version 发布成功! 📦"
131
- return 0
132
- fi
133
- fi
134
-
135
- echo -ne "\r${CYAN}📦 等待 NPM 包发布... (${attempt}/${max_attempts})${NC}"
136
- sleep $CHECK_INTERVAL
137
- ((attempt++))
138
- done
139
-
140
- echo # 换行
141
- print_warning "NPM 包检查超时 (${MAX_WAIT_MINUTES}分钟)"
142
- return 2
143
- }
144
-
145
- # 检查GitHub Release状态
146
- check_github_release() {
147
- local version=$1
148
- local tag_name="v$version"
149
- local max_attempts=$((MAX_WAIT_MINUTES * 60 / CHECK_INTERVAL))
150
- local attempt=0
151
-
152
- print_check "监控 GitHub Release 状态..."
153
-
154
- while [ $attempt -lt $max_attempts ]; do
155
- # 检查GitHub Release
156
- local release_response=$(curl -s "https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/tags/${tag_name}" 2>/dev/null || echo "")
157
-
158
- if [ -n "$release_response" ] && ! echo "$release_response" | grep -q '"message":"Not Found"'; then
159
- # 检查release状态
160
- local release_draft=$(echo "$release_response" | grep -o '"draft":[^,}]*' | cut -d':' -f2 | tr -d ' ' 2>/dev/null || echo "true")
161
-
162
- # 调试输出
163
- # echo "[DEBUG] release_draft = '$release_draft'" >&2
164
-
165
- if [ "$release_draft" = "false" ]; then
166
- echo # 换行
167
- print_success "GitHub Release v$version 创建成功! 🎉"
168
- return 0
169
- else
170
- echo -ne "\r${YELLOW}📝 GitHub Release 为草稿状态... (${attempt}/${max_attempts})${NC}"
171
- fi
172
- else
173
- echo -ne "\r${CYAN}🎯 等待 GitHub Release 创建... (${attempt}/${max_attempts})${NC}"
174
- fi
175
-
176
- sleep $CHECK_INTERVAL
177
- ((attempt++))
178
- done
179
-
180
- echo # 换行
181
- print_warning "GitHub Release 检查超时 (${MAX_WAIT_MINUTES}分钟)"
182
- return 2
183
- }
184
-
185
- # 状态图标映射函数
186
- get_status_icon() {
187
- case $1 in
188
- 0) echo "✅" ;;
189
- 1) echo "❌" ;;
190
- 2) echo "⏳" ;;
191
- *) echo "❓" ;;
192
- esac
193
- }
194
-
195
- # 生成发布总结
196
- generate_summary() {
197
- local version=$1
198
- local actions_status=$2
199
- local npm_status=$3
200
- local release_status=$4
201
-
202
- echo ""
203
- echo "📋 发布监控总结"
204
- echo "================"
205
-
206
- echo " 版本: v$version"
207
- echo " GitHub Actions: $(get_status_icon $actions_status)"
208
- echo " NPM 包发布: $(get_status_icon $npm_status)"
209
- echo " GitHub Release: $(get_status_icon $release_status)"
210
- echo ""
211
-
212
- # 整体状态判断
213
- if [ $actions_status -eq 0 ] && [ $npm_status -eq 0 ] && [ $release_status -eq 0 ]; then
214
- print_success "🎉 发布完全成功!所有组件都已正常发布"
215
- return 0
216
- elif [ $actions_status -eq 1 ]; then
217
- print_error "❌ 发布失败:GitHub Actions 构建失败"
218
- return 1
219
- elif [ $actions_status -eq 2 ] || [ $npm_status -eq 2 ] || [ $release_status -eq 2 ]; then
220
- print_warning "⏳ 发布可能仍在进行中,建议稍后手动检查"
221
- return 2
222
- else
223
- print_warning "⚠️ 发布部分成功,请检查失败的组件"
224
- return 3
225
- fi
226
- }
227
-
228
- # 主函数: 监控发布状态(只监控NPM和Release)
229
- monitor_release() {
230
- local version=$(get_version_info)
231
- local commit_id=$(get_latest_commit)
232
-
233
- echo "📊 CCM 发布状态监控器"
234
- echo "===================="
235
- print_info "版本: v$version"
236
- print_info "提交: ${commit_id:0:8}"
237
- print_info "超时: ${MAX_WAIT_MINUTES} 分钟"
238
- echo ""
239
-
240
- # 显示监控链接(只显示需要的)
241
- print_info "📊 监控链接:"
242
- echo " 🔗 NPM Package: https://www.npmjs.com/package/${PACKAGE_NAME}"
243
- echo " 🔗 NPM Version: https://www.npmjs.com/package/${PACKAGE_NAME}/v/${version}"
244
- echo " 🔗 GitHub Release: https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/tag/v${version}"
245
- echo ""
246
-
247
- # 检查curl是否可用
248
- if ! command -v curl &> /dev/null; then
249
- print_error "curl 未安装,无法进行状态检查"
250
- print_info "请手动访问上述链接检查发布状态"
251
- return 1
252
- fi
253
-
254
- print_info "开始监控发布状态... (最长等待 ${MAX_WAIT_MINUTES} 分钟)"
255
- echo ""
256
-
257
- # 检查NPM包发布
258
- check_npm_package "$version"
259
- local npm_status=$?
260
-
261
- # 检查GitHub Release
262
- check_github_release "$version"
263
- local release_status=$?
264
-
265
- # 生成总结报告
266
- echo ""
267
- echo "📋 发布监控总结"
268
- echo "================"
269
- echo " 版本: v$version"
270
- echo " NPM 包发布: $(get_status_icon $npm_status)"
271
- echo " GitHub Release: $(get_status_icon $release_status)"
272
- echo ""
273
-
274
- # 结果判断
275
- if [ $npm_status -eq 0 ] && [ $release_status -eq 0 ]; then
276
- print_success "🎉 发布完成!NPM包和GitHub Release都已正常发布"
277
- return 0
278
- elif [ $npm_status -eq 2 ] || [ $release_status -eq 2 ]; then
279
- print_warning "⚠️ 发布监控超时 (${MAX_WAIT_MINUTES}分钟),请手动检查:"
280
- if [ $npm_status -eq 2 ]; then
281
- echo " • NPM包状态: https://www.npmjs.com/package/${PACKAGE_NAME}/v/${version}"
282
- fi
283
- if [ $release_status -eq 2 ]; then
284
- echo " • GitHub Release: https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/tag/v${version}"
285
- fi
286
- return 2
287
- else
288
- print_warning "⚠️ 发布部分失败,请手动检查上述链接"
289
- return 1
290
- fi
291
- }
292
-
293
- # 如果直接运行此脚本
294
- if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
295
- monitor_release "$@"
296
- fi
@@ -1,262 +0,0 @@
1
- #!/bin/bash
2
-
3
- # 脚本2: 版本提升模块
4
- # 功能: 智能选择和执行版本号升级
5
-
6
- set -e
7
-
8
- # 颜色定义
9
- GREEN='\033[0;32m'
10
- YELLOW='\033[1;33m'
11
- RED='\033[0;31m'
12
- BLUE='\033[0;34m'
13
- NC='\033[0m'
14
-
15
- print_success() { echo -e "${GREEN}✅ $1${NC}"; }
16
- print_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
17
- print_error() { echo -e "${RED}❌ $1${NC}"; }
18
- print_info() { echo -e "${BLUE}ℹ️ $1${NC}"; }
19
-
20
- # 获取当前版本
21
- get_current_version() {
22
- if [ ! -f "package.json" ]; then
23
- print_error "package.json 未找到"
24
- exit 1
25
- fi
26
-
27
- current_version=$(node -p "require('./package.json').version" 2>/dev/null || echo "")
28
- if [ -z "$current_version" ]; then
29
- print_error "无法读取当前版本号"
30
- exit 1
31
- fi
32
-
33
- echo "$current_version"
34
- }
35
-
36
- # 计算版本预览
37
- calculate_version_preview() {
38
- local version_type=$1
39
- local preview=$(pnpm version $version_type --dry-run 2>/dev/null)
40
-
41
- if [ -n "$preview" ]; then
42
- # 移除前缀v并返回
43
- echo "$preview" | sed 's/^v//'
44
- else
45
- echo "计算失败"
46
- fi
47
- }
48
-
49
- # 分析git提交推荐版本类型
50
- analyze_commit_history() {
51
- local commits=$(git log --oneline -10 2>/dev/null | tr '[:upper:]' '[:lower:]' || echo "")
52
- local suggested_type="patch"
53
-
54
- if [[ $commits == *"breaking"* ]] || [[ $commits == *"major"* ]]; then
55
- suggested_type="major"
56
- elif [[ $commits == *"feat"* ]] || [[ $commits == *"feature"* ]] || [[ $commits == *"add"* ]]; then
57
- suggested_type="minor"
58
- fi
59
-
60
- echo "$suggested_type"
61
- }
62
-
63
- # 主函数: 版本选择和升级
64
- version_bump() {
65
- local current_version=$(get_current_version)
66
- local version_type=${1:-""}
67
-
68
- # 安静模式检测:如果被其他脚本调用,则静默运行
69
- if [ "$0" != "${BASH_SOURCE[0]}" ] || [ "$version_type" = "test" ] || [ "$version_type" = "--quiet" ]; then
70
- # 静默模式:只返回结果,不显示菜单
71
- if [ -n "$version_type" ] && [ "$version_type" != "test" ] && [ "$version_type" != "--quiet" ]; then
72
- execute_version_bump_quiet "$version_type" "$current_version"
73
- return $?
74
- else
75
- # 测试模式,只返回当前版本
76
- echo "$current_version"
77
- return 0
78
- fi
79
- fi
80
-
81
- echo "📦 CCM 版本管理器"
82
- echo "=================="
83
- print_info "当前版本: $current_version"
84
- echo ""
85
-
86
- # 如果已指定版本类型,直接执行
87
- if [ -n "$version_type" ] && [ "$version_type" != "test" ]; then
88
- execute_version_bump "$version_type" "$current_version"
89
- return $?
90
- fi
91
-
92
- # 获取智能推荐
93
- local suggested_type=$(analyze_commit_history)
94
-
95
- # 显示版本选择菜单
96
- show_version_menu "$current_version" "$suggested_type"
97
-
98
- # 获取用户选择
99
- read -p "请选择版本升级类型 (1-4, 回车默认选择推荐): " choice
100
-
101
- # 处理用户选择
102
- case ${choice:-""} in
103
- "")
104
- # 回车默认选择推荐版本
105
- version_type="$suggested_type"
106
- ;;
107
- 1) version_type="patch" ;;
108
- 2) version_type="minor" ;;
109
- 3) version_type="major" ;;
110
- 4) handle_custom_version ;;
111
- *)
112
- print_error "无效选择"
113
- exit 1
114
- ;;
115
- esac
116
-
117
- # 确认升级
118
- confirm_version_bump "$version_type" "$current_version"
119
-
120
- # 执行升级
121
- execute_version_bump "$version_type" "$current_version"
122
- }
123
-
124
- # 显示版本选择菜单
125
- show_version_menu() {
126
- local current_version=$1
127
- local suggested_type=$2
128
-
129
- print_info "版本升级选项:"
130
- echo ""
131
-
132
- # 计算各版本预览
133
- local patch_version=$(calculate_version_preview "patch")
134
- local minor_version=$(calculate_version_preview "minor")
135
- local major_version=$(calculate_version_preview "major")
136
-
137
- # 显示推荐标记
138
- local patch_mark=""
139
- local minor_mark=""
140
- local major_mark=""
141
-
142
- case $suggested_type in
143
- "patch") patch_mark="✨ [推荐] " ;;
144
- "minor") minor_mark="✨ [推荐] " ;;
145
- "major") major_mark="✨ [推荐] " ;;
146
- esac
147
-
148
- echo "1) ${patch_mark}🔧 Patch (修订版本) $current_version → $patch_version"
149
- echo " └─ 适用于: bug修复、小改进"
150
- echo ""
151
- echo "2) ${minor_mark}✨ Minor (次版本) $current_version → $minor_version"
152
- echo " └─ 适用于: 新功能、向后兼容改动"
153
- echo ""
154
- echo "3) ${major_mark}🚀 Major (主版本) $current_version → $major_version"
155
- echo " └─ 适用于: 破坏性更改、重大重构"
156
- echo ""
157
- echo "4) 📝 Custom (自定义版本)"
158
- echo " └─ 手动输入版本号"
159
- echo ""
160
-
161
- # 显示推荐原因
162
- case $suggested_type in
163
- "major")
164
- print_warning "💡 检测到破坏性更改提交,建议主版本升级"
165
- ;;
166
- "minor")
167
- print_warning "💡 检测到新功能提交,建议次版本升级"
168
- ;;
169
- "patch")
170
- print_info "💡 建议修订版本升级"
171
- ;;
172
- esac
173
- echo ""
174
- }
175
-
176
- # 处理自定义版本
177
- handle_custom_version() {
178
- read -p "请输入自定义版本号 (格式: x.y.z): " custom_version
179
-
180
- # 验证版本号格式
181
- if [[ ! $custom_version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+(\.[0-9]+)?)?$ ]]; then
182
- print_error "版本号格式不正确,应为 x.y.z 格式"
183
- exit 1
184
- fi
185
-
186
- version_type="$custom_version"
187
- }
188
-
189
- # 确认版本升级
190
- confirm_version_bump() {
191
- local version_type=$1
192
- local current_version=$2
193
-
194
- if [[ "$version_type" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
195
- local new_version="$version_type"
196
- else
197
- local new_version=$(calculate_version_preview "$version_type")
198
- fi
199
-
200
- echo ""
201
- print_info "即将执行版本升级: $current_version → $new_version"
202
- read -p "确认升级版本? (Y/n): " -n 1 -r
203
- echo
204
-
205
- if [[ $REPLY =~ ^[Nn]$ ]]; then
206
- print_warning "版本升级已取消"
207
- exit 0
208
- fi
209
- }
210
-
211
- # 执行版本升级(静默模式)
212
- execute_version_bump_quiet() {
213
- local version_type=$1
214
- local current_version=$2
215
-
216
- # 执行版本升级
217
- if [[ "$version_type" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
218
- # 自定义版本
219
- new_version=$(pnpm version "$version_type" --no-git-tag-version 2>/dev/null)
220
- else
221
- # 标准版本类型
222
- new_version=$(pnpm version "$version_type" --no-git-tag-version 2>/dev/null)
223
- fi
224
-
225
- if [ $? -eq 0 ]; then
226
- new_version=${new_version#v}
227
- echo "$new_version" # 输出新版本号供其他脚本使用
228
- else
229
- exit 1
230
- fi
231
- }
232
-
233
- # 执行版本升级(交互模式)
234
- execute_version_bump() {
235
- local version_type=$1
236
- local current_version=$2
237
-
238
- print_info "执行版本升级..."
239
-
240
- # 执行版本升级
241
- if [[ "$version_type" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
242
- # 自定义版本
243
- new_version=$(pnpm version "$version_type" --no-git-tag-version 2>/dev/null)
244
- else
245
- # 标准版本类型
246
- new_version=$(pnpm version "$version_type" --no-git-tag-version 2>/dev/null)
247
- fi
248
-
249
- if [ $? -eq 0 ]; then
250
- new_version=${new_version#v}
251
- print_success "版本升级成功: $current_version → $new_version"
252
- echo "$new_version" # 输出新版本号供其他脚本使用
253
- else
254
- print_error "版本升级失败"
255
- exit 1
256
- fi
257
- }
258
-
259
- # 如果直接运行此脚本
260
- if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
261
- version_bump "$@"
262
- fi
@@ -1,91 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Local NPM Publish Script
4
- # 本地 NPM 发布脚本(备用方案)
5
-
6
- set -e
7
-
8
- # 颜色定义
9
- GREEN='\033[0;32m'
10
- YELLOW='\033[1;33m'
11
- RED='\033[0;31m'
12
- BLUE='\033[0;34m'
13
- NC='\033[0m'
14
-
15
- print_success() { echo -e "${GREEN}✅ $1${NC}"; }
16
- print_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
17
- print_error() { echo -e "${RED}❌ $1${NC}"; exit 1; }
18
- print_info() { echo -e "${BLUE}ℹ️ $1${NC}"; }
19
-
20
- echo "🚀 CCM 本地 NPM 发布脚本"
21
- echo "==============================="
22
- echo ""
23
-
24
- # 检查前置条件
25
- [ ! -f "package.json" ] && print_error "package.json 未找到"
26
- [ ! -d "dist" ] && print_error "dist 目录不存在,请先运行 npm run build"
27
-
28
- # 检查 NPM 登录状态
29
- print_info "检查 NPM 登录状态..."
30
- if ! npm whoami > /dev/null 2>&1; then
31
- print_warning "未登录 NPM,开始登录流程..."
32
- npm login
33
- print_success "NPM 登录成功"
34
- else
35
- current_user=$(npm whoami)
36
- print_success "已登录 NPM,用户: $current_user"
37
- fi
38
-
39
- # 获取版本信息
40
- current_version=$(node -p "require('./package.json').version")
41
- package_name=$(node -p "require('./package.json').name")
42
-
43
- print_info "包名: $package_name"
44
- print_info "当前版本: $current_version"
45
-
46
- # 检查版本是否已存在
47
- print_info "检查版本是否已存在..."
48
- if npm view $package_name@$current_version > /dev/null 2>&1; then
49
- print_error "版本 $current_version 已存在于 NPM 上"
50
- fi
51
-
52
- print_success "版本检查通过"
53
-
54
- # 运行预发布检查
55
- print_info "运行预发布检查..."
56
- pnpm run lint
57
- pnpm run build
58
-
59
- print_success "预发布检查通过"
60
-
61
- # 确认发布
62
- echo ""
63
- print_warning "即将发布到 NPM:"
64
- echo " 包名: $package_name"
65
- echo " 版本: $current_version"
66
- echo " 用户: $(npm whoami)"
67
- echo ""
68
-
69
- read -p "确认发布? (y/N): " -n 1 -r
70
- echo
71
- [[ ! $REPLY =~ ^[Yy]$ ]] && { echo "取消发布"; exit 0; }
72
-
73
- # 执行发布
74
- print_info "开始发布..."
75
-
76
- # 检查是否为预发布版本
77
- if [[ $current_version =~ -beta\.|alpha\.|rc\. ]]; then
78
- print_info "检测到预发布版本,使用 beta tag"
79
- npm publish --tag beta --access public
80
- else
81
- print_info "发布稳定版本"
82
- npm publish --access public
83
- fi
84
-
85
- print_success "发布成功!"
86
- echo ""
87
- print_info "📦 NPM 包信息:"
88
- echo " URL: https://www.npmjs.com/package/$package_name/v/$current_version"
89
- echo " 安装: npm install -g $package_name@$current_version"
90
- echo ""
91
- print_success "本地发布完成!"