Skip to content

Commit

Permalink
Add support for custom commit message (#597)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Govind S <gvind4@gmail.com>
  • Loading branch information
3 people committed Feb 12, 2021
1 parent add5bd9 commit 65a674e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
2 changes: 2 additions & 0 deletions readme.md
Expand Up @@ -64,6 +64,7 @@ $ np --help
--release-draft-only Only opens a GitHub release draft
--test-script Name of npm run script to run tests before publishing (default: test)
--no-2fa Don't enable 2FA on new packages (not recommended)
--message Version bump commit message. `%s` will be replaced with version. (default: '%s' with npm and 'v%s' with yarn)
Examples
$ np
Expand Down Expand Up @@ -98,6 +99,7 @@ Currently, these are the flags you can configure:
- `releaseDraft` - Open a GitHub release draft after releasing (`true` by default).
- `testScript` - Name of npm run script to run tests before publishing (`test` by default).
- `2fa` - Enable 2FA on new packages (`true` by default) (setting this to `false` is not recommended).
- `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`.

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

Expand Down
4 changes: 4 additions & 0 deletions source/cli-implementation.js
Expand Up @@ -36,6 +36,7 @@ const cli = meow(`
--release-draft-only Only opens a GitHub release draft for the latest published version
--test-script Name of npm run script to run tests before publishing (default: test)
--no-2fa Don't enable 2FA on new packages (not recommended)
--message Version bump commit message, '%s' will be replaced with version (default: default: '%s' with npm and 'v%s' with yarn)
Examples
$ np
Expand Down Expand Up @@ -87,6 +88,9 @@ const cli = meow(`
},
'2fa': {
type: 'boolean'
},
message: {
type: 'string'
}
}
});
Expand Down
36 changes: 32 additions & 4 deletions source/index.js
Expand Up @@ -184,20 +184,48 @@ module.exports = async (input = 'patch', options) => {
enabled: () => options.yarn === true,
skip: () => {
if (options.preview) {
return `[Preview] Command not executed: yarn version --new-version ${input}.`;
let previewText = `[Preview] Command not executed: yarn version --new-version ${input}`;

if (options.message) {
previewText += ` --message '${options.message.replace(/%s/g, input)}'`;
}

return `${previewText}.`;
}
},
task: () => exec('yarn', ['version', '--new-version', input])
task: () => {
const args = ['version', '--new-version', input];

if (options.message) {
args.push('--message', options.message);
}

return exec('yarn', args);
}
},
{
title: 'Bumping version using npm',
enabled: () => options.yarn === false,
skip: () => {
if (options.preview) {
return `[Preview] Command not executed: npm version ${input}.`;
let previewText = `[Preview] Command not executed: npm version ${input}`;

if (options.message) {
previewText += ` --message '${options.message.replace(/%s/g, input)}'`;
}

return `${previewText}.`;
}
},
task: () => exec('npm', ['version', input])
task: () => {
const args = ['version', input];

if (options.message) {
args.push('--message', options.message);
}

return exec('npm', args);
}
}
]);

Expand Down

0 comments on commit 65a674e

Please sign in to comment.