cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject [04/11] ios commit: [CB-2982] Add a ./cordova/lib/install-emulator project-level helper script to iOS
Date Thu, 25 Apr 2013 13:42:57 GMT
[CB-2982] Add a ./cordova/lib/install-emulator project-level helper script to iOS


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/eacd50f5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/eacd50f5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/eacd50f5

Branch: refs/heads/master
Commit: eacd50f5ed911a2175339372b1de3f6548d32e1e
Parents: 075b139
Author: Shazron Abdullah <shazron@apache.org>
Authored: Thu Apr 25 05:24:57 2013 -0700
Committer: Shazron Abdullah <shazron@apache.org>
Committed: Thu Apr 25 06:36:37 2013 -0700

----------------------------------------------------------------------
 bin/templates/project/cordova/lib/install-emulator |  130 +++++++++++++++
 1 files changed, 130 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/eacd50f5/bin/templates/project/cordova/lib/install-emulator
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/lib/install-emulator b/bin/templates/project/cordova/lib/install-emulator
new file mode 100755
index 0000000..a5485cf
--- /dev/null
+++ b/bin/templates/project/cordova/lib/install-emulator
@@ -0,0 +1,130 @@
+#!/usr/bin/env bash 
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# Valid values for "--target" (case insensitive):
+#     "iPhone (Retina 3.5-inch)" (default)
+#     "iPhone (Retina 4-inch)"
+#     "iPhone"
+#     "iPad"
+#     "iPad (Retina)"
+
+set -e
+
+OPTION_RESULT=()
+TARGET="iPhone (Retina 3.5-inch)"
+TARGET_FLAG='--family iphone --retina'
+
+# separates "key=value", sets an array with 0th index as key, 1st index as value
+_parseOption() 
+{
+    local ARG=$@
+    OIFS=$IFS
+    IFS='='
+
+    OPTION_RESULT=()
+    for i in ${ARG[@]}
+    do
+      OPTION_RESULT+=($i)
+    done
+
+    IFS=$OIFS
+}
+
+# parses key=value arguments
+_parseArgs()
+{
+  for arg in "$@"
+  do
+    _parseOption ${arg}
+    case "${OPTION_RESULT[0]}" in
+      "--target")
+        TARGET=${OPTION_RESULT[1]}
+        ;;
+    esac
+  done
+}
+
+_parseArgs "$@"
+
+# lowercase the target string
+TARGET_LC=`echo $TARGET | tr '[:upper:]' '[:lower:]'` 
+
+# remember the comparison is lowercase
+case "$TARGET_LC" in
+  "iphone (retina 3.5-inch)")
+    TARGET_FLAG="--family iphone --retina"
+    ;;
+    "iphone (retina 4-inch)")
+    TARGET_FLAG="--family iphone --retina --tall"
+    ;;
+    "iphone")
+    TARGET_FLAG="--family iphone"
+    ;;
+    "ipad")
+    TARGET_FLAG="--family ipad"
+    ;;
+    "ipad (retina)")
+    TARGET_FLAG="--family ipad --retina"
+    ;;
+esac
+
+XCODE_VER=$(xcodebuild -version | head -n 1 | sed -e 's/Xcode //')
+XCODE_MIN_VERSION="4.5"
+
+if [[ "$XCODE_VER" < "$XCODE_MIN_VERSION" ]]; then
+	echo "Cordova can only run in Xcode version $XCODE_MIN_VERSION or greater."
+	exit 1
+fi
+
+LIB_PATH=$( cd "$( dirname "$0" )" && pwd -P)
+CORDOVA_PATH="$(dirname "$LIB_PATH")"
+PROJECT_PATH="$(dirname "$CORDOVA_PATH")"
+XCODEPROJ=$( ls "$PROJECT_PATH" | grep .xcodeproj  )
+PROJECT_NAME=$(basename "$XCODEPROJ" .xcodeproj)
+
+APP_PATH="$PROJECT_PATH/build/$PROJECT_NAME.app"
+
+if [ ! -d "$APP_PATH" ]; then
+	echo "Project '$APP_PATH' is not built."
+    exit 1
+fi
+
+if [ ! -d "$APP_PATH" ]; then
+	echo "$APP_PATH not found to emulate."
+	exit 1
+fi
+
+IOS_SIM_MIN_VERSION="1.5"
+IOS_SIM_LOCATION=$(which xcodebuild)
+if [ $? != 0 ]; then
+    echo -e "\033[31mError: ios-sim was not found. Please download, build and install version
$IOS_SIM_MIN_VERSION or greater from https://github.com/phonegap/ios-sim into your path. Or
'brew install ios-sim' using homebrew: http://mxcl.github.com/homebrew/\033[m"; exit 1;
+	exit 1
+fi
+
+IOS_SIM_VERSION=$(ios-sim --version)
+
+if [[ "$IOS_SIM_VERSION" < "$IOS_SIM_MIN_VERSION" ]]; then
+	echo "Cordova needs ios-sim version $IOS_SIM_MIN_VERSION or greater, you have version $IOS_SIM_VERSION."
+	exit 1
+fi
+
+# launch using ios-sim
+ios-sim launch "$APP_PATH" --stderr "$CORDOVA_PATH/console.log" --stdout "$CORDOVA_PATH/console.log"
$TARGET_FLAG --exit
+
+


Mime
View raw message