Skip to content

Instantly share code, notes, and snippets.

@barbarj
Last active February 5, 2019 22:57
Show Gist options
  • Select an option

  • Save barbarj/328083ca355301675830802bc2163d84 to your computer and use it in GitHub Desktop.

Select an option

Save barbarj/328083ca355301675830802bc2163d84 to your computer and use it in GitHub Desktop.
Ionic build tool
#!/usr/bin/env bash
# This will only work from the root directory of your ionic project
args=("$@")
argCount="$#"
usage() {
echo "usage: ibuild PLATFORM VERSION/--beta"
echo "allowed platforms:"
echo " android"
echo " ios"
}
buildAndroid() {
ionic cordova build android --release
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk idd
rm app.apk
# Modify the path to zipalign to reflect your local environment
/usr/local/Caskroom/android-sdk/4333796/build-tools/27.0.3/zipalign -v 4 platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk app.apk
}
handleBefore() {
if [[ ${args[1]} == "-beta" ]]; then
cordova plugin add cordova-plugin-ionic --save --variable CHANNEL_NAME="Beta"
echo "Changed to Beta Channel"
else
ionic monitoring syncmaps "${args[1]}"
fi
}
handleAfter() {
if [[ ${args[1]} == "--beta" ]]; then
cordova plugin add cordova-plugin-ionic --save --variable CHANNEL_NAME="Master"
echo "Changed back to Master Channel"
fi
}
validateParams() {
if [[ $argCount -lt 2 ]]; then
echo "Missing parameters"
usage
false
return
elif [[ -z ${args[0]} ]]; then
echo "Plaform required"
usage
false
return
elif [[ ${args[0]} != "android" ]] && [[ ${args[0]} != "ios" ]]; then
echo "Invalid plaftorm: $1"
usage
false
return
elif [[ -z ${args[1]} ]]; then
echo "Missing version number"
usage
false
return
fi
true
}
if validateParams; then
handleBefore
echo "created source maps"
if [[ ${args[0]} == "android" ]]; then
buildAndroid
elif [[ ${args[0]} == "ios" ]]; then
ionic cordova build ios --prod
fi
handleAfter
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment