2018-05-29 05:06:30 +02:00
|
|
|
/*
|
|
|
|
* Licensed to Elasticsearch B.V. under one or more contributor
|
|
|
|
* license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright
|
|
|
|
* ownership. Elasticsearch B.V. licenses this file to you under
|
|
|
|
* the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
2018-02-12 20:23:23 +01:00
|
|
|
const { resolve } = require('path');
|
|
|
|
|
|
|
|
const dedent = require('dedent');
|
|
|
|
const sao = require('sao');
|
|
|
|
const chalk = require('chalk');
|
|
|
|
const getopts = require('getopts');
|
|
|
|
const snakeCase = require('lodash.snakecase');
|
|
|
|
|
|
|
|
exports.run = function run(argv) {
|
|
|
|
const options = getopts(argv, {
|
|
|
|
alias: {
|
|
|
|
h: 'help',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!options.help && options._.length !== 1) {
|
|
|
|
console.log(chalk`{red {bold [name]} is a required argument}\n`);
|
|
|
|
options.help = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.help) {
|
|
|
|
console.log(
|
|
|
|
dedent(chalk`
|
|
|
|
{dim usage:} node scripts/generate-plugin {bold [name]}
|
|
|
|
|
2019-03-08 00:04:29 +01:00
|
|
|
generate a fresh Kibana plugin in the plugins/ directory
|
2018-02-12 20:23:23 +01:00
|
|
|
`) + '\n'
|
|
|
|
);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const name = options._[0];
|
|
|
|
const template = resolve(__dirname, './sao_template');
|
2019-03-08 00:04:29 +01:00
|
|
|
const kibanaPlugins = resolve(__dirname, '../../plugins');
|
|
|
|
const targetPath = resolve(kibanaPlugins, snakeCase(name));
|
2018-02-12 20:23:23 +01:00
|
|
|
|
|
|
|
sao({
|
|
|
|
template: template,
|
|
|
|
targetPath: targetPath,
|
|
|
|
configOptions: {
|
|
|
|
name,
|
|
|
|
},
|
|
|
|
}).catch(error => {
|
|
|
|
console.error(chalk`{red fatal error}!`);
|
|
|
|
console.error(error.stack);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
};
|