diff --git a/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/build-app.sh b/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/build-app.sh index 4e769224..fa7363db 100755 --- a/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/build-app.sh +++ b/stack_orchestrator/data/container-build/cerc-nextjs-base/scripts/build-app.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ -n "$CERC_SCRIPT_DEBUG" ]; then - set -x + set -x fi CERC_MIN_NEXTVER=13.4.2 @@ -20,18 +20,21 @@ if [ -z "$CERC_BUILD_TOOL" ]; then fi fi -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) WORK_DIR="${1:-/app}" cd "${WORK_DIR}" || exit 1 # If this file doesn't exist at all, we'll get errors below. -if [ ! -f "next.config.js" ]; then - touch next.config.js +NEXTJS_CONFIG_FILE="next.config.js" +if [ -f "next.config.mjs" ]; then + CONFIG_FILE_TO_BEAUTIFY="next.config.mjs" +elif [ ! -f "$NEXTJS_CONFIG_FILE" ]; then + touch "$NEXTJS_CONFIG_FILE" fi if [ ! -f "next.config.dist" ]; then - cp next.config.js next.config.dist + cp "$NEXTJS_CONFIG_FILE" next.config.dist fi which js-beautify >/dev/null @@ -39,17 +42,17 @@ if [ $? -ne 0 ]; then npm i -g js-beautify fi -js-beautify next.config.dist > next.config.js -echo "" >> next.config.js +js-beautify next.config.dist >"$NEXTJS_CONFIG_FILE" +echo "" >>"$NEXTJS_CONFIG_FILE" WEBPACK_REQ_LINE=$(grep -n "require([\'\"]webpack[\'\"])" next.config.js | cut -d':' -f1) if [ -z "$WEBPACK_REQ_LINE" ]; then - cat > next.config.js.0 <"$NEXTJS_CONFIG_FILE".0 < next.config.js.1 <"$NEXTJS_CONFIG_FILE".1 < next.config.js.2 - cat > next.config.js.3 <"$NEXTJS_CONFIG_FILE".2 + cat >"$NEXTJS_CONFIG_FILE".3 < next.config.js.2 - cat > next.config.js.3 <"$NEXTJS_CONFIG_FILE".2 + cat >"$NEXTJS_CONFIG_FILE".3 < { config.plugins.push(new webpack.DefinePlugin(envMap)); return config; @@ -91,35 +94,35 @@ EOF NEXT_SECTION_ADJUSTMENT=1 NEXT_SECTION_LINE=$ENV_LINE else - echo "WARNING: Cannot find location to insert environment variable map in next.config.js" 1>&2 - rm -f next.config.js.* + echo "WARNING: Cannot find location to insert environment variable map in "$NEXTJS_CONFIG_FILE"" 1>&2 + rm -f "$NEXTJS_CONFIG_FILE".* NEXT_SECTION_LINE=0 fi -tail -$(( ${CONFIG_LINES} - ${NEXT_SECTION_LINE} + ${NEXT_SECTION_ADJUSTMENT} )) next.config.js > next.config.js.5 +tail -$((${CONFIG_LINES} - ${NEXT_SECTION_LINE} + ${NEXT_SECTION_ADJUSTMENT})) "$NEXTJS_CONFIG_FILE" >"$NEXTJS_CONFIG_FILE".5 -cat next.config.js.* | sed 's/^ *//g' | js-beautify | grep -v 'process\.\env\.' | js-beautify > next.config.js -rm next.config.js.* +cat "$NEXTJS_CONFIG_FILE".* | sed 's/^ *//g' | js-beautify | grep -v 'process\.\env\.' | js-beautify >"$NEXTJS_CONFIG_FILE" +rm "$NEXTJS_CONFIG_FILE".* -"${SCRIPT_DIR}/find-env.sh" "$(pwd)" > .env-list.json +"${SCRIPT_DIR}/find-env.sh" "$(pwd)" >.env-list.json if [ ! -f "package.dist" ]; then cp package.json package.dist fi -cat package.dist | jq '.scripts.cerc_compile = "next experimental-compile"' | jq '.scripts.cerc_generate = "next experimental-generate"' > package.json +cat package.dist | jq '.scripts.cerc_compile = "next experimental-compile"' | jq '.scripts.cerc_generate = "next experimental-generate"' >package.json -CUR_NEXT_VERSION="`jq -r '.dependencies.next' package.json`" +CUR_NEXT_VERSION="$(jq -r '.dependencies.next' package.json)" if [ "$CERC_NEXT_VERSION" != "keep" ] && [ "$CUR_NEXT_VERSION" != "$CERC_NEXT_VERSION" ]; then echo "Changing 'next' version specifier from '$CUR_NEXT_VERSION' to '$CERC_NEXT_VERSION' (set with '--extra-build-args \"--build-arg CERC_NEXT_VERSION=$CERC_NEXT_VERSION\"')" - cat package.json | jq ".dependencies.next = \"$CERC_NEXT_VERSION\"" > package.json.$$ + cat package.json | jq ".dependencies.next = \"$CERC_NEXT_VERSION\"" >package.json.$$ mv package.json.$$ package.json fi time $CERC_BUILD_TOOL install || exit 1 -CUR_NEXT_VERSION=`jq -r '.version' node_modules/next/package.json` +CUR_NEXT_VERSION=$(jq -r '.version' node_modules/next/package.json) semver -p -r ">=$CERC_MIN_NEXTVER" $CUR_NEXT_VERSION if [ $? -ne 0 ]; then @@ -138,7 +141,7 @@ to use for the build with: ############################################################################### EOF - cat package.json | jq ".dependencies.next = \"^$CERC_MIN_NEXTVER\"" > package.json.$$ + cat package.json | jq ".dependencies.next = \"^$CERC_MIN_NEXTVER\"" >package.json.$$ mv package.json.$$ package.json time $CERC_BUILD_TOOL install || exit 1 fi