Guest User

setupCordovaProject

a guest
Aug 14th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.18 KB | None | 0 0
  1. #!/bin/bash
  2. platform=$(uname)
  3.  
  4. SCRIPT_NAME=$(basename $0)
  5. SCRIPT_DIR=$(cd $(dirname $0);pwd)
  6.  
  7. cd ${SCRIPT_DIR}
  8.  
  9. error_exit()
  10. {
  11.     echo "$SCRIPT_NAME:Fatal Failure in ${FUNCNAME[1]}:${BASH_LINENO[0]}:  $*"
  12.     exit -1
  13. }
  14.  
  15.  
  16.  
  17. error_trap_exit()
  18. {
  19.     errorno=$?
  20.     echo "$SCRIPT_NAME:ERR trapped at line #${BASH_LINENO[0]}:  \$?=$errorno"
  21.     exit $errorno
  22. }
  23.  
  24. trap error_trap_exit ERR
  25.  
  26.  
  27. if ! which cordova >/dev/null;then
  28.     echo "cordova not found, make sure you've installed cordova."
  29.     exit 1
  30. fi
  31.  
  32. npm install
  33.  
  34. if [ "$1" == "clean" ];then
  35.    rm -rf  plugins merges platforms
  36. fi
  37.  
  38. mkdir -p plugins merges platforms
  39.  
  40. if [ "$platform" == "Darwin" ];then # mac
  41.     PLATFORMS=(android ios)
  42. else # all others only support android
  43.     PLATFORMS=(android)
  44. fi
  45. #################################################################################
  46. # install or update cordova platforms as needed
  47. #################################################################################
  48.  
  49. rm -f platform_list.tmp
  50. cordova platform list | grep Installed | awk -F: '{ print $2 }' | tr , '\n' >platform_list.tmp
  51.  
  52. for i in ${PLATFORMS[@]};do
  53.     line=$(grep $i platform_list.tmp || echo -n) # the echo after the || is to surpess error returned by grep if string not found
  54.     if [ -z "$line" ];then
  55.     echo "adding cordova platform ${i}"
  56.     cordova platform add ${i}
  57.     else
  58.     platform_version=$(echo $line | awk '{ print $2 }')
  59.     cordova_version=$(cordova -v | awk -F- '{ print $1}')
  60.     if [ "$platform_version" != "$cordova_version" ];then
  61.         echo "updating cordova platform ${i}"
  62.         cordova platform up ${i}
  63.     fi
  64.     fi
  65. done
  66. #################################################################################
  67.  
  68. rm -f platform_list.tmp
  69.  
  70. #################################################################################
  71. # install any plugins that are needed
  72. #################################################################################
  73.  
  74. if [ ! -d plugins/de.appplant.cordova.plugin.email-composer ];then
  75.    cordova plugin add https://github.com/katzer/cordova-plugin-email-composer.git
  76. fi
  77.  
  78. #################################################################################
  79.  
  80. echo "Adding Splash screens"
  81. if [ "$platform" == "Darwin" ];then # mac
  82.     cp www/img/screens/ios/* platforms/ios/TestApp/Resources/splash/
  83. fi
  84. cp www/img/screens/android/screen-xhdpi-landscape.png platforms/android/res/drawable-land-xhdpi/screen.png
  85. cp www/img/screens/android/screen-hdpi-landscape.png platforms/android/res/drawable-land-hdpi/screen.png
  86. cp www/img/screens/android/screen-mdpi-landscape.png platforms/android/res/drawable-land-mdpi/screen.png
  87. cp www/img/screens/android/screen-ldpi-landscape.png platforms/android/res/drawable-land-ldpi/screen.png
  88. cp www/img/screens/android/screen-xhdpi-portrait.png platforms/android/res/drawable-port-xhdpi/screen.png
  89. cp www/img/screens/android/screen-hdpi-portrait.png platforms/android/res/drawable-port-hdpi/screen.png
  90. cp www/img/screens/android/screen-mdpi-portrait.png platforms/android/res/drawable-port-mdpi/screen.png
  91. cp www/img/screens/android/screen-ldpi-portrait.png platforms/android/res/drawable-port-ldpi/screen.png
  92.  
  93. echo "Cordova project setup successful."
Advertisement
Add Comment
Please, Sign In to add comment