Skip to content

Commit

Permalink
Merge pull request #20 from helsingborg-stad/feat/install-npm
Browse files Browse the repository at this point in the history
Add option "--install-npm" to build.php to install from NPM directly.
  • Loading branch information
Sven65 authored Sep 24, 2024
2 parents b65e6cc + 5116b93 commit d3d3451
Showing 1 changed file with 17 additions and 12 deletions.
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

0 comments on commit d3d3451

Please sign in to comment.