diff --git a/package.json b/package.json index 4374c50569957..d02e318d4d6eb 100644 --- a/package.json +++ b/package.json @@ -179,6 +179,7 @@ "makelogs": "3.0.0-beta3", "marked-text-renderer": "0.1.0", "mocha": "2.3.0", + "ncp": "2.0.0", "nock": "2.10.0", "npm": "2.11.0", "portscanner": "1.0.0", diff --git a/tasks/build/index.js b/tasks/build/index.js index 0f7c4d00de247..6a5ea09914a96 100644 --- a/tasks/build/index.js +++ b/tasks/build/index.js @@ -22,6 +22,7 @@ module.exports = function (grunt) { 'stop:optimizeBuild', '_build:downloadNodeBuilds:finish', '_build:versionedLinks', + '_build:osShellScripts', '_build:archives', grunt.option('os-packages') ? [ '_build:pleaseRun', diff --git a/tasks/build/os_shell_scripts.js b/tasks/build/os_shell_scripts.js new file mode 100644 index 0000000000000..0e511869ec657 --- /dev/null +++ b/tasks/build/os_shell_scripts.js @@ -0,0 +1,42 @@ +import {unlink} from 'fs'; +import {join, extname} from 'path'; +import {promisify} from 'bluebird'; +import {ncp} from 'ncp'; +const pncp = promisify(ncp); +const punlink = promisify(unlink); + +export default function (grunt) { + grunt.registerTask('_build:osShellScripts', async function osShellScripts() { + const done = this.async(); + const source = 'build/kibana/bin'; + const platforms = grunt.config.get('platforms'); + const allPlatforms = fn => invokeAllAsync(platforms, fn); + + try { + await allPlatforms(platform => punlink(join(platform.buildDir, 'bin'))); + await allPlatforms(platform => pncp(source, join(platform.buildDir, 'bin'))); + await allPlatforms(platform => removeExtraneousShellScripts(grunt, platform)); + done(); + } catch (err) { + done(err); + } + }); +}; + +function invokeAllAsync(all, fn) { + return Promise.all(all.map(fn)); +} + +function removeExtraneousShellScripts(grunt, platform) { + return Promise.all(grunt.file + .expand(join(platform.buildDir, 'bin', '*')) + .filter(file => isExtraneous(platform, file)) + .map(file => punlink(file))); +} + +function isExtraneous(platform, file) { + const ext = extname(file); + if (platform.win && ext === '') { return true; } + if (!platform.win && ext === '.bat') { return true; } + return false; +}