added an export_all_client script

This commit is contained in:
Spencer Alger
2013-12-04 20:11:24 -06:00
parent b43621322b
commit a772a4e070
8 changed files with 231 additions and 1429 deletions

103
scripts/_steps.js Normal file
View File

@ -0,0 +1,103 @@
module.exports = function (argv, steps) {
var async = require('async');
var fs = require('fs');
var path = require('path');
var format = require('util').format;
var cp = require('child_process');
function log() {
var out = format.apply(console, arguments);
if (argv.verbose) {
out = '\n' + out + '\n';
}
console.log(out);
}
var tasks = {
run: function (params, exitCb) {
var cmd = params.cmd;
var args = params.args;
var opts = {
stdio: argv.verbose ? 'inherit' : 'ignore'
};
if (params.cwd) {
opts.cwd = path.resolve(params.cwd);
}
log('running', cmd, args.join(' '), (opts.cwd ? 'in ' + opts.cwd : ''));
var proc = cp.spawn(cmd, args, opts);
proc.on('error', function (err) {
console.error('Error! --', err.message);
process.exit(1);
});
proc.on('exit', function (status) {
if (status) {
console.error('Error! --', cmd, 'exit status was', status);
process.exit(1);
} else {
exitCb();
}
});
},
copy: function (params, done) {
var from = params.from;
var to = params.to;
log('copying', from, 'to', to);
var read = fs.createReadStream(from);
var write = fs.createWriteStream(to);
read.pipe(write);
read.on('error', function (err) {
console.error('unable to read: ' + from);
console.error(err.message);
process.exit(1);
});
write.on('error', function (err) {
console.error('unable to write to: ' + to);
console.error(err.message);
process.exit(1);
});
write.on('finish', function () {
done();
});
}
};
async.forEachSeries(steps, function (args, done) {
// pass the callback to the task
args.push(done);
// get the task name
var taskName = args.shift();
// find the task
var task = tasks;
taskName.split('.').forEach(function (name) {
if (task && task[name]) {
task = task[name];
} else {
throw new Error(taskName + ' is an invalid task, unable to get ' + name + ' from ' + task);
}
});
if (typeof task === 'function') {
task.apply(null, args);
} else {
throw new Error(taskName + ' is an invalid task, does not resolve to a function.');
}
}, function () {
console.log('✔︎');
process.exit();
});
};

View File

