use git to manage esjs and k4d3 deps.

This commit is contained in:
Spencer Alger 2014-05-07 13:04:52 -07:00
parent 97040a15c6
commit ce9a8bd7b6
6 changed files with 105 additions and 3 deletions

View file

@ -1,3 +1,6 @@
{
"directory": "./src/bower_components"
"directory": "./src/bower_components",
"scripts": {
"postinstall": "grunt update"
}
}

View file

@ -10,6 +10,13 @@ module.exports = function (grunt) {
app: __dirname + '/src/kibana',
unitTestDir: __dirname + '/test/unit',
testUtilsDir: __dirname + '/test/utils',
bowerComponentsDir: __dirname + '/src/bower_components',
k4d3Repo: 'git@github.com:elasticsearch/K4D3.git',
k4d3Dir: '<%= bowerComponentsDir %>/K4D3',
esjsRepo: 'git@github.com:elasticsearch/elasticsearch-js.git',
esjsDir: '<%= bowerComponentsDir %>/elasticsearch',
meta: {
banner: '/*! <%= package.name %> - v<%= package.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +

View file

@ -23,8 +23,7 @@
"scripts": {
"test": "grunt test",
"server": "grunt server",
"update": "bower update elasticsearch && bower update K4D3 && npm run rebuild-esjs",
"rebuild-esjs": "cd ./src/bower_components/elasticsearch && npm install && grunt browser_clients:build"
"postinstall": "grunt update"
},
"repository": {
"type": "git",

28
tasks/update.js Normal file
View file

@ -0,0 +1,28 @@
module.exports = function (grunt) {
var Promise = require('bluebird');
var spawn = require('./utils/spawn');
var installOrUpdateRepo = require('./utils/install_or_update_repo');
// bower update elasticsearch && bower update K4D3 && npm run rebuild-esjs"
grunt.registerTask('update', [
'update-esjs',
'update-k4d3'
]);
grunt.registerTask('update-k4d3', function () {
var k4d3Dir = grunt.config('k4d3Dir');
installOrUpdateRepo(grunt.config('k4d3Repo'), k4d3Dir)
.then(spawn('grunt', ['production'], k4d3Dir))
.nodeify(this.async());
});
// cd ./src/bower_components/elasticsearch && npm install && grunt browser_clients:build
grunt.registerTask('update-esjs', function () {
var esjsDir = grunt.config('esjsDir');
installOrUpdateRepo(grunt.config('esjsRepo'), esjsDir)
.then(spawn('grunt', ['browser_clients:build'], esjsDir))
.nodeify(this.async());
});
};

View file

@ -0,0 +1,20 @@
var Promise = require('bluebird');
var spawn = require('./spawn');
var grunt = require('grunt');
module.exports = function (repo, dir) {
return Promise.resolve()
.then(function () {
if (!grunt.file.isDir(dir + '/.git')) {
if (grunt.file.isDir(dir)) {
throw new Error(dir + ' needs to be removed so that we can replace it with a git-repo');
}
return spawn('git', ['clone', repo, dir])();
} else {
return spawn('git', ['fetch', 'origin', 'master'], dir)();
}
})
.then(spawn('git', ['reset', '--hard', 'origin/master'], dir))
.then(spawn('npm', ['install'], dir));
};

45
tasks/utils/spawn.js Normal file
View file

@ -0,0 +1,45 @@
var Promise = require('bluebird');
var grunt = require('grunt');
var estream = require('event-stream');
var cp = require('child_process');
// create a function that will spawn another process based on the args when called
module.exports = function (cmd, args, cwd) {
return function () {
var defer = Promise.defer();
var opts = {
stdio: 'pipe',
cwd: cwd
};
var endsWithNlRE = /\n\r?$/;
grunt.log.writeln('$ ' + cmd + ' ' + args.join(' ') + (opts.cwd ? ' in ' + opts.cwd : ''));
var childProc = cp.spawn(cmd, args, opts);
// track when we are in a series of empty lines, and use this info to limit empty lines to one
var empty = 0;
var maxEmpty = 1;
['stdout', 'stderr'].forEach(function (stream) {
childProc[stream]
.pipe(estream.split())
.pipe(
estream.map(function (line, cb) {
if (!line) { empty ++; if (empty > maxEmpty) return; }
else empty = 0;
cb(null, ' ' + line + '\n');
})
)
.pipe(process[stream]);
});
childProc.on('close', function (code) {
if (code > 0) defer.reject('Process exitted with non-zero code ' + code);
else defer.resolve();
});
return defer.promise;
};
};