- 
      
 - 
        
Save Sunyang730/9bcec078975c5c02fc48bdc48c939c08 to your computer and use it in GitHub Desktop.  
    A bash script to bump versions for both package.json and bower.json, then publishes to npm
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| function bump { | |
| output=$(npm version ${release} --no-git-tag-version) | |
| version=${output:1} | |
| search='("version":[[:space:]]*").+(")' | |
| replace="\1${version}\2" | |
| sed -i ".tmp" -E "s/${search}/${replace}/g" "$1" | |
| rm "$1.tmp" | |
| } | |
| function help { | |
| echo "Usage: $(basename $0) [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease]" | |
| } | |
| if [ -z "$1" ] || [ "$1" = "help" ]; then | |
| help | |
| exit | |
| fi | |
| release=$1 | |
| if [ -d ".git" ]; then | |
| changes=$(git status --porcelain) | |
| if [ -z "${changes}" ]; then | |
| bump "bower.json" | |
| git add . | |
| git commit -m "Bump to ${version}" | |
| git tag -a "${output}" -m "${version}" | |
| git push origin --tags | |
| npm publish ./ | |
| else | |
| echo "Please commit staged files prior to bumping" | |
| fi | |
| else | |
| bump "bower.json" | |
| fi | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment