added an export_all_client script
This commit is contained in:
103
scripts/_steps.js
Normal file
103
scripts/_steps.js
Normal 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();
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
@ -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);
|
|
||||||
}
|
|
||||||
33
scripts/export_all_clients.js
Normal file
33
scripts/export_all_clients.js
Normal 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);
|
||||||
@ -1,7 +1,4 @@
|
|||||||
var path = require('path');
|
var path = require('path');
|
||||||
var fs = require('fs');
|
|
||||||
var format = require('util').format;
|
|
||||||
var cp = require('child_process');
|
|
||||||
|
|
||||||
var argv = require('optimist')
|
var argv = require('optimist')
|
||||||
.default({
|
.default({
|
||||||
@ -34,75 +31,19 @@ default:
|
|||||||
var outputFile = path.join(argv.outputDir, 'elasticsearch.js');
|
var outputFile = path.join(argv.outputDir, 'elasticsearch.js');
|
||||||
var minifiedOutputFile = path.join(argv.outputDir, 'elasticsearch.min.js');
|
var minifiedOutputFile = path.join(argv.outputDir, 'elasticsearch.min.js');
|
||||||
|
|
||||||
var steps = [
|
require('./_steps')(argv, [
|
||||||
[runInModule, 'npm', ['run', 'build_clients']],
|
['run', {
|
||||||
[copy, buildFile, outputFile],
|
cmd: 'npm',
|
||||||
[copy, minifiedBuildFile, minifiedOutputFile]
|
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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
var path = require('path');
|
var path = require('path');
|
||||||
var fs = require('fs');
|
|
||||||
var format = require('util').format;
|
|
||||||
var cp = require('child_process');
|
|
||||||
|
|
||||||
var argv = require('optimist')
|
var argv = require('optimist')
|
||||||
.default({
|
.default({
|
||||||
@ -14,83 +11,64 @@ var argv = require('optimist')
|
|||||||
})
|
})
|
||||||
.argv;
|
.argv;
|
||||||
|
|
||||||
var steps = [
|
require('./_steps')(argv, [
|
||||||
[runInModule, 'node', [path.join(__dirname, './generate/js_api'), '--force']],
|
['runInModule', {
|
||||||
[
|
cmd: 'node',
|
||||||
copy,
|
args: [path.join(__dirname, './generate/js_api'), '--force']
|
||||||
path.join(__dirname, '../docs/_methods.jade'),
|
}],
|
||||||
path.join(argv.outputDir, '_methods.jade')
|
['copy', {
|
||||||
],
|
from: path.join(__dirname, '../docs/_methods.jade'),
|
||||||
[
|
to: path.join(argv.outputDir, '_methods.jade')
|
||||||
copy,
|
}],
|
||||||
path.join(__dirname, '../docs/_method_list.jade'),
|
['copy', {
|
||||||
path.join(argv.outputDir, '_method_list.jade')
|
from: path.join(__dirname, '../docs/_method_list.jade'),
|
||||||
]
|
to: path.join(argv.outputDir, '_method_list.jade')
|
||||||
];
|
}]
|
||||||
|
]);
|
||||||
|
|
||||||
(function next() {
|
// function runInModule(cmd, args, exitCb) {
|
||||||
var step = steps.shift();
|
// log('running', cmd, args.join(' '));
|
||||||
if (step) {
|
|
||||||
var fn = step.shift();
|
|
||||||
step.push(next);
|
|
||||||
fn.apply(null, step);
|
|
||||||
} else {
|
|
||||||
console.log('Done');
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
function log() {
|
// var proc = cp.spawn(cmd, args, {
|
||||||
var out = format.apply(console, arguments);
|
// stdio: argv.verbose ? 'inherit' : 'ignore'
|
||||||
if (argv.verbose) {
|
// });
|
||||||
out = '\n' + out + '\n';
|
|
||||||
}
|
|
||||||
console.log(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
function runInModule(cmd, args, exitCb) {
|
// proc.on('error', function (err) {
|
||||||
log('running', cmd, args.join(' '));
|
// console.error('Error! --', err.message);
|
||||||
|
// process.exit(1);
|
||||||
|
// });
|
||||||
|
|
||||||
var proc = cp.spawn(cmd, args, {
|
// proc.on('exit', function (status) {
|
||||||
stdio: argv.verbose ? 'inherit' : 'ignore'
|
// if (status) {
|
||||||
});
|
// console.error('Error! --', cmd, 'exit status was', status);
|
||||||
|
// process.exit(1);
|
||||||
|
// } else {
|
||||||
|
// exitCb();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
proc.on('error', function (err) {
|
// function copy(from, to, done) {
|
||||||
console.error('Error! --', err.message);
|
// log('copying', from, 'to', to);
|
||||||
process.exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
proc.on('exit', function (status) {
|
// var read = fs.createReadStream(from);
|
||||||
if (status) {
|
// var write = fs.createWriteStream(to);
|
||||||
console.error('Error! --', cmd, 'exit status was', status);
|
|
||||||
process.exit(1);
|
|
||||||
} else {
|
|
||||||
exitCb();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function copy(from, to, done) {
|
// read.pipe(write);
|
||||||
log('copying', from, 'to', to);
|
|
||||||
|
|
||||||
var read = fs.createReadStream(from);
|
// read.on('error', function (err) {
|
||||||
var write = fs.createWriteStream(to);
|
// 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) {
|
// write.on('finish', function () {
|
||||||
console.error('unable to read: ' + from);
|
// done();
|
||||||
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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
var _ = require('../../../src/lib/utils');
|
var _ = require('../../../src/lib/utils');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var templates = require('./templates');
|
var templates = require('./templates');
|
||||||
var clean = require('../../clean');
|
|
||||||
var restSpecUpdated = require('../../rest_spec_updated');
|
var restSpecUpdated = require('../../rest_spec_updated');
|
||||||
|
|
||||||
var outputPath = _.joinPath(__dirname, '../../../src/lib/api.js');
|
var outputPath = _.joinPath(__dirname, '../../../src/lib/api.js');
|
||||||
@ -22,27 +21,28 @@ function download() {
|
|||||||
return action.proxy ? 'proxies' : 'normal';
|
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({
|
if (!fs.existsSync(docOutputDir)) {
|
||||||
actions: groups.normal,
|
fs.mkdirSync(docOutputDir);
|
||||||
proxies: groups.proxies,
|
}
|
||||||
namespaces: _.unique(namespaces.sort(), true)
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (!fs.existsSync(docOutputDir)) {
|
fs.writeFileSync(docOutputDir + '_method_list.jade', templates.apiMethodList({
|
||||||
fs.mkdirSync(docOutputDir);
|
actions: actions
|
||||||
}
|
}));
|
||||||
|
|
||||||
fs.writeFileSync(docOutputDir + '_method_list.jade', templates.apiMethodList({
|
fs.writeFileSync(docOutputDir + '_methods.jade', templates.apiMethods({
|
||||||
actions: actions
|
actions: actions
|
||||||
}));
|
}));
|
||||||
|
|
||||||
fs.writeFileSync(docOutputDir + '_methods.jade', templates.apiMethods({
|
});
|
||||||
actions: actions
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,6 @@ var fs = require('fs');
|
|||||||
var path = require('path');
|
var path = require('path');
|
||||||
var jsYaml = require('js-yaml');
|
var jsYaml = require('js-yaml');
|
||||||
var spec = require('../../get_spec');
|
var spec = require('../../get_spec');
|
||||||
var clean = require('../../clean');
|
|
||||||
var restSpecUpdated = require('../../rest_spec_updated');
|
var restSpecUpdated = require('../../rest_spec_updated');
|
||||||
|
|
||||||
var testFile = path.resolve(__dirname, '../../../test/integration/yaml_suite/yaml_tests.json');
|
var testFile = path.resolve(__dirname, '../../../test/integration/yaml_suite/yaml_tests.json');
|
||||||
@ -15,19 +14,20 @@ function download() {
|
|||||||
|
|
||||||
var tests = {};
|
var tests = {};
|
||||||
|
|
||||||
clean(testFile);
|
fs.unlink(testFile, function () {
|
||||||
spec.get('test/**/*.yaml')
|
spec.get('test/**/*.yaml')
|
||||||
.on('entry', function (entry) {
|
.on('entry', function (entry) {
|
||||||
var filename = path.relative('test', entry.path);
|
var filename = path.relative('test', entry.path);
|
||||||
var file = tests[filename] = [];
|
var file = tests[filename] = [];
|
||||||
jsYaml.loadAll(entry.data, function (doc) {
|
jsYaml.loadAll(entry.data, function (doc) {
|
||||||
file.push(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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user