Automating release process for Angular application using Webpack

Posted By : Deepak Rawat | 28-Dec-2017

Hi Guys,

 

For creating a git release tag we have to use the git command for creating tag, but what if we can automate this process? Backend developers use a Java plugin for automating this process, but we have an awesome tool, webpack, which helps us to automate this process.

 

For automating the release process you have to create a script in package.json file and write this command:

 

  npm version patch && git push --follow-tags

 

This script will bump up the patch version of your package and commits the changes then it’ll create a local tag and push it to github.

 

There are different version options for this command:

 

  • If you want to  bump up the major version then use this command

    npm version major && git push --follow-tags                
        
  • If you want to  bump up the minor version then use this command

    npm version minor && git push --follow-tags                
        

All of the above command will bump up their respective package version by 1 from the version present in package.json, but if you want to update the version from the version in the github then use this command

npm version from-git && git push --follow-tags                
    

If you write the above command with -m or --message option the it'll write a commit message for that version and if %s is present in the message then it'll be replaced with the new version number, e.g:

 

npm version patch -m "Upgrade to %s for reasons"

 

If you want more automation then you can write these scripts into your package.json:

  • preversion - this script will be used to run your test cases before deploying your build.
  • version - this script will be used to create deployment build
  • postversion - this script will be used to push the version tag or for cleaning your file system

For example:

 

"scripts": {
  "preversion": "npm test",
  "version": "npm run build && git add -A dist",
  "postversion": "git push && git push --tags && rm -rf build/temp"
}

 

When you run npm version, then first preversion gets executed and if it exceutes successfully then only version script will be executed and if it executes successfully then postversion will gets executed.

 

Note: For successfully running above command your branch should be clean i.e. there should not be any changes or commits.

 

 

About Author

Author Image
Deepak Rawat

Deepak is a Web and Mobile application Sr. Lead Frontend developer and good working experience with JQuery , AngularJS , Javascript and PhoneGap. His hobbies are listening to music and photography.

Request for Proposal

Name is required

Comment is required

Sending message..