Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option --install-npm to build.php to install from NPM directly. #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions build.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -55,7 +61,6 @@
'package.json',
'phpunit.xml.dist',
'README.md',
'gulpfile.js',
'./node_modules/',
'./source/sass/',
'./source/js/',
Expand Down