Skip to content

Commit

Permalink
Update build.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thulin committed Sep 1, 2023
1 parent 47226dd commit 57b2fbe
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions build.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
exit(0);
}

/* Parameters:
--no-composer Does not install vendors. Just create the autoloader.
--cleanup Remove removeables.
--allow-gulp Allow gulp to be used.
*/

// Any command needed to run and build plugin assets when newly cheched out of repo.
$buildCommands = [];

Expand All @@ -26,16 +32,19 @@
}

//Run build if package-lock.json is found
if(file_exists('package-lock.json')) {
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';
}

// Files and directories not suitable for prod to be removed.
$removables = [
'.git',
'.gitignore',
'.github',
'.gitattributes',
'build.php',
'.npmrc',
'composer.json',
Expand All @@ -45,7 +54,14 @@
'package-lock.json',
'package.json',
'phpunit.xml.dist',
'README.md'
'README.md',
'gulpfile.js',
'./node_modules/',
'./source/sass/',
'./source/js/',
'LICENSE',
'babel.config.js',
'yarn.lock'
];

$dirName = basename(dirname(__FILE__));
Expand All @@ -65,7 +81,7 @@
}

// Remove files and directories if '--cleanup' argument is supplied to save local developers from disasters.
if (isset($argv[1]) && $argv[1] === '--cleanup') {
if(is_array($argv) && in_array('--cleanup', $argv)) {
foreach ($removables as $removable) {
if (file_exists($removable)) {
print "Removing $removable from $dirName\n";
Expand Down

0 comments on commit 57b2fbe

Please sign in to comment.