@ -1,35 +0,0 @@
var fs = require('fs');
/**
* Stupid simple recursive file/directory clearing. Nothing serious.
*
* @param {String} path Location of the file/directory which should be wiped out
* @return {Boolean} frue on success
*/
module.exports = function (path) {
try {
var stats = fs.statSync(path);
if (stats && stats.isDirectory()) {
console.log('removing', path, 'directory recursively');
rmDirRecursive(path);
} else {
console.log('removing', path);
fs.unlinkSync(path);
}
return true;
} catch (e) {
return false;
}
};
function rmDirRecursive(path) {
fs.readdirSync(path).forEach(function (file) {
var curPath = path + '/' + file;
if (fs.statSync(curPath).isDirectory()) { // recurse
rmDirRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}

View File

@ -0,0 +1,33 @@
var path = require('path');
var fs = require('fs');
var argv = require('optimist')
.default({
verbose: false
})
.alias({
v: 'verbose'
})
.argv;
var steps = [];
['browser', 'jquery', 'angular'].forEach(function (build) {
if (!fs.existsSync('../bower-elasticsearch-' + build) ||
!fs.existsSync('../bower-elasticsearch-' + build + '/.git')
) {
throw new Error('Ensure that all of the bower repos are checked out next to this repo');
}
steps.push([
'run', {
cwd: '../bower-elasticsearch-' + build + '/',
cmd: 'npm',
args: ['run', 'generate']
}
]);
});
require('./_steps')(argv, steps);

View File

@ -1,7 +1,4 @@
var path = require('path');
var fs = require('fs');
var format = require('util').format;
var cp = require('child_process');
var argv = require('optimist')
.default({
@ -34,75 +31,19 @@ default:
var outputFile = path.join(argv.outputDir, 'elasticsearch.js');
var minifiedOutputFile = path.join(argv.outputDir, 'elasticsearch.min.js');
var steps = [
[runInModule, 'npm', ['run', 'build_clients']],
[copy, buildFile, outputFile],
[copy, minifiedBuildFile, minifiedOutputFile]
];
require('./_steps')(argv, [
['run', {
cmd: 'npm',
args: ['run', 'build_clients']
}],
['copy', {
from: buildFile,
to: outputFile
}],
['copy', {
from: minifiedBuildFile,
to: minifiedOutputFile
}]
]);
(function next() {
var step = steps.shift();
if (step) {
var fn = step.shift();
step.push(next);
fn.apply(null, step);
} else {
console.log('Done');
process.exit();
}
})();
function log() {
var out = format.apply(console, arguments);
if (argv.verbose) {
out = '\n' + out + '\n';
}
console.log(out);
}
function runInModule(cmd, args, exitCb) {
log('running', cmd, args.join(' '));
var proc = cp.spawn(cmd, args, {
stdio: argv.verbose ? 'inherit' : 'ignore'
});
proc.on('error', function (err) {
console.error('Error! --', err.message);
process.exit(1);
});
proc.on('exit', function (status) {
if (status) {
console.error('Error! --', cmd, 'exit status was', status);
process.exit(1);
} else {
exitCb();
}
});
}
function copy(from, to, done) {
log('copying', from, 'to', to);
var read = fs.createReadStream(from);
var write = fs.createWriteStream(to);
read.pipe(write);
read.on('error', function (err) {
console.error('unable to read: ' + from);
console.error(err.message);
process.exit(1);
});
write.on('error', function (err) {
console.error('unable to write to: ' + to);
console.error(err.message);
process.exit(1);
});
write.on('finish', function () {
done();
});
}

View File

@ -1,7 +1,4 @@
var path = require('path');
var fs = require('fs');
var format = require('util').format;
var cp = require('child_process');
var argv = require('optimist')
.default({
@ -14,83 +11,64 @@ var argv = require('optimist')
})
.argv;
var steps = [
[runInModule, 'node', [path.join(__dirname, './generate/js_api'), '--force']],
[
copy,
path.join(__dirname, '../docs/_methods.jade'),
path.join(argv.outputDir, '_methods.jade')
],
[
copy,
path.join(__dirname, '../docs/_method_list.jade'),
path.join(argv.outputDir, '_method_list.jade')
]
];
require('./_steps')(argv, [
['runInModule', {
cmd: 'node',
args: [path.join(__dirname, './generate/js_api'), '--force']
}],
['copy', {
from: path.join(__dirname, '../docs/_methods.jade'),
to: path.join(argv.outputDir, '_methods.jade')
}],
['copy', {
from: path.join(__dirname, '../docs/_method_list.jade'),
to: path.join(argv.outputDir, '_method_list.jade')
}]
]);
(function next() {
var step = steps.shift();
if (step) {
var fn = step.shift();
step.push(next);
fn.apply(null, step);
} else {
console.log('Done');
process.exit();
}
})();
// function runInModule(cmd, args, exitCb) {
// log('running', cmd, args.join(' '));
function log() {
var out = format.apply(console, arguments);
if (argv.verbose) {
out = '\n' + out + '\n';
}
console.log(out);
}
// var proc = cp.spawn(cmd, args, {
// stdio: argv.verbose ? 'inherit' : 'ignore'
// });
function runInModule(cmd, args, exitCb) {
log('running', cmd, args.join(' '));
// proc.on('error', function (err) {
// console.error('Error! --', err.message);
// process.exit(1);
// });
var proc = cp.spawn(cmd, args, {
stdio: argv.verbose ? 'inherit' : 'ignore'
});
// proc.on('exit', function (status) {
// if (status) {
// console.error('Error! --', cmd, 'exit status was', status);
// process.exit(1);
// } else {
// exitCb();
// }
// });
// }
proc.on('error', function (err) {
console.error('Error! --', err.message);
process.exit(1);
});
// function copy(from, to, done) {
// log('copying', from, 'to', to);
proc.on('exit', function (status) {
if (status) {
console.error('Error! --', cmd, 'exit status was', status);
process.exit(1);
} else {
exitCb();
}
});
}
// var read = fs.createReadStream(from);
// var write = fs.createWriteStream(to);
function copy(from, to, done) {
log('copying', from, 'to', to);
// read.pipe(write);
var read = fs.createReadStream(from);
var write = fs.createWriteStream(to);
// read.on('error', function (err) {
// console.error('unable to read: ' + from);
// console.error(err.message);
// process.exit(1);
// });
read.pipe(write);
// write.on('error', function (err) {
// console.error('unable to write to: ' + to);
// console.error(err.message);
// process.exit(1);
// });
read.on('error', function (err) {
console.error('unable to read: ' + from);
console.error(err.message);
process.exit(1);
});
write.on('error', function (err) {
console.error('unable to write to: ' + to);
console.error(err.message);
process.exit(1);
});
write.on('finish', function () {
done();
});
}
// write.on('finish', function () {
// done();
// });
// }

View File

@ -1,7 +1,6 @@
var _ = require('../../../src/lib/utils');
var fs = require('fs');
var templates = require('./templates');
var clean = require('../../clean');
var restSpecUpdated = require('../../rest_spec_updated');
var outputPath = _.joinPath(__dirname, '../../../src/lib/api.js');
@ -22,27 +21,28 @@ function download() {
return action.proxy ? 'proxies' : 'normal';
});
clean(outputPath);
fs.unlink(outputPath, function () {
console.log('writing', actions.length, 'api actions to', outputPath);
console.log('writing', actions.length, 'api actions to', outputPath);
fs.writeFileSync(outputPath, templates.apiFile({
actions: groups.normal,
proxies: groups.proxies,
namespaces: _.unique(namespaces.sort(), true)
}));
fs.writeFileSync(outputPath, templates.apiFile({
actions: groups.normal,
proxies: groups.proxies,
namespaces: _.unique(namespaces.sort(), true)
}));
if (!fs.existsSync(docOutputDir)) {
fs.mkdirSync(docOutputDir);
}
if (!fs.existsSync(docOutputDir)) {
fs.mkdirSync(docOutputDir);
}
fs.writeFileSync(docOutputDir + '_method_list.jade', templates.apiMethodList({
actions: actions
}));
fs.writeFileSync(docOutputDir + '_method_list.jade', templates.apiMethodList({
actions: actions
}));
fs.writeFileSync(docOutputDir + '_methods.jade', templates.apiMethods({
actions: actions
}));
fs.writeFileSync(docOutputDir + '_methods.jade', templates.apiMethods({
actions: actions
}));
});
});
}

View File

@ -6,7 +6,6 @@ var fs = require('fs');
var path = require('path');
var jsYaml = require('js-yaml');
var spec = require('../../get_spec');
var clean = require('../../clean');
var restSpecUpdated = require('../../rest_spec_updated');
var testFile = path.resolve(__dirname, '../../../test/integration/yaml_suite/yaml_tests.json');
@ -15,19 +14,20 @@ function download() {
var tests = {};
clean(testFile);
spec.get('test/**/*.yaml')
.on('entry', function (entry) {
var filename = path.relative('test', entry.path);
var file = tests[filename] = [];
jsYaml.loadAll(entry.data, function (doc) {
file.push(doc);
fs.unlink(testFile, function () {
spec.get('test/**/*.yaml')
.on('entry', function (entry) {
var filename = path.relative('test', entry.path);
var file = tests[filename] = [];
jsYaml.loadAll(entry.data, function (doc) {
file.push(doc);
});
})
.on('end', function () {
fs.writeFileSync(testFile, JSON.stringify(tests, null, ' '), 'utf8');
console.log('download yaml tests to', testFile);
});
})
.on('end', function () {
fs.writeFileSync(testFile, JSON.stringify(tests, null, ' '), 'utf8');
console.log('download yaml tests to', testFile);
});
});
}