Skip to content

Commit

Permalink
bump multiple files at once ... fix #90
Browse files Browse the repository at this point in the history
  • Loading branch information
astik authored and drublic committed Dec 3, 2014
1 parent b5ba8ab commit e5c250a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 11 deletions.
12 changes: 9 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function(grunt) {
grunt.initConfig({

clean: {
test: 'test/fixtures/_component.json'
test: 'test/fixtures/_*.json'
},
nodeunit: {
tests: 'test/release_test.js'
Expand All @@ -27,8 +27,13 @@ module.exports = function(grunt) {
},
setup: {
test: {
src: 'test/fixtures/component.json',
dest: 'test/fixtures/_component.json'
files: [{
src: 'test/fixtures/component.json',
dest: 'test/fixtures/_component.json'
},{
src: 'test/fixtures/bower.json',
dest: 'test/fixtures/_bower.json'
}]
}
}
});
Expand Down Expand Up @@ -57,5 +62,6 @@ module.exports = function(grunt) {
grunt.config.set('release.options.pushTags', false);
grunt.config.set('release.options.npm', false);
grunt.config.set('release.options.github', false);
grunt.config.set('release.options.additionalFiles', ['test/fixtures/_bower.json']);
});
};
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ grunt release --npmtag canary
NOTE: If the tag you pass is **true**, then the tag will be the *new* version number after the bump. Otherwise it will be the string you provided.


**Bump multuple files at once**

Sometimes you may need to bump multiple files while releasing.

```js
release: {
options: {
additionalFiles: 'bower.json',
}
}
```

The version to bump is set in the master file defined with otpion 'file' (default : package.json).
This version will be propagated to every additionalFiles.


**Dry Run:**
To see what grunt-release does, without really changing anything, use `--no-write` option.

Expand Down
32 changes: 24 additions & 8 deletions tasks/grunt-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ module.exports = function(grunt){
//defaults
var options = this.options({
bump: true,
// file is in charge of master information, ie, it is it which define the base version to work on
file: grunt.config('pkgFile') || 'package.json',
// additionalFiles are additional files that also need to be bumped
additionalFiles: [],
add: true,
commit: true,
tag: true,
Expand Down Expand Up @@ -65,7 +68,8 @@ module.exports = function(grunt){
if (options.bump) {
newVersion = semver.inc(pkg.version, type || 'patch');
}
return {file: file, pkg: pkg, newVersion: newVersion};
options.additionalFiles.push(file);
return {files: options.additionalFiles, newVersion: newVersion};
}

function getNpmTag(){
Expand Down Expand Up @@ -102,11 +106,13 @@ module.exports = function(grunt){
}

function add(){
return run('git add ' + config.file, ' staged ' + config.file);
var files = config.files.join(' ');
return run('git add ' + files, ' staged ' + files);
}

function commit(){
return run('git commit '+ config.file +' -m "'+ commitMessage +'"', 'committed ' + config.file);
var files = config.files.join(' ');
return run('git commit '+ files +' -m "'+ commitMessage +'"', 'committed ' + files);
}

function tag(){
Expand Down Expand Up @@ -135,11 +141,21 @@ module.exports = function(grunt){


function bump(){
return Q.fcall(function () {
config.pkg.version = config.newVersion;
grunt.file.write(config.file, JSON.stringify(config.pkg, null, indentation) + '\n');
grunt.log.ok('bumped version to ' + config.newVersion);
});
var i, l, file, pkg, promise;
var promises = [];
for (i = 0, l = config.files.length ; i < l ; i++) {
file = config.files[i];
promise = (function(file){
return Q.fcall(function () {
pkg = grunt.file.readJSON(file);
pkg.version = config.newVersion;
grunt.file.write(file, JSON.stringify(pkg, null, indentation) + '\n');
grunt.log.ok('bumped version of ' + file + ' to ' + config.newVersion);
});
}(file));
promises.push(promise);
}
return Q.all(promises);
}

function githubRelease(){
Expand Down
4 changes: 4 additions & 0 deletions test/expected/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "grunt-release-test-bower",
"version": "0.0.13"
}
4 changes: 4 additions & 0 deletions test/fixtures/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "grunt-release-test-bower",
"version": "0.0.1.who.care.I.will.take.component.version.anyway"
}
6 changes: 6 additions & 0 deletions test/release_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ exports.release = {
var expected = grunt.file.readJSON('test/expected/component.json');
test.equal(actual.version, expected.version, 'should set version 0.0.13');

test.done();
},
bumpMultiple: function(test){
var actual = grunt.file.readJSON('test/fixtures/_bower.json');
var expected = grunt.file.readJSON('test/expected/bower.json');
test.equal(actual.version, expected.version, 'bower.json should also have version 0.0.13');
test.done();
}
};

0 comments on commit e5c250a

Please sign in to comment.