@lu-dev/grunt-lu-version

0.0.3 • Public • Published

grunt-lu-version

opinionated versioning based on a git repo

Getting Started

npm install @lu-dev/grunt-lu-version --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-lu-version');

The "version" task

Overview

This task determines an appropriate string representing the current version and updates the version in package.json accordingly. It makes available a version variable in grunt.option that can be used by subsequent tasks. It will also print the version string to the build log. The version string is calculated based upon the current date as well as the state of the git repository.

Versioning scheme

The version string is formatted as follows:

{year}.{month}.{date}.{git_branch}.{git_revision_count}
  • year - the 4-digit current year
  • month - 2-digit month (1-12), with leading zero for single-digit months
  • date - 2-digit date (1-31), with leading zero for single-digit dates
  • git_branch - the current git branch. This is omitted if the current branch is master
  • git_revision_count - the number of revisions (commits) in the current tree. This serves to differentiate multiple versions built on the same date and branch

Git branch

The git branch is included in the version string for any branch other than master. The plugin will attempt to determine the current branch dynamically based on the state of the local git repo. Since this is not always possible (such as on bamboo where the local repo cache is always in a detached HEAD state), the git branch can be passed to the plugin via the GIT_BRANCH environment variable. If this variable is present, it will override the branch according to the local repo state regardless of whether or not that state can be determined.

Updating git remote

By default, the plugin will only print the version to the log and update package.json. It will not commit the updated package.json to git or create tags. However, if updateGitRemote is set to true (i.e. in the command line), the version task will commit and push the changed package.json along with a tag consisting of v followed by the version string.

grunt version --updateGitRemote=true

Release History

0.0.3

  • version calculation
  • automated maintenance of git tags and package.json version

Readme

Keywords

Package Sidebar

Install

npm i @lu-dev/grunt-lu-version

Weekly Downloads

0

Version

0.0.3

License

ISC

Last publish

Collaborators

  • lu-dev
  • whboyd