keepchanges 0.0.3 → 1.0.0-beta.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/README.md +48 -158
- package/README.zh-CN.md +181 -0
- package/dist/cli.d.mts +1 -14
- package/dist/cli.mjs +166 -254
- package/dist/commit-FX77u6Sj.mjs +190 -0
- package/dist/index.d.mts +152 -0
- package/dist/index.mjs +2 -0
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -2,162 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
Generate and maintain `CHANGELOG.md` from Conventional Commits.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Inspired by [changelogithub](https://github.com/antfu-collective/changelogithub).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
[简体中文](./README.zh-CN.md)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- 根据最近的 Git tag 到 `HEAD` 之间的 Conventional Commits 生成变更记录
|
|
12
|
-
- 首次发布时读取完整 Git 历史
|
|
13
|
-
- 将新版本插入 `CHANGELOG.md` 的已有内容之前
|
|
14
|
-
- 为 npm 项目同步更新 `package.json` 中的 `version`
|
|
15
|
-
- 为提交、对比页面、作者和共同作者生成 GitHub 信息
|
|
16
|
-
- 可选择自动提交、创建 tag、推送并发布 GitHub Release
|
|
17
|
-
- 没有 GitHub token 时提供预填内容的手动发布链接
|
|
18
|
-
|
|
19
|
-
当前会收录 `feat`、`fix`、带 `!` 的破坏性变更,以及包含
|
|
20
|
-
`BREAKING CHANGE` 或 `BREAKING-CHANGE` trailer 的提交。其他提交类型会被忽略。
|
|
21
|
-
|
|
22
|
-
### 快速开始
|
|
23
|
-
|
|
24
|
-
需要 Node.js 20.19.0 或更高版本。
|
|
25
|
-
|
|
26
|
-
在 Git 仓库根目录运行,并传入要发布的版本号:
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
npx keepchanges 1.1.0
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
也可以使用带 `v` 前缀的版本号:
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
npx keepchanges v1.1.0
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
默认行为会写入 `CHANGELOG.md`。如果当前项目是 npm 包,还会将
|
|
39
|
-
`package.json#version` 更新为 `1.1.0`,但不会自动创建 Git commit。
|
|
40
|
-
|
|
41
|
-
### 命令格式
|
|
42
|
-
|
|
43
|
-
```text
|
|
44
|
-
npx keepchanges <version> [options]
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
#### 参数
|
|
48
|
-
|
|
49
|
-
| 参数 | 默认值 | 说明 |
|
|
50
|
-
| --- | --- | --- |
|
|
51
|
-
| `<version>` | 必填 | 要生成的版本号。可以传入 `1.1.0` 或 `v1.1.0`;生成的标题和 tag 统一使用 `v1.1.0`。包含 `-` 的版本会作为预发布版本,例如 `1.1.0-beta.1`。 |
|
|
52
|
-
| `--output <path>` | `CHANGELOG.md` | 指定 changelog 文件路径。相对路径以当前工作目录为基准。 |
|
|
53
|
-
| `--dry` | `false` | 只预览,不写入 changelog 或版本文件。单独使用时输出完整 changelog;与 `--release` 一起使用时输出 Release notes 和手动发布链接。 |
|
|
54
|
-
| `--commit` | `false` | 写入文件后创建 Git commit。只提交 changelog 和检测到的版本文件,默认提交信息为 `chore(release): v<version>`。 |
|
|
55
|
-
| `--release` | `false` | 执行完整发布流程:写入文件、创建或复用 release commit、创建 annotated tag、推送 `HEAD` 和 tag,然后创建或更新仓库 Release。该参数隐含 `--commit`。 |
|
|
56
|
-
| `--author <author>` | Git 默认作者 | 设置自动创建的 release commit 作者,格式必须为 `"Name <email>"`。只影响作者,不改变仓库配置的 committer;需要与 `--commit` 或 `--release` 一起使用。 |
|
|
57
|
-
| `--token <token>` | 环境变量 | 仓库访问令牌,用于解析 GitHub 用户名以及创建或更新 GitHub Release。优先级为 `--token`、`GITHUB_TOKEN`、`GH_TOKEN`。 |
|
|
58
|
-
|
|
59
|
-
### 常见用法
|
|
60
|
-
|
|
61
|
-
指定输出文件:
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
npx keepchanges 1.1.0 --output docs/CHANGELOG.md
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
预览完整 changelog,不修改文件:
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
npx keepchanges 1.1.0 --dry
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
写入 changelog、更新版本并创建 commit:
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
npx keepchanges 1.1.0 --commit
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
指定 release commit 的作者:
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
npx keepchanges 1.1.0 --commit \
|
|
83
|
-
--author "Release Author <release@example.com>"
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
创建 GitHub Release:
|
|
87
|
-
|
|
88
|
-
```bash
|
|
89
|
-
GITHUB_TOKEN=github_pat_xxx npx keepchanges 1.1.0 --release
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
预览 Release,不写文件、不提交、不创建 tag、不推送且不调用发布 API:
|
|
93
|
-
|
|
94
|
-
```bash
|
|
95
|
-
npx keepchanges 1.1.0 --release --dry
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### 生成和发布行为
|
|
99
|
-
|
|
100
|
-
仓库地址优先读取 `package.json#repository`,不存在时读取 Git 的 `origin`。
|
|
101
|
-
GitHub 地址会被自动识别。自托管 Gitea 需要在 `package.json` 中显式声明:
|
|
102
|
-
|
|
103
|
-
```json
|
|
104
|
-
{
|
|
105
|
-
"repository": {
|
|
106
|
-
"type": "git",
|
|
107
|
-
"provider": "gitea",
|
|
108
|
-
"url": "http://10.102.248.21/edram/keepchanges.git"
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
识别到仓库后,每条记录会包含 commit 和 PR 链接,末尾会包含版本对比链接。
|
|
114
|
-
GitHub 和 Gitea 均支持作者解析和 Release 发布;Gitea 使用 `GITEA_TOKEN`
|
|
115
|
-
解析 commit 主作者并发布 Release。
|
|
116
|
-
|
|
117
|
-
默认使用 Git 提交中的作者名,并将 `Co-Authored-By` 参与者一起写入记录,bot
|
|
118
|
-
账号会被忽略。提供对应平台的 token 后,会尝试将邮箱解析为用户名。
|
|
119
|
-
|
|
120
|
-
`--commit` 只提交 changelog 和检测到的版本文件。其他已暂存或未暂存的改动会
|
|
121
|
-
保持原状。
|
|
122
|
-
|
|
123
|
-
`--release` 在 tag 不存在时:
|
|
124
|
-
|
|
125
|
-
1. 写入 changelog 并更新版本文件。
|
|
126
|
-
2. 创建或复用 release commit。
|
|
127
|
-
3. 创建 annotated tag。
|
|
128
|
-
4. 将 `HEAD` 和 tag 推送到 `origin`。
|
|
129
|
-
5. 创建 GitHub Release;没有 token 时输出手动发布链接。
|
|
130
|
-
|
|
131
|
-
`--release` 在 tag 已存在时不会移动 tag。它会根据前一个版本到现有 tag
|
|
132
|
-
重新生成 Release notes,并创建或更新 Release。只有远程存在 tag 时会先将它
|
|
133
|
-
拉取到本地;只有本地存在 tag 时会推送该 tag。本地与远程 tag 指向不同 commit
|
|
134
|
-
时会停止,不会强制覆盖。
|
|
135
|
-
|
|
136
|
-
稳定版本会与前一个稳定 tag 对比,预发布版本会与最近的前一个 tag 对比。与
|
|
137
|
-
`--release` 搭配的 `--dry` 优先级最高,不会执行任何写入或远程修改。
|
|
138
|
-
|
|
139
|
-
> [!NOTE]
|
|
140
|
-
> 没有 token 的普通 `--release` 仍会执行本地写入、commit、tag 和 push,
|
|
141
|
-
> 然后提供手动创建 GitHub Release 的链接。如需完全无副作用的预览,请使用
|
|
142
|
-
> `--release --dry`。
|
|
143
|
-
|
|
144
|
-
## English
|
|
145
|
-
|
|
146
|
-
### Features
|
|
9
|
+
## Features
|
|
147
10
|
|
|
148
11
|
- Generates release notes from Conventional Commits between the latest Git tag and `HEAD`
|
|
149
12
|
- Reads the complete Git history for a first release
|
|
150
13
|
- Inserts a new release before existing content in `CHANGELOG.md`
|
|
151
14
|
- Updates `package.json#version` for npm projects
|
|
152
|
-
- Adds
|
|
153
|
-
- Can commit, tag, push, and publish a GitHub Release
|
|
154
|
-
- Provides a
|
|
15
|
+
- Adds repository commit links, comparison links, authors, and co-authors
|
|
16
|
+
- Can commit, tag, push, and publish a GitHub or Gitea Release
|
|
17
|
+
- Provides a manual release URL when no GitHub/Gitea token is available
|
|
155
18
|
|
|
156
|
-
The current release includes `feat`, `fix`, breaking changes marked with `!`,
|
|
19
|
+
The current release includes `feat`, `fix`, `perf`, breaking changes marked with `!`,
|
|
157
20
|
and commits with a `BREAKING CHANGE` or `BREAKING-CHANGE` trailer. Other commit
|
|
158
21
|
types are ignored.
|
|
159
22
|
|
|
160
|
-
|
|
23
|
+
## Quick start
|
|
161
24
|
|
|
162
25
|
Node.js 20.19.0 or later is required.
|
|
163
26
|
|
|
@@ -176,25 +39,34 @@ npx keepchanges v1.1.0
|
|
|
176
39
|
By default, the command writes `CHANGELOG.md`. For an npm package, it also
|
|
177
40
|
updates `package.json#version` to `1.1.0`, but it does not create a Git commit.
|
|
178
41
|
|
|
179
|
-
|
|
42
|
+
## Command
|
|
180
43
|
|
|
181
44
|
```text
|
|
182
45
|
npx keepchanges <version> [options]
|
|
183
46
|
```
|
|
184
47
|
|
|
185
|
-
|
|
48
|
+
### Arguments and options
|
|
186
49
|
|
|
187
50
|
| Argument or option | Default | Description |
|
|
188
51
|
| --- | --- | --- |
|
|
189
52
|
| `<version>` | Required | Version to generate. Accepts `1.1.0` or `v1.1.0`; headings and tags use `v1.1.0`. A version containing `-`, such as `1.1.0-beta.1`, is treated as a prerelease. |
|
|
53
|
+
| `--from <ref>` | Latest tag | Overrides the starting Git ref used to read commits. |
|
|
54
|
+
| `--to <ref>` | `HEAD` | Sets the ending Git ref. It cannot be combined with `--release`, and must resolve to the current `HEAD` when used with `--commit`. |
|
|
55
|
+
| `--repository <source>` | Auto-detected | Sets a GitHub `owner/repo` slug or a complete GitHub/Gitea URL. It takes precedence over `package.json` and `origin`. |
|
|
190
56
|
| `--output <path>` | `CHANGELOG.md` | Sets the changelog file path. Relative paths are resolved from the current working directory. |
|
|
191
|
-
| `--dry` | `false` |
|
|
57
|
+
| `--dry` | `false` | Prints the current release preview without writing files or performing commit, tag, push, or release API mutations. |
|
|
192
58
|
| `--commit` | `false` | Creates a Git commit after writing. It commits only the changelog and detected version file, using `chore(release): v<version>` by default. |
|
|
193
59
|
| `--release` | `false` | Runs the complete release flow: writes files, creates or reuses a release commit, creates an annotated tag, pushes `HEAD` and the tag, then creates or updates the repository Release. This implies `--commit`. |
|
|
194
|
-
| `--author <author>` |
|
|
195
|
-
|
|
|
60
|
+
| `--author <author>` | Release bot | Sets the generated release commit author in `"Name <email>"` format; requires `--commit` or `--release`. |
|
|
61
|
+
| `-t, --token <token>` | Environment | Resolves authors and publishes Releases. GitHub precedence is `--token`, `GITHUB_TOKEN`, then `GH_TOKEN`; Gitea uses `GITEA_TOKEN`. |
|
|
62
|
+
| `--name <name>` | Version tag | Sets the remote Release name; only valid with `--release`. |
|
|
63
|
+
| `-d, --draft` | `false` | Creates a draft Release; only valid with `--release`. |
|
|
64
|
+
| `--prerelease` | Inferred | Explicitly marks a prerelease. By default it is inferred from `-` in the version; only valid with `--release`. |
|
|
65
|
+
| `--emoji` | `true` | Controls section title emojis. As with changelogithub, CAC's `--no-emoji` form disables them. |
|
|
66
|
+
| `--capitalize` | `true` | Controls entry capitalization; `--no-capitalize` disables it. |
|
|
67
|
+
| `--group` | `true` | Groups repeated scopes; `--no-group` disables it. |
|
|
196
68
|
|
|
197
|
-
|
|
69
|
+
## Examples
|
|
198
70
|
|
|
199
71
|
Write to a different file:
|
|
200
72
|
|
|
@@ -202,7 +74,7 @@ Write to a different file:
|
|
|
202
74
|
npx keepchanges 1.1.0 --output docs/CHANGELOG.md
|
|
203
75
|
```
|
|
204
76
|
|
|
205
|
-
Preview the
|
|
77
|
+
Preview the current release without changing files:
|
|
206
78
|
|
|
207
79
|
```bash
|
|
208
80
|
npx keepchanges 1.1.0 --dry
|
|
@@ -234,10 +106,10 @@ release API:
|
|
|
234
106
|
npx keepchanges 1.1.0 --release --dry
|
|
235
107
|
```
|
|
236
108
|
|
|
237
|
-
|
|
109
|
+
## Generation and release behavior
|
|
238
110
|
|
|
239
|
-
The repository
|
|
240
|
-
`origin`. GitHub URLs are detected automatically. A self-hosted Gitea repository
|
|
111
|
+
The repository is read from `--repository`, then `package.json#repository`, and
|
|
112
|
+
finally the Git `origin`. GitHub URLs are detected automatically. A self-hosted Gitea repository
|
|
241
113
|
must be declared explicitly in `package.json`:
|
|
242
114
|
|
|
243
115
|
```json
|
|
@@ -245,7 +117,7 @@ must be declared explicitly in `package.json`:
|
|
|
245
117
|
"repository": {
|
|
246
118
|
"type": "git",
|
|
247
119
|
"provider": "gitea",
|
|
248
|
-
"url": "
|
|
120
|
+
"url": "https://gitea.example.com/edram/keepchanges.git"
|
|
249
121
|
}
|
|
250
122
|
}
|
|
251
123
|
```
|
|
@@ -268,7 +140,7 @@ When the tag does not exist, `--release`:
|
|
|
268
140
|
2. Creates or reuses a release commit.
|
|
269
141
|
3. Creates an annotated tag.
|
|
270
142
|
4. Pushes `HEAD` and the tag to `origin`.
|
|
271
|
-
5. Creates a
|
|
143
|
+
5. Creates a repository Release, or prints a manual URL without a GitHub/Gitea token.
|
|
272
144
|
|
|
273
145
|
When the tag already exists, `--release` never moves it. It regenerates Release
|
|
274
146
|
notes from the previous version to the existing tag and creates or updates the
|
|
@@ -282,9 +154,27 @@ prevents all file writes and remote mutations.
|
|
|
282
154
|
|
|
283
155
|
> [!NOTE]
|
|
284
156
|
> A regular `--release` without a token still writes files, commits, tags, and
|
|
285
|
-
> pushes before providing the manual
|
|
157
|
+
> pushes before providing the manual Release URL. Use `--release --dry`
|
|
286
158
|
> for a completely non-mutating preview.
|
|
287
159
|
|
|
160
|
+
## Programmatic API
|
|
161
|
+
|
|
162
|
+
The package root exports `generateChangelog`, the commit parser, default config,
|
|
163
|
+
and core types. The CLI is only available as the `keepchanges` binary, while
|
|
164
|
+
programmatic callers can provide changelog style overrides:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
import { generateChangelog } from 'keepchanges'
|
|
168
|
+
|
|
169
|
+
const result = generateChangelog(
|
|
170
|
+
{ version: '1.1.0', commits },
|
|
171
|
+
{
|
|
172
|
+
emoji: false,
|
|
173
|
+
messages: { noSignificantChanges: 'Nothing noteworthy' },
|
|
174
|
+
},
|
|
175
|
+
)
|
|
176
|
+
```
|
|
177
|
+
|
|
288
178
|
## Development
|
|
289
179
|
|
|
290
180
|
```bash
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# keepchanges
|
|
2
|
+
|
|
3
|
+
基于 Conventional Commits 生成并维护 `CHANGELOG.md`。
|
|
4
|
+
|
|
5
|
+
灵感来自 [changelogithub](https://github.com/antfu-collective/changelogithub)。
|
|
6
|
+
|
|
7
|
+
[English](./README.md)
|
|
8
|
+
|
|
9
|
+
## 功能
|
|
10
|
+
|
|
11
|
+
- 根据最近的 Git tag 到 `HEAD` 之间的 Conventional Commits 生成变更记录
|
|
12
|
+
- 首次发布时读取完整 Git 历史
|
|
13
|
+
- 将新版本插入 `CHANGELOG.md` 的已有内容之前
|
|
14
|
+
- 为 npm 项目同步更新 `package.json` 中的 `version`
|
|
15
|
+
- 为提交、对比页面、作者和共同作者生成仓库平台信息
|
|
16
|
+
- 可选择自动提交、创建 tag、推送并发布 GitHub/Gitea Release
|
|
17
|
+
- 没有 GitHub/Gitea token 时提供手动发布链接
|
|
18
|
+
|
|
19
|
+
当前会收录 `feat`、`fix`、`perf`、带 `!` 的破坏性变更,以及包含
|
|
20
|
+
`BREAKING CHANGE` 或 `BREAKING-CHANGE` trailer 的提交。其他提交类型会被忽略。
|
|
21
|
+
|
|
22
|
+
## 快速开始
|
|
23
|
+
|
|
24
|
+
需要 Node.js 20.19.0 或更高版本。
|
|
25
|
+
|
|
26
|
+
在 Git 仓库根目录运行,并传入要发布的版本号:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx keepchanges 1.1.0
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
也可以使用带 `v` 前缀的版本号:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx keepchanges v1.1.0
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
默认行为会写入 `CHANGELOG.md`。如果当前项目是 npm 包,还会将
|
|
39
|
+
`package.json#version` 更新为 `1.1.0`,但不会自动创建 Git commit。
|
|
40
|
+
|
|
41
|
+
## 命令格式
|
|
42
|
+
|
|
43
|
+
```text
|
|
44
|
+
npx keepchanges <version> [options]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 参数
|
|
48
|
+
|
|
49
|
+
| 参数 | 默认值 | 说明 |
|
|
50
|
+
| --- | --- | --- |
|
|
51
|
+
| `<version>` | 必填 | 要生成的版本号。可以传入 `1.1.0` 或 `v1.1.0`;生成的标题和 tag 统一使用 `v1.1.0`。包含 `-` 的版本会作为预发布版本,例如 `1.1.0-beta.1`。 |
|
|
52
|
+
| `--from <ref>` | 最近的 tag | 指定读取 commit 的起始 Git ref,并覆盖自动选择结果。 |
|
|
53
|
+
| `--to <ref>` | `HEAD` | 指定读取 commit 的结束 Git ref。不能与 `--release` 一起使用;与 `--commit` 一起使用时必须指向当前 `HEAD`。 |
|
|
54
|
+
| `--repository <source>` | 自动检测 | 指定 `owner/repo` 格式的 GitHub 仓库或 GitHub/Gitea 完整 URL。优先级高于 `package.json` 和 `origin`。 |
|
|
55
|
+
| `--output <path>` | `CHANGELOG.md` | 指定 changelog 文件路径。相对路径以当前工作目录为基准。 |
|
|
56
|
+
| `--dry` | `false` | 输出当前版本预览,不写入文件,也不执行 commit、tag、push 或发布 API。 |
|
|
57
|
+
| `--commit` | `false` | 写入文件后创建 Git commit。只提交 changelog 和检测到的版本文件,默认提交信息为 `chore(release): v<version>`。 |
|
|
58
|
+
| `--release` | `false` | 执行完整发布流程:写入文件、创建或复用 release commit、创建 annotated tag、推送 `HEAD` 和 tag,然后创建或更新仓库 Release。该参数隐含 `--commit`。 |
|
|
59
|
+
| `--author <author>` | release bot | 设置自动创建的 release commit 作者,格式必须为 `"Name <email>"`;需要与 `--commit` 或 `--release` 一起使用。 |
|
|
60
|
+
| `-t, --token <token>` | 环境变量 | 仓库访问令牌,用于解析作者及发布 Release。GitHub 优先级为 `--token`、`GITHUB_TOKEN`、`GH_TOKEN`;Gitea 使用 `GITEA_TOKEN`。 |
|
|
61
|
+
| `--name <name>` | 版本 tag | 设置远程 Release 名称;仅适用于 `--release`。 |
|
|
62
|
+
| `-d, --draft` | `false` | 创建 draft Release;仅适用于 `--release`。 |
|
|
63
|
+
| `--prerelease` | 根据版本推断 | 显式标记为 prerelease;默认根据版本是否包含 `-` 推断,仅适用于 `--release`。 |
|
|
64
|
+
| `--emoji` | `true` | 控制 section 标题 emoji。与 changelogithub 一样,可使用 CAC 的 `--no-emoji` 形式关闭。 |
|
|
65
|
+
| `--capitalize` | `true` | 控制 changelog 条目首字母大写;可使用 `--no-capitalize` 关闭。 |
|
|
66
|
+
| `--group` | `true` | 当 scope 重复时分组;可使用 `--no-group` 关闭。 |
|
|
67
|
+
|
|
68
|
+
## 常见用法
|
|
69
|
+
|
|
70
|
+
指定输出文件:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npx keepchanges 1.1.0 --output docs/CHANGELOG.md
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
预览当前版本,不修改文件:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npx keepchanges 1.1.0 --dry
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
写入 changelog、更新版本并创建 commit:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npx keepchanges 1.1.0 --commit
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
指定 release commit 的作者:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npx keepchanges 1.1.0 --commit \
|
|
92
|
+
--author "Release Author <release@example.com>"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
创建 GitHub Release:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
GITHUB_TOKEN=github_pat_xxx npx keepchanges 1.1.0 --release
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
预览 Release,不写文件、不提交、不创建 tag、不推送且不调用发布 API:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
npx keepchanges 1.1.0 --release --dry
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 生成和发布行为
|
|
108
|
+
|
|
109
|
+
仓库地址优先读取 `--repository`,其次读取 `package.json#repository`,最后读取 Git 的 `origin`。
|
|
110
|
+
GitHub 地址会被自动识别。自托管 Gitea 需要在 `package.json` 中显式声明:
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"repository": {
|
|
115
|
+
"type": "git",
|
|
116
|
+
"provider": "gitea",
|
|
117
|
+
"url": "https://gitea.example.com/edram/keepchanges.git"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
识别到仓库后,每条记录会包含 commit 和 PR 链接,末尾会包含版本对比链接。
|
|
123
|
+
GitHub 和 Gitea 均支持作者解析和 Release 发布;Gitea 使用 `GITEA_TOKEN`
|
|
124
|
+
解析 commit 主作者并发布 Release。
|
|
125
|
+
|
|
126
|
+
默认使用 Git 提交中的作者名,并将 `Co-Authored-By` 参与者一起写入记录,bot
|
|
127
|
+
账号会被忽略。提供对应平台的 token 后,会尝试将邮箱解析为用户名。
|
|
128
|
+
|
|
129
|
+
`--commit` 只提交 changelog 和检测到的版本文件。其他已暂存或未暂存的改动会
|
|
130
|
+
保持原状。
|
|
131
|
+
|
|
132
|
+
`--release` 在 tag 不存在时:
|
|
133
|
+
|
|
134
|
+
1. 写入 changelog 并更新版本文件。
|
|
135
|
+
2. 创建或复用 release commit。
|
|
136
|
+
3. 创建 annotated tag。
|
|
137
|
+
4. 将 `HEAD` 和 tag 推送到 `origin`。
|
|
138
|
+
5. 创建仓库 Release;GitHub/Gitea 没有 token 时输出手动发布链接。
|
|
139
|
+
|
|
140
|
+
`--release` 在 tag 已存在时不会移动 tag。它会根据前一个版本到现有 tag
|
|
141
|
+
重新生成 Release notes,并创建或更新 Release。只有远程存在 tag 时会先将它
|
|
142
|
+
拉取到本地;只有本地存在 tag 时会推送该 tag。本地与远程 tag 指向不同 commit
|
|
143
|
+
时会停止,不会强制覆盖。
|
|
144
|
+
|
|
145
|
+
稳定版本会与前一个稳定 tag 对比,预发布版本会与最近的前一个 tag 对比。与
|
|
146
|
+
`--release` 搭配的 `--dry` 优先级最高,不会执行任何写入或远程修改。
|
|
147
|
+
|
|
148
|
+
> [!NOTE]
|
|
149
|
+
> 没有 token 的普通 `--release` 仍会执行本地写入、commit、tag 和 push,
|
|
150
|
+
> 然后提供手动创建 Release 的链接。如需完全无副作用的预览,请使用
|
|
151
|
+
> `--release --dry`。
|
|
152
|
+
|
|
153
|
+
## 程序化 API
|
|
154
|
+
|
|
155
|
+
包根入口导出 `generateChangelog`、commit parser、默认配置及核心类型。
|
|
156
|
+
CLI 仅作为 `keepchanges` 二进制命令。程序化调用可以传入 changelog 样式覆盖:
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
import { generateChangelog } from 'keepchanges'
|
|
160
|
+
|
|
161
|
+
const result = generateChangelog(
|
|
162
|
+
{ version: '1.1.0', commits },
|
|
163
|
+
{
|
|
164
|
+
emoji: false,
|
|
165
|
+
messages: { noSignificantChanges: 'Nothing noteworthy' },
|
|
166
|
+
},
|
|
167
|
+
)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## 开发
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
pnpm install
|
|
174
|
+
pnpm test
|
|
175
|
+
pnpm run typecheck
|
|
176
|
+
pnpm run build
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## 许可证
|
|
180
|
+
|
|
181
|
+
MIT
|
package/dist/cli.d.mts
CHANGED
|
@@ -1,14 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/run.d.ts
|
|
3
|
-
interface CliEnvironment {
|
|
4
|
-
cwd: string;
|
|
5
|
-
env?: NodeJS.ProcessEnv;
|
|
6
|
-
stdout?: (value: string) => void;
|
|
7
|
-
fetch?: typeof globalThis.fetch;
|
|
8
|
-
colors?: typeof ansis;
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
//#region src/cli.d.ts
|
|
12
|
-
declare function runCli(args: string[], environment: CliEnvironment): Promise<void>;
|
|
13
|
-
//#endregion
|
|
14
|
-
export { type CliEnvironment, runCli };
|
|
1
|
+
export {}
|