mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[build] ask for kibana version when set to "kibana"
Original commit: elastic/kibana-plugin-helpers@5fe34c47ae
This commit is contained in:
parent
efda634e85
commit
ddf67bf648
2 changed files with 73 additions and 19 deletions
|
@ -20,6 +20,8 @@
|
|||
"commander": "^2.9.0",
|
||||
"gulp-rename": "1.2.2",
|
||||
"gulp-zip": "3.1.0",
|
||||
"inquirer": "^1.2.2",
|
||||
"through2-map": "^3.0.0",
|
||||
"vinyl-fs": "2.3.1"
|
||||
},
|
||||
"directories": {
|
||||
|
|
|
@ -2,30 +2,82 @@ module.exports = function (plugin) {
|
|||
|
||||
var vfs = require('vinyl-fs');
|
||||
var zip = require('gulp-zip');
|
||||
var map = require('through2-map').obj;
|
||||
var rename = require('gulp-rename');
|
||||
var join = require('path').join;
|
||||
var inquirer = require('inquirer');
|
||||
|
||||
var deps = Object.keys(plugin.pkg.dependencies || {});
|
||||
var buildId = `${plugin.id}-${plugin.version}`;
|
||||
function main() {
|
||||
var kibanaVersion = (plugin.pkg.kibana && plugin.pkg.kibana.version) || plugin.pkg.version;
|
||||
var deps = Object.keys(plugin.pkg.dependencies || {});
|
||||
var buildId = `${plugin.id}-${plugin.version}`;
|
||||
|
||||
var files = [
|
||||
'package.json',
|
||||
'index.js',
|
||||
'{lib,public,server,webpackShims}/**/*'
|
||||
];
|
||||
|
||||
if (deps.length === 1) {
|
||||
files.push(`node_modules/${ deps[0] }/**/*`);
|
||||
} else {
|
||||
files.push(`node_modules/{${ deps.join(',') }}/**/*`);
|
||||
if (kibanaVersion === 'kibana') {
|
||||
askForKibanaVersion(function (customKibanaVersion) {
|
||||
build(buildId, deps, customKibanaVersion);
|
||||
});
|
||||
} else {
|
||||
build(buildId, deps, kibanaVersion);
|
||||
}
|
||||
}
|
||||
|
||||
vfs
|
||||
.src(files, { base: plugin.root })
|
||||
.pipe(rename(function nestFileInDir(path) {
|
||||
path.dirname = join('kibana', plugin.id, path.dirname);
|
||||
}))
|
||||
.pipe(zip(`${buildId}.zip`))
|
||||
.pipe(vfs.dest(join(plugin.root, 'build')));
|
||||
function askForKibanaVersion(cb) {
|
||||
inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
name: 'kibanaVersion',
|
||||
message: 'What version of Kibana are you building for?'
|
||||
}
|
||||
]).then(function (answers) {
|
||||
cb(answers.kibanaVersion);
|
||||
});
|
||||
}
|
||||
|
||||
function toBuffer(string) {
|
||||
if (typeof Buffer.from === 'function') {
|
||||
return Buffer.from(string, 'utf8');
|
||||
} else {
|
||||
// this was deprecated in node v5 in favor
|
||||
// of Buffer.from(string, encoding)
|
||||
return new Buffer(string, 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
function build(deps, kibanaVersion) {
|
||||
var files = [
|
||||
'package.json',
|
||||
'index.js',
|
||||
'{lib,public,server,webpackShims}/**/*'
|
||||
];
|
||||
|
||||
if (deps.length === 1) {
|
||||
files.push(`node_modules/${ deps[0] }/**/*`);
|
||||
} else {
|
||||
files.push(`node_modules/{${ deps.join(',') }}/**/*`);
|
||||
}
|
||||
|
||||
vfs
|
||||
.src(files, { base: plugin.root })
|
||||
|
||||
// rewrite the target kibana version while the
|
||||
// file is on it's way to the archive
|
||||
.pipe(map(function (file) {
|
||||
if (file.basename === 'package.json') {
|
||||
const pkg = JSON.parse(file.contents.toString('utf8'));
|
||||
if (!pkg.kibana) pkg.kibana = {};
|
||||
pkg.kibana.version = kibanaVersion;
|
||||
file.contents = toBuffer(JSON.stringify(pkg));
|
||||
}
|
||||
|
||||
return file;
|
||||
}))
|
||||
|
||||
// put all files inside the correct directoried
|
||||
.pipe(rename(function nestFileInDir(path) {
|
||||
path.dirname = join('kibana', plugin.id, path.dirname);
|
||||
}))
|
||||
|
||||
.pipe(zip(`${buildId}.zip`))
|
||||
.pipe(vfs.dest(join(plugin.root, 'build')));
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue