Skip to content

Commit 36593a5

Browse files
committed
feat(gen): add updateSubmodules task and run it beforeBump
1 parent 044cbd6 commit 36593a5

File tree

1 file changed

+47
-12
lines changed

1 file changed

+47
-12
lines changed

Gruntfile.js

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,19 @@ module.exports = function (grunt) {
3131
commitMessage: '<%= version %>',
3232
tagName: '<%= version %>',
3333
file: 'package.json',
34+
beforeBump: ['updateSubmodules'],
3435
afterBump: ['updateFixtures:deps', 'commitNgFullstackDeps'],
3536
beforeRelease: ['stage'],
3637
push: false,
3738
pushTags: false,
3839
npm: false
3940
}
4041
},
42+
updateSubmodules: {
43+
options: {
44+
modules: ['angular-fullstack-deps']
45+
}
46+
},
4147
commitNgFullstackDeps: {
4248
options: {
4349
cwd: 'angular-fullstack-deps',
@@ -113,12 +119,47 @@ module.exports = function (grunt) {
113119
}
114120
});
115121

116-
grunt.registerTask('stage', 'git add files before running the release task', function () {
117-
var files = grunt.config('stage.options').files, done = this.async();
122+
function gitCmd(args, opts, done) {
118123
grunt.util.spawn({
119124
cmd: process.platform === 'win32' ? 'git.cmd' : 'git',
120-
args: ['add'].concat(files)
125+
args: args,
126+
opts: opts || {}
121127
}, done);
128+
}
129+
function gitCmdAsync(args, opts) {
130+
return function() {
131+
var deferred = Q.defer();
132+
gitCmd(args, opts, function(err) {
133+
if (err) { return deferred.reject(err); }
134+
deferred.resolve();
135+
});
136+
return deferred.promise;
137+
};
138+
}
139+
140+
grunt.registerTask('stage', 'git add files before running the release task', function () {
141+
var files = grunt.config('stage.options').files;
142+
gitCmd(['add'].concat(files), {}, this.async());
143+
});
144+
145+
grunt.registerTask('updateSubmodules', function() {
146+
grunt.config.requires('updateSubmodules.options.modules');
147+
var modules = grunt.config.get('updateSubmodules').options.modules;
148+
149+
Q()
150+
.then(gitCmdAsync(['submodule', 'update', '--init', '--recursive']))
151+
.then(function() {
152+
var thens = [];
153+
for (var i = 0, modulesLength = modules.length; i < modulesLength; i++) {
154+
var opts = {cwd: modules[i]};
155+
thens.push(gitCmdAsync(['checkout', 'master'], opts));
156+
thens.push(gitCmdAsync(['fetch'], opts));
157+
thens.push(gitCmdAsync(['pull'], opts));
158+
}
159+
return thens.reduce(Q.when, Q());
160+
})
161+
.catch(grunt.fail.fatal.bind(grunt.fail))
162+
.finally(this.async());
122163
});
123164

124165
grunt.registerTask('commitNgFullstackDeps', function() {
@@ -129,15 +170,9 @@ module.exports = function (grunt) {
129170
var ops = grunt.config.get('commitNgFullstackDeps').options;
130171
var version = require('./package.json').version || 'NO VERSION SET';
131172
if (Array.isArray(ops.files) && ops.files.length > 0) {
132-
var done = this.async();
133-
var cwd = path.resolve(__dirname, ops.cwd);
134-
grunt.util.spawn({
135-
cmd: process.platform === 'win32' ? 'git.cmd' : 'git',
136-
args: ['commit', '-m', version].concat(ops.files),
137-
opts: {
138-
cwd: cwd
139-
}
140-
}, done);
173+
gitCmd(['commit', '-m', version].concat(ops.files), {
174+
cwd: path.resolve(__dirname, ops.cwd)
175+
}, this.async());
141176
} else {
142177
grunt.log.writeln('No files were commited');
143178
}

0 commit comments

Comments
 (0)