Skip to content

Commit

Permalink
Add automatic provision of the --tag option to npm publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq committed Jun 12, 2019
1 parent 35066dc commit 340d089
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ xyz uses a feature added in Bash 4, released in 2009. macOS users should run
Specify the level of the current version number to increment.
Valid levels: 'major', 'minor', 'patch', 'premajor', 'preminor',
'prepatch', and 'prerelease'. 'patch' is assumed if this option
is omitted.
is omitted. Choosing one of the pre-releases causes the npm dist-tag
to be set according to --prerelease-label.

-m --message <template>
Specify the format of the commit (and tag) message.
Expand All @@ -59,13 +60,17 @@ xyz uses a feature added in Bash 4, released in 2009. macOS users should run
--prerelease-label <label>
Specify the label to be used in the version number when publishing
a pre-release version (e.g. 'beta' is the label in '2.0.0-beta.0').
'rc' is assumed if this option is omitted.
'rc' is assumed if this option is omitted. If the release is a
pre-release, as indicated by --increment, the --prerelease-label will
be used to create an npm dist-tag for the release.

--publish-command <command>
Specify the command to be run to publish the package. It may refer
to the VERSION and PREVIOUS_VERSION environment variables. A no-op
command (':' or 'true') prevents the package from being published
to a registry. 'npm publish' is assumed if this option is omitted.
If this option is provided, the --prerelease-label will not be used
to create an npm dist-tag for the release.

-r --repo <repository>
Specify the remote repository to which to 'git push'.
Expand Down
20 changes: 17 additions & 3 deletions xyz
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Options:
Specify the level of the current version number to increment.
Valid levels: 'major', 'minor', 'patch', 'premajor', 'preminor',
'prepatch', and 'prerelease'. 'patch' is assumed if this option
is omitted.
is omitted. Choosing one of the pre-releases causes the npm dist-tag
to be set according to --prerelease-label.
-m --message <template>
Specify the format of the commit (and tag) message.
Expand All @@ -34,13 +35,17 @@ Options:
--prerelease-label <label>
Specify the label to be used in the version number when publishing
a pre-release version (e.g. 'beta' is the label in '2.0.0-beta.0').
'rc' is assumed if this option is omitted.
'rc' is assumed if this option is omitted. If the release is a
pre-release, as indicated by --increment, the --prerelease-label will
be used to create an npm dist-tag for the release.
--publish-command <command>
Specify the command to be run to publish the package. It may refer
to the VERSION and PREVIOUS_VERSION environment variables. A no-op
command (':' or 'true') prevents the package from being published
to a registry. 'npm publish' is assumed if this option is omitted.
If this option is provided, the --prerelease-label will not be used
to create an npm dist-tag for the release.
-r --repo <repository>
Specify the remote repository to which to 'git push'.
Expand Down Expand Up @@ -129,7 +134,6 @@ declare -A options=(
[increment]=patch
[message]='Version X.Y.Z'
[prerelease-label]=rc
[publish-command]='npm publish'
[repo]=origin
[tag]=vX.Y.Z
)
Expand Down Expand Up @@ -159,6 +163,8 @@ while (( $# > 0 )) ; do
scripts+=("$1") ; shift ;;
--dry-run|--edit)
options[${option:2}]=true ;;
--publish-command)
options[publish-command]="$1" ; shift ;;
*)
if [[ $option =~ ^--(.+)$ && -n ${options[${BASH_REMATCH[1]}]+x} ]] ; then
options[${BASH_REMATCH[1]}]="$1" ; shift
Expand All @@ -168,6 +174,14 @@ while (( $# > 0 )) ; do
esac
done

if [[ ${options[publish-command]+x} != x ]] ; then
if [[ "${options[increment]}" == pre* ]] ; then
options[publish-command]="npm publish --tag ${options[prerelease-label]}"
else
options[publish-command]="npm publish"
fi
fi

[[ $(git rev-parse --abbrev-ref HEAD) == "${options[branch]}" ]] ||
abort "Current branch does not match specified --branch"

Expand Down

0 comments on commit 340d089

Please sign in to comment.