Skip to content

Instantly share code, notes, and snippets.

@rmpel
Last active March 21, 2023 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmpel/fba9597367928840eb8a19d48df960c5 to your computer and use it in GitHub Desktop.
Save rmpel/fba9597367928840eb8a19d48df960c5 to your computer and use it in GitHub Desktop.
Universal build script for themes/plugins - WORK IN PROGRESS
#!/usr/bin/env bash
# Usage: /path/to/build.sh target-environment-using-a-pipelines-variable
# Example: /path/to/build.sh production
# Expected behaviour; in production, build for production, for all else build uncompressed.
# For local (argo; NO environment given, or local specified) buld in debug mode.
### CONFIGURATION
NODE_VER=14
BUILD_TASK_PROD=production
BUILD_TASK_LOCAL=dev
BUILD_TASK_OTHER=production
### /CONFIGURATION
# You probably don't need to edit what's below.
TARGET=$1
[[ "" = "$TARGET" ]] && TARGET=local
if [[ "local" = "$TARGET" ]]; then
if [[ $(node --version) =~ ^v$NODE_VER\. ]]; then
echo "The required node version $NODE_VER is available and activated. Continuing with building ..." >&2
else
echo "The required node version $NODE_VER failed to install/activate. Please do this manually and try again." >&2
echo " nvm install $NODE_VER ; nvm use $NODE_VER" >&2
exit 1;
fi
else
echo "The required node version is $NODE_VER" >&2
echo "The installed node version is $(node --version)" >&2
echo "We're continuing with building, if this failes, please change the pipeline to include installation of" >&2
echo "the correct version of NodeJS." >&2
fi
# installation of dependencies
cd "$(dirname "$0")"
if [[ "local" = "$TARGET" ]] && [[ -d node_modules ]]; then
echo "Local development, node_modules present. Not running install" >&2
echo "If you have problems; rm -rf node-modules and try again." >&2
else
npm install
fi
# kicking off the build script.
[[ "local" = "$TARGET" ]] && npm run $BUILD_TASK_LOCAL && exit;
[[ "production" = "$TARGET" ]] && npm run $BUILD_TASK_PROD && exit;
npm run $BUILD_TASK_OTHER && exit;
#!/usr/bin/env bash
# Usage: /path/to/build.sh target-environment-using-a-pipelines-variable
# Example: /path/to/build.sh production
# Expected behaviour; in production, build for production, for all else build uncompressed.
# For local (argo; NO environment given, or local specified) buld in debug mode.
# this file is in the project root and only does one thing; find all build.sh script and execute them, in parallel.
cd "$(dirname "$0")"
echo "Starting parallel execution of all build scripts"
for build_script in $(find . -name build.sh | egrep -v '/(node_modules|bower_components)/'); do
if [ './build.sh' != "$build_script" ]; then
echo "Spawning sub-process for $build_script"
"$build_script" "$1" &
fi
done
echo "Waiting for all processes to finish"
wait
echo "All processes finished"
echo "We're done building"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment