Created
April 4, 2018 18:59
-
-
Save mcblum/fa87d804bc8214face57994a283b06ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
usage() { echo "Usage: $0 [-b optional <jit|aot> ]" 1>&2; exit 1; } | |
# parse our environment | |
unameOut="$(uname -s)" | |
case "${unameOut}" in | |
Linux*) machine=Linux;; | |
Darwin*) machine=Mac;; | |
CYGWIN*) machine=Cygwin;; | |
MINGW*) machine=MinGw;; | |
*) machine="UNKNOWN:${unameOut}" | |
esac | |
### build functions | |
pre_build() { | |
echo "Installing dependencies..." | |
yarn install | |
echo "Dependencies installed." | |
} | |
build () { | |
echo "Building ${1} with AOT compilation..." | |
node --stack_size=4048 --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng "build" "--prod" "--aot" "--app=${1}" | |
if [ $? -eq 0 ] | |
then | |
echo "Your app has been build with ahead-of-time compilation." | |
else | |
echo "Your AOT build has failed." | |
exit 1; | |
fi | |
} | |
### end build functions | |
# determine which apps we should build | |
while getopts a:s:r option | |
do | |
case "${option}" | |
in | |
a) APP=${OPTARG};; | |
s) SHA=${OPTARG};; | |
r) REPORT_ONLY=true;; | |
esac | |
done | |
# if an application was specified then build that app only | |
# if not, look for any applications that have changed between | |
# master and our current HEAD and build. | |
if [[ -n $APP ]]; then | |
apps=($APP) | |
else | |
if [[ -n $SHA ]]; then | |
STARTING_SHA=${SHA} | |
else | |
STARTING_SHA=$(git merge-base origin/master HEAD) | |
fi | |
CURRENT_SHA=$(git rev-parse HEAD) | |
if [[ -z $REPORT_ONLY ]]; then | |
echo "Determining all changed applications starting at $STARTING_SHA and ending at $CURRENT_SHA..." | |
fi | |
TOBUILD=$(npm run affected:apps -s -- ${STARTING_SHA} ${CURRENT_SHA}) | |
if [[ -z $REPORT_ONLY ]]; then | |
echo "Done!" | |
fi | |
apps=($TOBUILD) | |
fi | |
# if the apps array is empty, then nothing has changed and we're done here | |
if [ ${#apps[@]} -eq 0 ]; then | |
echo "-1" | |
exit 0 | |
fi | |
# if the script is in report-only mode, return the array of | |
# applications that have changed | |
if [[ -n $REPORT_ONLY ]]; then | |
echo ${apps[@]} | |
exit 0 | |
fi | |
# run the pre-build script | |
pre_build | |
# build each specified app | |
for i in ${apps[@]}; do build ${i}; done | |
# all done | |
echo "Build complete!" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment