refactor: add mulitple customization features

This commit is contained in:
Rainer Killinger
2022-01-28 12:25:48 +01:00
parent 3afeb0e936
commit d22e6ff87f
14 changed files with 226 additions and 304 deletions

View File

@@ -1,35 +1,37 @@
#!/usr/bin/env sh
DEFAULT_APP_LINK_URL="your.deep.link.host.tld"
APP_LINK_URL="${APP_LINK_URL:-$DEFAULT_APP_LINK_URL}"
. $PWD/app.conf
if [ -n "$(xmlstarlet sel -T -t -v "/manifest/application/activity[intent-filter/@android:autoVerify='true']" app/android/app/src/main/AndroidManifest.xml)" ]; then
echo "Deep link capability already defined in AndroidManifest.xml"
else
echo "Adding deep link capability to AndroidManifest.xml"
xmlstarlet edit -L -s /manifest/application/activity -t elem -n tmpElement -v "" \
-i //tmpElement -t attr -n "android:autoVerify" -v "true" \
-r //tmpElement -v intent-filter \
app/android/app/src/main/AndroidManifest.xml
DEFAULT_APP_URL_SCHEME="de.anyschool.app"
APP_URL_SCHEME="${APP_URL_SCHEME:-$DEFAULT_APP_URL_SCHEME}"
xmlstarlet edit -L -s "/manifest/application/activity/intent-filter[@android:autoVerify='true']" -t elem -n tmpElement -v "" \
-i //tmpElement -t attr -n "android:name" -v "android.intent.action.VIEW" \
-r //tmpElement -v action \
app/android/app/src/main/AndroidManifest.xml
ANDROID_MANIFEST_PATH="app/android/app/src/main/AndroidManifest.xml"
ANDROID_STRINGS_PATH="app/android/app/src/main/res/values/strings.xml"
xmlstarlet edit -L -s "/manifest/application/activity/intent-filter[@android:autoVerify='true']" -t elem -n tmpElement -v "" \
-i //tmpElement -t attr -n "android:name" -v "android.intent.action.DEFAULT" \
-r //tmpElement -v category \
app/android/app/src/main/AndroidManifest.xml
xmlstarlet edit -L -s "/manifest/application/activity/intent-filter[@android:autoVerify='true']" -t elem -n tmpElement -v "" \
-i //tmpElement -t attr -n "android:name" -v "android.intent.action.BROWSABLE" \
-r //tmpElement -v category \
app/android/app/src/main/AndroidManifest.xml
git -C app checkout -- android/build.gradle
git -C app checkout -- android/app/src/main/AndroidManifest.xml
xmlstarlet edit -L -s "/manifest/application/activity/intent-filter[@android:autoVerify='true']" -t elem -n tmpElement -v "" \
-i //tmpElement -t attr -n "android:scheme" -v "https" \
-i //tmpElement -t attr -n "android:host" -v "$APP_LINK_URL" \
-r //tmpElement -v data \
app/android/app/src/main/AndroidManifest.xml
fi
# AndroidManifest.xml
xmlstarlet edit --pf --inplace \
--update "/manifest/@package" --value "$ANDROID_PACKAGE_NAME" \
$ANDROID_MANIFEST_PATH
xmlstarlet edit --pf --inplace \
--update "/manifest/application/activity/@android:name" --value "$ANDROID_PACKAGE_NAME".MainActivity \
$ANDROID_MANIFEST_PATH
# strings.xml
xmlstarlet edit --pf --inplace \
--update "/resources/string[@name='package_name']" --value "$ANDROID_PACKAGE_NAME" \
$ANDROID_STRINGS_PATH
xmlstarlet edit --pf --inplace \
--update "/resources/string[@name='custom_url_scheme']" --value "$APP_URL_SCHEME" \
$ANDROID_STRINGS_PATH
xmlstarlet edit --inplace \
--delete "/resources/string[@name='app_host']" \
--append "/resources/string[@name='custom_url_scheme']" --type elem -n string --value "$APP_LINK_HOST" \
--insert "/resources/string[not(@name)]" --type attr -n name --value "app_host" \
$ANDROID_STRINGS_PATH

View File

