Use standard and prettier (#10)
* switch from custom eslint config to standard + prettier * fix new standard eslint violations * add editorconfig file * auto-fix all other violations * update lint yarn script * remove jshint comment
This commit is contained in:
@ -1,25 +1,40 @@
|
||||
module.exports = function (done) {
|
||||
module.exports = function(done) {
|
||||
var _ = require('lodash');
|
||||
var gruntUtils = require('../../grunt/utils');
|
||||
|
||||
var chalk = require('chalk');
|
||||
var fromRoot = _.partial(require('path').join, require('find-root')(__dirname));
|
||||
var fromRoot = _.partial(
|
||||
require('path').join,
|
||||
require('find-root')(__dirname)
|
||||
);
|
||||
var write = require('fs').writeFileSync;
|
||||
|
||||
var nodeApiIndex = fromRoot('src/lib/apis/index.js');
|
||||
var browserApiIndex = fromRoot('src/lib/apis/browser_index.js');
|
||||
|
||||
write(nodeApiIndex, require('./templates').apiIndex({
|
||||
branches: gruntUtils.branches
|
||||
}), 'utf8');
|
||||
write(
|
||||
nodeApiIndex,
|
||||
require('./templates').apiIndex({
|
||||
branches: gruntUtils.branches,
|
||||
}),
|
||||
'utf8'
|
||||
);
|
||||
|
||||
console.log(chalk.white.bold('wrote'), 'api index to', nodeApiIndex);
|
||||
|
||||
write(browserApiIndex, require('./templates').apiIndexBrowser({
|
||||
branches: gruntUtils.browserBranches
|
||||
}), 'utf8');
|
||||
write(
|
||||
browserApiIndex,
|
||||
require('./templates').apiIndexBrowser({
|
||||
branches: gruntUtils.browserBranches,
|
||||
}),
|
||||
'utf8'
|
||||
);
|
||||
|
||||
console.log(chalk.white.bold('wrote'), 'browser api index to', browserApiIndex);
|
||||
console.log(
|
||||
chalk.white.bold('wrote'),
|
||||
'browser api index to',
|
||||
browserApiIndex
|
||||
);
|
||||
|
||||
done();
|
||||
};
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
module.exports = function (done) {
|
||||
module.exports = function(done) {
|
||||
var _ = require('lodash');
|
||||
|
||||
var chalk = require('chalk');
|
||||
var fromRoot = _.partial(require('path').join, require('find-root')(__dirname));
|
||||
var fromRoot = _.partial(
|
||||
require('path').join,
|
||||
require('find-root')(__dirname)
|
||||
);
|
||||
var write = require('fs').writeFile;
|
||||
|
||||
var outputPath = fromRoot('docs/configuration.asciidoc');
|
||||
|
||||
@ -1,18 +1,26 @@
|
||||
module.exports = function (done) {
|
||||
module.exports = function(done) {
|
||||
var _ = require('lodash');
|
||||
var gruntUtils = require('../../grunt/utils');
|
||||
|
||||
var chalk = require('chalk');
|
||||
var fromRoot = _.partial(require('path').join, require('find-root')(__dirname));
|
||||
var fromRoot = _.partial(
|
||||
require('path').join,
|
||||
require('find-root')(__dirname)
|
||||
);
|
||||
var write = require('fs').writeFile;
|
||||
|
||||
var outputPath = fromRoot('docs/index.asciidoc');
|
||||
|
||||
write(outputPath, require('./templates').docsIndex({
|
||||
apiFiles: gruntUtils.stableBranches.map(function (branch) {
|
||||
return 'api_methods' + gruntUtils.branchSuffix(branch) + '.asciidoc';
|
||||
})
|
||||
}), 'utf8', done);
|
||||
write(
|
||||
outputPath,
|
||||
require('./templates').docsIndex({
|
||||
apiFiles: gruntUtils.stableBranches.map(function(branch) {
|
||||
return 'api_methods' + gruntUtils.branchSuffix(branch) + '.asciidoc';
|
||||
}),
|
||||
}),
|
||||
'utf8',
|
||||
done
|
||||
);
|
||||
|
||||
console.log(chalk.white.bold('wrote'), 'doc index to', outputPath);
|
||||
};
|
||||
|
||||
@ -2,30 +2,29 @@
|
||||
var async = require('async');
|
||||
var fs = require('fs');
|
||||
var spawn = require('../_spawn');
|
||||
var argv = require('optimist')
|
||||
.options({
|
||||
verbose: {
|
||||
alias: 'v',
|
||||
default: false,
|
||||
boolean: true
|
||||
},
|
||||
api: {
|
||||
default: true,
|
||||
boolean: true
|
||||
},
|
||||
tests: {
|
||||
default: true,
|
||||
boolean: true
|
||||
},
|
||||
update: {
|
||||
default: true,
|
||||
boolean: true
|
||||
},
|
||||
branch: {
|
||||
default: null,
|
||||
string: true
|
||||
}
|
||||
});
|
||||
var argv = require('optimist').options({
|
||||
verbose: {
|
||||
alias: 'v',
|
||||
default: false,
|
||||
boolean: true,
|
||||
},
|
||||
api: {
|
||||
default: true,
|
||||
boolean: true,
|
||||
},
|
||||
tests: {
|
||||
default: true,
|
||||
boolean: true,
|
||||
},
|
||||
update: {
|
||||
default: true,
|
||||
boolean: true,
|
||||
},
|
||||
branch: {
|
||||
default: null,
|
||||
string: true,
|
||||
},
|
||||
});
|
||||
|
||||
var path = require('path');
|
||||
var fromRoot = path.join.bind(path, require('find-root')(__dirname));
|
||||
@ -59,82 +58,101 @@ var paths = {
|
||||
docs: fromRoot('docs'),
|
||||
docsIndex: fromRoot('docs/index.asciidoc'),
|
||||
apiSrc: 'src/lib/apis',
|
||||
getArchiveDir: function (branch) {
|
||||
getArchiveDir: function(branch) {
|
||||
return fromRoot('src/_elasticsearch_' + utils.snakeCase(branch));
|
||||
},
|
||||
getArchiveTarball: function (branch) {
|
||||
getArchiveTarball: function(branch) {
|
||||
return fromRoot('src/_elasticsearch_' + utils.snakeCase(branch) + '.tar');
|
||||
},
|
||||
getSpecPathInRepo: function (branch) {
|
||||
return /^v?(master|[2-9]\.)/.test(branch) ? 'rest-api-spec/src/main/resources/rest-api-spec' : 'rest-api-spec';
|
||||
}
|
||||
getSpecPathInRepo: function(branch) {
|
||||
return /^v?(master|[2-9]\.)/.test(branch)
|
||||
? 'rest-api-spec/src/main/resources/rest-api-spec'
|
||||
: 'rest-api-spec';
|
||||
},
|
||||
};
|
||||
|
||||
function isDirectory(dir) {
|
||||
var stat;
|
||||
try { stat = fs.statSync(dir); } catch (e) {}
|
||||
return (stat && stat.isDirectory());
|
||||
try {
|
||||
stat = fs.statSync(dir);
|
||||
} catch (e) {}
|
||||
return stat && stat.isDirectory();
|
||||
}
|
||||
|
||||
function dirFilter(dir, fn) {
|
||||
try {
|
||||
return fs.readdirSync(dir)
|
||||
.filter(function (name) {
|
||||
return name !== '.' && name !== '..' && fn(name);
|
||||
})
|
||||
.map(function (filename) {
|
||||
return path.join(dir, filename);
|
||||
});
|
||||
return fs
|
||||
.readdirSync(dir)
|
||||
.filter(function(name) {
|
||||
return name !== '.' && name !== '..' && fn(name);
|
||||
})
|
||||
.map(function(filename) {
|
||||
return path.join(dir, filename);
|
||||
});
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function dirRegex(dir, regexp) {
|
||||
return dirFilter(dir, function (name) {
|
||||
return dirFilter(dir, function(name) {
|
||||
return name.match(regexp);
|
||||
});
|
||||
}
|
||||
|
||||
function dirOpts(dir, opts) {
|
||||
opts = _.isArray(opts) ? opts : [opts];
|
||||
return dirFilter(dir, function (name) {
|
||||
return dirFilter(dir, function(name) {
|
||||
return _.includes(opts, name);
|
||||
});
|
||||
}
|
||||
|
||||
function spawnStep(cmd, args, cwd) {
|
||||
return function (done) {
|
||||
spawn(cmd, args, {
|
||||
verbose: argv.verbose,
|
||||
cwd: cwd
|
||||
}, function (status) {
|
||||
done(status ? new Error('Non-zero exit code: ' + status) : void 0);
|
||||
});
|
||||
return function(done) {
|
||||
spawn(
|
||||
cmd,
|
||||
args,
|
||||
{
|
||||
verbose: argv.verbose,
|
||||
cwd: cwd,
|
||||
},
|
||||
function(status) {
|
||||
done(status ? new Error('Non-zero exit code: ' + status) : void 0);
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
function initStep() {
|
||||
return function (done) {
|
||||
return function(done) {
|
||||
if (isDirectory(paths.esSrc)) {
|
||||
async.series([
|
||||
spawnStep('git', ['remote', 'set-url', 'origin', esUrl], paths.esSrc)
|
||||
], done);
|
||||
async.series(
|
||||
[spawnStep('git', ['remote', 'set-url', 'origin', esUrl], paths.esSrc)],
|
||||
done
|
||||
);
|
||||
} else {
|
||||
async.series([
|
||||
spawnStep('git', ['init', '--bare', paths.esSrc], paths.root),
|
||||
spawnStep('git', ['remote', 'add', 'origin', esUrl], paths.esSrc)
|
||||
], done);
|
||||
async.series(
|
||||
[
|
||||
spawnStep('git', ['init', '--bare', paths.esSrc], paths.root),
|
||||
spawnStep('git', ['remote', 'add', 'origin', esUrl], paths.esSrc),
|
||||
],
|
||||
done
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function fetchBranchesStep() {
|
||||
var branchArgs = branches.map(function (b) { return b + ':' + b; });
|
||||
return spawnStep('git', ['fetch', '--no-tags', '--force', 'origin'].concat(branchArgs), paths.esSrc);
|
||||
var branchArgs = branches.map(function(b) {
|
||||
return b + ':' + b;
|
||||
});
|
||||
return spawnStep(
|
||||
'git',
|
||||
['fetch', '--no-tags', '--force', 'origin'].concat(branchArgs),
|
||||
paths.esSrc
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function findGeneratedApiFiles() {
|
||||
var anyApiMethodDocs = /^(configuration|index|api_methods).*\.asciidoc$/;
|
||||
var anyApiJsFiled = /^.+\.js$/;
|
||||
@ -143,11 +161,11 @@ function findGeneratedApiFiles() {
|
||||
if (allBranches) {
|
||||
return [
|
||||
dirRegex(paths.docs, anyApiMethodDocs),
|
||||
dirRegex(paths.apiSrc, anyApiJsFiled)
|
||||
dirRegex(paths.apiSrc, anyApiJsFiled),
|
||||
];
|
||||
}
|
||||
|
||||
return branches.reduce(function (files, branch) {
|
||||
return branches.reduce(function(files, branch) {
|
||||
var b = utils.snakeCase(branch);
|
||||
|
||||
files.push(dirOpts(paths.docs, 'api_methods_' + b + '.asciidoc'));
|
||||
@ -163,7 +181,6 @@ function findGeneratedApiFiles() {
|
||||
}, []);
|
||||
}
|
||||
|
||||
|
||||
function clearGeneratedFiles() {
|
||||
var esArchives = /^_elasticsearch_(master|[\dx_]+|\.tar)$/;
|
||||
var generatedFiles = [];
|
||||
@ -175,16 +192,16 @@ function clearGeneratedFiles() {
|
||||
generatedFiles.push(dirRegex(paths.src, esArchives));
|
||||
|
||||
var rmSteps = _.chain(generatedFiles)
|
||||
.flattenDeep()
|
||||
.uniq()
|
||||
.map(function (path) {
|
||||
return spawnStep('rm', ['-rf', path]);
|
||||
})
|
||||
.value();
|
||||
.flattenDeep()
|
||||
.uniq()
|
||||
.map(function(path) {
|
||||
return spawnStep('rm', ['-rf', path]);
|
||||
})
|
||||
.value();
|
||||
|
||||
if (!rmSteps.length) return;
|
||||
|
||||
return function (done) {
|
||||
return function(done) {
|
||||
return async.series(rmSteps, done);
|
||||
};
|
||||
}
|
||||
@ -199,7 +216,7 @@ function removePrevArchive(branch) {
|
||||
}
|
||||
|
||||
function createArchive(branch) {
|
||||
return function (done) {
|
||||
return function(done) {
|
||||
var dir = paths.getArchiveDir(branch);
|
||||
var tarball = paths.getArchiveTarball(branch);
|
||||
var specPathInRepo = paths.getSpecPathInRepo(branch);
|
||||
@ -210,36 +227,65 @@ function createArchive(branch) {
|
||||
return process.nextTick(done);
|
||||
}
|
||||
|
||||
async.series([
|
||||
spawnStep('mkdir', [dir], paths.root),
|
||||
spawnStep('git', ['archive', '--format', 'tar', '--output', tarball, branch, specPathInRepo], paths.esSrc),
|
||||
spawnStep('tar', ['-x', '-f', tarball, '-C', dir, '--strip-components', subDirCount]),
|
||||
spawnStep('rm', [tarball])
|
||||
], done);
|
||||
async.series(
|
||||
[
|
||||
spawnStep('mkdir', [dir], paths.root),
|
||||
spawnStep(
|
||||
'git',
|
||||
[
|
||||
'archive',
|
||||
'--format',
|
||||
'tar',
|
||||
'--output',
|
||||
tarball,
|
||||
branch,
|
||||
specPathInRepo,
|
||||
],
|
||||
paths.esSrc
|
||||
),
|
||||
spawnStep('tar', [
|
||||
'-x',
|
||||
'-f',
|
||||
tarball,
|
||||
'-C',
|
||||
dir,
|
||||
'--strip-components',
|
||||
subDirCount,
|
||||
]),
|
||||
spawnStep('rm', [tarball]),
|
||||
],
|
||||
done
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
function generateStep(branch) {
|
||||
return function (done) {
|
||||
async.parallel([
|
||||
argv.api && async.apply(require('./js_api'), branch),
|
||||
argv.tests && async.apply(require('./yaml_tests'), branch)
|
||||
].filter(Boolean), done);
|
||||
return function(done) {
|
||||
async.parallel(
|
||||
[
|
||||
argv.api && async.apply(require('./js_api'), branch),
|
||||
argv.tests && async.apply(require('./yaml_tests'), branch),
|
||||
].filter(Boolean),
|
||||
done
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
var steps = [
|
||||
initStep(),
|
||||
clearGeneratedFiles(),
|
||||
fetchBranchesStep()
|
||||
].filter(Boolean);
|
||||
var steps = [initStep(), clearGeneratedFiles(), fetchBranchesStep()].filter(
|
||||
Boolean
|
||||
);
|
||||
|
||||
branches.forEach(function (branch) {
|
||||
steps.push(_.partial(async.series, [
|
||||
removePrevArchive(branch),
|
||||
createArchive(branch),
|
||||
generateStep(branch)
|
||||
].filter(Boolean)));
|
||||
branches.forEach(function(branch) {
|
||||
steps.push(
|
||||
_.partial(
|
||||
async.series,
|
||||
[
|
||||
removePrevArchive(branch),
|
||||
createArchive(branch),
|
||||
generateStep(branch),
|
||||
].filter(Boolean)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
if (argv.api) {
|
||||
@ -251,15 +297,15 @@ if (argv.api) {
|
||||
}
|
||||
|
||||
async.series(
|
||||
steps.map(function (step) {
|
||||
return function (done) {
|
||||
step(function (err) {
|
||||
steps.map(function(step) {
|
||||
return function(done) {
|
||||
step(function(err) {
|
||||
console.log('----\n');
|
||||
done(err);
|
||||
});
|
||||
};
|
||||
}),
|
||||
function (err) {
|
||||
function(err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = function (branch, done) {
|
||||
module.exports = function(branch, done) {
|
||||
/**
|
||||
* Read the API actions form the rest-api-spec repo.
|
||||
* @type {[type]}
|
||||
@ -34,32 +34,29 @@ module.exports = function (branch, done) {
|
||||
|
||||
var steps = [
|
||||
readSpecFiles,
|
||||
function (done) {
|
||||
function(done) {
|
||||
parseSpecFiles(branch, done);
|
||||
},
|
||||
writeApiFile
|
||||
writeApiFile,
|
||||
];
|
||||
|
||||
if (!~gruntUtils.unstableBranches.indexOf(branch)) {
|
||||
steps.push(
|
||||
ensureDocsDir,
|
||||
formatDocVars,
|
||||
writeMethodDocs
|
||||
);
|
||||
steps.push(ensureDocsDir, formatDocVars, writeMethodDocs);
|
||||
}
|
||||
|
||||
// generate the API
|
||||
async.series(steps, function (err) {
|
||||
async.series(steps, function(err) {
|
||||
done(err);
|
||||
});
|
||||
|
||||
function readSpecFiles(done) {
|
||||
var apiDir = path.join(esDir, 'rest-api-spec/api/');
|
||||
files = fs.readdirSync(apiDir)
|
||||
.filter(function (filename) {
|
||||
return filename[0] !== '_'
|
||||
files = fs
|
||||
.readdirSync(apiDir)
|
||||
.filter(function(filename) {
|
||||
return filename[0] !== '_';
|
||||
})
|
||||
.map(function (filename) {
|
||||
.map(function(filename) {
|
||||
var module = require(apiDir + filename);
|
||||
delete require.cache[apiDir + filename];
|
||||
return module;
|
||||
@ -70,23 +67,25 @@ module.exports = function (branch, done) {
|
||||
function parseSpecFiles(branch, done) {
|
||||
var actions = [];
|
||||
|
||||
files.forEach(function (spec) {
|
||||
__puke__transformSpec(branch, spec).forEach(function (action) {
|
||||
files.forEach(function(spec) {
|
||||
__puke__transformSpec(branch, spec).forEach(function(action) {
|
||||
actions.push(action);
|
||||
});
|
||||
});
|
||||
|
||||
// collect the namespaces from the action locations
|
||||
var namespaces = _.filter(_.map(actions, function (action) {
|
||||
return action.location
|
||||
.split('.')
|
||||
.slice(0, -1)
|
||||
.filter(step => step !== 'prototype')
|
||||
.join('.prototype.')
|
||||
}));
|
||||
var namespaces = _.filter(
|
||||
_.map(actions, function(action) {
|
||||
return action.location
|
||||
.split('.')
|
||||
.slice(0, -1)
|
||||
.filter(step => step !== 'prototype')
|
||||
.join('.prototype.');
|
||||
})
|
||||
);
|
||||
|
||||
// seperate the proxy actions
|
||||
var groups = _.groupBy(actions, function (action) {
|
||||
var groups = _.groupBy(actions, function(action) {
|
||||
return action.proxy ? 'proxies' : 'normal';
|
||||
});
|
||||
|
||||
@ -94,7 +93,7 @@ module.exports = function (branch, done) {
|
||||
actions: groups.normal || [],
|
||||
proxies: groups.proxies || [],
|
||||
namespaces: _.uniq(namespaces.sort()),
|
||||
clientActionModifier: overrides.clientActionModifier
|
||||
clientActionModifier: overrides.clientActionModifier,
|
||||
};
|
||||
|
||||
if (!_.find(apiSpec.actions, { name: 'create' })) {
|
||||
@ -105,7 +104,7 @@ module.exports = function (branch, done) {
|
||||
name: 'create',
|
||||
location: 'create',
|
||||
proxy: 'index',
|
||||
transformBody: 'params.op_type = \'create\';'
|
||||
transformBody: "params.op_type = 'create';",
|
||||
}
|
||||
);
|
||||
|
||||
@ -116,36 +115,50 @@ module.exports = function (branch, done) {
|
||||
apiSpec.proxies.push(create);
|
||||
}
|
||||
|
||||
[].concat(apiSpec.actions, apiSpec.proxies)
|
||||
.forEach(function (action) {
|
||||
var examplePath = overrides.examples[action.name] || action.name + '.asciidoc';
|
||||
var descriptionPath = overrides.descriptions[action.name] || action.name + '.asciidoc';
|
||||
[].concat(apiSpec.actions, apiSpec.proxies).forEach(function(action) {
|
||||
var examplePath =
|
||||
overrides.examples[action.name] || action.name + '.asciidoc';
|
||||
var descriptionPath =
|
||||
overrides.descriptions[action.name] || action.name + '.asciidoc';
|
||||
|
||||
try {
|
||||
action.examples = fs.readFileSync(fromRoot('docs/_examples', examplePath), 'utf8');
|
||||
action.examples = fs.readFileSync(
|
||||
fromRoot('docs/_examples', examplePath),
|
||||
'utf8'
|
||||
);
|
||||
} catch (e) {
|
||||
action.examples = '// no examples';
|
||||
}
|
||||
|
||||
try {
|
||||
action.description = fs.readFileSync(fromRoot('docs/_descriptions', descriptionPath), 'utf8');
|
||||
action.description = fs.readFileSync(
|
||||
fromRoot('docs/_descriptions', descriptionPath),
|
||||
'utf8'
|
||||
);
|
||||
} catch (e) {
|
||||
action.description = '// no description';
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
done();
|
||||
}
|
||||
|
||||
function writeApiFile(done) {
|
||||
var outputPath = fromRoot('src/lib/apis/' + utils.snakeCase(branch) + '.js');
|
||||
var outputPath = fromRoot(
|
||||
'src/lib/apis/' + utils.snakeCase(branch) + '.js'
|
||||
);
|
||||
fs.writeFileSync(outputPath, templates.apiFile(apiSpec));
|
||||
console.log(chalk.white.bold('wrote'), apiSpec.actions.length, 'api actions to', outputPath);
|
||||
console.log(
|
||||
chalk.white.bold('wrote'),
|
||||
apiSpec.actions.length,
|
||||
'api actions to',
|
||||
outputPath
|
||||
);
|
||||
done();
|
||||
}
|
||||
|
||||
function ensureDocsDir(done) {
|
||||
fs.stat(fromRoot('docs'), function (err, stat) {
|
||||
fs.stat(fromRoot('docs'), function(err, stat) {
|
||||
if (err) {
|
||||
if (err.message.match(/enoent/i)) {
|
||||
fs.mkdir('../../docs', done);
|
||||
@ -177,34 +190,37 @@ module.exports = function (branch, done) {
|
||||
|
||||
function writeMethodDocs(done) {
|
||||
var filename = fromRoot('docs/api_methods' + branchSuffix + '.asciidoc');
|
||||
fs.writeFile(
|
||||
filename,
|
||||
templates.apiMethods(docVars),
|
||||
function (err) {
|
||||
if (!err) {
|
||||
console.log(chalk.white.bold('wrote'), branch + ' method docs to', filename);
|
||||
}
|
||||
done(err);
|
||||
fs.writeFile(filename, templates.apiMethods(docVars), function(err) {
|
||||
if (!err) {
|
||||
console.log(
|
||||
chalk.white.bold('wrote'),
|
||||
branch + ' method docs to',
|
||||
filename
|
||||
);
|
||||
}
|
||||
);
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
|
||||
function __puke__transformSpec(branch, spec) { // eslint-disable-line
|
||||
var actions = [];
|
||||
|
||||
// itterate all of the specs within the file, should only be one
|
||||
_.each(spec, function (def, name) {
|
||||
_.each(spec, function(def, name) {
|
||||
// camelcase the name
|
||||
name = _.map(name.split('.'), utils.camelCase).join('.');
|
||||
|
||||
if (name === 'cat.aliases') {
|
||||
def.documentation = 'http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat.html';
|
||||
def.documentation =
|
||||
'http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/cat.html';
|
||||
}
|
||||
|
||||
def.documentation = def.documentation ? def.documentation.replace(
|
||||
/^https?:\/\/.+?\/guide\/en\/elasticsearch\/(.+?)\/.+?\//,
|
||||
`https://www.elastic.co/guide/en/elasticsearch/$1/${branch}/`
|
||||
) : '';
|
||||
def.documentation = def.documentation
|
||||
? def.documentation.replace(
|
||||
/^https?:\/\/.+?\/guide\/en\/elasticsearch\/(.+?)\/.+?\//,
|
||||
`https://www.elastic.co/guide/en/elasticsearch/$1/${branch}/`
|
||||
)
|
||||
: '';
|
||||
|
||||
var steps = name.split('.');
|
||||
|
||||
@ -222,27 +238,36 @@ module.exports = function (branch, done) {
|
||||
|
||||
var allParams = _.extend({}, def.url.params, def.url.parts);
|
||||
_.forOwn(allParams, (paramSpec, paramName) => {
|
||||
const toMerge = _.get(overrides, ['mergeConcatParams', name, paramName])
|
||||
const toMerge = _.get(overrides, [
|
||||
'mergeConcatParams',
|
||||
name,
|
||||
paramName,
|
||||
]);
|
||||
if (toMerge) {
|
||||
_.mergeWith(paramSpec, toMerge, (dest, src) => {
|
||||
if (_.isArray(dest) && _.isArray(src)) {
|
||||
return dest.concat(src)
|
||||
return dest.concat(src);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
if (paramSpec.options) {
|
||||
const invalidOpts = paramSpec.options.some(opt => typeof opt !== 'string')
|
||||
if (invalidOpts) throw new Error(`${name} has options that are not strings...`)
|
||||
const invalidOpts = paramSpec.options.some(
|
||||
opt => typeof opt !== 'string'
|
||||
);
|
||||
if (invalidOpts)
|
||||
throw new Error(`${name} has options that are not strings...`);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
var spec = {
|
||||
name: name,
|
||||
methods: _.map(def.methods, function (m) { return m.toUpperCase(); }),
|
||||
methods: _.map(def.methods, function(m) {
|
||||
return m.toUpperCase();
|
||||
}),
|
||||
params: def.url.params,
|
||||
body: def.body || null,
|
||||
path2lib: utils.repeat('../', steps.length + 1) + 'lib/'
|
||||
path2lib: utils.repeat('../', steps.length + 1) + 'lib/',
|
||||
};
|
||||
|
||||
if (def.body && def.body.required) {
|
||||
@ -255,63 +280,83 @@ module.exports = function (branch, done) {
|
||||
|
||||
var urls = _.difference(def.url.paths, overrides.aliases[name]);
|
||||
var urlSignatures = [];
|
||||
urls = _.map(urls, function (url) {
|
||||
urls = _.map(urls, function(url) {
|
||||
var optionalVars = {};
|
||||
var requiredVars = {};
|
||||
var param;
|
||||
var name;
|
||||
var target;
|
||||
var match;
|
||||
|
||||
if (url.charAt(0) !== '/') {
|
||||
url = '/' + url;
|
||||
}
|
||||
|
||||
while (match = urlParamRE.exec(url)) {
|
||||
while (true) {
|
||||
const match = urlParamRE.exec(url);
|
||||
if (!match) {
|
||||
break;
|
||||
}
|
||||
|
||||
name = utils.camelCase(match[1]);
|
||||
param = def.url.parts[name] || {};
|
||||
target = (param.required || !param.default) ? requiredVars : optionalVars;
|
||||
target =
|
||||
param.required || !param.default ? requiredVars : optionalVars;
|
||||
target[name] = _.omit(param, ['required', 'description', 'name']);
|
||||
}
|
||||
|
||||
urlSignatures.push(_.union(_.keys(optionalVars), _.keys(requiredVars)).sort().join(':'));
|
||||
urlSignatures.push(
|
||||
_.union(_.keys(optionalVars), _.keys(requiredVars))
|
||||
.sort()
|
||||
.join(':')
|
||||
);
|
||||
|
||||
return _.omitBy({
|
||||
fmt: url.replace(urlParamRE, function (full, match) {
|
||||
return '<%=' + utils.camelCase(match) + '%>';
|
||||
}),
|
||||
opt: _.size(optionalVars) ? optionalVars : null,
|
||||
req: _.size(requiredVars) ? requiredVars : null,
|
||||
sortOrder: _.size(requiredVars) * -1
|
||||
}, function (v) {
|
||||
return !v;
|
||||
});
|
||||
return _.omitBy(
|
||||
{
|
||||
fmt: url.replace(urlParamRE, function(full, match) {
|
||||
return '<%=' + utils.camelCase(match) + '%>';
|
||||
}),
|
||||
opt: _.size(optionalVars) ? optionalVars : null,
|
||||
req: _.size(requiredVars) ? requiredVars : null,
|
||||
sortOrder: _.size(requiredVars) * -1,
|
||||
},
|
||||
function(v) {
|
||||
return !v;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (urlSignatures.length !== _.uniq(urlSignatures).length) {
|
||||
throw new Error(
|
||||
'Multiple URLS with the same signature detected for ' +
|
||||
spec.name +
|
||||
'\n' +
|
||||
_.map(urls, 'fmt').join('\n') +
|
||||
'\n'
|
||||
spec.name +
|
||||
'\n' +
|
||||
_.map(urls, 'fmt').join('\n') +
|
||||
'\n'
|
||||
);
|
||||
}
|
||||
|
||||
if (urls.length > 1) {
|
||||
spec.urls = _.map(_.sortBy(urls, 'sortOrder'), function (url) {
|
||||
spec.urls = _.map(_.sortBy(urls, 'sortOrder'), function(url) {
|
||||
return _.omit(url, 'sortOrder');
|
||||
});
|
||||
} else {
|
||||
spec.url = _.omit(urls[0], 'sortOrder');
|
||||
}
|
||||
|
||||
spec.params = _.transform(spec.params, function (note, param, name) {
|
||||
// param.name = name;
|
||||
note[name] = _.pick(param, [
|
||||
'type', 'default', 'options', 'required', 'name'
|
||||
]);
|
||||
}, {});
|
||||
spec.params = _.transform(
|
||||
spec.params,
|
||||
function(note, param, name) {
|
||||
// param.name = name;
|
||||
note[name] = _.pick(param, [
|
||||
'type',
|
||||
'default',
|
||||
'options',
|
||||
'required',
|
||||
'name',
|
||||
]);
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
if (overrides.paramAsBody[name]) {
|
||||
spec.paramAsBody = overrides.paramAsBody[name];
|
||||
@ -322,8 +367,10 @@ module.exports = function (branch, done) {
|
||||
}
|
||||
|
||||
// escape method names with "special" keywords
|
||||
var location = spec.name.split('.').join('.prototype.')
|
||||
.replace(/(^|\.)(delete|default)(\.|$)/g, '[\'$2\']');
|
||||
var location = spec.name
|
||||
.split('.')
|
||||
.join('.prototype.')
|
||||
.replace(/(^|\.)(delete|default)(\.|$)/g, "['$2']");
|
||||
|
||||
var action = {
|
||||
_methods: spec.methods,
|
||||
@ -334,13 +381,16 @@ module.exports = function (branch, done) {
|
||||
'needBody',
|
||||
'requestTimeout',
|
||||
'bulkBody',
|
||||
'paramAsBody'
|
||||
'paramAsBody',
|
||||
]),
|
||||
location: location,
|
||||
docUrl: def.documentation,
|
||||
name: spec.name,
|
||||
namespace: spec.name.split('.').slice(0, -1).join('.'),
|
||||
allParams: allParams
|
||||
namespace: spec.name
|
||||
.split('.')
|
||||
.slice(0, -1)
|
||||
.join('.'),
|
||||
allParams: allParams,
|
||||
};
|
||||
|
||||
function hasMethod(/* ...methods */) {
|
||||
@ -354,7 +404,10 @@ module.exports = function (branch, done) {
|
||||
return true;
|
||||
}
|
||||
function methodsAre(/* ...methods */) {
|
||||
return hasMethod.apply(null, arguments) && arguments.length === action._methods.length;
|
||||
return (
|
||||
hasMethod.apply(null, arguments) &&
|
||||
arguments.length === action._methods.length
|
||||
);
|
||||
}
|
||||
|
||||
var method;
|
||||
@ -365,17 +418,13 @@ module.exports = function (branch, done) {
|
||||
// we need to define what the default method(s) will be
|
||||
if (hasMethod('DELETE', 'POST')) {
|
||||
method = 'POST';
|
||||
}
|
||||
else if (methodsAre('DELETE')) {
|
||||
} else if (methodsAre('DELETE')) {
|
||||
method = 'DELETE';
|
||||
}
|
||||
else if (methodsAre('POST', 'PUT')) {
|
||||
} else if (methodsAre('POST', 'PUT')) {
|
||||
method = action.name.match(/put/i) ? 'PUT' : 'POST';
|
||||
}
|
||||
else if (methodsAre('GET', 'POST')) {
|
||||
} else if (methodsAre('GET', 'POST')) {
|
||||
method = 'POST';
|
||||
}
|
||||
else if (methodsAre('GET', 'HEAD')) {
|
||||
} else if (methodsAre('GET', 'HEAD')) {
|
||||
method = 'GET';
|
||||
}
|
||||
}
|
||||
@ -385,7 +434,9 @@ module.exports = function (branch, done) {
|
||||
action.spec.method = method;
|
||||
}
|
||||
} else {
|
||||
throw new Error('unable to pick a method for ' + JSON.stringify(action, null, ' '));
|
||||
throw new Error(
|
||||
'unable to pick a method for ' + JSON.stringify(action, null, ' ')
|
||||
);
|
||||
}
|
||||
|
||||
actions.push(action);
|
||||
|
||||
@ -4,7 +4,7 @@ module.exports = [
|
||||
paramAsBody: {
|
||||
scroll: 'scrollId',
|
||||
clearScroll: 'scrollId',
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
version: '0.90.x',
|
||||
@ -15,7 +15,7 @@ module.exports = [
|
||||
'/_nodes/hot_threads',
|
||||
'/_cluster/nodes/{node_id}/hotthreads',
|
||||
'/_cluster/nodes/{node_id}/hot_threads',
|
||||
'/_nodes/{node_id}/hot_threads'
|
||||
'/_nodes/{node_id}/hot_threads',
|
||||
],
|
||||
'cluster.nodeInfo': [
|
||||
'/_cluster/nodes',
|
||||
@ -37,25 +37,19 @@ module.exports = [
|
||||
'/_nodes/{node_id}/network',
|
||||
'/_nodes/{node_id}/transport',
|
||||
'/_nodes/{node_id}/http',
|
||||
'/_nodes/{node_id}/plugin'
|
||||
],
|
||||
'cluster.nodeShutdown': [
|
||||
'/_cluster/nodes/_shutdown'
|
||||
'/_nodes/{node_id}/plugin',
|
||||
],
|
||||
'cluster.nodeShutdown': ['/_cluster/nodes/_shutdown'],
|
||||
'cluster.nodeStats': [
|
||||
'/_cluster/nodes/stats',
|
||||
'/_nodes/stats/{metric_family}',
|
||||
'/_nodes/stats/indices/{metric}/{fields}',
|
||||
'/_cluster/nodes/{node_id}/stats',
|
||||
'/_nodes/{node_id}/stats/{metric_family}',
|
||||
'/_nodes/{node_id}/stats/indices/{metric}/{fields}'
|
||||
],
|
||||
'get': [
|
||||
'/{index}/{type}/{id}/_source'
|
||||
],
|
||||
'indices.deleteMapping': [
|
||||
'/{index}/{type}/_mapping'
|
||||
'/_nodes/{node_id}/stats/indices/{metric}/{fields}',
|
||||
],
|
||||
get: ['/{index}/{type}/{id}/_source'],
|
||||
'indices.deleteMapping': ['/{index}/{type}/_mapping'],
|
||||
'indices.stats': [
|
||||
'_stats/{metric_family}',
|
||||
'/_stats/indexing',
|
||||
@ -65,9 +59,9 @@ module.exports = [
|
||||
'/{index}/_stats/{metric_family}',
|
||||
'/{index}/_stats/indexing',
|
||||
'/{index}/_stats/search/{search_groups}',
|
||||
'/{index}/_stats/fielddata/{fields}'
|
||||
]
|
||||
}
|
||||
'/{index}/_stats/fielddata/{fields}',
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
version: '>=1.0.0',
|
||||
@ -78,7 +72,7 @@ module.exports = [
|
||||
'/_nodes/hot_threads',
|
||||
'/_cluster/nodes/{node_id}/hotthreads',
|
||||
'/_cluster/nodes/{node_id}/hot_threads',
|
||||
'/_nodes/{node_id}/hot_threads'
|
||||
'/_nodes/{node_id}/hot_threads',
|
||||
],
|
||||
'nodes.info': [
|
||||
'/_cluster/nodes',
|
||||
@ -100,27 +94,23 @@ module.exports = [
|
||||
'/_nodes/{node_id}/network',
|
||||
'/_nodes/{node_id}/transport',
|
||||
'/_nodes/{node_id}/http',
|
||||
'/_nodes/{node_id}/plugin'
|
||||
],
|
||||
'nodes.shutdown': [
|
||||
'/_cluster/nodes/_shutdown'
|
||||
'/_nodes/{node_id}/plugin',
|
||||
],
|
||||
'nodes.shutdown': ['/_cluster/nodes/_shutdown'],
|
||||
'nodes.stats': [
|
||||
'/_cluster/nodes/stats',
|
||||
'/_nodes/stats/{metric_family}',
|
||||
'/_nodes/stats/indices/{metric}/{fields}',
|
||||
'/_cluster/nodes/{node_id}/stats',
|
||||
'/_nodes/{node_id}/stats/{metric_family}',
|
||||
'/_nodes/{node_id}/stats/indices/{metric}/{fields}'
|
||||
],
|
||||
'get': [
|
||||
'/{index}/{type}/{id}/_source'
|
||||
'/_nodes/{node_id}/stats/indices/{metric}/{fields}',
|
||||
],
|
||||
get: ['/{index}/{type}/{id}/_source'],
|
||||
'indices.deleteMapping': [
|
||||
'/{index}/{type}',
|
||||
'/{index}/_mapping/{type}',
|
||||
'/{index}/{type}/_mappings',
|
||||
'/{index}/_mappings/{type}'
|
||||
'/{index}/_mappings/{type}',
|
||||
],
|
||||
'indices.putWarmer': [
|
||||
// '/_warmer/{name}',
|
||||
@ -128,23 +118,23 @@ module.exports = [
|
||||
// '/{index}/{type}/_warmer/{name}',
|
||||
'/_warmers/{name}',
|
||||
'/{index}/_warmers/{name}',
|
||||
'/{index}/{type}/_warmers/{name}'
|
||||
'/{index}/{type}/_warmers/{name}',
|
||||
],
|
||||
'indices.deleteWarmer': [
|
||||
// '/{index}/_warmer/{name}',
|
||||
'/{index}/_warmer',
|
||||
'/{index}/_warmers',
|
||||
'/{index}/_warmers/{name}'
|
||||
'/{index}/_warmers/{name}',
|
||||
],
|
||||
'indices.deleteAlias': [
|
||||
// '/{index}/_alias/{name}',
|
||||
'/{index}/_aliases/{name}'
|
||||
'/{index}/_aliases/{name}',
|
||||
],
|
||||
'indices.putAlias': [
|
||||
// '/{index}/_alias/{name}',
|
||||
// '/_alias/{name}',
|
||||
'/{index}/_aliases/{name}',
|
||||
'/_aliases/{name}'
|
||||
'/_aliases/{name}',
|
||||
],
|
||||
'indices.putMapping': [
|
||||
// '/{index}/_mapping/{type}',
|
||||
@ -154,7 +144,7 @@ module.exports = [
|
||||
'/{index}/{type}/_mappings',
|
||||
'/{index}/_mappings/{type}',
|
||||
'/{index}/_mappings',
|
||||
'/_mappings/{type}'
|
||||
'/_mappings/{type}',
|
||||
],
|
||||
'indices.stats': [
|
||||
'_stats/{metric_family}',
|
||||
@ -165,31 +155,29 @@ module.exports = [
|
||||
'/{index}/_stats/{metric_family}',
|
||||
'/{index}/_stats/indexing',
|
||||
'/{index}/_stats/search/{search_groups}',
|
||||
'/{index}/_stats/fielddata/{fields}'
|
||||
]
|
||||
}
|
||||
'/{index}/_stats/fielddata/{fields}',
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
version: '>1.4.0',
|
||||
aliases: {
|
||||
'indices.putAlias': [
|
||||
// '/{index}/_alias/{name}',
|
||||
'/{index}/_aliases/{name}'
|
||||
]
|
||||
}
|
||||
'/{index}/_aliases/{name}',
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
version: '<1.6.0',
|
||||
aliases: {
|
||||
'snapshot.create': [
|
||||
'/_snapshot/{repository}/{snapshot}'
|
||||
]
|
||||
}
|
||||
'snapshot.create': ['/_snapshot/{repository}/{snapshot}'],
|
||||
},
|
||||
},
|
||||
{
|
||||
version: '>=1.6.0',
|
||||
|
||||
// strange indentation makes pretty api files
|
||||
// strange indentation makes pretty api files
|
||||
/* eslint-disable */
|
||||
clientActionModifier:
|
||||
function (spec) {
|
||||
@ -202,95 +190,92 @@ function (spec) {
|
||||
}
|
||||
});
|
||||
}
|
||||
/* eslint-enable */
|
||||
|
||||
/* eslint-enable */
|
||||
},
|
||||
{
|
||||
version: '>=2.0.0',
|
||||
aliases: {
|
||||
'reindex.rethrottle': [
|
||||
'/_update_by_query/{task_id}/_rethrottle',
|
||||
'/_delete_by_query/{task_id}/_rethrottle'
|
||||
'/_delete_by_query/{task_id}/_rethrottle',
|
||||
],
|
||||
'reindexRethrottle': [
|
||||
'/_update_by_query/{task_id}/_rethrottle'
|
||||
]
|
||||
}
|
||||
reindexRethrottle: ['/_update_by_query/{task_id}/_rethrottle'],
|
||||
},
|
||||
},
|
||||
{
|
||||
version: '>=5.0.0',
|
||||
mergeConcatParams: {
|
||||
bulk: {
|
||||
refresh: {
|
||||
options: ['']
|
||||
}
|
||||
options: [''],
|
||||
},
|
||||
},
|
||||
create: {
|
||||
refresh: {
|
||||
options: ['']
|
||||
}
|
||||
options: [''],
|
||||
},
|
||||
},
|
||||
index: {
|
||||
refresh: {
|
||||
options: ['']
|
||||
}
|
||||
options: [''],
|
||||
},
|
||||
},
|
||||
update: {
|
||||
refresh: {
|
||||
options: ['']
|
||||
}
|
||||
options: [''],
|
||||
},
|
||||
},
|
||||
delete: {
|
||||
refresh: {
|
||||
options: ['']
|
||||
}
|
||||
}
|
||||
options: [''],
|
||||
},
|
||||
},
|
||||
},
|
||||
aliases: {
|
||||
'reindexRethrottle': [
|
||||
reindexRethrottle: [
|
||||
'/_update_by_query/{task_id}/_rethrottle',
|
||||
'/_delete_by_query/{task_id}/_rethrottle'
|
||||
]
|
||||
}
|
||||
'/_delete_by_query/{task_id}/_rethrottle',
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
version: '>=2.0',
|
||||
paramAsBody: {
|
||||
scroll: {
|
||||
param: 'scrollId',
|
||||
body: 'scroll_id'
|
||||
body: 'scroll_id',
|
||||
},
|
||||
clearScroll: {
|
||||
param: 'scrollId',
|
||||
body: 'scroll_id'
|
||||
}
|
||||
}
|
||||
body: 'scroll_id',
|
||||
},
|
||||
},
|
||||
},
|
||||
// description overrides by major version
|
||||
{
|
||||
version: '0.90.x',
|
||||
descriptions: {
|
||||
search: 'search_1.x.asciidoc'
|
||||
}
|
||||
search: 'search_1.x.asciidoc',
|
||||
},
|
||||
},
|
||||
{
|
||||
version: '1.x',
|
||||
descriptions: {
|
||||
search: 'search_1.x.asciidoc'
|
||||
}
|
||||
search: 'search_1.x.asciidoc',
|
||||
},
|
||||
},
|
||||
{
|
||||
version: '2.x',
|
||||
descriptions: {
|
||||
search: 'search_2.x.asciidoc'
|
||||
}
|
||||
search: 'search_2.x.asciidoc',
|
||||
},
|
||||
},
|
||||
// examples changed at 5.0
|
||||
{
|
||||
version: '<5.0.0',
|
||||
examples: {
|
||||
scroll: 'scroll_<5.0.asciidoc'
|
||||
}
|
||||
scroll: 'scroll_<5.0.asciidoc',
|
||||
},
|
||||
},
|
||||
{
|
||||
version: '>=5.2 <5.5',
|
||||
@ -299,7 +284,7 @@ function (spec) {
|
||||
param: 'scrollId',
|
||||
body: 'scroll_id',
|
||||
castToArray: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
|
||||
var _ = require('lodash');
|
||||
var utils = require('../../../src/lib/utils');
|
||||
var gruntUtils = require('../../../grunt/utils');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
|
||||
/**
|
||||
* we want strings in code to use single-quotes, so this will JSON encode vars, but then
|
||||
* modify them to follow our code standards.
|
||||
@ -14,18 +12,20 @@ var path = require('path');
|
||||
* @return {String} - our pretty string
|
||||
*/
|
||||
function stringify(thing, pretty) {
|
||||
return (pretty ? JSON.stringify(thing, null, ' ') : JSON.stringify(thing))
|
||||
.replace(/'/g, '\\\'')
|
||||
.replace(/\\?"/g, function (quote) {
|
||||
// replace external (unescaped) double quotes with single quotes
|
||||
return quote === '\\"' ? '"' : '\'';
|
||||
})
|
||||
// inject a space between STRING array parts
|
||||
.replace(/([^\\])','/g, '$1\', \'')
|
||||
// remove quotes around key names that are only made up of letters
|
||||
.replace(/^( +)'([a-zA-Z_]+)':/gm, '$1$2:')
|
||||
// requote "special" key names
|
||||
.replace(/^( +)(default):/gm, '$1\'$2\':');
|
||||
return (
|
||||
(pretty ? JSON.stringify(thing, null, ' ') : JSON.stringify(thing))
|
||||
.replace(/'/g, "\\'")
|
||||
.replace(/\\?"/g, function(quote) {
|
||||
// replace external (unescaped) double quotes with single quotes
|
||||
return quote === '\\"' ? '"' : "'";
|
||||
})
|
||||
// inject a space between STRING array parts
|
||||
.replace(/([^\\])','/g, "$1', '")
|
||||
// remove quotes around key names that are only made up of letters
|
||||
.replace(/^( +)'([a-zA-Z_]+)':/gm, '$1$2:')
|
||||
// requote "special" key names
|
||||
.replace(/^( +)(default):/gm, "$1'$2':")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,28 +39,30 @@ var templates = {};
|
||||
* @type {Object}
|
||||
*/
|
||||
var templateGlobals = {
|
||||
|
||||
stringify: stringify,
|
||||
|
||||
_: _,
|
||||
utils: utils,
|
||||
|
||||
indent: function (block, spaces) {
|
||||
indent: function(block, spaces) {
|
||||
var indent = utils.repeat(' ', spaces);
|
||||
return block.split('\n').map(function (line) {
|
||||
return indent + line;
|
||||
}).join('\n');
|
||||
return block
|
||||
.split('\n')
|
||||
.map(function(line) {
|
||||
return indent + line;
|
||||
})
|
||||
.join('\n');
|
||||
},
|
||||
|
||||
joinParagraphs: function (block) {
|
||||
joinParagraphs: function(block) {
|
||||
return block.split('\n\n').join('\n+\n');
|
||||
},
|
||||
|
||||
paramType: function (type, paramName) {
|
||||
paramType: function(type, paramName) {
|
||||
switch (type && type.toLowerCase ? type.toLowerCase() : 'any') {
|
||||
case 'time':
|
||||
case 'duration':
|
||||
if (paramName === 'timestamp') return 'Timestamp'
|
||||
if (paramName === 'timestamp') return 'Timestamp';
|
||||
return '<<api-param-type-duration-string,`DurationString`>>';
|
||||
case 'any':
|
||||
return 'anything';
|
||||
@ -84,7 +86,7 @@ var templateGlobals = {
|
||||
}
|
||||
},
|
||||
|
||||
paramWithDefault: function (name, def) {
|
||||
paramWithDefault: function(name, def) {
|
||||
if (def) {
|
||||
return '[' + name + '=' + def + ']';
|
||||
} else {
|
||||
@ -94,16 +96,16 @@ var templateGlobals = {
|
||||
|
||||
partials: templates,
|
||||
|
||||
gruntUtils: gruntUtils
|
||||
gruntUtils: gruntUtils,
|
||||
};
|
||||
|
||||
fs.readdirSync(path.resolve(__dirname)).forEach(function (filename) {
|
||||
fs.readdirSync(path.resolve(__dirname)).forEach(function(filename) {
|
||||
var name = filename.replace(/\..+$/, '');
|
||||
if (name !== 'index') {
|
||||
templates[name] = _.template(
|
||||
fs.readFileSync(path.resolve(__dirname, filename), 'utf8'),
|
||||
{
|
||||
imports: templateGlobals
|
||||
imports: templateGlobals,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
module.exports = function (branch, done) {
|
||||
module.exports = function(branch, done) {
|
||||
/**
|
||||
* Creates a JSON version of the YAML test suite that can be simply bundled for use in the browser.
|
||||
*/
|
||||
@ -14,24 +14,20 @@ module.exports = function (branch, done) {
|
||||
var esDir = fromRoot('src/_elasticsearch_' + utils.snakeCase(branch));
|
||||
|
||||
// generate the yaml tests
|
||||
async.series([
|
||||
readYamlTests,
|
||||
writeYamlTests,
|
||||
writeTestIndex
|
||||
], done);
|
||||
async.series([readYamlTests, writeYamlTests, writeTestIndex], done);
|
||||
|
||||
function readYamlTests(done) {
|
||||
var testDir = path.join(esDir, 'rest-api-spec/test/');
|
||||
|
||||
function readDirectories(dir) {
|
||||
fs.readdirSync(dir).forEach(function (filename) {
|
||||
fs.readdirSync(dir).forEach(function(filename) {
|
||||
var filePath = path.join(dir, filename);
|
||||
var stat = fs.statSync(filePath);
|
||||
if (stat.isDirectory()) {
|
||||
readDirectories(filePath);
|
||||
} else if (filename.match(/\.yaml$/)) {
|
||||
var file = tests[path.relative(testDir, filePath)] = [];
|
||||
jsYaml.loadAll(fs.readFileSync(filePath, 'utf8'), function (doc) {
|
||||
var file = (tests[path.relative(testDir, filePath)] = []);
|
||||
jsYaml.loadAll(fs.readFileSync(filePath, 'utf8'), function(doc) {
|
||||
file.push(doc);
|
||||
});
|
||||
}
|
||||
@ -43,15 +39,21 @@ module.exports = function (branch, done) {
|
||||
}
|
||||
|
||||
function writeYamlTests(done) {
|
||||
var testFile = fromRoot('test/integration/yaml_suite/yaml_tests_' + utils.snakeCase(branch) + '.json');
|
||||
var testFile = fromRoot(
|
||||
'test/integration/yaml_suite/yaml_tests_' +
|
||||
utils.snakeCase(branch) +
|
||||
'.json'
|
||||
);
|
||||
fs.writeFileSync(testFile, JSON.stringify(tests, null, ' '), 'utf8');
|
||||
console.log(chalk.white.bold('wrote') + ' YAML tests as JSON to', testFile);
|
||||
done();
|
||||
}
|
||||
|
||||
function writeTestIndex(done) {
|
||||
var file = fromRoot('test/integration/yaml_suite/index_' + utils.snakeCase(branch) + '.js');
|
||||
fs.writeFileSync(file, 'require(\'./run\')(\'' + branch + '\');\n', 'utf8');
|
||||
var file = fromRoot(
|
||||
'test/integration/yaml_suite/index_' + utils.snakeCase(branch) + '.js'
|
||||
);
|
||||
fs.writeFileSync(file, "require('./run')('" + branch + "');\n", 'utf8');
|
||||
console.log(chalk.white.bold('wrote') + ' YAML index to', file);
|
||||
done();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user