From 6242c8676e6fea917ad356cb4dd804361de2996d Mon Sep 17 00:00:00 2001 From: Chris Hubbard Date: Mon, 1 Apr 2024 10:04:11 -0400 Subject: [PATCH] Add Modern PWA build support --- .../cron/scripts/upload/default/build.sh | 37 +++++++++++++++++++ .../cron/scripts/upload/default/publish.sh | 6 ++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/application/console/views/cron/scripts/upload/default/build.sh b/application/console/views/cron/scripts/upload/default/build.sh index 4911cb1..da86c21 100644 --- a/application/console/views/cron/scripts/upload/default/build.sh +++ b/application/console/views/cron/scripts/upload/default/build.sh @@ -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" @@ -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}" @@ -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 diff --git a/application/console/views/cron/scripts/upload/default/publish.sh b/application/console/views/cron/scripts/upload/default/publish.sh index d0bee16..b628314 100644 --- a/application/console/views/cron/scripts/upload/default/publish.sh +++ b/application/console/views/cron/scripts/upload/default/publish.sh @@ -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" @@ -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" }