diff --git a/build.sh b/build.sh index a596668e..45e1d564 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash +declare -A cht_versions=( + ["cht-core-4-6"]="42807deaae818bf2085d0457f9f161073493aec1" +) + exit_on_error() { exit_code=$? if [[ $exit_code -ne 0 ]]; then @@ -11,27 +15,29 @@ set -e trap exit_on_error EXIT if [ "$1" == "--force" ]; then - FORCE=true + FORCE=1 fi npm ci --legacy-peer-deps +rm -Rf build + +if [[ 1 == "$FORCE" ]]; then + rm -Rf dist +else + for item in `ls dist | grep -v cht-core`; do + rm -rf dist/"$item" + done +fi -for item in `ls build | grep -v cht-core`; do - rm -rf $item -done - -declare -a versions=("cht-core-4-6") -for version in "${versions[@]}"; do - if [ -z ${FORCE+x} ] && [ -d dist/"$version" ]; then +for version in "${!cht_versions[@]}"; do + if [[ ! 1 == "$FORCE" ]] && [ -d dist/"$version" ]; then printf "\033[0;32m== SKIPPING $version ==\n" continue fi - if [ -d build/"$version" ]; then - (cd build/"$version" && git fetch && git reset --hard origin/master) - else - git clone -b master https://github.com/medic/cht-core.git build/"$version" - fi + git clone https://github.com/medic/cht-core.git build/"$version" + (cd build/"$version" && git reset --hard "${cht_versions[$version]}") + (cd build/"$version" && git clean -df) (cd build/"$version" && npm ci) @@ -47,9 +53,9 @@ for version in "${versions[@]}"; do mkdir -p dist/"$version"/enketo-transformer/xsl cp ./build/cht-core-4-6/api/src/xsl/openrosa2html5form.xsl dist/"$version"/xsl cp ./build/cht-core-4-6/api/src/enketo-transformer/xsl/* dist/"$version"/enketo-transformer/xsl -done -npx webpack --config cht-bundles/webpack.config.cht-core.js --env.cht='cht-core-4-6' + npx webpack --config cht-bundles/webpack.config.cht-core.js --env.cht="$version" +done npx webpack