code everywhere

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 = new Date();
var 
version '1.0.1';
var 
build = [ n.getFullYear()-2000, (n.getMonth()+10) ? ''n.getMonth()+1, (n.getDate()<10) ? ''n.getDate(), '-'n.getHours(), (n.getMinutes() < 10) ? ''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)";
giving you a trackable date/time for the current build your looking at.

recent posts

< back
find something helpful? send us some coin BTC 19u6CWTxH4cH9V2yTfAemA7gmmh7rANgiv

(ad) Need Hosting? Try Linode, VPS Starting from $5

privacy policy