@@ -1,17 +1,37 @@
#!/usr/bin/env sh
DEFAULT_APP_NAME="Open StApps"
DEFAULT_APP_DISPLAY_NAME="StApps"
DEFAULT_APP_ID="de.any_school.app"
. $PWD/app.conf
DEFAULT_APP_ID="de.anyschool.app"
DEFAULT_CONFIG_MODE="WEB"
APP_NAME="${APP_NAME:-$DEFAULT_APP_NAME}"
APP_DISPLAY_NAME="${APP_DISPLAY_NAME:-$DEFAULT_APP_DISPLAY_NAME}"
APP_ID="${APP_ID:-$DEFAULT_APP_ID}"
APP_VERSION=$(jq '.version' app/package.json)
CONFIG_MODE="${CONFIG_MODE:-$DEFAULT_CONFIG_MODE}"
if [ "$CONFIG_MODE" = 'ANDROID' ]; then
APP_ID="$ANDROID_PACKAGE_NAME"
fi
if [ "$CONFIG_MODE" = 'IOS' ]; then
APP_ID="$IOS_BUNDLE_IDENTIFIER"
fi
# ionic config
cat app/ionic.config.json | jq '.name = $newName' --arg newName "$APP_NAME" > tmp.$$.json && mv tmp.$$.json app/ionic.config.json
sed -i -e 's@<title>StApps<\/title>@<title>'"$APP_DISPLAY_NAME"'<\/title>@g' app/src/index.html
ROOT_THEME_DEFINITONS=$(cat app/src/theme/variables.scss | grep -o :root | wc -l)
if [ $ROOT_THEME_DEFINITONS -gt 1 ]; then
#update
echo "SCSS theme has already been set"
else
#insert
cat customizable/theme/variables.scss >> app/src/theme/variables.scss
fi
# capacitor config
awk "/appName:.*,/ && !done { gsub(/appName:.*,/, \"appName: '$APP_NAME',\"); done=1}; 1" app/capacitor.config.ts > tmp.$$.json && mv tmp.$$.json app/capacitor.config.ts
@@ -22,7 +42,9 @@ xmlstarlet edit -L --update "/widget/@id" --value "$APP_ID" app/config.xml
xmlstarlet edit -L --update "/widget/@version" --value "$APP_VERSION" app/config.xml
xmlstarlet edit -L -N x="http://www.w3.org/ns/widgets" --update "//x:name" --value "$APP_NAME" app/config.xml
if [ -n $(xmlstarlet sel -N x="http://www.w3.org/ns/widgets" -T -t -v "//x:name[@short]" app/config.xml) ]; then
SHORT_EXISTS=$(xmlstarlet sel -N x='http://www.w3.org/ns/widgets' -T -t -v '//x:name[@short]' app/config.xml)
if [ -z "${SHORT_EXISTS:-}" ]; then
#insert
xmlstarlet edit -L -N x="http://www.w3.org/ns/widgets" -s "//x:name" -t attr -n "short" -v "$APP_DISPLAY_NAME" app/config.xml
else
@@ -31,5 +53,7 @@ else
fi
# environment config
awk "/backend_url:.*,/ && !done { gsub(/backend_url:.*,/, \"backend_url: '$BACKEND_URL',\"); done=1}; 1" app/src/environments/environment.prod.ts > tmp.$$.json && mv tmp.$$.json app/src/environments/environment.prod.t
awk "/backend_version:.*,/ && !done { gsub(/backend_version:.*,/, \"backend_version: '$BACKEND_VERSION',\"); done=1}; 1" app/src/environments/environment.prod.t > tmp.$$.json && mv tmp.$$.json app/src/environments/environment.prod.t
awk "/backend_url:.*,/ && !done { gsub(/backend_url:.*,/, \"backend_url: '$BACKEND_URL',\"); done=1}; 1" app/src/environments/environment.prod.ts > tmp.$$.json && mv tmp.$$.json app/src/environments/environment.prod.ts
awk "/backend_version:.*,/ && !done { gsub(/backend_version:.*,/, \"backend_version: '$BACKEND_VERSION',\"); done=1}; 1" app/src/environments/environment.prod.ts > tmp.$$.json && mv tmp.$$.json app/src/environments/environment.prod.ts
awk "/app_host:.*,/ && !done { gsub(/app_host:.*,/, \"app_host: '$APP_LINK_HOST',\"); done=1}; 1" app/src/environments/environment.prod.ts > tmp.$$.json && mv tmp.$$.json app/src/environments/environment.prod.ts
awk "/custom_url_scheme:.*,/ && !done { gsub(/custom_url_scheme:.*,/, \"custom_url_scheme: '$APP_URL_SCHEME',\"); done=1}; 1" app/src/environments/environment.prod.ts > tmp.$$.json && mv tmp.$$.json app/src/environments/environment.prod.ts

View File

@@ -1,9 +1,17 @@
#!/usr/bin/env sh
DEFAULT_APP_LINK_URL="your.deep.link.host.tld"
APP_LINK_URL="${APP_LINK_URL:-$DEFAULT_APP_LINK_URL}"
ENTITLEMENTS_FILE="app/ios/App/App/App.entitlements"
. $PWD/app.conf
/usr/libexec/PlistBuddy -c "Delete :com.apple.developer.associated-domains string $APP_LINK_URL" $ENTITLEMENTS_FILE
ENTITLEMENTS_FILE="app/ios/App/App/App.entitlements"
INFOPLIST_FILE="app/ios/App/App/Info.plist"
/usr/libexec/PlistBuddy -c "Delete :com.apple.developer.associated-domains string applinks:$APP_LINK_HOST" $ENTITLEMENTS_FILE
/usr/libexec/PlistBuddy -c "Add :com.apple.developer.associated-domains array" $ENTITLEMENTS_FILE
/usr/libexec/PlistBuddy -c "Add :com.apple.developer.associated-domains:0 string $APP_LINK_URL" $ENTITLEMENTS_FILE
/usr/libexec/PlistBuddy -c "Add :com.apple.developer.associated-domains:0 string applinks:$APP_LINK_HOST" $ENTITLEMENTS_FILE
/usr/libexec/PlistBuddy -c "Delete :BGTaskSchedulerPermittedIdentifiers string com.transistorsoft.fetch" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :BGTaskSchedulerPermittedIdentifiers array" $INFOPLIST_FILE
/usr/libexec/PlistBuddy -c "Add :BGTaskSchedulerPermittedIdentifiers:0 string com.transistorsoft.fetch" $INFOPLIST_FILE
git -C app checkout -- ios/App/App/AppDelegate.swift