commit-and-tag-version 9.5.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.
Files changed (43) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintrc +6 -0
  3. package/.github/ISSUE_TEMPLATE/ask-a-question.md +7 -0
  4. package/.github/ISSUE_TEMPLATE/bug-report.md +29 -0
  5. package/.github/workflows/ci.yaml +33 -0
  6. package/.github/workflows/release-please.yml +31 -0
  7. package/.versionrc +10 -0
  8. package/CHANGELOG.md +524 -0
  9. package/LICENSE.txt +16 -0
  10. package/README.md +480 -0
  11. package/bin/cli.js +14 -0
  12. package/command.js +145 -0
  13. package/defaults.js +40 -0
  14. package/index.js +92 -0
  15. package/lib/checkpoint.js +12 -0
  16. package/lib/configuration.js +41 -0
  17. package/lib/format-commit-message.js +4 -0
  18. package/lib/latest-semver-tag.js +17 -0
  19. package/lib/lifecycles/bump.js +172 -0
  20. package/lib/lifecycles/changelog.js +66 -0
  21. package/lib/lifecycles/commit.js +69 -0
  22. package/lib/lifecycles/tag.js +39 -0
  23. package/lib/preset-loader.js +17 -0
  24. package/lib/print-error.js +12 -0
  25. package/lib/run-exec.js +18 -0
  26. package/lib/run-execFile.js +18 -0
  27. package/lib/run-lifecycle-script.js +13 -0
  28. package/lib/updaters/index.js +85 -0
  29. package/lib/updaters/types/json.js +25 -0
  30. package/lib/updaters/types/plain-text.js +7 -0
  31. package/lib/write-file.js +6 -0
  32. package/package.json +69 -0
  33. package/renovate.json +9 -0
  34. package/test/config-files.spec.js +179 -0
  35. package/test/core.spec.js +850 -0
  36. package/test/git.spec.js +468 -0
  37. package/test/mocks/VERSION-1.0.0.txt +1 -0
  38. package/test/mocks/VERSION-6.3.1.txt +1 -0
  39. package/test/mocks/manifest-6.3.1.json +3 -0
  40. package/test/mocks/mix.exs +28 -0
  41. package/test/mocks/updater/customer-updater.js +12 -0
  42. package/test/mocks/version.txt +0 -0
  43. package/test/preset.spec.js +52 -0
