format
All checks were successful
Lint Checks / Run linter (pull_request) Successful in 41s
Webapp Test / Run webapp test suite (pull_request) Successful in 4m35s
Smoke Test / Run basic test suite (pull_request) Successful in 4m18s
Deploy Test / Run deploy test suite (pull_request) Successful in 5m5s
K8s Deploy Test / Run deploy test suite on kind/k8s (pull_request) Successful in 7m34s
All checks were successful
Lint Checks / Run linter (pull_request) Successful in 41s
Webapp Test / Run webapp test suite (pull_request) Successful in 4m35s
Smoke Test / Run basic test suite (pull_request) Successful in 4m18s
Deploy Test / Run deploy test suite (pull_request) Successful in 5m5s
K8s Deploy Test / Run deploy test suite on kind/k8s (pull_request) Successful in 7m34s
This commit is contained in:
parent
6928a60751
commit
32cbdc9008
@ -26,12 +26,15 @@ WORK_DIR="${1:-/app}"
|
|||||||
cd "${WORK_DIR}" || exit 1
|
cd "${WORK_DIR}" || exit 1
|
||||||
|
|
||||||
# If this file doesn't exist at all, we'll get errors below.
|
# If this file doesn't exist at all, we'll get errors below.
|
||||||
if [ ! -f "next.config.js" ]; then
|
NEXTJS_CONFIG_FILE="next.config.js"
|
||||||
touch 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
|
fi
|
||||||
|
|
||||||
if [ ! -f "next.config.dist" ]; then
|
if [ ! -f "next.config.dist" ]; then
|
||||||
cp next.config.js next.config.dist
|
cp "$NEXTJS_CONFIG_FILE" next.config.dist
|
||||||
fi
|
fi
|
||||||
|
|
||||||
which js-beautify >/dev/null
|
which js-beautify >/dev/null
|
||||||
@ -39,17 +42,17 @@ if [ $? -ne 0 ]; then
|
|||||||
npm i -g js-beautify
|
npm i -g js-beautify
|
||||||
fi
|
fi
|
||||||
|
|
||||||
js-beautify next.config.dist > next.config.js
|
js-beautify next.config.dist > "$NEXTJS_CONFIG_FILE"
|
||||||
echo "" >> next.config.js
|
echo "" >> "$NEXTJS_CONFIG_FILE"
|
||||||
|
|
||||||
WEBPACK_REQ_LINE=$(grep -n "require([\'\"]webpack[\'\"])" next.config.js | cut -d':' -f1)
|
WEBPACK_REQ_LINE=$(grep -n "require([\'\"]webpack[\'\"])" "$NEXTJS_CONFIG_FILE" | cut -d':' -f1)
|
||||||
if [ -z "$WEBPACK_REQ_LINE" ]; then
|
if [ -z "$WEBPACK_REQ_LINE" ]; then
|
||||||
cat > next.config.js.0 <<EOF
|
cat > "$NEXTJS_CONFIG_FILE".0 <<EOF
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat > next.config.js.1 <<EOF
|
cat > "$NEXTJS_CONFIG_FILE".1 <<EOF
|
||||||
let envMap;
|
let envMap;
|
||||||
try {
|
try {
|
||||||
// .env-list.json provides us a list of identifiers which should be replaced at runtime.
|
// .env-list.json provides us a list of identifiers which should be replaced at runtime.
|
||||||
@ -68,21 +71,21 @@ try {
|
|||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
CONFIG_LINES=$(wc -l next.config.js | awk '{ print $1 }')
|
CONFIG_LINES=$(wc -l "$NEXTJS_CONFIG_FILE" | awk '{ print $1 }')
|
||||||
ENV_LINE=$(grep -n 'env:' next.config.js | cut -d':' -f1)
|
ENV_LINE=$(grep -n 'env:' "$NEXTJS_CONFIG_FILE" | cut -d':' -f1)
|
||||||
WEBPACK_CONF_LINE=$(egrep -n 'webpack:\s+\([^,]+,' next.config.js | cut -d':' -f1)
|
WEBPACK_CONF_LINE=$(egrep -n 'webpack:\s+\([^,]+,' "$NEXTJS_CONFIG_FILE" | cut -d':' -f1)
|
||||||
NEXT_SECTION_ADJUSTMENT=0
|
NEXT_SECTION_ADJUSTMENT=0
|
||||||
|
|
||||||
if [ -n "$WEBPACK_CONF_LINE" ]; then
|
if [ -n "$WEBPACK_CONF_LINE" ]; then
|
||||||
WEBPACK_CONF_VAR=$(egrep -n 'webpack:\s+\([^,]+,' next.config.js | cut -d',' -f1 | cut -d'(' -f2)
|
WEBPACK_CONF_VAR=$(egrep -n 'webpack:\s+\([^,]+,' "$NEXTJS_CONFIG_FILE" | cut -d',' -f1 | cut -d'(' -f2)
|
||||||
head -$(( ${WEBPACK_CONF_LINE} )) next.config.js > next.config.js.2
|
head -$(( ${WEBPACK_CONF_LINE} )) "$NEXTJS_CONFIG_FILE" > "$NEXTJS_CONFIG_FILE".2
|
||||||
cat > next.config.js.3 <<EOF
|
cat > "$NEXTJS_CONFIG_FILE".3 <<EOF
|
||||||
$WEBPACK_CONF_VAR.plugins.push(new webpack.DefinePlugin(envMap));
|
$WEBPACK_CONF_VAR.plugins.push(new webpack.DefinePlugin(envMap));
|
||||||
EOF
|
EOF
|
||||||
NEXT_SECTION_LINE=$((WEBPACK_CONF_LINE))
|
NEXT_SECTION_LINE=$((WEBPACK_CONF_LINE))
|
||||||
elif [ -n "$ENV_LINE" ]; then
|
elif [ -n "$ENV_LINE" ]; then
|
||||||
head -$(( ${ENV_LINE} - 1 )) next.config.js > next.config.js.2
|
head -$(( ${ENV_LINE} - 1 )) "$NEXTJS_CONFIG_FILE" > "$NEXTJS_CONFIG_FILE".2
|
||||||
cat > next.config.js.3 <<EOF
|
cat > "$NEXTJS_CONFIG_FILE".3 <<EOF
|
||||||
webpack: (config) => {
|
webpack: (config) => {
|
||||||
config.plugins.push(new webpack.DefinePlugin(envMap));
|
config.plugins.push(new webpack.DefinePlugin(envMap));
|
||||||
return config;
|
return config;
|
||||||
@ -91,15 +94,15 @@ EOF
|
|||||||
NEXT_SECTION_ADJUSTMENT=1
|
NEXT_SECTION_ADJUSTMENT=1
|
||||||
NEXT_SECTION_LINE=$ENV_LINE
|
NEXT_SECTION_LINE=$ENV_LINE
|
||||||
else
|
else
|
||||||
echo "WARNING: Cannot find location to insert environment variable map in next.config.js" 1>&2
|
echo "WARNING: Cannot find location to insert environment variable map in "$NEXTJS_CONFIG_FILE"" 1>&2
|
||||||
rm -f next.config.js.*
|
rm -f "$NEXTJS_CONFIG_FILE".*
|
||||||
NEXT_SECTION_LINE=0
|
NEXT_SECTION_LINE=0
|
||||||
fi
|
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
|
cat "$NEXTJS_CONFIG_FILE".* | sed 's/^ *//g' | js-beautify | grep -v 'process\.\env\.' | js-beautify > "$NEXTJS_CONFIG_FILE"
|
||||||
rm next.config.js.*
|
rm "$NEXTJS_CONFIG_FILE".*
|
||||||
|
|
||||||
"${SCRIPT_DIR}/find-env.sh" "$(pwd)" > .env-list.json
|
"${SCRIPT_DIR}/find-env.sh" "$(pwd)" > .env-list.json
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user