Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom commit message #597

Merged
merged 18 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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: <version>)
nnmrts marked this conversation as resolved.
Show resolved Hide resolved

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
Original file line number Diff line number Diff line change
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}.`;
nnmrts marked this conversation as resolved.
Show resolved Hide resolved
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