Skip to content

Commit 65a674e

Browse files
nnmrtssindresorhusdopecodez
authored
Add support for custom commit message (#597)
Co-authored-by: Sindre Sorhus <[email protected]> Co-authored-by: Govind S <[email protected]>
1 parent add5bd9 commit 65a674e

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ $ np --help
6464
--release-draft-only Only opens a GitHub release draft
6565
--test-script Name of npm run script to run tests before publishing (default: test)
6666
--no-2fa Don't enable 2FA on new packages (not recommended)
67+
--message Version bump commit message. `%s` will be replaced with version. (default: '%s' with npm and 'v%s' with yarn)
6768
6869
Examples
6970
$ np
@@ -98,6 +99,7 @@ Currently, these are the flags you can configure:
9899
- `releaseDraft` - Open a GitHub release draft after releasing (`true` by default).
99100
- `testScript` - Name of npm run script to run tests before publishing (`test` by default).
100101
- `2fa` - Enable 2FA on new packages (`true` by default) (setting this to `false` is not recommended).
102+
- `message` - The commit message used for the version bump. Any `%s` in the string will be replaced with the new version. By default, npm uses `%s` and Yarn uses `v%s`.
101103

102104
For example, this configures `np` to never use Yarn and to use `dist` as the subdirectory to publish:
103105

source/cli-implementation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const cli = meow(`
3636
--release-draft-only Only opens a GitHub release draft for the latest published version
3737
--test-script Name of npm run script to run tests before publishing (default: test)
3838
--no-2fa Don't enable 2FA on new packages (not recommended)
39+
--message Version bump commit message, '%s' will be replaced with version (default: default: '%s' with npm and 'v%s' with yarn)
3940
4041
Examples
4142
$ np
@@ -87,6 +88,9 @@ const cli = meow(`
8788
},
8889
'2fa': {
8990
type: 'boolean'
91+
},
92+
message: {
93+
type: 'string'
9094
}
9195
}
9296
});

source/index.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,48 @@ module.exports = async (input = 'patch', options) => {
184184
enabled: () => options.yarn === true,
185185
skip: () => {
186186
if (options.preview) {
187-
return `[Preview] Command not executed: yarn version --new-version ${input}.`;
187+
let previewText = `[Preview] Command not executed: yarn version --new-version ${input}`;
188+
189+
if (options.message) {
190+
previewText += ` --message '${options.message.replace(/%s/g, input)}'`;
191+
}
192+
193+
return `${previewText}.`;
188194
}
189195
},
190-
task: () => exec('yarn', ['version', '--new-version', input])
196+
task: () => {
197+
const args = ['version', '--new-version', input];
198+
199+
if (options.message) {
200+
args.push('--message', options.message);
201+
}
202+
203+
return exec('yarn', args);
204+
}
191205
},
192206
{
193207
title: 'Bumping version using npm',
194208
enabled: () => options.yarn === false,
195209
skip: () => {
196210
if (options.preview) {
197-
return `[Preview] Command not executed: npm version ${input}.`;
211+
let previewText = `[Preview] Command not executed: npm version ${input}`;
212+
213+
if (options.message) {
214+
previewText += ` --message '${options.message.replace(/%s/g, input)}'`;
215+
}
216+
217+
return `${previewText}.`;
198218
}
199219
},
200-
task: () => exec('npm', ['version', input])
220+
task: () => {
221+
const args = ['version', input];
222+
223+
if (options.message) {
224+
args.push('--message', options.message);
225+
}
226+
227+
return exec('npm', args);
228+
}
201229
}
202230
]);
203231

0 commit comments

Comments
 (0)