From b6921d75590b286abffd3c6b2a42b0fd05733066 Mon Sep 17 00:00:00 2001 From: Sven65 Date: Tue, 24 Sep 2024 15:35:49 +0200 Subject: [PATCH] Add option --install-npm to build.php to install from NPM directly. --- build.php | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/build.php b/build.php index 4f7617c..48ec59a 100644 --- a/build.php +++ b/build.php @@ -8,40 +8,41 @@ /* 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. $buildCommands = []; //Add composer build, if flag --no-composer is undefined. -//Dump autloader. +//Dump autloader. //Only if composer.json exists. -if (file_exists('composer.json')) { - if (is_array($argv) && !in_array('--no-composer', $argv)) { - $buildCommands[] = 'composer install --prefer-dist --no-progress --no-dev'; +if(file_exists('composer.json')) { + if(is_array($argv) && !in_array('--no-composer', $argv)) { + $buildCommands[] = 'composer install --prefer-dist --no-progress --no-dev'; } $buildCommands[] = 'composer dump-autoload'; } //Run npm if package.json is found -if (file_exists('package.json') && file_exists('package-lock.json')) { - $buildCommands[] = 'npm ci --no-progress --no-audit'; -} 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(file_exists('package.json') && file_exists('package-lock.json')) { + 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')) { + 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. @@ -60,13 +61,12 @@ 'package.json', 'phpunit.xml.dist', 'README.md', - 'gulpfile.js', './node_modules/', './source/sass/', './source/js/', 'LICENSE', 'babel.config.js', - 'yarn.lock', + 'yarn.lock' ]; $dirName = basename(dirname(__FILE__)); @@ -86,7 +86,7 @@ } // Remove files and directories if '--cleanup' argument is supplied to save local developers from disasters. -if (is_array($argv) && in_array('--cleanup', $argv)) { +if(is_array($argv) && in_array('--cleanup', $argv)) { foreach ($removables as $removable) { if (file_exists($removable)) { print "Removing $removable from $dirName\n"; @@ -111,7 +111,7 @@ function executeCommand($command) $proc = popen($fullCommand, 'r'); - $liveOutput = ''; + $liveOutput = ''; $completeOutput = ''; while (!feof($proc)) {