Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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: <version>)

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 (`%s` when using npm and `v%s` when using yarn by default)

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>)

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}.`;
let previewText = `[Preview] Command not executed: yarn version --new-version ${input}`;

if (options.message) {
previewText += ` -m '${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('-m', 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 += ` -m '${options.message.replace(/%s/g, input)}'`;
}

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

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

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

Expand Down