added version upgrade task
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
"node": true,
|
||||
"white": true,
|
||||
"bitwise": false,
|
||||
"curly": true,
|
||||
"curly": false,
|
||||
"eqnull": true,
|
||||
"eqeqeq": true,
|
||||
"forin": true,
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
module.exports = function (grunt) {
|
||||
var Promise = require('bluebird');
|
||||
var utils = require('./utils');
|
||||
var readFile = Promise.promisify(require('fs').readFile);
|
||||
var writeFile = Promise.promisify(require('fs').writeFile);
|
||||
|
||||
|
||||
// Default task runs the build process.
|
||||
grunt.registerTask('default', [
|
||||
@ -37,4 +41,37 @@ module.exports = function (grunt) {
|
||||
'mochacov:make_coverage_html',
|
||||
'open:coverage'
|
||||
]);
|
||||
|
||||
grunt.registerTask('version', function (type) {
|
||||
var root = require('path').join.bind(null, __dirname, '..');
|
||||
var readmePath = root('README.md');
|
||||
var packagePath = root('package.json');
|
||||
var browserBuildsPath = root('docs/browser_builds.asciidoc');
|
||||
|
||||
Promise.all([
|
||||
require(packagePath),
|
||||
readFile(readmePath, 'utf8'),
|
||||
readFile(browserBuildsPath, 'utf8')
|
||||
])
|
||||
.spread(function (pkg, readme, browserBuilds) {
|
||||
var current = pkg.version;
|
||||
var next = utils.increaseVersion(current, type);
|
||||
|
||||
pkg.version = next;
|
||||
browserBuilds = utils.replaceAll(browserBuilds, current, next);
|
||||
readme = utils.replaceAll(readme, current, next);
|
||||
readme = utils.replaceAll(
|
||||
readme,
|
||||
'branch=' + utils.minorVersion(current),
|
||||
'branch=' + utils.minorVersion(next)
|
||||
);
|
||||
|
||||
// write all files to disk
|
||||
return Promise.all([
|
||||
writeFile(readmePath, readme),
|
||||
writeFile(browserBuildsPath, browserBuilds),
|
||||
writeFile(packagePath, JSON.stringify(pkg, null, ' '))
|
||||
]);
|
||||
}).nodeify(this.async());
|
||||
});
|
||||
};
|
||||
@ -16,4 +16,61 @@ var utils = {
|
||||
|
||||
utils.branches._default = pkg.config.default_api_branch;
|
||||
|
||||
/*
|
||||
* trim down a version id to the minor version number ('1.5.1' => '1.5')
|
||||
*/
|
||||
utils.minorVersion = function (version) {
|
||||
return version.split('.').slice(0, 2).join('.');
|
||||
};
|
||||
|
||||
/*
|
||||
* increment the version based on the release "type"
|
||||
*/
|
||||
utils.increaseVersion = function (version, type) {
|
||||
var i;
|
||||
switch (type) {
|
||||
case 'major':
|
||||
i = 0;
|
||||
break;
|
||||
case 'minor':
|
||||
i = 1;
|
||||
break;
|
||||
case 'bug':
|
||||
case 'patch':
|
||||
case 'bugfix':
|
||||
i = 2;
|
||||
break;
|
||||
default:
|
||||
throw new TypeError('unexpected version bump type');
|
||||
}
|
||||
|
||||
// breakout the current version
|
||||
var next = version.split('.').map(function (n) {
|
||||
return parseInt(n, 10);
|
||||
});
|
||||
|
||||
// increment the version type
|
||||
next[i] += 1;
|
||||
// clear out all following numbers
|
||||
for (i ++; i < next.length; i++) next[i] = 0;
|
||||
// join back together with '.'
|
||||
return next.join('.');
|
||||
};
|
||||
|
||||
/*
|
||||
* replace all instances of `replace` with `replacement` without creating a regexp object
|
||||
*/
|
||||
utils.replaceAll = function (str, replace, replacement) {
|
||||
var out = '';
|
||||
var remaining = str;
|
||||
var i = 0;
|
||||
|
||||
while (~(i = remaining.indexOf(replace))) {
|
||||
out += remaining.substring(0, i) + replacement;
|
||||
remaining = remaining.substr(i + replace.length);
|
||||
}
|
||||
|
||||
return out + remaining;
|
||||
};
|
||||
|
||||
module.exports = utils;
|
||||
Reference in New Issue
Block a user