node.jsgitgulpgulp-watchgulp-header

"npm version <major|minor|patch>" and the "dist" directory


I am using node.js along with gulp as an infrastructure for my environment. I am using this environment to write a jQuery plugin. The directory structure looks like this:

jquery-plugin
    |
    ---- dist (contains complied and minified plugin files)
    |
    ---- src (source code)
    |
    ---- gulpfile.js
    |
    ---- package.json

Now, I have written my gulp file to contain instructions to contain a watch task, that will copy files from src to dist whenever a change is saved. Also note that the banner in the header section of the js files is set through gulp-header, which includes version number that is automatically pulled from package.json

So far everything is correct.

Now, assuming I start with version 0.0.1, and go through a development cycle (which is done in my develop branch), then eventually my code is ready. I would commit everything in my develop branch, then switch to master, merge the code from develop. Now code is ready to be published.

I would go to my terminal, and run npm version minor. This would make the version 0.1.0 and check in a new version to master, and add tag v0.1.0. The problem is, the files in src and dist will still have version 0.0.1 in their header (which were pulled from the previous version, before running the version command, because no actually saving in those files has been made after running the version command).

How do I ensure that the version is automatically updated in the header section of js files in the dist directory?

Thanks.


Solution

  • After further investigating the issue, I did the following:

    1. Run npm --no-git-tag-version version minor. This would bump the version, but would not check in any files nor add tags.

    2. Touch/save one of the src files. This will update the header with the correct version number in the dist directory

    3. Manually check-in in git, and add a new tag in the format vMa.Mi.P (where Ma is the major number, Mi is the minor number, and P is the patch number)

    Reference: https://docs.npmjs.com/cli/version