package/README.md ADDED
@@ -0,0 +1,480 @@
1
+ # Standard Version
2
+
3
+ > **`commit-and-tag-version` is a fork of `standard-version`**. Because of maintainer availability, `standard-version` was [deprecated on 15th May 2022](https://github.com/conventional-changelog/standard-version/pull/907). The previous maintainer recommends [release-please](https://github.com/googleapis/release-please) as an alternative for those who are using GitHub actions. This fork exists for those who can't switch to `release-please`, or who would like to continue using `standard-version`.
4
+
5
+ > **`Why was it renamed commit-and-tag-version?`**. I wanted to make the purpose of the tool clearer, and to distinguish it from my other tool, [`absolute-version`](https://github.com/absolute-version/absolute-version-js), which just prints version information for pre-releases. To migrate, you can drop in `commit-and-tag-version` in place of `standard-version`. There are no changes in 9.5.0, other than to add the package.json config key `commit-and-tag-version` (the previous configuration key `standard-version` will still work).
6
+
7
+
8
+ A utility for versioning using [semver](https://semver.org/) and CHANGELOG generation powered by [Conventional Commits](https://conventionalcommits.org).
9
+
10
+ ![ci](https://github.com/absolute-version/commit-and-tag-version/workflows/ci/badge.svg)
11
+ [![NPM version](https://img.shields.io/npm/v/commit-and-tag-version.svg)](https://www.npmjs.com/package/commit-and-tag-version)
12
+ [![codecov](https://codecov.io/gh/absolute-version/commit-and-tag-version/branch/master/graph/badge.svg?token=J7zMN7vTTd)](https://codecov.io/gh/absolute-version/commit-and-tag-version)
13
+ [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
14
+ [![Community slack](http://devtoolscommunity.herokuapp.com/badge.svg)](http://devtoolscommunity.herokuapp.com)
15
+
16
+ _Having problems? Want to contribute? Join us on the [node-tooling community Slack](http://devtoolscommunity.herokuapp.com)_.
17
+
18
+ _How It Works:_
19
+
20
+ 1. Follow the [Conventional Commits Specification](https://conventionalcommits.org) in your repository.
21
+ 2. When you're ready to release, run `commit-and-tag-version`.
22
+
23
+ `commit-and-tag-version` will then do the following:
24
+
25
+ 1. Retrieve the current version of your repository by looking at `packageFiles`[[1]](#bumpfiles-packagefiles-and-updaters), falling back to the last `git tag`.
26
+ 2. `bump` the version in `bumpFiles`[[1]](#bumpfiles-packagefiles-and-updaters) based on your commits.
27
+ 3. Generates a `changelog` based on your commits (uses [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) under the hood).
28
+ 4. Creates a new `commit` including your `bumpFiles`[[1]](#bumpfiles-packagefiles-and-updaters) and updated CHANGELOG.
29
+ 5. Creates a new `tag` with the new version number.
30
+
31
+ ### `bumpFiles`, `packageFiles` and `updaters`
32
+
33
+ `commit-and-tag-version` uses a few key concepts for handling version bumping in your project.
34
+
35
+ - **`packageFiles`** – User-defined files where versions can be read from _and_ be "bumped".
36
+ - Examples: `package.json`, `manifest.json`
37
+ - In most cases (including the default), `packageFiles` are a subset of `bumpFiles`.
38
+ - **`bumpFiles`** – User-defined files where versions should be "bumped", but not explicitly read from.
39
+ - Examples: `package-lock.json`, `npm-shrinkwrap.json`
40
+ - **`updaters`** – Simple modules used for reading `packageFiles` and writing to `bumpFiles`.
41
+
42
+ By default, `commit-and-tag-version` assumes you're working in a NodeJS based project... because of this, for the majority of projects you might never need to interact with these options.
43
+
44
+ That said, if you find your self asking [How can I use commit-and-tag-version for additional metadata files, languages or version files?](#can-i-use-commit-and-tag-version-for-additional-metadata-files-languages-or-version-files) – these configuration options will help!
45
+
46
+ ## Installing `commit-and-tag-version`
47
+
48
+ ### As a local `npm run` script
49
+
50
+ Install and add to `devDependencies`:
51
+
52
+ ```
53
+ npm i --save-dev commit-and-tag-version
54
+ ```
55
+
56
+ Add an [`npm run` script](https://docs.npmjs.com/cli/run-script) to your `package.json`:
57
+
58
+ ```json
59
+ {
60
+ "scripts": {
61
+ "release": "commit-and-tag-version"
62
+ }
63
+ }
64
+ ```
65
+
66
+ Now you can use `npm run release` in place of `npm version`.
67
+
68
+ This has the benefit of making your repo/package more portable, so that other developers can cut releases without having to globally install `commit-and-tag-version` on their machine.
69
+
70
+ ### As global `bin`
71
+
72
+ Install globally (add to your `PATH`):
73
+
74
+ ```
75
+ npm i -g commit-and-tag-version
76
+ ```
77
+
78
+ Now you can use `commit-and-tag-version` in place of `npm version`.
79
+
80
+ This has the benefit of allowing you to use `commit-and-tag-version` on any repo/package without adding a dev dependency to each one.
81
+
82
+ ### Using `npx`
83
+
84
+ As of `npm@5.2.0`, `npx` is installed alongside `npm`. Using `npx` you can use `commit-and-tag-version` without having to keep a `package.json` file by running: `npx commit-and-tag-version`.
85
+
86
+ This method is especially useful when using `commit-and-tag-version` in non-JavaScript projects.
87
+
88
+ ## Configuration
89
+
90
+ You can configure `commit-and-tag-version` either by:
91
+
92
+ 1. Placing a `commit-and-tag-version` stanza in your `package.json` (assuming
93
+ your project is JavaScript).
94
+
95
+ > Note for users who have migrated to
96
+ `commit-and-tag-version` from `standard-version`: the previous package.json configuration key of `standard-version` will still work.
97
+
98
+ 2. Creating a `.versionrc`, `.versionrc.json` or `.versionrc.js`.
99
+
100
+ - If you are using a `.versionrc.js` your default export must be a configuration object, or a function returning a configuration object.
101
+
102
+
103
+
104
+ Any of the command line parameters accepted by `commit-and-tag-version` can instead
105
+ be provided via configuration. Please refer to the [conventional-changelog-config-spec](https://github.com/conventional-changelog/conventional-changelog-config-spec/) for details on available configuration options.
106
+
107
+ ### Customizing CHANGELOG Generation
108
+
109
+ By default (as of `6.0.0`), `commit-and-tag-version` uses the [conventionalcommits preset](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits).
110
+
111
+ This preset:
112
+
113
+ - Adheres closely to the [conventionalcommits.org](https://www.conventionalcommits.org)
114
+ specification.
115
+ - Is highly configurable, following the configuration specification
116
+ [maintained here](https://github.com/conventional-changelog/conventional-changelog-config-spec).
117
+ - _We've documented these config settings as a recommendation to other tooling makers._
118
+
119
+ There are a variety of dials and knobs you can turn related to CHANGELOG generation.
120
+
121
+ As an example, suppose you're using GitLab, rather than GitHub, you might modify the following variables:
122
+
123
+ - `commitUrlFormat`: the URL format of commit SHAs detected in commit messages.
124
+ - `compareUrlFormat`: the URL format used to compare two tags.
125
+ - `issueUrlFormat`: the URL format used to link to issues.
126
+
127
+ Making these URLs match GitLab's format, rather than GitHub's.
128
+
129
+ ## CLI Usage
130
+
131
+ > **NOTE:** To pass nested configurations to the CLI without defining them in the `package.json` use dot notation as the parameters `e.g. --skip.changelog`.
132
+
133
+ ### First Release
134
+
135
+ To generate your changelog for your first release, simply do:
136
+
137
+ ```sh
138
+ # npm run script
139
+ npm run release -- --first-release
140
+ # global bin
141
+ commit-and-tag-version --first-release
142
+ # npx
143
+ npx commit-and-tag-version --first-release
144
+ ```
145
+
146
+ This will tag a release **without bumping the version `bumpFiles`[1]()**.
147
+
148
+ When you are ready, push the git tag and `npm publish` your first release. \o/
149
+
150
+ ### Cutting Releases
151
+
152
+ If you typically use `npm version` to cut a new release, do this instead:
153
+
154
+ ```sh
155
+ # npm run script
156
+ npm run release
157
+ # or global bin
158
+ commit-and-tag-version
159
+ ```
160
+
161
+ As long as your git commit messages are conventional and accurate, you no longer need to specify the semver type - and you get CHANGELOG generation for free! \o/
162
+
163
+ After you cut a release, you can push the new git tag and `npm publish` (or `npm publish --tag next`) when you're ready.
164
+
165
+ ### Release as a Pre-Release
166
+
167
+ Use the flag `--prerelease` to generate pre-releases:
168
+
169
+ Suppose the last version of your code is `1.0.0`, and your code to be committed has patched changes. Run:
170
+
171
+ ```bash
172
+ # npm run script
173
+ npm run release -- --prerelease
174
+ ```
175
+
176
+ This will tag your version as: `1.0.1-0`.
177
+
178
+ If you want to name the pre-release, you specify the name via `--prerelease <name>`.
179
+
180
+ For example, suppose your pre-release should contain the `alpha` prefix:
181
+
182
+ ```bash
183
+ # npm run script
184
+ npm run release -- --prerelease alpha
185
+ ```
186
+
187
+ This will tag the version as: `1.0.1-alpha.0`
188
+
189
+ ### Release as a Target Type Imperatively (`npm version`-like)
190
+
191
+ To forgo the automated version bump use `--release-as` with the argument `major`, `minor` or `patch`.
192
+
193
+ Suppose the last version of your code is `1.0.0`, you've only landed `fix:` commits, but
194
+ you would like your next release to be a `minor`. Simply run the following:
195
+
196
+ ```bash
197
+ # npm run script
198
+ npm run release -- --release-as minor
199
+ # Or
200
+ npm run release -- --release-as 1.1.0
201
+ ```
202
+
203
+ You will get version `1.1.0` rather than what would be the auto-generated version `1.0.1`.
204
+
205
+ > **NOTE:** you can combine `--release-as` and `--prerelease` to generate a release. This is useful when publishing experimental feature(s).
206
+
207
+ ### Prevent Git Hooks
208
+
209
+ If you use git hooks, like pre-commit, to test your code before committing, you can prevent hooks from being verified during the commit step by passing the `--no-verify` option:
210
+
211
+ ```sh
212
+ # npm run script
213
+ npm run release -- --no-verify
214
+ # or global bin
215
+ commit-and-tag-version --no-verify
216
+ ```
217
+
218
+ ### Signing Commits and Tags
219
+
220
+ If you have your GPG key set up, add the `--sign` or `-s` flag to your `commit-and-tag-version` command.
221
+
222
+ ### Lifecycle Scripts
223
+
224
+ `commit-and-tag-version` supports lifecycle scripts. These allow you to execute your
225
+ own supplementary commands during the release. The following
226
+ hooks are available and execute in the order documented:
227
+
228
+ - `prerelease`: executed before anything happens. If the `prerelease` script returns a
229
+ non-zero exit code, versioning will be aborted, but it has no other effect on the
230
+ process.
231
+ - `prebump`/`postbump`: executed before and after the version is bumped. If the `prebump`
232
+ script returns a version #, it will be used rather than
233
+ the version calculated by `commit-and-tag-version`.
234
+ - `prechangelog`/`postchangelog`: executes before and after the CHANGELOG is generated.
235
+ - `precommit`/`postcommit`: called before and after the commit step.
236
+ - `pretag`/`posttag`: called before and after the tagging step.
237
+
238
+ Simply add the following to your package.json to configure lifecycle scripts:
239
+
240
+ ```json
241
+ {
242
+ "commit-and-tag-version": {
243
+ "scripts": {
244
+ "prebump": "echo 9.9.9"
245
+ }
246
+ }
247
+ }
248
+ ```
249
+
250
+ As an example to change from using GitHub to track your items to using your projects Jira use a
251
+ `postchangelog` script to replace the url fragment containing 'https://github.com/`myproject`/issues/'
252
+ with a link to your Jira - assuming you have already installed [replace](https://www.npmjs.com/package/replace)
253
+
254
+ ```json
255
+ {
256
+ "commit-and-tag-version": {
257
+ "scripts": {
258
+ "postchangelog": "replace 'https://github.com/myproject/issues/' 'https://myjira/browse/' CHANGELOG.md"
259
+ }
260
+ }
261
+ }
262
+ ```
263
+
264
+ ### Skipping Lifecycle Steps
265
+
266
+ You can skip any of the lifecycle steps (`bump`, `changelog`, `commit`, `tag`),
267
+ by adding the following to your package.json:
268
+
269
+ ```json
270
+ {
271
+ "commit-and-tag-version": {
272
+ "skip": {
273
+ "changelog": true
274
+ }
275
+ }
276
+ }
277
+ ```
278
+
279
+ ### Committing Generated Artifacts in the Release Commit
280
+
281
+ If you want to commit generated artifacts in the release commit, you can use the `--commit-all` or `-a` flag. You will need to stage the artifacts you want to commit, so your `release` command could look like this:
282
+
283
+ ```json
284
+ {
285
+ "commit-and-tag-version": {
286
+ "scripts": {
287
+ "prerelease": "webpack -p --bail && git add <file(s) to commit>"
288
+ }
289
+ }
290
+ }
291
+ ```
292
+
293
+ ```json
294
+ {
295
+ "scripts": {
296
+ "release": "commit-and-tag-version -a"
297
+ }
298
+ }
299
+ ```
300
+
301
+ ### Dry Run Mode
302
+
303
+ running `commit-and-tag-version` with the flag `--dry-run` allows you to see what
304
+ commands would be run, without committing to git or updating files.
305
+
306
+ ```sh
307
+ # npm run script
308
+ npm run release -- --dry-run
309
+ # or global bin
310
+ commit-and-tag-version --dry-run
311
+ ```
312
+
313
+ ### Prefix Tags
314
+
315
+ Tags are prefixed with `v` by default. If you would like to prefix your tags with something else, you can do so with the `-t` flag.
316
+
317
+ ```sh
318
+ commit-and-tag-version -t @scope/package\@
319
+ ```
320
+
321
+ This will prefix your tags to look something like `@scope/package@2.0.0`
322
+
323
+ If you do not want to have any tag prefix you can use the `-t` flag and provide it with an **empty string** as value.
324
+
325
+ > Note: simply -t or --tag-prefix without any value will fallback to the default 'v'
326
+
327
+ ### CLI Help
328
+
329
+ ```sh
330
+ # npm run script
331
+ npm run release -- --help
332
+ # or global bin
333
+ commit-and-tag-version --help
334
+ ```
335
+
336
+ ## Code Usage
337
+
338
+ ```js
339
+ const standardVersion = require("commit-and-tag-version");
340
+
341
+ // Options are the same as command line, except camelCase
342
+ // standardVersion returns a Promise
343
+ standardVersion({
344
+ noVerify: true,
345
+ infile: "docs/CHANGELOG.md",
346
+ silent: true,
347
+ })
348
+ .then(() => {
349
+ // commit-and-tag-version is done
350
+ })
351
+ .catch((err) => {
352
+ console.error(`commit-and-tag-version failed with message: ${err.message}`);
353
+ });
354
+ ```
355
+
356
+ _TIP: Use the `silent` option to prevent `commit-and-tag-version` from printing to the `console`._
357
+
358
+ ## FAQ
359
+
360
+ ### How is `commit-and-tag-version` different from `semantic-release`?
361
+
362
+ [`semantic-release`](https://github.com/semantic-release/semantic-release) is described as:
363
+
364
+ > semantic-release automates the whole package release workflow including: determining the next version number, generating the release notes and publishing the package.
365
+
366
+ While both are based on the same foundation of structured commit messages, `commit-and-tag-version` takes a different approach by handling versioning, changelog generation, and git tagging for you **without** automatic pushing (to GitHub) or publishing (to an npm registry). Use of `commit-and-tag-version` only affects your local git repo - it doesn't affect remote resources at all. After you run `commit-and-tag-version`, you can review your release state, correct mistakes and follow the release strategy that makes the most sense for your codebase.
367
+
368
+ We think they are both fantastic tools, and we encourage folks to use `semantic-release` instead of `commit-and-tag-version` if it makes sense for their use-case.
369
+
370
+ ### Should I always squash commits when merging PRs?
371
+
372
+ The instructions to squash commits when merging pull requests assumes that **one PR equals, at most, one feature or fix**.
373
+
374
+ If you have multiple features or fixes landing in a single PR and each commit uses a structured message, then you can do a standard merge when accepting the PR. This will preserve the commit history from your branch after the merge.
375
+
376
+ Although this will allow each commit to be included as separate entries in your CHANGELOG, the entries will **not** be able to reference the PR that pulled the changes in because the preserved commit messages do not include the PR number.
377
+
378
+ For this reason, we recommend keeping the scope of each PR to one general feature or fix. In practice, this allows you to use unstructured commit messages when committing each little change and then squash them into a single commit with a structured message (referencing the PR number) once they have been reviewed and accepted.
379
+
380
+ ### Can I use `commit-and-tag-version` for additional metadata files, languages or version files?
381
+
382
+ As of version `7.1.0` you can configure multiple `bumpFiles` and `packageFiles`.
383
+
384
+ 1. Specify a custom `bumpFile` "`filename`", this is the path to the file you want to "bump"
385
+ 2. Specify the `bumpFile` "`updater`", this is _how_ the file will be bumped.
386
+ a. If you're using a common type, you can use one of `commit-and-tag-version`'s built-in `updaters` by specifying a `type`.
387
+ b. If your using an less-common version file, you can create your own `updater`.
388
+
389
+ ```js
390
+ // .versionrc
391
+ {
392
+ "bumpFiles": [
393
+ {
394
+ "filename": "MY_VERSION_TRACKER.txt",
395
+ // The `plain-text` updater assumes the file contents represents the version.
396
+ "type": "plain-text"
397
+ },
398
+ {
399
+ "filename": "a/deep/package/dot/json/file/package.json",
400
+ // The `json` updater assumes the version is available under a `version` key in the provided JSON document.
401
+ "type": "json"
402
+ },
403
+ {
404
+ "filename": "VERSION_TRACKER.json",
405
+ // See "Custom `updater`s" for more details.
406
+ "updater": "commit-and-tag-version-updater.js"
407
+ }
408
+ ]
409
+ }
410
+ ```
411
+
412
+ If using `.versionrc.js` as your configuration file, the `updater` may also be set as an object, rather than a path:
413
+
414
+ ```js
415
+ // .versionrc.js
416
+ const tracker = {
417
+ filename: "VERSION_TRACKER.json",
418
+ updater: require("./path/to/custom-version-updater"),
419
+ };
420
+
421
+ module.exports = {
422
+ bumpFiles: [tracker],
423
+ packageFiles: [tracker],
424
+ };
425
+ ```
426
+
427
+ #### Custom `updater`s
428
+
429
+ An `updater` is expected to be a Javascript module with _atleast_ two methods exposed: `readVersion` and `writeVersion`.
430
+
431
+ ##### `readVersion(contents = string): string`
432
+
433
+ This method is used to read the version from the provided file contents.
434
+
435
+ The return value is expected to be a semantic version string.
436
+
437
+ ##### `writeVersion(contents = string, version: string): string`
438
+
439
+ This method is used to write the version to the provided contents.
440
+
441
+ The return value will be written directly (overwrite) to the provided file.
442
+
443
+ ---
444
+
445
+ Let's assume our `VERSION_TRACKER.json` has the following contents:
446
+
447
+ ```json
448
+ {
449
+ "tracker": {
450
+ "package": {
451
+ "version": "1.0.0"
452
+ }
453
+ }
454
+ }
455
+ ```
456
+
457
+ An acceptable `commit-and-tag-version-updater.js` would be:
458
+
459
+ ```js
460
+ // commit-and-tag-version-updater.js
461
+ const stringifyPackage = require("stringify-package");
462
+ const detectIndent = require("detect-indent");
463
+ const detectNewline = require("detect-newline");
464
+
465
+ module.exports.readVersion = function (contents) {
466
+ return JSON.parse(contents).tracker.package.version;
467
+ };
468
+
469
+ module.exports.writeVersion = function (contents, version) {
470
+ const json = JSON.parse(contents);
471
+ let indent = detectIndent(contents).indent;
472
+ let newline = detectNewline(contents);
473
+ json.tracker.package.version = version;
474
+ return stringifyPackage(json, indent, newline);
475
+ };
476
+ ```
477
+
478
+ ## License
479
+
480
+ ISC
package/bin/cli.js ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+
3
+ /* istanbul ignore if */
4
+ if (process.version.match(/v(\d+)\./)[1] < 6) {
5
+ console.error(
6
+ 'commit-and-tag-version: Node v6 or greater is required. `commit-and-tag-version` did not run.'
7
+ )
8
+ } else {
9
+ const standardVersion = require('../index')
10
+ const cmdParser = require('../command')
11
+ standardVersion(cmdParser.argv).catch(() => {
12
+ process.exit(1)
13
+ })
14
+ }
package/command.js ADDED
@@ -0,0 +1,145 @@
1
+ const spec = require('conventional-changelog-config-spec')
2
+ const { getConfiguration } = require('./lib/configuration')
3
+ const defaults = require('./defaults')
4
+
5
+ const yargs = require('yargs')
6
+ .usage('Usage: $0 [options]')
7
+ .option('packageFiles', {
8
+ default: defaults.packageFiles,
9
+ array: true
10
+ })
11
+ .option('bumpFiles', {
12
+ default: defaults.bumpFiles,
13
+ array: true
14
+ })
15
+ .option('release-as', {
16
+ alias: 'r',
17
+ describe:
18
+ 'Specify the release type manually (like npm version <major|minor|patch>)',
19
+ requiresArg: true,
20
+ string: true
21
+ })
22
+ .option('prerelease', {
23
+ alias: 'p',
24
+ describe:
25
+ 'make a pre-release with optional option value to specify a tag id',
26
+ string: true
27
+ })
28
+ .option('infile', {
29
+ alias: 'i',
30
+ describe: 'Read the CHANGELOG from this file',
31
+ default: defaults.infile
32
+ })
33
+ .option('message', {
34
+ alias: ['m'],
35
+ describe:
36
+ '[DEPRECATED] Commit message, replaces %s with new version.\nThis option will be removed in the next major version, please use --releaseCommitMessageFormat.',
37
+ type: 'string'
38
+ })
39
+ .option('first-release', {
40
+ alias: 'f',
41
+ describe: 'Is this the first release?',
42
+ type: 'boolean',
43
+ default: defaults.firstRelease
44
+ })
45
+ .option('sign', {
46
+ alias: 's',
47
+ describe: 'Should the git commit and tag be signed?',
48
+ type: 'boolean',
49
+ default: defaults.sign
50
+ })
51
+ .option('no-verify', {
52
+ alias: 'n',
53
+ describe:
54
+ 'Bypass pre-commit or commit-msg git hooks during the commit phase',
55
+ type: 'boolean',
56
+ default: defaults.noVerify
57
+ })
58
+ .option('commit-all', {
59
+ alias: 'a',
60
+ describe:
61
+ 'Commit all staged changes, not just files affected by commit-and-tag-version',
62
+ type: 'boolean',
63
+ default: defaults.commitAll
64
+ })
65
+ .option('silent', {
66
+ describe: "Don't print logs and errors",
67
+ type: 'boolean',
68
+ default: defaults.silent
69
+ })
70
+ .option('tag-prefix', {
71
+ alias: 't',
72
+ describe: 'Set a custom prefix for the git tag to be created',
73
+ type: 'string',
74
+ default: defaults.tagPrefix
75
+ })
76
+ .option('scripts', {
77
+ describe:
78
+ 'Provide scripts to execute for lifecycle events (prebump, precommit, etc.,)',
79
+ default: defaults.scripts
80
+ })
81
+ .option('skip', {
82
+ describe: 'Map of steps in the release process that should be skipped',
83
+ default: defaults.skip
84
+ })
85
+ .option('dry-run', {
86
+ type: 'boolean',
87
+ default: defaults.dryRun,
88
+ describe: 'See the commands that running commit-and-tag-version would run'
89
+ })
90
+ .option('git-tag-fallback', {
91
+ type: 'boolean',
92
+ default: defaults.gitTagFallback,
93
+ describe:
94
+ 'fallback to git tags for version, if no meta-information file is found (e.g., package.json)'
95
+ })
96
+ .option('path', {
97
+ type: 'string',
98
+ describe: 'Only populate commits made under this path'
99
+ })
100
+ .option('changelogHeader', {
101
+ type: 'string',
102
+ describe:
103
+ '[DEPRECATED] Use a custom header when generating and updating changelog.\nThis option will be removed in the next major version, please use --header.'
104
+ })
105
+ .option('preset', {
106
+ type: 'string',
107
+ default: defaults.preset,
108
+ describe: 'Commit message guideline preset'
109
+ })
110
+ .option('lerna-package', {
111
+ type: 'string',
112
+ describe: 'Name of the package from which the tags will be extracted'
113
+ })
114
+ .check((argv) => {
115
+ if (typeof argv.scripts !== 'object' || Array.isArray(argv.scripts)) {
116
+ throw Error('scripts must be an object')
117
+ } else if (typeof argv.skip !== 'object' || Array.isArray(argv.skip)) {
118
+ throw Error('skip must be an object')
119
+ } else {
120
+ return true
121
+ }
122
+ })
123
+ .alias('version', 'v')
124
+ .alias('help', 'h')
125
+ .example('$0', 'Update changelog and tag release')
126
+ .example(
127
+ '$0 -m "%s: see changelog for details"',
128
+ 'Update changelog and tag release with custom commit message'
129
+ )
130
+ .pkgConf('standard-version')
131
+ .pkgConf('commit-and-tag-version')
132
+ .config(getConfiguration())
133
+ .wrap(97)
134
+
135
+ Object.keys(spec.properties).forEach((propertyKey) => {
136
+ const property = spec.properties[propertyKey]
137
+ yargs.option(propertyKey, {
138
+ type: property.type,
139
+ describe: property.description,
140
+ default: defaults[propertyKey] ? defaults[propertyKey] : property.default,
141
+ group: 'Preset Configuration:'
142
+ })
143
+ })
144
+
145
+ module.exports = yargs
package/defaults.js ADDED
@@ -0,0 +1,40 @@
1
+ const spec = require('conventional-changelog-config-spec')
2
+
3
+ const defaults = {
4
+ infile: 'CHANGELOG.md',
5
+ firstRelease: false,
6
+ sign: false,
7
+ noVerify: false,
8
+ commitAll: false,
9
+ silent: false,
10
+ tagPrefix: 'v',
11
+ scripts: {},
12
+ skip: {},
13
+ dryRun: false,
14
+ gitTagFallback: true,
15
+ preset: require.resolve('conventional-changelog-conventionalcommits')
16
+ }
17
+
18
+ /**
19
+ * Merge in defaults provided by the spec
20
+ */
21
+ Object.keys(spec.properties).forEach((propertyKey) => {
22
+ const property = spec.properties[propertyKey]
23
+ defaults[propertyKey] = property.default
24
+ })
25
+
26
+ /**
27
+ * Sets the default for `header` (provided by the spec) for backwards
28
+ * compatibility. This should be removed in the next major version.
29
+ */
30
+ defaults.header =
31
+ '# Changelog\n\nAll notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.\n'
32
+
33
+ defaults.packageFiles = ['package.json', 'bower.json', 'manifest.json']
34
+
35
+ defaults.bumpFiles = defaults.packageFiles.concat([
36
+ 'package-lock.json',
37
+ 'npm-shrinkwrap.json'
38
+ ])
39
+
40
+ module.exports = defaults