Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Allow custom build target via --build-destination flag (#30)
Browse files Browse the repository at this point in the history
* pass buildTarget into createBuild

allow override from options

* add cli option to override build destination

--build-destination

* fix tests

* resolve build destination from plugin.root

this allows both relative and absolute paths to be used

* add short option

* update the help
  • Loading branch information
w33ble committed Dec 23, 2016
1 parent b85da87 commit c311e0d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/kbn-plugin-helpers/bin/plugin-helpers.js
Expand Up @@ -34,10 +34,12 @@ program
.command('build [files...]')
.description('Build a distributable archive')
.on('--help', docs('build'))
.option('-d, --build-destination <path>', 'Target path for the build output, absolute or relative to the plugin root')
.option('-b, --build-version <version>', 'Version for the build output')
.option('-k, --kibana-version <version>', 'Kibana version for the build output')
.action(taskRunner(function (command, files) {
run('build', {
buildDestination: command.buildDestination,
buildVersion: command.buildVersion,
kibanaVersion: command.kibanaVersion,
files: files,
Expand Down
10 changes: 10 additions & 0 deletions packages/kbn-plugin-helpers/tasks/build/README.md
Expand Up @@ -7,3 +7,13 @@ be found at:
```
build/{pkg.name}-{pkg.version}.zip
```

If you use the `--build-destination` flag, the resulting build will be found
in that directory.

```
plugin-helpers build --build-destination build/some/child/path
# This will place the resulting build at:
build/some/child/path/{pkg.name}-{pkg.version}.zip
```
8 changes: 6 additions & 2 deletions packages/kbn-plugin-helpers/tasks/build/build_action.js
@@ -1,3 +1,5 @@
var join = require('path').join;
var resolve = require('path').resolve;
var inquirer = require('inquirer');

var createBuild = require('./create_build');
Expand All @@ -7,22 +9,24 @@ module.exports = function (plugin, run, options) {
var buildVersion = plugin.version;
var kibanaVersion = (plugin.pkg.kibana && plugin.pkg.kibana.version) || plugin.pkg.version;
var buildFiles = plugin.buildSourcePatterns;
var buildTarget = join(plugin.root, 'build');

// allow source files to be overridden
if (options.files && options.files.length) {
buildFiles = options.files;
}

// allow options to override plugin info
if (options.buildDestination) buildTarget = resolve(plugin.root, options.buildDestination);
if (options.buildVersion) buildVersion = options.buildVersion;
if (options.kibanaVersion) kibanaVersion = options.kibanaVersion;

if (kibanaVersion === 'kibana') {
return askForKibanaVersion().then(function (customKibanaVersion) {
return createBuild(plugin, buildVersion, customKibanaVersion, buildFiles);
return createBuild(plugin, buildTarget, buildVersion, customKibanaVersion, buildFiles);
});
} else {
return createBuild(plugin, buildVersion, kibanaVersion, buildFiles);
return createBuild(plugin, buildTarget, buildVersion, kibanaVersion, buildFiles);
}
};

Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-plugin-helpers/tasks/build/build_action.spec.js
Expand Up @@ -44,7 +44,7 @@ describe('build_action', () => {

return buildAction(PLUGIN, noop, options).then(() => {
expect(mockBuild.mock.calls).toHaveLength(1);
const [ plugin, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
const [ plugin, buildTarget, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
expect(buildVersion).toBe('1.2.3');
expect(kibanaVersion).toBe('4.5.6');
});
Expand All @@ -53,7 +53,7 @@ describe('build_action', () => {
it('uses default file list without files option', function () {
return buildAction(PLUGIN).then(() => {
expect(mockBuild.mock.calls).toHaveLength(1);
const [ plugin, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
const [ plugin, buildTarget, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
PLUGIN.buildSourcePatterns.forEach(file => expect(files).toContain(file));
});
});
Expand All @@ -70,7 +70,7 @@ describe('build_action', () => {

return buildAction(PLUGIN, noop, options).then(() => {
expect(mockBuild.mock.calls).toHaveLength(1);
const [ plugin, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
const [ plugin, buildTarget, buildVersion, kibanaVersion, files ] = mockBuild.mock.calls[0];
options.files.forEach(file => expect(files).toContain(file));
});
});
Expand Down
3 changes: 1 addition & 2 deletions packages/kbn-plugin-helpers/tasks/build/create_build.js
Expand Up @@ -5,10 +5,9 @@ var zip = require('gulp-zip');
var map = require('through2-map').obj;
var rename = require('gulp-rename');

module.exports = function createBuild(plugin, buildVersion, kibanaVersion, files) {
module.exports = function createBuild(plugin, buildTarget, buildVersion, kibanaVersion, files) {
var buildId = `${plugin.id}-${buildVersion}`;
var buildSource = plugin.root;
var buildTarget = join(plugin.root, 'build');

return new Promise(function (resolve) {
vfs
Expand Down

0 comments on commit c311e0d

Please sign in to comment.