worked out bower release process

This commit is contained in:
Spencer Alger
2014-01-30 13:17:53 -07:00
parent 5d6f6165dc
commit 5b07717116
8 changed files with 143 additions and 62 deletions

View File

@ -4,10 +4,11 @@
module.exports = function (grunt) {
// load plugins
require('load-grunt-config')(grunt, {
configPath: require('path').join(__dirname, 'grunt/config'),
configPath: __dirname + '/grunt/config',
init: true,
config: {
distDir: 'dist',
distDir: __dirname + '/dist',
bowerSubmodule: __dirname + '/src/bower-elasticsearch-js',
meta: {
banner: '/*! <%= package.name %> - v<%= package.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +

View File

@ -5,7 +5,12 @@ module.exports = function (grunt) {
'saucelabs-mocha:all'
]);
grunt.registerTask('browser_clients:build', [
grunt.registerTask('browser_clients:build', function () {
// prevent this from running more than once accidentally
grunt.task.renameTask('browser_clients:build', 'browser_clients:rebuild');
grunt.task.registerTask('browser_clients:build', []);
grunt.task.run([
'clean:dist',
'browserify:browser_client',
'browserify:angular_client',
@ -13,26 +18,33 @@ module.exports = function (grunt) {
'uglify:dist',
'concat:dist_banners'
]);
});
grunt.registerTask('browser_clients:distribute', [
'browser_clients:build',
'copy:dist_to_named_dir',
'compress:master_zip',
'compress:master_tarball',
's3:upload_archives'
'_upload_archive:master'
]);
grunt.registerTask('browser_clients:release', [
'prompt:confirm_release',
'__check_for_confirmation',
'_check_for_confirmation',
'_upload_archive:release',
'browser_clients:build',
'copy:dist_to_named_dir',
'compress:release_zip',
'compress:release_tarball',
's3:upload_archives'
'run:init_submodules',
'copy:dist_to_bower',
'run:release_bower_subm_tag'
]);
grunt.registerTask('__check_for_confirmation', function () {
grunt.registerTask('_upload_archive', function (type) {
grunt.run([
'browser_clients:build',
'copy:dist_to_named_dir',
'compress:' + type + '_zip',
'compress:' + type + '_tarball',
's3:upload_archives'
]);
});
grunt.registerTask('_check_for_confirmation', function () {
if (grunt.config.get('confirm.release')) {
grunt.log.verbose.writeln('release confirmed');
} else {

View File

@ -4,5 +4,11 @@ module.exports = {
src: '*.js',
dest: '<%= distDir %>/elasticsearch-js/',
expand: true
},
dist_to_bower: {
cwd: '<%= distDir %>',
src: '*.js',
dest: '<%= bowerSubmodule %>',
expand: true
}
};

View File

@ -52,5 +52,14 @@ module.exports = {
wait: false,
quiet: true
}
},
init_submodules: {
exec: 'git submodule update --init',
options: {
quiet: true
}
},
release_bower_subm_tag: {
exec: 'node ./scripts/release/bower'
}
};

37
scripts/_spawn.js Normal file
View File

@ -0,0 +1,37 @@
module.exports = spawn;
var estream = require('event-stream');
var chalk = require('chalk');
var cp = require('child_process');
function spawn(cmd, args, opts, cb) {
opts = opts || {};
console.log(chalk.white.bold('$ ' + cmd + ' ' + args.join(' ')));
var proc = cp.spawn(cmd, args, {
stdio: 'pipe',
cwd: opts.cwd
});
var out = estream.split();
if (opts.verbose) {
proc.stdout.pipe(out);
} else {
proc.stdout.resume();
}
proc.stderr.pipe(out);
out
.pipe(estream.mapSync(function indent(line) {
return ' ' + line + '\n';
}))
.pipe(process.stdout);
if (typeof cb === 'function') {
proc.on('exit', cb);
}
return proc;
}

View File

@ -1,8 +1,6 @@
var cp = require('child_process');
var async = require('async');
var estream = require('event-stream');
var chalk = require('chalk');
var _ = require('lodash');
var spawn = require('../_spawn');
var argv = require('optimist')
.options({
force: {
@ -41,40 +39,15 @@ if (!argv.force && process.env.FORCE || process.env.FORCE_GEN) {
argv.force = argv.f = process.env.FORCE || process.env.FORCE_GEN;
}
function spawn(cmd, args) {
console.log(chalk.white.bold('$ ' + cmd + ' ' + args.join(' ')));
var proc = cp.spawn(cmd, args, { stdio: 'pipe'});
var out = estream.split();
if (argv.verbose) {
proc.stdout.pipe(out);
} else {
proc.stdout.resume();
}
proc.stderr.pipe(out);
out
.pipe(estream.mapSync(function indent(line) {
return ' ' + line + '\n';
}))
.pipe(process.stdout);
return proc;
}
function initSubmodule(done) {
spawn('git', ['submodule', 'update', '--init'])
.on('exit', function (status) {
spawn('git', ['submodule', 'update', '--init'], argv, function (status) {
done(status ? new Error('Unable to init submodules.') : void 0);
});
return;
}
function fetch(done) {
spawn('git', ['submodule', 'foreach', 'git fetch origin'])
.on('exit', function (status) {
spawn('git', ['submodule', 'foreach', 'git fetch origin'], argv, function (status) {
done(status ? new Error('Unable fetch lastest changes.') : void 0);
});
return;
@ -83,10 +56,13 @@ function fetch(done) {
function generateBranch(branch, done) {
async.series([
function (done) {
spawn('git', ['submodule', 'foreach', [
'git reset --hard', 'git clean -fdx', 'git checkout origin/' + branch
].join(' && ')])
.on('exit', function (status) {
var cmd = [
'git reset --hard',
'git clean -fdx',
'git checkout origin/' + branch
].join(' && ');
spawn('git', ['submodule', 'foreach', cmd], function (status) {
done(status ? new Error('Unable to checkout ' + branch) : void 0);
});
},

40
scripts/release/bower.js Normal file
View File

@ -0,0 +1,40 @@
var fs = require('fs');
var spawn = require('../_spawn');
var async = require('async');
var _ = require('lodash');
var root = require('path').join(__dirname, '../..');
var bowerDir = root + '/src/bower-elasticsearch-js';
// get both the bower and node package files
var bowerJson = require(bowerDir + '/bower.json');
var esjsJson = require(root + '/package.json');
// update the version to match the node version
bowerJson.version = esjsJson.version;
// write the new bower.json file
fs.writeFileSync(bowerDir + '/bower.json', JSON.stringify(bowerJson, null, ' '));
function make(cmd, args) {
return _.bind(spawn, null, cmd, args, {
verbose: true,
cwd: bowerDir
});
}
async.series([
make('git', ['add', '-A']),
make('git', ['commit', '-m', 'version ' + bowerJson.version]),
make('git', ['tag', '-a', 'v' + bowerJson.version, '-m', 'version ' + bowerJson.version]),
make('git', ['push', 'origin', 'master']),
make('git', ['push', '--tags', 'origin'])
], function (err) {
if (err) {
if (_.isNumber(err)) {
console.log('Non-zero exit code: %d', err);
} else {
console.log('Error: ', err.message ? err.message : err);
}
}
});