From d65b84ff28bb3da610db8c5e347a43b054e02c1b Mon Sep 17 00:00:00 2001 From: Sven65 Date: Tue, 24 Sep 2024 15:35:51 +0200 Subject: [PATCH] Add option --install-npm to build.php to install from NPM directly. --- build.php | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/build.php b/build.php index 3dfb7a3..48ec59a 100644 --- a/build.php +++ b/build.php @@ -8,7 +8,7 @@ /* Parameters: --no-composer Does not install vendors. Just create the autoloader. --cleanup Remove removeables. - --allow-gulp Allow gulp to be used. + --install-npm Install NPM package instead */ // Any command needed to run and build plugin assets when newly cheched out of repo. @@ -26,17 +26,23 @@ //Run npm if package.json is found if(file_exists('package.json') && file_exists('package-lock.json')) { - $buildCommands[] = 'npm ci --no-progress --no-audit'; + if(is_array($argv) && !in_array('--install-npm', $argv)) { + $buildCommands[] = 'npm ci --no-progress --no-audit'; + } else { + $npmPackage = json_decode(file_get_contents('package.json')); + $buildCommands[] = "npm install $npmPackage->name"; + $buildCommands[] = "rm -rf ./dist"; + $buildCommands[] = "mv node_modules/$npmPackage->name/dist ./"; + } } elseif(file_exists('package.json') && !file_exists('package-lock.json')) { - $buildCommands[] = 'npm install --no-progress --no-audit'; -} - -//Run build if package-lock.json is found -if(file_exists('package-lock.json') && !file_exists('gulp.js')) { - $buildCommands[] = 'npx --yes browserslist@latest --update-db'; - $buildCommands[] = 'npm run build'; -} elseif(file_exists('package-lock.json') && file_exists('gulp.js') && is_array($argv) && in_array('--allow-gulp', $argv)) { - $buildCommands[] = 'gulp'; + if(is_array($argv) && !in_array('--install-npm', $argv)) { + $buildCommands[] = 'npm install --no-progress --no-audit'; + } else { + $npmPackage = json_decode(file_get_contents('package.json')); + $buildCommands[] = "npm install $npmPackage->name"; + $buildCommands[] = "rm -rf ./dist"; + $buildCommands[] = "mv node_modules/$npmPackage->name/dist ./"; + } } // Files and directories not suitable for prod to be removed. @@ -55,7 +61,6 @@ 'package.json', 'phpunit.xml.dist', 'README.md', - 'gulpfile.js', './node_modules/', './source/sass/', './source/js/',