ops-toolkit 1.2.1 → 1.2.3

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/.env.example CHANGED
@@ -1,6 +1,15 @@
1
1
  # Environment variables for ops-toolkit
2
2
  # Copy this file to .env and fill in your values
3
3
 
4
+ # Publishing to npm
5
+ # Get an automation token from: https://www.npmjs.com/settings/tokens
6
+ NPM_TOKEN=your_npm_automation_token_here
7
+
8
+ # GitHub releases (optional, for creating GitHub releases)
9
+ # Get a personal access token from: https://github.com/settings/tokens
10
+ # Required scopes: repo
11
+ GITHUB_TOKEN=your_github_token_here
12
+
4
13
  # Debug mode
5
14
  DEBUG=false
6
15
  NODE_ENV=development
package/.release-it.json CHANGED
@@ -13,7 +13,8 @@
13
13
  },
14
14
  "npm": {
15
15
  "publish": true,
16
- "access": "public"
16
+ "access": "public",
17
+ "skipChecks": true
17
18
  },
18
19
  "hooks": {
19
20
  "before:init": ["bun run lint", "bun run typecheck"],
package/AGENTS.md CHANGED
@@ -36,6 +36,9 @@ bun test # Run all tests
36
36
  ### Git & Release
37
37
 
38
38
  ```bash
39
+ bun run publish:patch # Upgrade patch version and publish (e.g., 1.2.1 → 1.2.2)
40
+ bun run publish:minor # Upgrade minor version and publish (e.g., 1.2.1 → 1.3.0)
41
+ bun run publish:major # Upgrade major version and publish (e.g., 1.2.1 → 2.0.0)
39
42
  bun run release # Create release with changelog
40
43
  bun run release:minor # Minor version bump
41
44
  bun run release:major # Major version bump
@@ -199,15 +202,17 @@ try {
199
202
 
200
203
  ## Quick Reference
201
204
 
202
- | Task | Command |
203
- | ---------------- | ------------------- |
204
- | Start dev server | `bun run dev` |
205
- | Build project | `bun run build` |
206
- | Run tests | `bun test` |
207
- | Type check | `bun run typecheck` |
208
- | Lint and fix | `bun run lint:fix` |
209
- | Format code | `bun run format` |
210
- | Debug | F5 in VS Code |
205
+ | Task | Command |
206
+ | ---------------- | ------------------------ |
207
+ | Start dev server | `bun run dev` |
208
+ | Build project | `bun run build` |
209
+ | Run tests | `bun test` |
210
+ | Type check | `bun run typecheck` |
211
+ | Lint and fix | `bun run lint:fix` |
212
+ | Format code | `bun run format` |
213
+ | Publish to npm | `bun run publish:patch` |
214
+ | Publish docs | See `docs/PUBLISHING.md` |
215
+ | Debug | F5 in VS Code |
211
216
 
212
217
  ## OpenCode Custom Commands
213
218
 
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+
2
+
3
+ ## [1.2.3](https://github.com/liangshaojie/ops-toolkit/compare/v1.2.1...v1.2.3) (2026-01-11)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * 更新版本号 ([7e32b53](https://github.com/liangshaojie/ops-toolkit/commit/7e32b53027845b2768706944b4f1f483cf215c13))
9
+
10
+
11
+ ### Features
12
+
13
+ * add optimized npm publish commands ([5e96ee6](https://github.com/liangshaojie/ops-toolkit/commit/5e96ee649f1aa0cb9c9200c3a918800003029c27))
14
+
1
15
  # Changelog
2
16
 
3
17
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
@@ -23,4 +37,4 @@ All notable changes to this project will be documented in this file. See [standa
23
37
  ### Documentation
24
38
 
25
39
  - add custom commands reference ([340cc12](https://github.com/username/ops-toolkit/commits/340cc12889d30b99a21334457e28e601a5fc2bb9))
26
- - add development guide with tips and tricks ([b8017af](https://github.com/username/ops-toolkit/commits/b8017affb22ff7448c897d47e4b3b57c548c80b1))
40
+ - add development guide with tips and tricks ([b8017af](https://github.com/username/ops-toolkit/commits/b8017affb22ff7448c897d47e4b3b57c548c80b1))
@@ -0,0 +1,172 @@
1
+ # Publishing to npm
2
+
3
+ ## Quick Start
4
+
5
+ To publish a new version to npm, run one of the following commands:
6
+
7
+ ```bash
8
+ # Patch version (bug fixes): 1.2.1 → 1.2.2
9
+ bun run publish:patch
10
+
11
+ # Minor version (new features): 1.2.1 → 1.3.0
12
+ bun run publish:minor
13
+
14
+ # Major version (breaking changes): 1.2.1 → 2.0.0
15
+ bun run publish:major
16
+ ```
17
+
18
+ ## What Happens When You Publish
19
+
20
+ The `publish:*` commands automatically:
21
+
22
+ 1. **Quality Checks**
23
+ - Run ESLint to check code quality
24
+ - Run TypeScript type checking
25
+
26
+ 2. **Version Bump**
27
+ - Increment version number in package.json
28
+ - Create git tag (e.g., v1.2.2)
29
+ - Create git commit with changelog
30
+
31
+ 3. **Build**
32
+ - Build the project
33
+ - Generate distribution files in `dist/`
34
+
35
+ 4. **Changelog**
36
+ - Update CHANGELOG.md with changes
37
+ - Based on git commit history
38
+
39
+ 5. **Publish**
40
+ - Publish package to npm registry
41
+ - Create GitHub release
42
+ - Push git tags and commits to remote
43
+
44
+ ## Prerequisites
45
+
46
+ Before publishing, make sure:
47
+
48
+ 1. **Code is committed**
49
+ - All changes are committed to git
50
+ - Working directory is clean
51
+
52
+ 2. **Tests pass**
53
+
54
+ ```bash
55
+ bun test
56
+ ```
57
+
58
+ 3. **Build succeeds**
59
+
60
+ ```bash
61
+ bun run build
62
+ ```
63
+
64
+ 4. **You're logged in to npm**
65
+ ```bash
66
+ npm login
67
+ ```
68
+
69
+ ## Version Guidelines
70
+
71
+ ### Patch (bug fixes)
72
+
73
+ ```bash
74
+ bun run publish:patch
75
+ ```
76
+
77
+ Use for:
78
+
79
+ - Bug fixes
80
+ - Small improvements
81
+ - Non-breaking changes
82
+ - Documentation updates
83
+
84
+ ### Minor (new features)
85
+
86
+ ```bash
87
+ bun run publish:minor
88
+ ```
89
+
90
+ Use for:
91
+
92
+ - New features
93
+ - Backwards compatible changes
94
+ - Adding functionality
95
+
96
+ ### Major (breaking changes)
97
+
98
+ ```bash
99
+ bun run publish:major
100
+ ```
101
+
102
+ Use for:
103
+
104
+ - Breaking changes
105
+ - API changes
106
+ - Removing features
107
+
108
+ ## Troubleshooting
109
+
110
+ ### "Git working directory not clean"
111
+
112
+ ```bash
113
+ # Commit your changes first
114
+ git add .
115
+ git commit -m "your commit message"
116
+ ```
117
+
118
+ ### "403 Forbidden - You cannot publish over previously published versions"
119
+
120
+ This means the version already exists on npm. The publish commands will automatically bump the version, so you shouldn't see this error.
121
+
122
+ ### Build errors
123
+
124
+ ```bash
125
+ # Check build output
126
+ bun run build
127
+
128
+ # Fix any errors, then try publishing again
129
+ bun run publish:patch
130
+ ```
131
+
132
+ ## Manual Publishing
133
+
134
+ If you need more control, you can use `release-it` directly:
135
+
136
+ ```bash
137
+ # Interactive release
138
+ npx release-it
139
+
140
+ # Specific version
141
+ npx release-it 1.2.5
142
+
143
+ # Skip git operations
144
+ npx release-it --no-git --no-github
145
+ ```
146
+
147
+ ## After Publishing
148
+
149
+ Once published, users can install your package:
150
+
151
+ ```bash
152
+ # Global installation
153
+ npm install -g ops-toolkit
154
+
155
+ # Or using bun
156
+ bun install -g ops-toolkit
157
+
158
+ # Run the CLI
159
+ ops --help
160
+ ```
161
+
162
+ ## Configuration
163
+
164
+ Publishing behavior is configured in `.release-it.json`:
165
+
166
+ - **Git**: Automatic commits and tags
167
+ - **NPM**: Automatic publishing to public registry
168
+ - **GitHub**: Automatic releases
169
+ - **Hooks**: Pre-publish checks and post-build actions
170
+ - **Changelog**: Auto-generated from commit history
171
+
172
+ For more details, see [release-it documentation](https://github.com/release-it/release-it).
@@ -0,0 +1,321 @@
1
+ # ops-toolkit 发布指南
2
+
3
+ ## 概述
4
+
5
+ 本文档说明如何将 ops-toolkit 发布到 npm registry。
6
+
7
+ ## 重要变更(2025年12月)
8
+
9
+ npm 已永久撤销 classic tokens,现在使用以下认证方式:
10
+
11
+ - **Granular Access Tokens**:最多90天有效期,需要2FA
12
+ - **Session Tokens**:2小时有效期,通过 `npm login` 获取
13
+ - **OIDC Trusted Publishing**:推荐用于CI/CD,无需管理token
14
+
15
+ ## 发布流程
16
+
17
+ ### 1. 准备工作
18
+
19
+ 确保代码已提交并通过检查:
20
+
21
+ ```bash
22
+ # 检查工作目录是否干净
23
+ git status
24
+
25
+ # 运行代码检查
26
+ bun run lint
27
+ bun run typecheck
28
+
29
+ # 构建项目
30
+ bun run build
31
+ ```
32
+
33
+ ### 2. 登录 npm(可选)
34
+
35
+ 如果使用 session token(2小时有效期):
36
+
37
+ ```bash
38
+ npm login
39
+ ```
40
+
41
+ 这会创建一个2小时的 session token,期间可以发布无需 OTP。
42
+
43
+ ### 3. 发布到 npm
44
+
45
+ 使用以下命令发布不同版本:
46
+
47
+ ```bash
48
+ # Patch 版本(bug fixes):1.2.1 → 1.2.2
49
+ bun run publish:patch
50
+
51
+ # Minor 版本(新功能):1.2.1 → 1.3.0
52
+ bun run publish:minor
53
+
54
+ # Major 版本(破坏性变更):1.2.1 → 2.0.0
55
+ bun run publish:major
56
+ ```
57
+
58
+ ## 自动化发布流程
59
+
60
+ `publish:*` 命令自动执行以下步骤:
61
+
62
+ 1. **质量检查**
63
+ - 运行 ESLint
64
+ - 运行 TypeScript 类型检查
65
+
66
+ 2. **版本升级**
67
+ - 升级 package.json 中的版本号
68
+ - 创建 git tag(如 v1.2.2)
69
+ - 生成 changelog
70
+
71
+ 3. **构建**
72
+ - 编译 TypeScript 代码
73
+ - 生成 dist/ 目录
74
+ - 设置可执行权限
75
+
76
+ 4. **发布**
77
+ - 发布到 npm registry
78
+ - 创建 GitHub release(需要 GITHUB_TOKEN)
79
+
80
+ 5. **推送**
81
+ - 推送 git commits 和 tags 到远程仓库
82
+
83
+ ## 版本选择指南
84
+
85
+ ### Patch 版本
86
+
87
+ ```bash
88
+ bun run publish:patch
89
+ ```
90
+
91
+ 使用场景:
92
+
93
+ - Bug 修复
94
+ - 小改进
95
+ - 非破坏性更改
96
+ - 文档更新
97
+
98
+ ### Minor 版本
99
+
100
+ ```bash
101
+ bun run publish:minor
102
+ ```
103
+
104
+ 使用场景:
105
+
106
+ - 新功能
107
+ - 向后兼容的更改
108
+ - 添加功能
109
+
110
+ ### Major 版本
111
+
112
+ ```bash
113
+ bun run publish:major
114
+ ```
115
+
116
+ 使用场景:
117
+
118
+ - 破坏性更改
119
+ - API 更改
120
+ - 移除功能
121
+
122
+ ## 配置说明
123
+
124
+ ### .npmrc 项目配置
125
+
126
+ 项目根目录包含 `.npmrc` 文件,配置:
127
+
128
+ - registry 地址
129
+ - 公开访问权限
130
+
131
+ **重要**:认证 tokens 不应提交到 `.npmrc`,应通过以下方式设置:
132
+
133
+ 1. 全局 `~/.npmrc`(推荐用于开发)
134
+ 2. 环境变量 `NPM_TOKEN`(推荐用于 CI/CD)
135
+ 3. 通过 `npm login` 创建 session token
136
+
137
+ ### .release-it.json 配置
138
+
139
+ 发布自动化配置包含:
140
+
141
+ - Git 操作(commit, tag, push)
142
+ - GitHub releases
143
+ - npm 发布设置
144
+ - 预发布和后发布 hooks
145
+
146
+ ## 故障排除
147
+
148
+ ### 错误:403 Forbidden
149
+
150
+ **原因**:版本已存在或权限问题
151
+
152
+ **解决方案**:
153
+
154
+ - 检查版本是否已发布:`npm view ops-toolkit versions`
155
+ - 确保有发布权限
156
+ - 检查 token 是否有效
157
+
158
+ ### 错误:EOTP / 需要一次性密码
159
+
160
+ **原因**:启用了 2FA
161
+
162
+ **解决方案**:
163
+
164
+ ```bash
165
+ # 方法1:使用 npm login 创建 session token(推荐)
166
+ npm login
167
+ bun run publish:patch
168
+
169
+ # 方法2:手动提供 OTP
170
+ NPM_OTP=123456 bun run publish:patch
171
+ ```
172
+
173
+ ### 错误:Access token expired or revoked
174
+
175
+ **原因**:token 已过期或被撤销
176
+
177
+ **解决方案**:
178
+
179
+ 1. 创建新的 granular token:https://www.npmjs.com/settings/~/tokens
180
+ 2. 选择 "Granular Access Token"
181
+ 3. 勾选 "Publish" 权限
182
+ 4. 勾选 "Bypass 2FA"(用于自动化)
183
+ 5. 设置过期时间(最长90天)
184
+ 6. 更新 token 配置
185
+
186
+ ### 错误:Git push 被阻止(包含密钥)
187
+
188
+ **原因**:GitHub 检测到 commit 中的敏感信息
189
+
190
+ **解决方案**:
191
+
192
+ ```bash
193
+ # 1. 回退到包含密钥之前的 commit
194
+ git log --oneline
195
+ git reset --hard <commit-hash>
196
+
197
+ # 2. 清理历史(如有必要)
198
+ # 注意:这会重写历史,谨慎使用
199
+ git filter-branch --force --tree-filter 'sed -i "" "s/<TOKEN>//g" .release-it.json'
200
+
201
+ # 3. 强制推送
202
+ git push origin master --force
203
+ ```
204
+
205
+ ### 错误:Working dir must be clean
206
+
207
+ **原因**:有未提交的更改
208
+
209
+ **解决方案**:
210
+
211
+ ```bash
212
+ git add .
213
+ git commit -m "your commit message"
214
+ ```
215
+
216
+ ## 手动发布
217
+
218
+ 如果自动化脚本失败,可以手动发布:
219
+
220
+ ```bash
221
+ # 1. 构建项目
222
+ bun run build
223
+
224
+ # 2. 升级版本
225
+ npm version patch # 或 minor, major
226
+
227
+ # 3. 发布
228
+ npm publish --access public
229
+
230
+ # 4. 推送 git tags
231
+ git push origin master --tags
232
+ ```
233
+
234
+ ## 环境变量
235
+
236
+ ### NPM_TOKEN
237
+
238
+ 用于 CI/CD 环境的 granular token:
239
+
240
+ ```bash
241
+ export NPM_TOKEN=npm_xxxxxxxxxxxxxxxxx
242
+ ```
243
+
244
+ ### NPM_OTP
245
+
246
+ 用于提供一次性密码:
247
+
248
+ ```bash
249
+ export NPM_OTP=123456
250
+ ```
251
+
252
+ ### GITHUB_TOKEN
253
+
254
+ 用于自动创建 GitHub releases:
255
+
256
+ ```bash
257
+ export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxx
258
+ ```
259
+
260
+ 获取方式:
261
+
262
+ - 访问 https://github.com/settings/tokens
263
+ - 生成新的 personal access token
264
+ - 勾选 `repo` 权限
265
+
266
+ ## CI/CD 集成
267
+
268
+ ### GitHub Actions 示例
269
+
270
+ ```yaml
271
+ name: Release
272
+
273
+ on:
274
+ push:
275
+ tags:
276
+ - 'v*'
277
+
278
+ jobs:
279
+ publish:
280
+ runs-on: ubuntu-latest
281
+ steps:
282
+ - uses: actions/checkout@v3
283
+
284
+ - uses: actions/setup-node@v3
285
+ with:
286
+ node-version: '18'
287
+ registry-url: 'https://registry.npmjs.org'
288
+
289
+ - run: npm ci
290
+
291
+ - name: Publish to npm
292
+ run: npm publish --access public
293
+ env:
294
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
295
+ ```
296
+
297
+ ## 安全最佳实践
298
+
299
+ 1. **永远不要**将 tokens 提交到 git
300
+ 2. 使用 `.gitignore` 排除 `.npmrc`(如果包含 tokens)
301
+ 3. 定期轮换 tokens(granular tokens 最多90天)
302
+ 4. 使用最小权限原则
303
+ 5. 考虑使用 OIDC trusted publishing(推荐用于 CI/CD)
304
+
305
+ ## 相关链接
306
+
307
+ - npm 发布文档:https://docs.npmjs.com/cli/v9/commands/npm-publish
308
+ - Granular tokens:https://docs.npmjs.com/creating-and-viewing-access-tokens
309
+ - OIDC trusted publishing:https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow
310
+ - release-it 文档:https://github.com/release-it/release-it
311
+
312
+ ## 快速参考
313
+
314
+ | 命令 | 用途 |
315
+ | ------------------------------- | ------------------ |
316
+ | `bun run publish:patch` | 发布 patch 版本 |
317
+ | `bun run publish:minor` | 发布 minor 版本 |
318
+ | `bun run publish:major` | 发布 major 版本 |
319
+ | `npm login` | 创建 session token |
320
+ | `npm view ops-toolkit versions` | 查看已发布版本 |
321
+ | `npm pack --dry-run` | 预览将要发布的内容 |
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "ops-toolkit",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "A comprehensive DevOps CLI toolkit with terminal UI",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
7
- "ops": "./dist/bin/ops-toolkit.js",
8
- "ops-toolkit": "./dist/bin/ops-toolkit.js"
7
+ "ops": "dist/bin/ops-toolkit.js",
8
+ "ops-toolkit": "dist/bin/ops-toolkit.js"
9
9
  },
10
10
  "scripts": {
11
11
  "dev": "bun --watch src/index.ts",
@@ -20,7 +20,10 @@
20
20
  "release": "standard-version",
21
21
  "release:minor": "standard-version --release-as minor",
22
22
  "release:major": "standard-version --release-as major",
23
- "publish": "release-it"
23
+ "publish": "release-it",
24
+ "publish:patch": "release-it --increment=patch --ci",
25
+ "publish:minor": "release-it --increment=minor --ci",
26
+ "publish:major": "release-it --increment=major --ci"
24
27
  },
25
28
  "keywords": [
26
29
  "cli",
@@ -37,7 +40,7 @@
37
40
  "license": "MIT",
38
41
  "repository": {
39
42
  "type": "git",
40
- "url": "https://github.com/liangshaojie/ops-toolkit.git"
43
+ "url": "git+https://github.com/liangshaojie/ops-toolkit.git"
41
44
  },
42
45
  "bugs": {
43
46
  "url": "https://github.com/liangshaojie/ops-toolkit/issues"