Use npm/yarn to install build dependencies (elastic/kibana-plugin-helpers#28)

* remove scripts and devDependencies from package

these are only useful in development, and serve no purpose in the build

* refactor the package rewriter

* clean up the buildTarget before building

* run npm install after build creation

* break apart the create_build module

* add create_package modules

call it from within the build_action

* add flag to skip package zip creation

* rename skip-package flag to skip-archive

* rename rewritePackage to rewritePackageJson

* include lock and shrinkwrap files if they exist

* add test for skipping zip creation

* add some tests to build creation

Original commit: elastic/kibana-plugin-helpers@ef6b9c6332
This commit is contained in:
Joe Fleming 2017-01-11 14:41:05 -07:00 committed by GitHub
parent 569ac1f3d1
commit 85234f979b
11 changed files with 223 additions and 84 deletions

View file

@ -1,5 +1,5 @@
var resolve = require('path').resolve;
var readFileSync = require('fs').readFileSync;
var statSync = require('fs').statSync;
var configFile = require('./config_file');
module.exports = function (root) {
@ -14,13 +14,13 @@ module.exports = function (root) {
'{lib,public,server,webpackShims}/**/*',
];
// add dependency files
var deps = Object.keys(pkg.dependencies || {});
if (deps.length === 1) {
buildSourcePatterns.push(`node_modules/${ deps[0] }/**/*`);
} else if (deps.length) {
buildSourcePatterns.push(`node_modules/{${ deps.join(',') }}/**/*`);
}
// add shrinkwrap and lock files, if they exist
['npm-shrinkwrap.json', 'yarn.lock']
.forEach(function (file) {
if (fileExists(resolve(root, file))) {
buildSourcePatterns.push(file);
}
});
return Object.assign({
root: root,
@ -32,3 +32,12 @@ module.exports = function (root) {
version: pkg.version,
}, config);
};
function fileExists(path) {
try {
var stat = statSync(path);
return stat.isFile();
} catch (e) {
return false;
}
}