@varlet/release 2.1.0 → 2.2.0
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 +267 -83
- package/README.zh-CN.md +267 -83
- package/dist/cli.js +12 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{src-_TFLfQjD.js → src-JMmGEAWu.js} +13 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,151 +20,335 @@
|
|
|
20
20
|
|
|
21
21
|
> `Varlet Release` requires `Node.js` ^20.19.0 || >=22.12.0 and `esm` only.
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
Install dependencies:
|
|
24
26
|
|
|
25
27
|
```shell
|
|
26
|
-
pnpm add @varlet/release -D
|
|
28
|
+
pnpm add @varlet/release simple-git-hooks -D
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Add the following configuration to `package.json`:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"scripts": {
|
|
36
|
+
"prepare": "simple-git-hooks",
|
|
37
|
+
"release": "vr release",
|
|
38
|
+
"changelog": "vr changelog"
|
|
39
|
+
},
|
|
40
|
+
"simple-git-hooks": {
|
|
41
|
+
"commit-msg": "pnpm exec vr commit-lint $1",
|
|
42
|
+
"post-merge": "pnpm exec vr lockfile-check --install"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
27
45
|
```
|
|
28
46
|
|
|
47
|
+
Now you can:
|
|
48
|
+
|
|
49
|
+
- Write commits following the [Conventional Commits](https://www.conventionalcommits.org/) format, `commit-lint` will automatically validate them.
|
|
50
|
+
- After pulling or merging code, `lockfile-check` will automatically detect lockfile changes (`pnpm-lock.yaml`, `yarn.lock`, `package-lock.json`) and reinstall dependencies.
|
|
51
|
+
- Run `pnpm release` to start the interactive release workflow.
|
|
52
|
+
|
|
29
53
|
## Usage
|
|
30
54
|
|
|
31
|
-
###
|
|
55
|
+
### Features Overview
|
|
32
56
|
|
|
33
|
-
|
|
57
|
+
- [release](#release) - Automatically complete the standard workflow from version modification to publishing and creating git tags.
|
|
58
|
+
- [publish](#publish) - Execute the npm publish process independently, usually suitable for CI/CD environments.
|
|
59
|
+
- [changelog](#changelog) - Automatically generate formatted changelogs based on Git Commit conventions.
|
|
60
|
+
- [commit-lint](#commit-lint) - Validate whether the Git Commit Message adheres to specifications, helping teams unify commit formats.
|
|
61
|
+
- [lockfile-check](#lockfile-check) - Check the status of the project's lockfile and provide dependency update mechanisms when changes occur.
|
|
34
62
|
|
|
35
|
-
|
|
36
|
-
2. Execute the user-defined `task` function (optional, e.g., to rebuild projects based on the new version)
|
|
37
|
-
3. Update the `package.json` **version** programmatically
|
|
38
|
-
4. Generate the **Changelog**
|
|
39
|
-
5. **Git Commit** & **Git Tag**
|
|
40
|
-
6. **Publish** to npm
|
|
63
|
+
---
|
|
41
64
|
|
|
42
|
-
###
|
|
65
|
+
### release
|
|
43
66
|
|
|
44
|
-
|
|
45
|
-
# Release all packages and run the full workflow
|
|
46
|
-
npx vr release
|
|
67
|
+
**Description**: The core functional collection for package release, integrating all release preparation and subsequent operations.
|
|
47
68
|
|
|
48
|
-
|
|
49
|
-
npx vr release -r origin
|
|
50
|
-
# or
|
|
51
|
-
npx vr release --remote origin
|
|
69
|
+
**Use cases**: Used when a new version needs to be released and all workspace changes have been committed. It guides through the publication via an intuitive command-line interaction.
|
|
52
70
|
|
|
53
|
-
|
|
54
|
-
npx vr changelog
|
|
71
|
+
**Core Workflow**:
|
|
55
72
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
73
|
+
1. Interactively prompt and confirm the new version number (automatically calculate patch, minor, major upgrades).
|
|
74
|
+
2. Execute the user-customized `task` function (e.g., modifying files, bundling assets).
|
|
75
|
+
3. Automatically update the version number in the project's `package.json`.
|
|
76
|
+
4. Generate the `Changelog` for the corresponding version.
|
|
77
|
+
5. Automatically complete the Git commit and create a new version Tag.
|
|
78
|
+
6. Publish the updated packages to npm.
|
|
60
79
|
|
|
61
|
-
|
|
62
|
-
npx vr commit-lint -p .git/COMMIT_EDITMSG
|
|
80
|
+
**CLI Commands**:
|
|
63
81
|
|
|
64
|
-
|
|
65
|
-
npx vr publish
|
|
82
|
+
_Flags Reference_:
|
|
66
83
|
|
|
67
|
-
|
|
68
|
-
|
|
84
|
+
```text
|
|
85
|
+
Usage: vr release [flags...]
|
|
69
86
|
|
|
70
|
-
|
|
71
|
-
|
|
87
|
+
Flags:
|
|
88
|
+
--remote string Remote repository name # default: 'origin'
|
|
89
|
+
--skip-npm-publish Skip npm publish
|
|
90
|
+
--skip-changelog Skip generating changelog
|
|
91
|
+
--skip-git-tag Skip git tag
|
|
92
|
+
--npm-tag string npm tag
|
|
93
|
+
--check-remote-version Check remote version
|
|
72
94
|
```
|
|
73
95
|
|
|
74
|
-
|
|
96
|
+
_Example_:
|
|
75
97
|
|
|
76
|
-
|
|
98
|
+
```shell
|
|
99
|
+
# Release all packages and execute the full workflow
|
|
100
|
+
pnpm exec vr release
|
|
101
|
+
|
|
102
|
+
# Skip npm publishing
|
|
103
|
+
pnpm exec vr release --skip-npm-publish
|
|
104
|
+
# Skip generating changelog
|
|
105
|
+
pnpm exec vr release --skip-changelog
|
|
106
|
+
# Check remote version, interrupt execution if the identical version already exists
|
|
107
|
+
pnpm exec vr release --check-remote-version
|
|
108
|
+
|
|
109
|
+
# Specify the git remote name for pushing tags (useful when multiple remotes are configured, e.g. upstream, fork)
|
|
110
|
+
pnpm exec vr release --remote upstream
|
|
111
|
+
```
|
|
77
112
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
113
|
+
**Node API**:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { release } from '@varlet/release'
|
|
117
|
+
|
|
118
|
+
release({
|
|
119
|
+
remote?: string // Remote repository name, defaults to 'origin'
|
|
120
|
+
npmTag?: string // NPM tag to publish, such as 'next', 'alpha'
|
|
121
|
+
cwd?: string // Working directory, defaults to process.cwd()
|
|
122
|
+
skipNpmPublish?: boolean // Whether to skip the npm publish process
|
|
123
|
+
skipChangelog?: boolean // Whether to skip changelog generation
|
|
124
|
+
skipGitTag?: boolean // Whether to skip git tag creation
|
|
125
|
+
checkRemoteVersion?: boolean // Whether to check remote version to avoid conflicts
|
|
126
|
+
task?(newVersion: string, oldVersion: string): Promise<void> // Custom task executed during the release
|
|
127
|
+
})
|
|
84
128
|
```
|
|
85
129
|
|
|
86
|
-
|
|
130
|
+
_Example: Add custom handling logic_
|
|
87
131
|
|
|
88
|
-
|
|
132
|
+
```javascript
|
|
133
|
+
import { release } from '@varlet/release'
|
|
89
134
|
|
|
90
|
-
|
|
91
|
-
|
|
135
|
+
async function task(newVersion, oldVersion) {
|
|
136
|
+
// Execute building or file writing operations here
|
|
137
|
+
await doBuild()
|
|
138
|
+
}
|
|
92
139
|
|
|
93
|
-
|
|
94
|
-
-r, --remote <string> Remote name
|
|
95
|
-
-s, --skip-npm-publish Skip npm publish
|
|
96
|
-
--skip-changelog Skip generate changelog
|
|
97
|
-
--skip-git-tag Skip git tag
|
|
98
|
-
-t, --npm-tag <string> Npm tag
|
|
99
|
-
-c, --check-remote-version Check remote version
|
|
140
|
+
release({ task })
|
|
100
141
|
```
|
|
101
142
|
|
|
102
|
-
|
|
143
|
+
---
|
|
103
144
|
|
|
104
|
-
|
|
145
|
+
### publish
|
|
146
|
+
|
|
147
|
+
**Description**: Publish the package independently to the npm registry.
|
|
148
|
+
|
|
149
|
+
**Use cases**: Applicable in scenarios where manual version selection, changelog generation, or git tags are not needed, often used in CI/CD pipelines to trigger automated publication based on specific processes.
|
|
150
|
+
|
|
151
|
+
**Core Workflow**: Read the version number from the current package.json and run the corresponding publish process.
|
|
152
|
+
|
|
153
|
+
**CLI Commands**:
|
|
154
|
+
|
|
155
|
+
_Flags Reference_:
|
|
156
|
+
|
|
157
|
+
```text
|
|
105
158
|
Usage: vr publish [flags...]
|
|
106
159
|
|
|
107
160
|
Flags:
|
|
108
|
-
|
|
109
|
-
|
|
161
|
+
--check-remote-version Check remote version
|
|
162
|
+
--npm-tag string npm tag
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
_Example_:
|
|
166
|
+
|
|
167
|
+
```shell
|
|
168
|
+
# Publish directly to npm
|
|
169
|
+
pnpm exec vr publish
|
|
170
|
+
|
|
171
|
+
# Check if the same version already exists due to network or other reasons, and abort if so
|
|
172
|
+
pnpm exec vr publish --check-remote-version
|
|
173
|
+
# Specify the npm dist-tag
|
|
174
|
+
pnpm exec vr publish --npm-tag alpha
|
|
110
175
|
```
|
|
111
176
|
|
|
112
|
-
|
|
177
|
+
**Node API**:
|
|
113
178
|
|
|
179
|
+
```typescript
|
|
180
|
+
import { publish } from '@varlet/release'
|
|
181
|
+
|
|
182
|
+
publish({
|
|
183
|
+
preRelease?: boolean // Pre-release indicator, will add the '--tag alpha' option
|
|
184
|
+
checkRemoteVersion?: boolean // Check if the same version exists on the remote npm before publishing
|
|
185
|
+
npmTag?: string // NPM tag to publish
|
|
186
|
+
cwd?: string // Working directory, defaults to process.cwd()
|
|
187
|
+
})
|
|
114
188
|
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
### changelog
|
|
193
|
+
|
|
194
|
+
**Description**: Automatically generate Markdown-formatted changelogs based on standard Commit history.
|
|
195
|
+
|
|
196
|
+
**Use cases**: Useful for updating the `CHANGELOG.md` file independently without triggering the full release process.
|
|
197
|
+
|
|
198
|
+
**Core Workflow**: Traverse the Git commit history and format the output classified by predefined conventional commit rules (e.g., feat, fix).
|
|
199
|
+
|
|
200
|
+
**CLI Commands**:
|
|
201
|
+
|
|
202
|
+
_Flags Reference_:
|
|
203
|
+
|
|
204
|
+
```text
|
|
115
205
|
Usage: vr changelog [flags...]
|
|
116
206
|
|
|
117
207
|
Flags:
|
|
118
|
-
|
|
119
|
-
|
|
208
|
+
--release-count number Release count # default: 0
|
|
209
|
+
--file string Changelog filename # default: 'CHANGELOG.md'
|
|
120
210
|
```
|
|
121
211
|
|
|
122
|
-
|
|
212
|
+
_Example_:
|
|
123
213
|
|
|
214
|
+
```shell
|
|
215
|
+
# Generate changelogs for all history and output as CHANGELOG.md in the current directory
|
|
216
|
+
pnpm exec vr changelog
|
|
217
|
+
|
|
218
|
+
# Specify the generated changelog filename
|
|
219
|
+
pnpm exec vr changelog --file my-changelog.md
|
|
220
|
+
# Limit the range of release versions to generate changelogs for (0 means all)
|
|
221
|
+
pnpm exec vr changelog --release-count 0
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Node API**:
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
import { changelog } from '@varlet/release'
|
|
228
|
+
|
|
229
|
+
changelog({
|
|
230
|
+
cwd?: string // Working directory, defaults to process.cwd()
|
|
231
|
+
releaseCount?: number // Number of recent releases to include in the log, defaults to 0 (all)
|
|
232
|
+
file?: string // Output changelog filename, defaults to 'CHANGELOG.md'
|
|
233
|
+
showTypes?: string[] // Commit types to display, defaults to ['feat', 'fix', 'perf', 'revert', 'refactor']
|
|
234
|
+
outputUnreleased?: boolean // Whether to output unreleased changes
|
|
235
|
+
writerOpt?: object // Specific configuration for conventional-changelog-writer
|
|
236
|
+
})
|
|
124
237
|
```
|
|
125
|
-
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
### commit-lint
|
|
242
|
+
|
|
243
|
+
**Description**: Validate Git commit message formats.
|
|
244
|
+
|
|
245
|
+
**Use cases**: Used in combination with `git hooks` to enforce high-quality commit descriptions, ensuring the quality of the changelog.
|
|
246
|
+
|
|
247
|
+
**Core Workflow**: Read the commit file. If it matches the configured regex, the process continues; otherwise, it prints specific failure messages and aborts the commit.
|
|
248
|
+
|
|
249
|
+
**CLI Commands**:
|
|
250
|
+
|
|
251
|
+
_Parameters Reference_:
|
|
252
|
+
|
|
253
|
+
```text
|
|
254
|
+
Usage: vr commit-lint <commit-message-path> [flags...]
|
|
255
|
+
|
|
256
|
+
Parameters:
|
|
257
|
+
<commit-message-path> Git commit message path (required)
|
|
126
258
|
|
|
127
259
|
Flags:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
-w, --warning-message <string> Validation failed to display warning messages
|
|
260
|
+
--commit-message-re string Validate the regex for commit message
|
|
261
|
+
--error-message string Error message displayed on validation failure
|
|
262
|
+
--warning-message string Warning message displayed on validation failure
|
|
132
263
|
```
|
|
133
264
|
|
|
134
|
-
|
|
265
|
+
_Example_:
|
|
135
266
|
|
|
267
|
+
```shell
|
|
268
|
+
# Check if the commit message at the given path is standard
|
|
269
|
+
pnpm exec vr commit-lint .git/COMMIT_EDITMSG
|
|
270
|
+
|
|
271
|
+
# Customize regex validation and prompt message
|
|
272
|
+
pnpm exec vr commit-lint .git/COMMIT_EDITMSG --commit-message-re "^feat: .*" --error-message "Commit validation failed"
|
|
136
273
|
```
|
|
137
|
-
Usage: vr lockfile-sync-check [flags...]
|
|
138
274
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
275
|
+
_It is recommended to integrate with `simple-git-hooks` or `husky` in `package.json`:_
|
|
276
|
+
|
|
277
|
+
```json
|
|
278
|
+
{
|
|
279
|
+
"simple-git-hooks": {
|
|
280
|
+
"commit-msg": "pnpm exec vr commit-lint $1"
|
|
281
|
+
}
|
|
282
|
+
}
|
|
142
283
|
```
|
|
143
284
|
|
|
144
|
-
|
|
285
|
+
**Node API**:
|
|
145
286
|
|
|
146
|
-
|
|
287
|
+
```typescript
|
|
288
|
+
import { commitLint } from '@varlet/release'
|
|
147
289
|
|
|
148
|
-
|
|
290
|
+
commitLint({
|
|
291
|
+
commitMessagePath: string // Required: Path to Git commit message file
|
|
292
|
+
commitMessageRe?: string | RegExp // Regex to validate the commit message format
|
|
293
|
+
errorMessage?: string // Error message printed upon failure
|
|
294
|
+
warningMessage?: string // Supplemental warning information printed upon failure
|
|
295
|
+
})
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
### lockfile-check
|
|
301
|
+
|
|
302
|
+
**Description**: Detect and visually output in the console whether the lockfile of frontend dependencies has been modified, and automatically install dependencies by default to keep in sync.
|
|
303
|
+
|
|
304
|
+
**Use cases**: Recommended to use after Git operations such as pulling updates (`git pull`), switching branches (`git checkout`), or merging code. It helps detect if upstream dependency lockfiles (like `pnpm-lock.yaml`) have changed. If a change is detected, it will automatically invoke a package manager's installation command to synchronize the local environment with upstream instantly, preventing obscure bugs caused by outdated dependencies.
|
|
305
|
+
|
|
306
|
+
**Core Workflow**: Execute a Git diff comparing the project's lockfile (e.g. `pnpm-lock.yaml` or corresponding environment lockfile) from the original HEAD. Print its modification status in the console. Furthermore, trigger the package manager to reinstall dependencies to sync with upstream by default, or skip installation if directed by the command options.
|
|
149
307
|
|
|
150
|
-
|
|
151
|
-
import { changelog, release } from '@varlet/release'
|
|
308
|
+
**CLI Commands**:
|
|
152
309
|
|
|
153
|
-
|
|
154
|
-
|
|
310
|
+
_Flags Reference_:
|
|
311
|
+
|
|
312
|
+
```text
|
|
313
|
+
Usage: vr lockfile-check [flags...]
|
|
314
|
+
|
|
315
|
+
Flags:
|
|
316
|
+
--package-manager string Package manager (npm, yarn, pnpm) # default: 'pnpm'
|
|
317
|
+
--skip-install Skip install dependencies when lockfile changed
|
|
155
318
|
```
|
|
156
319
|
|
|
157
|
-
|
|
320
|
+
_Example_:
|
|
158
321
|
|
|
159
|
-
```
|
|
160
|
-
|
|
322
|
+
```shell
|
|
323
|
+
# Check the synchronization status of the current lockfile and install dependencies if changed
|
|
324
|
+
pnpm exec vr lockfile-check
|
|
161
325
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
326
|
+
# Check current status but skip installation even if updates exist
|
|
327
|
+
pnpm exec vr lockfile-check --skip-install
|
|
328
|
+
|
|
329
|
+
# Specify other package managers for checking
|
|
330
|
+
pnpm exec vr lockfile-check --package-manager npm
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
_It is also recommended to integrate with `simple-git-hooks` or `husky` in `package.json` (e.g. trigger checks and installations automatically during the `post-merge` or `post-checkout` hooks):_
|
|
334
|
+
|
|
335
|
+
```json
|
|
336
|
+
{
|
|
337
|
+
"simple-git-hooks": {
|
|
338
|
+
"post-merge": "pnpm exec vr lockfile-check"
|
|
339
|
+
}
|
|
165
340
|
}
|
|
341
|
+
```
|
|
166
342
|
|
|
167
|
-
|
|
343
|
+
**Node API**:
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
import { lockfileCheck } from '@varlet/release'
|
|
347
|
+
|
|
348
|
+
lockfileCheck({
|
|
349
|
+
packageManager?: 'npm' | 'yarn' | 'pnpm' // Choose package manager, defaults to 'pnpm'
|
|
350
|
+
skipInstall?: boolean // Whether to skip installation if lockfile is out of sync
|
|
351
|
+
})
|
|
168
352
|
```
|
|
169
353
|
|
|
170
354
|
## License
|
package/README.zh-CN.md
CHANGED
|
@@ -20,151 +20,335 @@
|
|
|
20
20
|
|
|
21
21
|
> `Varlet Release` 需要 `Node.js` ^20.19.0 || >=22.12.0,并且仅支持 `esm`。
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## 快速开始
|
|
24
|
+
|
|
25
|
+
安装依赖:
|
|
24
26
|
|
|
25
27
|
```shell
|
|
26
|
-
pnpm add @varlet/release -D
|
|
28
|
+
pnpm add @varlet/release simple-git-hooks -D
|
|
27
29
|
```
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
在 `package.json` 中添加以下配置:
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"scripts": {
|
|
36
|
+
"prepare": "simple-git-hooks",
|
|
37
|
+
"release": "vr release",
|
|
38
|
+
"changelog": "vr changelog"
|
|
39
|
+
},
|
|
40
|
+
"simple-git-hooks": {
|
|
41
|
+
"commit-msg": "pnpm exec vr commit-lint $1",
|
|
42
|
+
"post-merge": "pnpm exec vr lockfile-check --install"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
32
46
|
|
|
33
|
-
|
|
47
|
+
现在你可以:
|
|
34
48
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
4. 自动生成符合规范的 Changelog
|
|
39
|
-
5. Git 提交 (Commit) 与打标签 (Tag)
|
|
40
|
-
6. 发布至 npm
|
|
49
|
+
- 按照 [Conventional Commits](https://www.conventionalcommits.org/) 规范编写提交信息,`commit-lint` 会自动校验。
|
|
50
|
+
- 拉取或合并代码后,`lockfile-check` 会自动检测 lockfile 变化(`pnpm-lock.yaml`、`yarn.lock`、`package-lock.json`)并重新安装依赖。
|
|
51
|
+
- 运行 `pnpm release` 启动交互式发布流程。
|
|
41
52
|
|
|
42
|
-
|
|
53
|
+
## 使用
|
|
43
54
|
|
|
44
|
-
|
|
45
|
-
# 发布所有包并执行完整工作流程
|
|
46
|
-
npx vr release
|
|
55
|
+
### 功能概览
|
|
47
56
|
|
|
48
|
-
#
|
|
49
|
-
|
|
50
|
-
#
|
|
51
|
-
|
|
57
|
+
- [release](#release) - 自动完成从版本号变更到发布、打标签的标准工作流。
|
|
58
|
+
- [publish](#publish) - 单独执行 npm 发布流程,通常适用于 CI/CD 环境。
|
|
59
|
+
- [changelog](#changelog) - 根据 Git Commit 规范自动生成格式化的变更日志。
|
|
60
|
+
- [commit-lint](#commit-lint) - 校验 Git Commit Message 是否符合规范,帮助团队统一提交格式。
|
|
61
|
+
- [lockfile-check](#lockfile-check) - 检查项目 lockfile 状态并在变化时提供更新依赖机制。
|
|
52
62
|
|
|
53
|
-
|
|
54
|
-
npx vr changelog
|
|
63
|
+
---
|
|
55
64
|
|
|
56
|
-
|
|
57
|
-
npx vr changelog -f changelog.md
|
|
58
|
-
# 或
|
|
59
|
-
npx vr changelog --file changelog.md
|
|
65
|
+
### release
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
npx vr commit-lint -p .git/COMMIT_EDITMSG
|
|
67
|
+
**作用**:包版本发布的核心功能集合,集成和串联了所有的发布准备及后续操作。
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
npx vr publish
|
|
69
|
+
**使用场景**:在项目需要发布新版本且工作区变更已全部提交时使用。通过直观的命令行交互完成发布。
|
|
66
70
|
|
|
67
|
-
|
|
68
|
-
npx vr lockfile-sync-check
|
|
71
|
+
**核心流程**:
|
|
69
72
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
1. 交互式提示并确认发布版本号(自动计算 patch、minor 等升级维度)。
|
|
74
|
+
2. 执行用户自定义的 `task` 函数(例如修改文件,打包构建)。
|
|
75
|
+
3. 自动更新项目中 `package.json` 的版本号。
|
|
76
|
+
4. 生成对应该版本的 `Changelog`。
|
|
77
|
+
5. 自动完成 Git 提交动作并且打上新版本标签 (Tag)。
|
|
78
|
+
6. 自动将更新后的包发布至 npm。
|
|
73
79
|
|
|
74
|
-
|
|
80
|
+
**CMD 命令**:
|
|
75
81
|
|
|
76
|
-
|
|
82
|
+
_标志参考_:
|
|
77
83
|
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
```text
|
|
85
|
+
用法: vr release [标志...]
|
|
86
|
+
|
|
87
|
+
标志:
|
|
88
|
+
--remote string 远程仓库名称 # 默认: 'origin'
|
|
89
|
+
--skip-npm-publish 跳过 npm 发布
|
|
90
|
+
--skip-changelog 跳过生成变更日志
|
|
91
|
+
--skip-git-tag 跳过 git tag
|
|
92
|
+
--npm-tag string npm tag
|
|
93
|
+
--check-remote-version 检查远程版本
|
|
84
94
|
```
|
|
85
95
|
|
|
86
|
-
|
|
96
|
+
_使用示例_:
|
|
97
|
+
|
|
98
|
+
```shell
|
|
99
|
+
# 发布所有包并执行完整工作流程
|
|
100
|
+
pnpm exec vr release
|
|
87
101
|
|
|
88
|
-
|
|
102
|
+
# 跳过 npm 发布
|
|
103
|
+
pnpm exec vr release --skip-npm-publish
|
|
104
|
+
# 跳过生成变更日志
|
|
105
|
+
pnpm exec vr release --skip-changelog
|
|
106
|
+
# 检查远程版本,若已存在相同版本则中断执行
|
|
107
|
+
pnpm exec vr release --check-remote-version
|
|
89
108
|
|
|
109
|
+
# 指定推送 tag 的 git remote 名称(适用于配置了多个 remote 的场景,如 upstream、fork 等)
|
|
110
|
+
pnpm exec vr release --remote upstream
|
|
90
111
|
```
|
|
91
|
-
用法: vr release [标志...]
|
|
92
112
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
113
|
+
**Node 调用**:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { release } from '@varlet/release'
|
|
117
|
+
|
|
118
|
+
release({
|
|
119
|
+
remote?: string // 远程仓库名称,默认为 'origin'
|
|
120
|
+
npmTag?: string // 发布的 npm tag,如 'next'、'alpha'
|
|
121
|
+
cwd?: string // 工作目录,默认为 process.cwd()
|
|
122
|
+
skipNpmPublish?: boolean // 是否跳过 npm publish 过程
|
|
123
|
+
skipChangelog?: boolean // 是否跳过生成变更日志
|
|
124
|
+
skipGitTag?: boolean // 是否跳过构建 git tag 过程
|
|
125
|
+
checkRemoteVersion?: boolean // 是否检查远程版本,保证不发生版本冲突
|
|
126
|
+
task?(newVersion: string, oldVersion: string): Promise<void> // 发布过程中执行的自定义任务
|
|
127
|
+
})
|
|
100
128
|
```
|
|
101
129
|
|
|
102
|
-
|
|
130
|
+
_例:增加自定义处理逻辑_
|
|
103
131
|
|
|
132
|
+
```javascript
|
|
133
|
+
import { release } from '@varlet/release'
|
|
134
|
+
|
|
135
|
+
async function task(newVersion, oldVersion) {
|
|
136
|
+
// 在此处执行构建或写入文件的操作
|
|
137
|
+
await doBuild()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
release({ task })
|
|
104
141
|
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
### publish
|
|
146
|
+
|
|
147
|
+
**作用**:单独将包发布至 npm 仓库。
|
|
148
|
+
|
|
149
|
+
**使用场景**:适用于无需手动选择版本、生成 Changelog 或打 Git Tag 的场景,常用于在 CI/CD 流水线中针对特定过程触发自动化发布。
|
|
150
|
+
|
|
151
|
+
**核心流程**:读取当前 package.json 中的版本号,运行对应的 publish 流程。
|
|
152
|
+
|
|
153
|
+
**CMD 命令**:
|
|
154
|
+
|
|
155
|
+
_标志参考_:
|
|
156
|
+
|
|
157
|
+
```text
|
|
105
158
|
用法: vr publish [标志...]
|
|
106
159
|
|
|
107
160
|
标志:
|
|
108
|
-
|
|
109
|
-
|
|
161
|
+
--check-remote-version 检查远程版本
|
|
162
|
+
--npm-tag string npm tag
|
|
110
163
|
```
|
|
111
164
|
|
|
112
|
-
|
|
165
|
+
_使用示例_:
|
|
113
166
|
|
|
167
|
+
```shell
|
|
168
|
+
# 直接发布到 npm
|
|
169
|
+
pnpm exec vr publish
|
|
170
|
+
|
|
171
|
+
# 检查由于网络等原因是否已存在相同版本,存在则放弃发布
|
|
172
|
+
pnpm exec vr publish --check-remote-version
|
|
173
|
+
# 指定 npm 的 dist-tag
|
|
174
|
+
pnpm exec vr publish --npm-tag alpha
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Node 调用**:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { publish } from '@varlet/release'
|
|
181
|
+
|
|
182
|
+
publish({
|
|
183
|
+
preRelease?: boolean // 预发布标示,将添加 '--tag alpha' 选项
|
|
184
|
+
checkRemoteVersion?: boolean // 发布前检查远程 npm 上是否已存在相同版本
|
|
185
|
+
npmTag?: string // 发布的 npm tag
|
|
186
|
+
cwd?: string // 工作目录,默认为 process.cwd()
|
|
187
|
+
})
|
|
114
188
|
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
### changelog
|
|
193
|
+
|
|
194
|
+
**作用**:基于规范的 Commit 历史自动生成 Markdown 格式的变更日志。
|
|
195
|
+
|
|
196
|
+
**使用场景**:单独更新 `CHANGELOG.md` 记录,单点生成所需日志。
|
|
197
|
+
|
|
198
|
+
**核心流程**:遍历 Git 提交历史,依据预设的 conventional commit 规则分类(如 feat、fix 等),格式化输出。
|
|
199
|
+
|
|
200
|
+
**CMD 命令**:
|
|
201
|
+
|
|
202
|
+
_标志参考_:
|
|
203
|
+
|
|
204
|
+
```text
|
|
115
205
|
用法: vr changelog [标志...]
|
|
116
206
|
|
|
117
207
|
标志:
|
|
118
|
-
|
|
119
|
-
|
|
208
|
+
--release-count number 发布数量 # 默认: 0
|
|
209
|
+
--file string 变更日志文件名 # 默认: 'CHANGELOG.md'
|
|
120
210
|
```
|
|
121
211
|
|
|
122
|
-
|
|
212
|
+
_使用示例_:
|
|
213
|
+
|
|
214
|
+
```shell
|
|
215
|
+
# 生成所有历史的变更日志并在当前目录输出为 CHANGELOG.md
|
|
216
|
+
pnpm exec vr changelog
|
|
123
217
|
|
|
218
|
+
# 指定生成的变更日志文件名
|
|
219
|
+
pnpm exec vr changelog --file my-changelog.md
|
|
220
|
+
# 限定发布版本的范围数量以生成变更日志 (0 为全量)
|
|
221
|
+
pnpm exec vr changelog --release-count 0
|
|
124
222
|
```
|
|
125
|
-
|
|
223
|
+
|
|
224
|
+
**Node 调用**:
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
import { changelog } from '@varlet/release'
|
|
228
|
+
|
|
229
|
+
changelog({
|
|
230
|
+
cwd?: string // 工作目录,默认为 process.cwd()
|
|
231
|
+
releaseCount?: number // 输出日志涉及的最近发布的版本数量,默认为 0(全部)
|
|
232
|
+
file?: string // 输出的日志文件名,默认为 'CHANGELOG.md'
|
|
233
|
+
showTypes?: string[] // 显示的 commit 类型,默认 ['feat', 'fix', 'perf', 'revert', 'refactor']
|
|
234
|
+
outputUnreleased?: boolean // 是否输出 unreleased 版本变更
|
|
235
|
+
writerOpt?: object // conventional-changelog-writer 具体配置参数
|
|
236
|
+
})
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
### commit-lint
|
|
242
|
+
|
|
243
|
+
**作用**:校验 Git 提交信息格式。
|
|
244
|
+
|
|
245
|
+
**使用场景**:结合 `git hooks` 一同工作,强制保障书写高质量的提交说明以保证 Changelog 质量。
|
|
246
|
+
|
|
247
|
+
**核心流程**:读取提交文件,若是符合配置的正则格式则通过处理,否则打印具体的失败信息报错,并终止提交。
|
|
248
|
+
|
|
249
|
+
**CMD 命令**:
|
|
250
|
+
|
|
251
|
+
_参数参考_:
|
|
252
|
+
|
|
253
|
+
```text
|
|
254
|
+
用法: vr commit-lint <commit-message-path> [标志...]
|
|
255
|
+
|
|
256
|
+
参数:
|
|
257
|
+
<commit-message-path> Git commit message 路径(必填)
|
|
126
258
|
|
|
127
259
|
标志:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
-w, --warning-message <string> 验证失败时显示的警告信息
|
|
260
|
+
--commit-message-re string 验证 commit message 是否通过的正则表达式
|
|
261
|
+
--error-message string 验证失败时显示的错误信息
|
|
262
|
+
--warning-message string 验证失败时显示的警告信息
|
|
132
263
|
```
|
|
133
264
|
|
|
134
|
-
|
|
265
|
+
_使用示例_:
|
|
266
|
+
|
|
267
|
+
```shell
|
|
268
|
+
# 检测指路径的 commit message 是否符合规范
|
|
269
|
+
pnpm exec vr commit-lint .git/COMMIT_EDITMSG
|
|
135
270
|
|
|
271
|
+
# 定制指定的校验正则表达式和提示信息
|
|
272
|
+
pnpm exec vr commit-lint .git/COMMIT_EDITMSG --commit-message-re "^feat: .*" --error-message "提交校验失败"
|
|
136
273
|
```
|
|
137
|
-
用法: vr lockfile-sync-check [标志...]
|
|
138
274
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
275
|
+
_建议配合并在 `package.json` 中的 `simple-git-hooks` 或 `husky` 一同集成运作:_
|
|
276
|
+
|
|
277
|
+
```json
|
|
278
|
+
{
|
|
279
|
+
"simple-git-hooks": {
|
|
280
|
+
"commit-msg": "pnpm exec vr commit-lint $1"
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
**Node 调用**:
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
import { commitLint } from '@varlet/release'
|
|
289
|
+
|
|
290
|
+
commitLint({
|
|
291
|
+
commitMessagePath: string // 必选:Git commit message 文件路径
|
|
292
|
+
commitMessageRe?: string | RegExp // 验证 msg 格式的正则表达式
|
|
293
|
+
errorMessage?: string // 验证失败时打印的提示文本
|
|
294
|
+
warningMessage?: string // 验证失败时打印的补充警告文档链接
|
|
295
|
+
})
|
|
142
296
|
```
|
|
143
297
|
|
|
144
|
-
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
### lockfile-check
|
|
145
301
|
|
|
146
|
-
|
|
302
|
+
**作用**:检测并在控制台直观地输出前端依赖包的 lockfile 文件是否发生变更,并默认自动安装依赖以保持同步。
|
|
147
303
|
|
|
148
|
-
|
|
304
|
+
**使用场景**:通常在进行 `git 操作` (如 `git pull`拉取最新代码、`git checkout`切换分支、或合并代码) 之后使用。它能帮助你检测上游的依赖锁文件(如 `pnpm-lock.yaml`)是否发生了变动。如果检测到有变更,默认会自动执行 install 安装命令,从而确保本地环境快速与上游依赖保持一致,避免因依赖版本陈旧导致的疑难 bug。
|
|
149
305
|
|
|
150
|
-
|
|
151
|
-
import { changelog, release } from '@varlet/release'
|
|
306
|
+
**核心流程**:比对项目原始游标的锁文件(如 pnpm-lock.yaml 或对应环境的 lockfile)的 Git diff,在控制台输出其是否存在变动;默认会触发包管理器的依赖重装程序以同步上游,也可以通过指令跳过安装。
|
|
152
307
|
|
|
153
|
-
|
|
154
|
-
|
|
308
|
+
**CMD 命令**:
|
|
309
|
+
|
|
310
|
+
_标志参考_:
|
|
311
|
+
|
|
312
|
+
```text
|
|
313
|
+
用法: vr lockfile-check [标志...]
|
|
314
|
+
|
|
315
|
+
标志:
|
|
316
|
+
--package-manager string 包管理器 (npm, yarn, pnpm) # 默认: 'pnpm'
|
|
317
|
+
--skip-install 当 lockfile 发生变化时跳过安装依赖
|
|
155
318
|
```
|
|
156
319
|
|
|
157
|
-
|
|
320
|
+
_使用示例_:
|
|
158
321
|
|
|
159
|
-
```
|
|
160
|
-
|
|
322
|
+
```shell
|
|
323
|
+
# 检查当前 lockfile 的同步状态,若有变化则自动安装依赖
|
|
324
|
+
pnpm exec vr lockfile-check
|
|
161
325
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
326
|
+
# 检查当前状态,即使有更新也跳过安装
|
|
327
|
+
pnpm exec vr lockfile-check --skip-install
|
|
328
|
+
|
|
329
|
+
# 指定其他包管理器进行检查
|
|
330
|
+
pnpm exec vr lockfile-check --package-manager npm
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
_建议配合并在 `package.json` 中的 `simple-git-hooks` 或 `husky` 一同集成运作(例如在拉取代码的 `post-merge` 或 `post-checkout` 阶段自动触发检查与安装):_
|
|
334
|
+
|
|
335
|
+
```json
|
|
336
|
+
{
|
|
337
|
+
"simple-git-hooks": {
|
|
338
|
+
"post-merge": "pnpm exec vr lockfile-check"
|
|
339
|
+
}
|
|
165
340
|
}
|
|
341
|
+
```
|
|
166
342
|
|
|
167
|
-
|
|
343
|
+
**Node 调用**:
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
import { lockfileCheck } from '@varlet/release'
|
|
347
|
+
|
|
348
|
+
lockfileCheck({
|
|
349
|
+
packageManager?: 'npm' | 'yarn' | 'pnpm' // 选择包管理器,默认为 'pnpm'
|
|
350
|
+
skipInstall?: boolean // 检测到 lock 不同步时是否跳过安装
|
|
351
|
+
})
|
|
168
352
|
```
|
|
169
353
|
|
|
170
354
|
## 许可证
|
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { c as release, i as lockfileCheck, p as commitLint, s as publish, u as changelog } from "./src-
|
|
2
|
+
import { c as release, i as lockfileCheck, p as commitLint, s as publish, u as changelog } from "./src-JMmGEAWu.js";
|
|
3
3
|
import { cli, command } from "cleye";
|
|
4
4
|
//#endregion
|
|
5
5
|
//#region src/cli.ts
|
|
6
6
|
cli({
|
|
7
7
|
name: "vr",
|
|
8
|
-
version: "2.
|
|
8
|
+
version: "2.2.0",
|
|
9
9
|
commands: [
|
|
10
10
|
command({
|
|
11
11
|
name: "release",
|
|
@@ -76,13 +76,8 @@ cli({
|
|
|
76
76
|
}, (argv) => changelog(argv.flags)),
|
|
77
77
|
command({
|
|
78
78
|
name: "commit-lint",
|
|
79
|
+
parameters: ["<commitMessagePath>"],
|
|
79
80
|
flags: {
|
|
80
|
-
commitMessagePath: {
|
|
81
|
-
type: String,
|
|
82
|
-
alias: "p",
|
|
83
|
-
default: "",
|
|
84
|
-
description: "Git commit message path"
|
|
85
|
-
},
|
|
86
81
|
commitMessageRe: {
|
|
87
82
|
type: String,
|
|
88
83
|
alias: "r",
|
|
@@ -100,7 +95,12 @@ cli({
|
|
|
100
95
|
}
|
|
101
96
|
},
|
|
102
97
|
help: { description: "Lint commit message" }
|
|
103
|
-
}, (argv) => commitLint(
|
|
98
|
+
}, (argv) => commitLint({
|
|
99
|
+
commitMessagePath: argv._.commitMessagePath,
|
|
100
|
+
commitMessageRe: argv.flags.commitMessageRe,
|
|
101
|
+
errorMessage: argv.flags.errorMessage,
|
|
102
|
+
warningMessage: argv.flags.warningMessage
|
|
103
|
+
})),
|
|
104
104
|
command({
|
|
105
105
|
name: "lockfile-check",
|
|
106
106
|
flags: {
|
|
@@ -110,10 +110,10 @@ cli({
|
|
|
110
110
|
default: "pnpm",
|
|
111
111
|
description: "Package manager (npm, yarn, pnpm), default pnpm"
|
|
112
112
|
},
|
|
113
|
-
|
|
113
|
+
skipInstall: {
|
|
114
114
|
type: Boolean,
|
|
115
|
-
alias: "
|
|
116
|
-
description: "
|
|
115
|
+
alias: "s",
|
|
116
|
+
description: "Skip install dependencies when lockfile changed"
|
|
117
117
|
}
|
|
118
118
|
},
|
|
119
119
|
help: { description: "Check if lockfile has been updated and optionally install dependencies" }
|
package/dist/index.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ declare function commitLint(options: CommitLintCommandOptions): void;
|
|
|
84
84
|
type PackageManager = "npm" | "yarn" | "pnpm";
|
|
85
85
|
interface LockfileCheckOptions {
|
|
86
86
|
packageManager?: PackageManager;
|
|
87
|
-
|
|
87
|
+
skipInstall?: boolean;
|
|
88
88
|
}
|
|
89
89
|
declare function getLockfilePath(packageManager: PackageManager): string;
|
|
90
90
|
declare function checkLockfileSync(packageManager: PackageManager): Promise<boolean>;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as getPackageJsons, c as release, d as COMMIT_HEADER_RE, f as COMMIT_MESSAGE_RE, h as isVersionCommitMessage, i as lockfileCheck, l as updateVersion, m as getCommitMessage, n as getLockfilePath, o as isSameVersion, p as commitLint, r as installDependencies, s as publish, t as checkLockfileSync, u as changelog } from "./src-
|
|
1
|
+
import { a as getPackageJsons, c as release, d as COMMIT_HEADER_RE, f as COMMIT_MESSAGE_RE, h as isVersionCommitMessage, i as lockfileCheck, l as updateVersion, m as getCommitMessage, n as getLockfilePath, o as isSameVersion, p as commitLint, r as installDependencies, s as publish, t as checkLockfileSync, u as changelog } from "./src-JMmGEAWu.js";
|
|
2
2
|
export { COMMIT_HEADER_RE, COMMIT_MESSAGE_RE, changelog, checkLockfileSync, commitLint, getCommitMessage, getLockfilePath, getPackageJsons, installDependencies, isSameVersion, isVersionCommitMessage, lockfileCheck, publish, release, updateVersion };
|
|
@@ -39,9 +39,7 @@ Allowed types:
|
|
|
39
39
|
- revert
|
|
40
40
|
- merge
|
|
41
41
|
- wip
|
|
42
|
-
|
|
43
|
-
Commit message reference: https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y
|
|
44
|
-
参考阮一峰Commit message编写指南: https://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html`;
|
|
42
|
+
`;
|
|
45
43
|
function isVersionCommitMessage(message) {
|
|
46
44
|
return Boolean(message.startsWith("v") && semver.valid(message.slice(1)));
|
|
47
45
|
}
|
|
@@ -353,10 +351,10 @@ function computeExpectVersion(currentVersion, type) {
|
|
|
353
351
|
}
|
|
354
352
|
async function getReleaseType(currentVersion) {
|
|
355
353
|
return unwrapPromptResult(await select({
|
|
356
|
-
message:
|
|
354
|
+
message: `Please select release type, current version ${currentVersion}`,
|
|
357
355
|
options: RELEASE_TYPES.map((type) => {
|
|
358
356
|
return {
|
|
359
|
-
label: `${type} (${
|
|
357
|
+
label: `${type} (${computeExpectVersion(currentVersion, type)})`,
|
|
360
358
|
value: type
|
|
361
359
|
};
|
|
362
360
|
})
|
|
@@ -460,10 +458,18 @@ async function installDependencies(packageManager) {
|
|
|
460
458
|
async function lockfileCheck(options = {}) {
|
|
461
459
|
try {
|
|
462
460
|
const pkgManager = options.packageManager || "pnpm";
|
|
463
|
-
const
|
|
461
|
+
const skipInstallFlag = options.skipInstall || false;
|
|
462
|
+
if (![
|
|
463
|
+
"npm",
|
|
464
|
+
"yarn",
|
|
465
|
+
"pnpm"
|
|
466
|
+
].includes(pkgManager)) {
|
|
467
|
+
logger.error(`Unsupported package manager: ${pkgManager}`);
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
464
470
|
if (await checkLockfileSync(pkgManager)) {
|
|
465
471
|
logger.warn("Lockfile has been updated!");
|
|
466
|
-
if (
|
|
472
|
+
if (!skipInstallFlag) await installDependencies(pkgManager);
|
|
467
473
|
}
|
|
468
474
|
} catch (error) {
|
|
469
475
|
logger.error("Error checking lockfile sync:", error);
|