From 5b07717116d49253f0c475e8199a76866db53724 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Thu, 30 Jan 2014 13:17:53 -0700 Subject: [PATCH] worked out bower release process --- Gruntfile.js | 5 ++-- grunt/browser_clients.js | 50 +++++++++++++++++++++------------- grunt/config/copy.js | 6 ++++ grunt/config/run.js | 9 ++++++ scripts/_spawn.js | 37 +++++++++++++++++++++++++ scripts/generate/index.js | 56 +++++++++++--------------------------- scripts/release/bower.js | 40 +++++++++++++++++++++++++++ src/bower-elasticsearch-js | 2 +- 8 files changed, 143 insertions(+), 62 deletions(-) create mode 100644 scripts/_spawn.js create mode 100644 scripts/release/bower.js diff --git a/Gruntfile.js b/Gruntfile.js index 643083cd9..64493d794 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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' + diff --git a/grunt/browser_clients.js b/grunt/browser_clients.js index b0417d237..5e22f1846 100644 --- a/grunt/browser_clients.js +++ b/grunt/browser_clients.js @@ -5,34 +5,46 @@ module.exports = function (grunt) { 'saucelabs-mocha:all' ]); - grunt.registerTask('browser_clients:build', [ - 'clean:dist', - 'browserify:browser_client', - 'browserify:angular_client', - 'browserify:jquery_client', - 'uglify:dist', - 'concat:dist_banners' - ]); + 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', + 'browserify:jquery_client', + '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 { diff --git a/grunt/config/copy.js b/grunt/config/copy.js index 27dc96de8..1f6d57aba 100644 --- a/grunt/config/copy.js +++ b/grunt/config/copy.js @@ -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 } }; \ No newline at end of file diff --git a/grunt/config/run.js b/grunt/config/run.js index 3ea192b5b..6d380c67c 100644 --- a/grunt/config/run.js +++ b/grunt/config/run.js @@ -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' } }; \ No newline at end of file diff --git a/scripts/_spawn.js b/scripts/_spawn.js new file mode 100644 index 000000000..9b743a95b --- /dev/null +++ b/scripts/_spawn.js @@ -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; +} \ No newline at end of file diff --git a/scripts/generate/index.js b/scripts/generate/index.js index f006b1689..1c1d19af2 100644 --- a/scripts/generate/index.js +++ b/scripts/generate/index.js @@ -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,54 +39,32 @@ 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) { - done(status ? new Error('Unable to init submodules.') : void 0); - }); + 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) { - done(status ? new Error('Unable fetch lastest changes.') : void 0); - }); + spawn('git', ['submodule', 'foreach', 'git fetch origin'], argv, function (status) { + done(status ? new Error('Unable fetch lastest changes.') : void 0); + }); return; } 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) { - done(status ? new Error('Unable to checkout ' + branch) : void 0); - }); + 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); + }); }, function (done) { var tasks = []; diff --git a/scripts/release/bower.js b/scripts/release/bower.js new file mode 100644 index 000000000..79e0135ff --- /dev/null +++ b/scripts/release/bower.js @@ -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); + } + } +}); \ No newline at end of file diff --git a/src/bower-elasticsearch-js b/src/bower-elasticsearch-js index bb8d403ad..55b727d72 160000 --- a/src/bower-elasticsearch-js +++ b/src/bower-elasticsearch-js @@ -1 +1 @@ -Subproject commit bb8d403ad262e0ba1f2ff0322fdb44576afd4c7b +Subproject commit 55b727d727032554eba2cc5b0c334b94dbe92bf6