creating build versions with gulp.js
posted on May 27, 2016, 11:03 pm in
Working with a CI (continuous integration) environment, you probably have multiple builds going out each day. This makes it hard to keep track of what version your actually using.
Lets add some build numbers using npmjs.com/package/gulp-replace .
In your gulpFile.js, add this new section changing the version as appropriate.
var n = new Date();
var version = '1.0.1';
var build = [ n.getFullYear()-2000, (n.getMonth()+1 < 10) ? 0 : '', n.getMonth()+1, (n.getDate()<10) ? 0 : '', n.getDate(), '-', n.getHours(), (n.getMinutes() < 10) ? 0 : '', n.getMinutes()].join('');
then in the gulp build process:
.src('./path/to/file.js')
.pipe(replace('Version X (Build YYMMDD-HHMM)', 'Version ' + version + ' (Build ' + build + ')'))
.pipe(gulp.dest('./dist.js'))
In your JS file, any mention of:
var build = "Version X (Build YYMMDD-HHMM)";
will be convert to
var build = "Version 1.0.1 (Build 160927-1834)";