I would like to replace a string indicating version number in a javascript file (myConstantsFile.js
), with another string. So, for example, my version number looks like this: "01.11.15", written like this in myConstantsFile.js
with other constants:
.constant('productVersion', '1.11.15');
Right now, my task looks like this:
gulp.task('increment-version', function(){
gulp.src(['./somedir/myConstantsFile.js'])
.pipe(replace(/'productVersion', '(.*)'/g, '99.99.99'))
.pipe(gulp.dest('./somedir/'));
});
As you can see, I am using a constant, not running incrementation code, which would look like this:
var numberString = '0.0.1';
var versionParts = numberString.split('.');
var vArray = {
vMajor : versionParts[0],
vMinor : versionParts[1],
vPatch : versionParts[2]
}
vArray.vPatch = parseFloat(vArray.vPatch) + 1;
var periodString = ".";
var newVersionNumberString = vArray.vMajor + periodString +
vArray.vMinor+ periodString +
vArray.vPatch;
I need:
- A way to select the current version number via regex via the file.
- To know where I can put the logic in the last code block to increment the number and build the new string.
Install gulp-bump
Install yargs
Require gulp-bump
Require yargs
Your bump task
VSO Note: I believe a lot of people coming to this thread will be looking exactly for the answer above. The code below is to edit a version number stored somewhere BESIDES the npm/bower package files, such as in angular constants:
I ommitted some mumbo-jumbo that writes my constant in a pretty string, but that's the gist and it works.
Started looking into gulp since past 5 hours,as I had a task to fix the requirement. So, being a definite noob to gulp I came out with the below code which is without the regex expression. Thanks to @VSO and @Wilmer Saint for a quick start. Might be a tiny change, but this helped me.
or the return code could be as below to override the number in version.js file
My version.js has only below code
I used the below in my main function(loads on loading the app)