ccman 0.0.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/.editorconfig +15 -0
- package/.eslintrc.js +28 -0
- package/.github/workflows/release.yml +213 -0
- package/.prettierrc +10 -0
- package/CLAUDE.md +215 -0
- package/README.md +361 -0
- package/README_zh.md +361 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +476 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/ConfigManager.d.ts +67 -0
- package/dist/config/ConfigManager.d.ts.map +1 -0
- package/dist/config/ConfigManager.js +226 -0
- package/dist/config/ConfigManager.js.map +1 -0
- package/dist/config/EnvironmentManager.d.ts +83 -0
- package/dist/config/EnvironmentManager.d.ts.map +1 -0
- package/dist/config/EnvironmentManager.js +280 -0
- package/dist/config/EnvironmentManager.js.map +1 -0
- package/dist/config/constants.d.ts +40 -0
- package/dist/config/constants.d.ts.map +1 -0
- package/dist/config/constants.js +97 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/shell/ShellManager.d.ts +73 -0
- package/dist/shell/ShellManager.d.ts.map +1 -0
- package/dist/shell/ShellManager.js +391 -0
- package/dist/shell/ShellManager.js.map +1 -0
- package/dist/types/index.d.ts +55 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/version.d.ts +67 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +199 -0
- package/dist/utils/version.js.map +1 -0
- package/docs/npm-publish-guide.md +71 -0
- package/docs/release-guide.md +86 -0
- package/docs/version-management.md +64 -0
- package/jest.config.js +22 -0
- package/package.json +57 -0
- package/release-temp/README.md +361 -0
- package/release-temp/package.json +57 -0
- package/scripts/publish-local.sh +91 -0
- package/scripts/quick-release.sh +100 -0
- package/scripts/release.sh +430 -0
- package/src/cli.ts +510 -0
- package/src/config/ConfigManager.ts +227 -0
- package/src/config/EnvironmentManager.ts +327 -0
- package/src/config/constants.ts +64 -0
- package/src/index.ts +5 -0
- package/src/shell/ShellManager.ts +416 -0
- package/src/types/index.ts +60 -0
- package/src/utils/version.ts +189 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
# CCM - Claude Code Manager
|
|
2
|
+
|
|
3
|
+
A TypeScript-based command-line tool to manage Claude Code API configurations with **safe shell integration** through independent configuration files.
|
|
4
|
+
|
|
5
|
+
> **English Documentation** | [中文文档](./README_zh.md)
|
|
6
|
+
|
|
7
|
+
## ✨ Features
|
|
8
|
+
|
|
9
|
+
✅ **Environment Group Management** - Add, remove, switch between Claude Code environments
|
|
10
|
+
✅ **Safe Shell Integration** - Uses independent `~/.ccman/.ccmanrc` file to avoid modifying user configs
|
|
11
|
+
✅ **Interactive Source Control** - Choose manual or automatic source with risk warnings
|
|
12
|
+
✅ **Type Safety** - Full TypeScript implementation with strict typing
|
|
13
|
+
✅ **Interactive CLI** - User-friendly commands with colored output and inquirer prompts
|
|
14
|
+
✅ **Multi-Shell Support** - Works with bash, zsh, and fish
|
|
15
|
+
✅ **Complete Workflow** - From setup to usage in one seamless flow
|
|
16
|
+
|
|
17
|
+
## 🚀 Quick Start
|
|
18
|
+
|
|
19
|
+
### Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Install from NPM
|
|
23
|
+
npm install -g ccman
|
|
24
|
+
|
|
25
|
+
# Or install dependencies for development
|
|
26
|
+
npm install && npm run build
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Basic Usage
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Interactive setup (recommended)
|
|
33
|
+
ccman config
|
|
34
|
+
|
|
35
|
+
# Or add environment directly
|
|
36
|
+
ccman add default https://api.anthropic.com your-api-key
|
|
37
|
+
|
|
38
|
+
# List all environments
|
|
39
|
+
ccman ls
|
|
40
|
+
|
|
41
|
+
# Switch to an environment with source options
|
|
42
|
+
ccman use default
|
|
43
|
+
|
|
44
|
+
# Show current environment
|
|
45
|
+
ccman current
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 📖 Commands Reference
|
|
49
|
+
|
|
50
|
+
### Core Environment Management
|
|
51
|
+
```bash
|
|
52
|
+
ccman add <name> <baseUrl> [apiKey] # Add environment (interactive API key if not provided)
|
|
53
|
+
ccman remove <name> # Remove environment group
|
|
54
|
+
ccman use <name> # Switch environment with source interaction
|
|
55
|
+
ccman list|ls # List all environments (* = current)
|
|
56
|
+
ccman current # Show current environment details
|
|
57
|
+
ccman clear|clearall # Clear ALL environments and shell integration (DESTRUCTIVE)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Interactive Configuration
|
|
61
|
+
```bash
|
|
62
|
+
ccman config # Full interactive configuration wizard
|
|
63
|
+
# - Add/switch/edit/remove environments
|
|
64
|
+
# - No existing environments? Guided setup
|
|
65
|
+
# - Complete menu-driven interface
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Advanced Operations
|
|
69
|
+
```bash
|
|
70
|
+
ccman status # Show detailed CCM statistics
|
|
71
|
+
ccman test [name] # Test environment configuration
|
|
72
|
+
ccman env # Generate shell export script
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Shell Integration Options
|
|
76
|
+
```bash
|
|
77
|
+
# Disable automatic shell writing
|
|
78
|
+
ccman add <name> <url> --no-auto-write
|
|
79
|
+
ccman use <name> --no-auto-write
|
|
80
|
+
|
|
81
|
+
# Force automatic source (risky)
|
|
82
|
+
ccman use <name> --auto-source
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 🔧 Interactive Workflows
|
|
86
|
+
|
|
87
|
+
### 1. Adding Environment with Smart Use Flow
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
$ ccman add myenv https://api.example.com
|
|
91
|
+
? Enter API Key: ****************
|
|
92
|
+
✓ Added environment group "myenv"
|
|
93
|
+
Base URL: https://api.example.com
|
|
94
|
+
Created: 2025-08-06 11:45:30
|
|
95
|
+
|
|
96
|
+
? Set "myenv" as current environment? Yes
|
|
97
|
+
✓ Environment variables written to /home/user/.ccman/.ccmanrc
|
|
98
|
+
|
|
99
|
+
? How would you like to apply the environment variables?
|
|
100
|
+
❯ Manual - I will restart terminal or source manually (Recommended)
|
|
101
|
+
Auto-source - Try to source automatically (May not work in all environments)
|
|
102
|
+
|
|
103
|
+
> Manual
|
|
104
|
+
To apply changes, restart your terminal or run:
|
|
105
|
+
source ~/.bashrc (or ~/.zshrc)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 2. Interactive Configuration Menu
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
$ ccman config
|
|
112
|
+
? What would you like to do?
|
|
113
|
+
❯ Switch environment
|
|
114
|
+
Add new environment
|
|
115
|
+
Edit environment
|
|
116
|
+
Remove environment
|
|
117
|
+
Show current status
|
|
118
|
+
|
|
119
|
+
> Add new environment
|
|
120
|
+
? Environment name: staging
|
|
121
|
+
? Base URL: https://staging-api.example.com
|
|
122
|
+
? API Key: ****************
|
|
123
|
+
✓ Added environment "staging"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 3. Environment Switching with Source Control
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
$ ccman use production
|
|
130
|
+
✓ Switched to environment "production"
|
|
131
|
+
Base URL: https://api.anthropic.com
|
|
132
|
+
✓ Environment variables written to /home/user/.ccman/.ccmanrc
|
|
133
|
+
|
|
134
|
+
? How would you like to apply the environment variables?
|
|
135
|
+
Manual - I will restart terminal or source manually (Recommended)
|
|
136
|
+
❯ Auto-source - Try to source automatically (May not work in all environments)
|
|
137
|
+
|
|
138
|
+
> Auto-source
|
|
139
|
+
⚠️ Attempting auto-source - this may not work in all terminal environments
|
|
140
|
+
✓ Shell configuration sourced successfully
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 🛡️ Safe Shell Integration Architecture
|
|
144
|
+
|
|
145
|
+
### How It Works
|
|
146
|
+
|
|
147
|
+
CCM uses a **two-tier architecture** for safe shell integration:
|
|
148
|
+
|
|
149
|
+
1. **Independent Configuration File**: `~/.ccman/.ccmanrc`
|
|
150
|
+
```bash
|
|
151
|
+
# CCM (Claude Code Manager) Environment Variables - Auto Generated
|
|
152
|
+
# Generated at: 2025-08-06 11:45:30
|
|
153
|
+
# Environment: production
|
|
154
|
+
export ANTHROPIC_BASE_URL="https://api.anthropic.com"
|
|
155
|
+
export ANTHROPIC_AUTH_TOKEN="your-api-key"
|
|
156
|
+
# End CCM Environment Variables
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
2. **Minimal Shell Reference**: One line added to `.bashrc`/`.zshrc`
|
|
160
|
+
```bash
|
|
161
|
+
# CCM (Claude Code Manager) - Auto Generated Reference
|
|
162
|
+
[ -f "/home/user/.ccman/.ccmanrc" ] && source "/home/user/.ccman/.ccmanrc"
|
|
163
|
+
# End CCM Reference
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Benefits
|
|
167
|
+
- ✅ **Non-invasive**: Only adds one reference line to shell config
|
|
168
|
+
- ✅ **Safe**: User's existing shell config remains untouched
|
|
169
|
+
- ✅ **Clean**: Easy to remove completely
|
|
170
|
+
- ✅ **Isolated**: All CCM variables in separate file
|
|
171
|
+
|
|
172
|
+
### Environment Variables Managed
|
|
173
|
+
- `ANTHROPIC_BASE_URL` - API base URL
|
|
174
|
+
- `ANTHROPIC_AUTH_TOKEN` - API authentication token
|
|
175
|
+
|
|
176
|
+
## 📊 Configuration Structure
|
|
177
|
+
|
|
178
|
+
CCM stores configuration in `~/.ccman/config.json`:
|
|
179
|
+
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"current": "production",
|
|
183
|
+
"environments": {
|
|
184
|
+
"production": {
|
|
185
|
+
"name": "production",
|
|
186
|
+
"baseUrl": "https://api.anthropic.com",
|
|
187
|
+
"apiKey": "your-key",
|
|
188
|
+
"createdAt": "2025-08-06T03:45:30.000Z",
|
|
189
|
+
"lastUsed": "2025-08-06T03:50:15.000Z"
|
|
190
|
+
},
|
|
191
|
+
"staging": {
|
|
192
|
+
"name": "staging",
|
|
193
|
+
"baseUrl": "https://staging-api.example.com",
|
|
194
|
+
"apiKey": "staging-key",
|
|
195
|
+
"createdAt": "2025-08-06T03:46:00.000Z"
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
"settings": {
|
|
199
|
+
"autoWriteShell": true,
|
|
200
|
+
"preferredShell": "auto",
|
|
201
|
+
"shellConfigPath": null
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 💡 Usage Examples
|
|
207
|
+
|
|
208
|
+
### Complete Setup Workflow
|
|
209
|
+
```bash
|
|
210
|
+
# Start with interactive setup
|
|
211
|
+
ccman config
|
|
212
|
+
# → Guided through adding first environment
|
|
213
|
+
# → Automatically prompted to set as current
|
|
214
|
+
# → Choose source method (manual/auto)
|
|
215
|
+
|
|
216
|
+
# Add more environments
|
|
217
|
+
ccman add staging https://staging.example.com
|
|
218
|
+
ccman add dev https://dev.example.com
|
|
219
|
+
|
|
220
|
+
# Switch with full interaction
|
|
221
|
+
ccman use dev
|
|
222
|
+
# → Writes to ~/.ccman/.ccmanrc
|
|
223
|
+
# → Asks about sourcing method
|
|
224
|
+
# → Provides clear instructions
|
|
225
|
+
|
|
226
|
+
# Check status
|
|
227
|
+
ccman status
|
|
228
|
+
# CCM Status:
|
|
229
|
+
# Total environments: 3
|
|
230
|
+
# Current environment: dev
|
|
231
|
+
# Shell integration: Enabled
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Manual Environment Variable Setup
|
|
235
|
+
```bash
|
|
236
|
+
# If you prefer manual control
|
|
237
|
+
ccman use prod --no-auto-write
|
|
238
|
+
ccman env # Shows export script
|
|
239
|
+
source <(ccman env) # Apply manually
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Advanced Usage
|
|
243
|
+
```bash
|
|
244
|
+
# Test environment connectivity
|
|
245
|
+
ccman test production
|
|
246
|
+
|
|
247
|
+
# Force auto-source (with risk warning)
|
|
248
|
+
ccman use staging --auto-source
|
|
249
|
+
|
|
250
|
+
# Edit existing environment
|
|
251
|
+
ccman config # → Edit environment → Select → Update values
|
|
252
|
+
|
|
253
|
+
# Complete reset (removes EVERYTHING - environments, shell config)
|
|
254
|
+
ccman clear # Interactive confirmation required
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## ⚙️ Development
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
# Development mode (with file watching)
|
|
261
|
+
npm run dev
|
|
262
|
+
|
|
263
|
+
# Build TypeScript
|
|
264
|
+
npm run build
|
|
265
|
+
|
|
266
|
+
# Clean build artifacts
|
|
267
|
+
npm run clean
|
|
268
|
+
|
|
269
|
+
# Start built CLI
|
|
270
|
+
npm start
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## 🎯 Command Line Options
|
|
274
|
+
|
|
275
|
+
### Global Options
|
|
276
|
+
All commands support standard CLI conventions:
|
|
277
|
+
- `-h, --help` - Show command help
|
|
278
|
+
- `-V, --version` - Show version
|
|
279
|
+
|
|
280
|
+
### Add Command Options
|
|
281
|
+
```bash
|
|
282
|
+
ccman add <name> <baseUrl> [apiKey] [options]
|
|
283
|
+
|
|
284
|
+
Options:
|
|
285
|
+
--no-auto-write Do not automatically write to shell config
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Use Command Options
|
|
289
|
+
```bash
|
|
290
|
+
ccman use <name> [options]
|
|
291
|
+
|
|
292
|
+
Options:
|
|
293
|
+
--no-auto-write Do not automatically write to shell config
|
|
294
|
+
--auto-source Automatically source shell config (risky)
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## 🔍 Troubleshooting
|
|
298
|
+
|
|
299
|
+
### Environment Variables Not Applied
|
|
300
|
+
```bash
|
|
301
|
+
# Check if .ccmanrc exists
|
|
302
|
+
ls -la ~/.ccman/.ccmanrc
|
|
303
|
+
|
|
304
|
+
# Check shell reference
|
|
305
|
+
grep "ccman" ~/.bashrc ~/.zshrc
|
|
306
|
+
|
|
307
|
+
# Manual application
|
|
308
|
+
source ~/.ccman/.ccmanrc
|
|
309
|
+
|
|
310
|
+
# Or regenerate
|
|
311
|
+
ccman use <current-env>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Shell Integration Issues
|
|
315
|
+
```bash
|
|
316
|
+
# Check shell type detection
|
|
317
|
+
ccman status
|
|
318
|
+
|
|
319
|
+
# Force manual setup
|
|
320
|
+
ccman use <env> --no-auto-write
|
|
321
|
+
source <(ccman env)
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## 📋 Requirements
|
|
325
|
+
|
|
326
|
+
- Node.js >= 16.0.0
|
|
327
|
+
- TypeScript 5.0+
|
|
328
|
+
- Supported shells: bash, zsh, fish
|
|
329
|
+
- Operating systems: Linux, macOS, Windows (WSL)
|
|
330
|
+
|
|
331
|
+
## 📄 License
|
|
332
|
+
|
|
333
|
+
MIT License - see LICENSE file for details.
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## 🚀 From Setup to Usage - Complete Flow
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
# 1. Interactive first-time setup
|
|
341
|
+
ccman config
|
|
342
|
+
→ No environments? Guided creation
|
|
343
|
+
→ Set as current? Yes
|
|
344
|
+
→ Source method? Manual/Auto
|
|
345
|
+
|
|
346
|
+
# 2. Add more environments
|
|
347
|
+
ccman add dev https://dev.api.com
|
|
348
|
+
→ Interactive API key input
|
|
349
|
+
→ Set as current? Yes/No
|
|
350
|
+
→ Full source interaction if Yes
|
|
351
|
+
|
|
352
|
+
# 3. Switch anytime with full control
|
|
353
|
+
ccman use production
|
|
354
|
+
→ Safe .ccmanrc update
|
|
355
|
+
→ Source method choice
|
|
356
|
+
→ Clear instructions
|
|
357
|
+
|
|
358
|
+
# 4. Everything just works! ✨
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
*CCM - Making Claude Code API configuration management safe, interactive, and user-friendly.*
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ccman",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Claude Code Manager - A TypeScript tool to manage Claude Code API configurations",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"packageManager": "pnpm@8.15.1",
|
|
7
|
+
"bin": {
|
|
8
|
+
"ccman": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsx src/cli.ts",
|
|
13
|
+
"start": "node dist/cli.js",
|
|
14
|
+
"test": "jest --passWithNoTests",
|
|
15
|
+
"lint": "eslint src/**/*.ts",
|
|
16
|
+
"clean": "rm -rf dist",
|
|
17
|
+
"release": "./scripts/release.sh",
|
|
18
|
+
"release:patch": "./scripts/quick-release.sh patch",
|
|
19
|
+
"release:minor": "./scripts/quick-release.sh minor",
|
|
20
|
+
"release:major": "./scripts/quick-release.sh major",
|
|
21
|
+
"release:interactive": "./scripts/quick-release.sh",
|
|
22
|
+
"publish:local": "./scripts/publish-local.sh",
|
|
23
|
+
"prepublishOnly": "pnpm run clean && pnpm run build && pnpm run lint"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"claude",
|
|
27
|
+
"claude-code",
|
|
28
|
+
"api",
|
|
29
|
+
"config",
|
|
30
|
+
"manager",
|
|
31
|
+
"cli",
|
|
32
|
+
"typescript"
|
|
33
|
+
],
|
|
34
|
+
"author": "",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"commander": "^11.0.0",
|
|
38
|
+
"chalk": "^4.1.2",
|
|
39
|
+
"inquirer": "^8.2.6"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^20.0.0",
|
|
43
|
+
"@types/inquirer": "^9.0.0",
|
|
44
|
+
"typescript": "^5.0.0",
|
|
45
|
+
"tsx": "^4.0.0",
|
|
46
|
+
"eslint": "^8.0.0",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
48
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
49
|
+
"jest": "^29.0.0",
|
|
50
|
+
"@types/jest": "^29.0.0",
|
|
51
|
+
"ts-jest": "^29.0.0",
|
|
52
|
+
"prettier": "^3.0.0"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=16.0.0"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 "本地发布完成!"
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# CCM Quick Release Script
|
|
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}"; exit 1; }
|
|
18
|
+
print_info() { echo -e "${BLUE}ℹ️ $1${NC}"; }
|
|
19
|
+
|
|
20
|
+
# 快速检查
|
|
21
|
+
[ ! -f "package.json" ] && print_error "package.json 未找到"
|
|
22
|
+
[ ! -d ".git" ] && print_error "不在 Git 仓库中"
|
|
23
|
+
git diff-index --quiet HEAD -- || print_error "工作目录有未提交更改"
|
|
24
|
+
|
|
25
|
+
# 获取当前版本和升级类型
|
|
26
|
+
current_version=$(node -p "require('./package.json').version")
|
|
27
|
+
version_type=${1:-""}
|
|
28
|
+
|
|
29
|
+
echo "🚀 CCM 快速发布"
|
|
30
|
+
echo "当前版本: $current_version"
|
|
31
|
+
|
|
32
|
+
# 如果没有提供版本类型,让用户选择
|
|
33
|
+
if [ -z "$version_type" ]; then
|
|
34
|
+
echo ""
|
|
35
|
+
print_info "选择版本类型:"
|
|
36
|
+
echo "1) patch (修订版本): $current_version → $(pnpm version patch --dry-run 2>/dev/null | cut -d'v' -f2 || echo '计算中...')"
|
|
37
|
+
echo "2) minor (次版本): $current_version → $(pnpm version minor --dry-run 2>/dev/null | cut -d'v' -f2 || echo '计算中...')"
|
|
38
|
+
echo "3) major (主版本): $current_version → $(pnpm version major --dry-run 2>/dev/null | cut -d'v' -f2 || echo '计算中...')"
|
|
39
|
+
echo ""
|
|
40
|
+
|
|
41
|
+
read -p "请选择 (1-3, 回车默认选择 patch): " choice
|
|
42
|
+
|
|
43
|
+
case ${choice:-1} in
|
|
44
|
+
1|"") version_type="patch" ;;
|
|
45
|
+
2) version_type="minor" ;;
|
|
46
|
+
3) version_type="major" ;;
|
|
47
|
+
*) print_error "无效选择" ;;
|
|
48
|
+
esac
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
print_info "升级类型: $version_type"
|
|
52
|
+
|
|
53
|
+
# 确认发布
|
|
54
|
+
echo ""
|
|
55
|
+
read -p "确认发布? (y/N): " -n 1 -r
|
|
56
|
+
echo
|
|
57
|
+
[[ ! $REPLY =~ ^[Yy]$ ]] && { print_warning "取消发布"; exit 0; }
|
|
58
|
+
|
|
59
|
+
# 执行发布流程
|
|
60
|
+
print_success "开始发布流程..."
|
|
61
|
+
|
|
62
|
+
# 1. 构建和测试
|
|
63
|
+
print_info "运行构建和代码检查..."
|
|
64
|
+
pnpm run build
|
|
65
|
+
pnpm run lint
|
|
66
|
+
|
|
67
|
+
# 2. 更新版本
|
|
68
|
+
print_info "更新版本号..."
|
|
69
|
+
new_version=$(pnpm version $version_type --no-git-tag-version)
|
|
70
|
+
new_version=${new_version#v}
|
|
71
|
+
|
|
72
|
+
print_success "版本已更新: $current_version → $new_version"
|
|
73
|
+
|
|
74
|
+
# 3. 提交和打标签
|
|
75
|
+
print_info "创建提交和标签..."
|
|
76
|
+
git add .
|
|
77
|
+
git commit -m "chore: 发布版本 v$new_version
|
|
78
|
+
|
|
79
|
+
🚀 快速发布 $version_type 版本
|
|
80
|
+
⏰ $(date '+%Y-%m-%d %H:%M:%S')
|
|
81
|
+
|
|
82
|
+
🤖 Generated with [Claude Code](https://claude.ai/code)
|
|
83
|
+
|
|
84
|
+
Co-Authored-By: Claude <noreply@anthropic.com>"
|
|
85
|
+
|
|
86
|
+
git tag -a "v$new_version" -m "Release v$new_version"
|
|
87
|
+
|
|
88
|
+
# 4. 推送
|
|
89
|
+
print_info "推送到远程仓库..."
|
|
90
|
+
git push origin $(git branch --show-current)
|
|
91
|
+
git push origin "v$new_version"
|
|
92
|
+
|
|
93
|
+
print_success "发布完成!版本 v$new_version 已推送"
|
|
94
|
+
echo ""
|
|
95
|
+
print_info "🔗 相关链接:"
|
|
96
|
+
echo " GitHub Actions: https://github.com/2ue/ccm/actions"
|
|
97
|
+
echo " GitHub Release: https://github.com/2ue/ccm/releases/tag/v$new_version"
|
|
98
|
+
echo ""
|
|
99
|
+
print_info "📦 NPM 包将在 GitHub Actions 完成后发布:"
|
|
100
|
+
echo " https://www.npmjs.com/package/ccm"
|