Home > Enterprise >  how to parse package.json version for github "gh release" tag?
how to parse package.json version for github "gh release" tag?

Time:12-24

I want to create a single command that would do following:

  • increase the package.json version (I could do this by running npm version patch)
  • create Github release with that version as tag (not sure how to achieve this step?)

Brownie points if I could supply patch/minor/major flag while running the command so that npm version _flag_ runs instead of always patching.

I'm using gh package https://cli.github.com/manual/gh_release_create

CodePudding user response:

To get the version node -pe "require('./package.json').version"

A script with optional argument as asked, if no args this will do a patch. Then launch interactive release creation with the new version

#!/bin/sh

if [ $# -eq 0 ]
then
    action="patch"
else
    case $1 in
        minor | major | patch)
            action=$1
            ;;
        *)
            echo "Unknow $1 command"
            return -1
            ;;
    esac
fi
npm version $action
version=`node -pe "require('./package.json').version"`

echo "new version $version"
gh release create $version

CodePudding user response:

check out the package semantic-release for node projects.

  • Related