Working codepen: http://codepen.io/leongaban/pen/oxwLzE?editors=1010
The function below takes in user entered text through the cli: V=patch gulp build
It then checks for the last version of the build folder, then iterates the appropriate version number.
Hoping to condense all the if/else into more functional code.
lastVersion starts as an empty string var lastVersion = '';
The ver
value that is passed into this function from the user will be 1 of these commands:
V=major gulp build
V=minor gulp build
V=patch gulp build
So ver
will be major
, minor
or patch
...
function generateNextVersion(ver) {
var major, minor, patch;
var versionArray = lastVersion.split('.');
major = parseInt(versionArray[0]);
minor = parseInt(versionArray[1]);
patch = parseInt(versionArray[2]);
if (ver === 'major') {
major = parseInt(versionArray[0]) + 1;
}
else if (ver === 'minor') {
minor = parseInt(versionArray[1]) + 1;
}
else if (ver === 'patch') {
patch = parseInt(versionArray[2]) + 1;
}
version = major + '.' + minor + '.' + patch;
if (ver === '' || ver === undefined) {
version = '0.0.0';
}
gutil.log(gutil.colors.blue.bold('##################################################'));
gutil.log(gutil.colors.blue.bold(' Building Dashboard version '+version));
gutil.log(gutil.colors.green.bold('~~ All change is detectable ~~'));
gutil.log(gutil.colors.blue.bold('##################################################'));
}
lastVersion
? We are missing something here, it'd be helpful if you post a working demo. \$\endgroup\$