Skip to content

Commit

Permalink
Add Modern PWA build support
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvire committed Apr 1, 2024
1 parent 808b10f commit 6242c86
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
37 changes: 37 additions & 0 deletions application/console/views/cron/scripts/upload/default/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,23 @@ build_pwa() {
APPDEF_PACKAGE_NAME=""
}

build_modern_pwa() {
echo "Build Modern PWA"
echo "OUTPUT_DIR=${OUTPUT_DIR}"
cd "$PROJECT_DIR" || exit 1

PWA_OUTPUT_DIR=/tmp/output/pwa
mkdir -p "${PWA_OUTPUT_DIR}"

# shellcheck disable=SC2086
$APP_BUILDER_SCRIPT_PATH -load build.appDef -no-save -build-modern-pwa -fp pwa.output="${PWA_OUTPUT_DIR}" ${SCRIPT_OPT}
pushd "${PWA_OUTPUT_DIR}/${APPDEF_PACKAGE_NAME}/build"
zip -r "${OUTPUT_DIR}/pwa.zip" .
popd
VERSION_CODE=""
APPDEF_PACKAGE_NAME=""
}

set_default_asset_package() {
ASSET_FILENAME="${APPDEF_PACKAGE_NAME}.zip"
echo "Updating ipa-app-type=assets"
Expand Down Expand Up @@ -554,6 +571,25 @@ prepare_appbuilder_project() {
fi
fi

# If modern-pwa, then use the subdirectory configuration for the rclone publish path if not defined
for target in $TARGETS; do
if [ "$target" = "modern-pwa" ]; then
PUBLISH_TMP=$(mktemp)
INPUT_PUBLISH_PROPERTIES=$PUBLISH_PROPERTIES
if [ -f "${OUTPUT_PUBLISH_PROPERTIES}" ]; then
INPUT_PUBLISH_PROPERTIES=$OUTPUT_PUBLISH_PROPERTIES
fi
if jq -e '.PUBLISH_CLOUD_REMOTE_PATH' "${INPUT_PUBLISH_PROPERTIES}" >/dev/null; then
echo "PUBLISH_CLOUD_REMOTE_PATH exists."
else
echo "PUBLISH_CLOUD_REMOTE_PATH set to PWA SUBDIR."
PWA_SUBDIR=$(xmllint --xpath "/app-definition/pwa-manifest/pwa-sub-directory/text()" build.appDef)
jq -cM ".PUBLISH_CLOUD_REMOTE_PATH += \"${PWA_SUBDIR}\"" "${INPUT_PUBLISH_PROPERTIES}" > "${PUBLISH_TMP}"
cp "${PUBLISH_TMP}" "${OUTPUT_PUBLISH_PROPERTIES}"
fi
fi
done

if [ ! -f "${OUTPUT_PUBLISH_PROPERTIES}" ]; then
# if no Scripture Earth record, then copy straight as normal
cp "${PUBLISH_PROPERTIES}" "${OUTPUT_PUBLISH_PROPERTIES}"
Expand Down Expand Up @@ -612,6 +648,7 @@ do
"play-listing") build_play_listing ;;
"html") build_html ;;
"pwa") build_pwa ;;
"modern-pwa") build_modern_pwa ;;
*) build_gradle "$target" ;;
esac
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ publish_rclone() {
mkdir "${ARTIFACTS_DIR}/pwa"
unzip "${ARTIFACTS_DIR}/pwa.zip" -d "${ARTIFACTS_DIR}/pwa"
PUBLISH_CLOUD_SOURCE_PATH="${ARTIFACTS_DIR}/pwa"
PUBLISH_FILE="index.html"
PUBLISH_FILE=""
elif [[ -f "${ARTIFACTS_DIR}/html.zip" ]]; then
# html: unzip the files to a directory and push the directory
mkdir "${ARTIFACTS_DIR}/html"
Expand Down Expand Up @@ -307,6 +307,10 @@ publish_rclone() {
if [[ "${PUBLISH_SERVER_PATH_ROOT}" != "null" ]]; then
PUBLISH_REMOTE_PATH=${PUBLISH_REMOTE_PATH//$PUBLISH_SERVER_PATH_ROOT\//}
fi
if [[ "${PUBLISH_REMOTE_PATH}" == /* ]]; then
# If PUBLISH_REMOTE_PATH starts with a slash, remove it to avoid double slashes in the URL
PUBLISH_REMOTE_PATH="${PUBLISH_REMOTE_PATH:1}"
fi
PUBLISH_URL="${PUBLISH_BASE_URL}/${PUBLISH_REMOTE_PATH}/${PUBLISH_FILE}"
echo "${PUBLISH_URL}" > "${OUTPUT_DIR}/publish_url.txt"
}
Expand Down

0 comments on commit 6242c86

Please sign in to comment.