You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2015/03/06 23:27:36 UTC
[04/31] ios commit: CB-8197 Convert all bash scripts to node.js
(close #126)
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/985fb6e9/bin/templates/scripts/cordova/lib/install-device
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/lib/install-device b/bin/templates/scripts/cordova/lib/install-device
deleted file mode 100755
index bb57e93..0000000
--- a/bin/templates/scripts/cordova/lib/install-device
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/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.
-#
-
-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)
-
-DEVICE_APP_PATH="$PROJECT_PATH/build/device/$PROJECT_NAME.app"
-
-source "$CORDOVA_PATH/check_reqs"
-
-if [ ! -d "$DEVICE_APP_PATH" ]; then
- echo "Project '$DEVIC_APP_PATH' is not built."
- exit 1
-fi
-
-
-IOS_DEPLOY_MIN_VERSION="1.2.0"
-IOS_DEPLOY_LOCATION=$(which ios-deploy)
-if [ $? != 0 ]; then
- echo -e "\033[31mError: ios-deploy was not found. Please download, build and install version $IOS_DEPLOY_MIN_VERSION or greater from https://github.com/phonegap/ios-deploy into your path. Or 'npm install -g ios-deploy' using node.js: http://nodejs.org/\033[m"; exit 1;
- exit 1
-fi
-
-IOS_DEPLOY_VERSION=$(ios-deploy --version)
-if [[ "$IOS_DEPLOY_VERSION" < "$IOS_DEPLOY_MIN_VERSION" ]]; then
- echo "Cordova needs ios-deploy version $IOS_DEPLOY_MIN_VERSION or greater, you have version $IOS_DEPLOY_VERSION."
- exit 1
-fi
-
-# if we got here, we can deploy the app, then exit success
-ios-deploy -b "$DEVICE_APP_PATH"
-exit 0
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/985fb6e9/bin/templates/scripts/cordova/lib/install-emulator
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/lib/install-emulator b/bin/templates/scripts/cordova/lib/install-emulator
deleted file mode 100755
index bcf926e..0000000
--- a/bin/templates/scripts/cordova/lib/install-emulator
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/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.
-#
-
-OPTION_RESULT=()
-TARGET="iPhone-6"
-
-# 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 "$@"
-
-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)
-
-SIMULATOR_APP_PATH="$PROJECT_PATH/build/emulator/$PROJECT_NAME.app"
-
-source "$CORDOVA_PATH/check_reqs"
-
-if [ ! -d "$SIMULATOR_APP_PATH" ]; then
- echo "Project '$SIMULATOR_APP_PATH' is not built."
- exit 1
-fi
-
-if [ ! -d "$SIMULATOR_APP_PATH" ]; then
- echo "$SIMULATOR_APP_PATH not found to emulate."
- exit 1
-fi
-
-IOS_SIM_MIN_VERSION="3.0"
-IOS_SIM_LOCATION=$(which ios-sim)
-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 'npm install -g ios-sim' using node.js: http://nodejs.org/\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 "$SIMULATOR_APP_PATH" --stderr "$CORDOVA_PATH/console.log" --stdout "$CORDOVA_PATH/console.log" --devicetypeid "com.apple.CoreSimulator.SimDeviceType.$TARGET" --exit
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/985fb6e9/bin/templates/scripts/cordova/lib/list-devices
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/lib/list-devices b/bin/templates/scripts/cordova/lib/list-devices
index feacfba..a12abd7 100755
--- a/bin/templates/scripts/cordova/lib/list-devices
+++ b/bin/templates/scripts/cordova/lib/list-devices
@@ -1,23 +1,62 @@
-#!/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.
-#
-
-system_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2 " iPad"}'
-system_profiler SPUSBDataType | sed -n -e '/iPhone/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2 " iPhone"}'
-system_profiler SPUSBDataType | sed -n -e '/iPod/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2 " iPod"}'
+#!/usr/bin/env node
+
+/*
+ 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.
+*/
+
+/*jshint node: true*/
+
+var Q = require('Q'),
+ exec = require('child_process').exec;
+
+/**
+ * Gets list of connected iOS devices
+ * @return {Promise} Promise fulfilled with list of available iOS devices
+ */
+function listDevices() {
+ var commands = [
+ Q.nfcall(exec, 'system_profiler SPUSBDataType | sed -n -e \'/iPad/,/Serial/p\' | grep "Serial Number:" | awk -F ": " \'{print $2 " iPad"}\''),
+ Q.nfcall(exec, 'system_profiler SPUSBDataType | sed -n -e \'/iPhone/,/Serial/p\' | grep "Serial Number:" | awk -F ": " \'{print $2 " iPhone"}\''),
+ Q.nfcall(exec, 'system_profiler SPUSBDataType | sed -n -e \'/iPod/,/Serial/p\' | grep "Serial Number:" | awk -F ": " \'{print $2 " iPod"}\'')
+ ];
+
+ // wrap al lexec calls into promises and wait until they're fullfilled
+ return Q.all(commands).then(function (promises) {
+ var accumulator = [];
+ promises.forEach(function (promise) {
+ if (promise.state === 'fulfilled') {
+ // Each command promise resolves with array [stout, stderr], and we need stdout only
+ // Append stdout lines to accumulator
+ accumulator.concat(promise.value[0].trim().split('\n'));
+ }
+ });
+ return accumulator;
+ });
+}
+
+exports.run = listDevices;
+
+// Check if module is started as separate script.
+// If so, then invoke main method and print out results.
+if (!module.parent) {
+ listDevices().then(function (devices) {
+ devices.forEach(function (device) {
+ console.log(device);
+ });
+ });
+}
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/985fb6e9/bin/templates/scripts/cordova/lib/list-emulator-images
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/lib/list-emulator-images b/bin/templates/scripts/cordova/lib/list-emulator-images
index c831370..0c7f0c5 100755
--- a/bin/templates/scripts/cordova/lib/list-emulator-images
+++ b/bin/templates/scripts/cordova/lib/list-emulator-images
@@ -1,39 +1,53 @@
-#!/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.
-
-set -e
-
-IOS_SIM_MIN_VERSION="3.0"
-IOS_SIM_LOCATION=$(which ios-sim)
-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 'npm install -g ios-sim' using node.js: http://nodejs.org/\033[m" 1>&2;
- 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." 1>&2;
- exit 1
-fi
-
-ios-sim showdevicetypes 2>&1 | sed "s/com.apple.CoreSimulator.SimDeviceType.//g" | awk -F',' '{print $1}'
-
-
-
+#!/usr/bin/env node
+
+/*
+ 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.
+*/
+
+/*jshint node: true*/
+
+var Q = require('q'),
+ exec = require('child_process').exec,
+ check_reqs = require('./check_reqs');
+
+/**
+ * Gets list of iOS devices available for simulation
+ * @return {Promise} Promise fulfilled with list of devices available for simulation
+ */
+function listEmulatorImages () {
+ return check_reqs.check_ios_sim().then(function () {
+ return Q.nfcall(exec, 'ios-sim showdevicetypes 2>&1 | ' +
+ 'sed "s/com.apple.CoreSimulator.SimDeviceType.//g" | ' +
+ 'awk -F\',\' \'{print $1}\'');
+ }).then(function (stdio) {
+ // Exec promise resolves with array [stout, stderr], and we need stdout only
+ return stdio[0].trim().split('\n');
+ });
+}
+
+exports.run = listEmulatorImages;
+
+// Check if module is started as separate script.
+// If so, then invoke main method and print out results.
+if (!module.parent) {
+ listEmulatorImages().then(function (names) {
+ names.forEach(function (name) {
+ console.log(name);
+ });
+ });
+}
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/985fb6e9/bin/templates/scripts/cordova/lib/list-started-emulators
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/lib/list-started-emulators b/bin/templates/scripts/cordova/lib/list-started-emulators
index badab2c..1269e47 100755
--- a/bin/templates/scripts/cordova/lib/list-started-emulators
+++ b/bin/templates/scripts/cordova/lib/list-started-emulators
@@ -1,30 +1,51 @@
-#!/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.
-#
-
-set -e
-
-SIM_RUNNING=$(ps aux | grep -i "[i]OS Simulator" | wc -l)
-if [ $SIM_RUNNING == 0 ]; then
- echo "No emulators are running."
- exit 1
-fi
-
-SIM_ID=`defaults read com.apple.iphonesimulator "SimulateDevice"`
-echo \"$SIM_ID\"
+#!/usr/bin/env node
+
+/*
+ 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.
+*/
+
+/*jshint node: true*/
+
+var Q = require('q'),
+ exec = require('child_process').exec;
+
+/**
+ * Gets list of running iOS simulators
+ * @return {Promise} Promise fulfilled with list of running iOS simulators
+ */
+function listStartedEmulators () {
+ // wrap exec call into promise
+ return Q.nfcall(exec, 'ps aux | grep -i "[i]OS Simulator"')
+ .then(function () {
+ return Q.nfcall(exec, 'defaults read com.apple.iphonesimulator "SimulateDevice"');
+ }).then(function (stdio) {
+ return stdio[0].trim().split('\n');
+ });
+}
+
+exports.run = listStartedEmulators;
+
+// Check if module is started as separate script.
+// If so, then invoke main method and print out results.
+if (!module.parent) {
+ listStartedEmulators().then(function (emulators) {
+ emulators.forEach(function (emulator) {
+ console.log(emulator);
+ });
+ });
+}
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/985fb6e9/bin/templates/scripts/cordova/lib/run.js
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/lib/run.js b/bin/templates/scripts/cordova/lib/run.js
new file mode 100644
index 0000000..53153fc
--- /dev/null
+++ b/bin/templates/scripts/cordova/lib/run.js
@@ -0,0 +1,177 @@
+/*
+ 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.
+*/
+
+/*jshint node: true*/
+
+var Q = require('q'),
+ nopt = require('nopt'),
+ path = require('path'),
+ build = require('./build'),
+ spawn = require('./spawn'),
+ check_reqs = require('./check_reqs');
+
+var cordovaPath = path.join(__dirname, '..');
+var projectPath = path.join(__dirname, '..', '..');
+
+module.exports.run = function (argv) {
+
+ // parse args here
+ // --debug and --release args not parsed here
+ // but still valid since they can be passed down to build command
+ var args = nopt({
+ // "archs": String, // TODO: add support for building different archs
+ "list": Boolean,
+ "nobuild": Boolean,
+ "device": Boolean, "emulator": Boolean, "target": String
+ }, {}, argv);
+
+ // Validate args
+ if (args.device && args.emulator) {
+ return Q.reject('Only one of "device"/"emulator" options should be specified');
+ }
+
+ // validate target device for ios-sim
+ // Valid values for "--target" (case sensitive):
+ var validTargets = ["iPhone-4s", "iPhone-5", "iPhone-5s", "iPhone-6-Plus", "iPhone-6",
+ "iPad-2", "iPad-Retina", "iPad-Air", "Resizable-iPhone", "Resizable-iPad"];
+ if (args.target && validTargets.indexOf(args.target) < 0 ) {
+ return Q.reject(args.target + " is not a valid target for emulator");
+ }
+
+ // support for CB-8168 `cordova/run --list`
+ if (args.list) {
+ if (args.device) return listDevices();
+ if (args.emulator) return listEmulators();
+ // if no --device or --emulator flag is specified, list both devices and emulators
+ return listDevices().then(function () {
+ return listEmulators();
+ });
+ }
+
+ // check for either ios-sim or ios-deploy is available
+ // depending on arguments provided
+ var checkTools = args.device ? check_reqs.check_ios_deploy() : check_reqs.check_ios_sim();
+
+ return checkTools.then(function () {
+ // if --nobuild isn't specified then build app first
+ if (!args.nobuild) {
+ return build.run(argv);
+ }
+ }).then(function () {
+ return build.findXCodeProjectIn(projectPath);
+ }).then(function (projectName) {
+ var appPath = path.join(projectPath, 'build', (args.device ? 'device' : 'emulator'), projectName + '.app');
+ // select command to run and arguments depending whether
+ // we're running on device/emulator
+ if (args.device) {
+ return checkDeviceConnected().then(function () {
+ return deployToDevice(appPath);
+ }, function () {
+ // if device connection check failed use emulator then
+ return deployToSim(appPath, args.target);
+ });
+ } else {
+ return deployToSim(appPath, args.target);
+ }
+ });
+};
+
+/**
+ * Checks if any iOS device is connected
+ * @return {Promise} Fullfilled when any device is connected, rejected otherwise
+ */
+function checkDeviceConnected() {
+ return spawn('ios-deploy', ['-c']);
+}
+
+/**
+ * Deploy specified app package to connected device
+ * using ios-deploy command
+ * @param {String} appPath Path to application package
+ * @return {Promise} Resolves when deploy succeeds otherwise rejects
+ */
+function deployToDevice(appPath) {
+ // Deploying to device...
+ return spawn('ios-deploy', ['-d', '-b', appPath]);
+}
+
+/**
+ * Deploy specified app package to ios-sim simulator
+ * @param {String} appPath Path to application package
+ * @param {String} target Target device type
+ * @return {Promise} Resolves when deploy succeeds otherwise rejects
+ */
+function deployToSim(appPath, target) {
+ // Select target device for emulator. Default is 'iPhone-6'
+ if (!target) {
+ target = 'iPhone-6';
+ console.log('No target specified for emulator. Deploying to ' + target + ' simulator');
+ }
+ var logPath = path.join(cordovaPath, 'console.log');
+ var simArgs = ['launch', appPath,
+ '--devicetypeid', 'com.apple.CoreSimulator.SimDeviceType.' + target,
+ // We need to redirect simulator output here to use cordova/log command
+ // TODO: Is there any other way to get emulator's output to use in log command?
+ '--stderr', logPath, '--stdout', logPath,
+ '--exit'];
+ return spawn('ios-sim', simArgs);
+}
+
+function listDevices() {
+ return require('./list-devices').run()
+ .then(function (devices) {
+ console.log("Available iOS Devices:");
+ devices.forEach(function (device) {
+ console.log('\t' + device);
+ });
+ });
+}
+
+function listEmulators() {
+ return require('./list-emulator-images').run()
+ .then(function (emulators) {
+ console.log("Available iOS Virtual Devices:");
+ emulators.forEach(function (emulator) {
+ console.log('\t' + emulator);
+ });
+ });
+}
+
+module.exports.help = function () {
+ console.log("\nUsage: run [ --device | [ --emulator [ --target=<id> ] ] ] [ --debug | --release | --nobuild ]");
+ // TODO: add support for building different archs
+ // console.log(" [ --archs=\"<list of target architectures>\" ] ");
+ console.log(" --device : Deploys and runs the project on the connected device.");
+ console.log(" --emulator : Deploys and runs the project on an emulator.");
+ console.log(" --target=<id> : Deploys and runs the project on the specified target.");
+ console.log(" --debug : Builds project in debug mode. (Passed down to build command, if necessary)");
+ console.log(" --release : Builds project in release mode. (Passed down to build command, if necessary)");
+ console.log(" --nobuild : Uses pre-built package, or errors if project is not built.");
+ // TODO: add support for building different archs
+ // console.log(" --archs : Specific chip architectures (`anycpu`, `arm`, `x86`, `x64`).");
+ console.log("");
+ console.log("Examples:");
+ console.log(" run");
+ console.log(" run --device");
+ console.log(" run --emulator --target=\"iPhone-6-Plus\"");
+ console.log(" run --device --release");
+ console.log(" run --emulator --debug");
+ console.log("");
+ process.exit(0);
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/985fb6e9/bin/templates/scripts/cordova/lib/spawn.js
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/lib/spawn.js b/bin/templates/scripts/cordova/lib/spawn.js
new file mode 100644
index 0000000..1cb3161
--- /dev/null
+++ b/bin/templates/scripts/cordova/lib/spawn.js
@@ -0,0 +1,50 @@
+/*
+ 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.
+*/
+
+/*jshint node: true*/
+
+var Q = require('q'),
+ proc = require('child_process');
+
+/**
+ * Run specified command with arguments
+ * @param {String} cmd Command
+ * @param {Array} args Array of arguments that should be passed to command
+ * @param {String} opt_cwd Working directory for command
+ * @param {String} opt_verbosity Verbosity level for command stdout output, "verbose" by default
+ * @return {Promise} Promise either fullfilled or rejected with error code
+ */
+module.exports = function(cmd, args, opt_cwd) {
+ var d = Q.defer();
+ try {
+ var child = proc.spawn(cmd, args, {cwd: opt_cwd, stdio: 'inherit'});
+
+ child.on('exit', function(code) {
+ if (code) {
+ d.reject('Error code ' + code + ' for command: ' + cmd + ' with args: ' + args);
+ } else {
+ d.resolve();
+ }
+ });
+ } catch(e) {
+ console.error('error caught: ' + e);
+ d.reject(e);
+ }
+ return d.promise;
+};
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/985fb6e9/bin/templates/scripts/cordova/run
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/run b/bin/templates/scripts/cordova/run
index 2cd0811..d2c376d 100755
--- a/bin/templates/scripts/cordova/run
+++ b/bin/templates/scripts/cordova/run
@@ -1,186 +1,36 @@
-#!/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 sensitive):
-# iPhone-4s
-# iPhone-5
-# iPhone-5s
-# iPhone-6-Plus
-# iPhone-6
-# iPad-2
-# iPad-Retina
-# iPad-Air
-# Resizable-iPhone
-# Resizable-iPad
-
-
-OPTION_RESULT=()
-TARGET="iPhone-6"
-
-# multi-device flow default
-USE_DEVICE=true
-USE_SIMULATOR=false
-
-# options
-NO_BUILD=false
-
-# display list
-DISPLAY_LIST=false
-DISPLAY_DEVICE=false
-DISPLAY_EMULATOR=false
-
-# 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]}
- ;;
- "--device")
- USE_DEVICE=true
- USE_SIMULATOR=false
- DISPLAY_DEVICE=true
- ;;
- "--emulator")
- USE_DEVICE=false
- USE_SIMULATOR=true
- DISPLAY_EMULATOR=true
- ;;
- "--list")
- DISPLAY_LIST=true
- ;;
- "--nobuild")
- NO_BUILD=true
- ;;
- esac
- done
-}
-
-_displayDevices()
-{
- echo "Available iOS Devices:"
- "$CORDOVA_PATH/lib/list-devices" 2>&1 | sed 's/^/ /'
-}
-
-_displayVirtualDevices()
-{
- echo "Available iOS Virtual Devices:"
- "$CORDOVA_PATH/lib/list-emulator-images" 2>&1 | sed 's/^/ /'
-}
-
-_parseArgs "$@"
-
-CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd -P)
-PROJECT_PATH="$(dirname "$CORDOVA_PATH")"
-XCODEPROJ=$( ls "$PROJECT_PATH" | grep .xcodeproj )
-PROJECT_NAME=$(basename "$XCODEPROJ" .xcodeproj)
-
-SIMULATOR_APP_PATH="$PROJECT_PATH/build/emulator/$PROJECT_NAME.app"
-DEVICE_APP_PATH="$PROJECT_PATH/build/device/$PROJECT_NAME.app"
-
-source "$CORDOVA_PATH/check_reqs"
-
-# check if it's a list command
-if "$DISPLAY_LIST"; then
- if "$DISPLAY_DEVICE" || "$DISPLAY_EMULATOR"; then
- if "$DISPLAY_EMULATOR"; then
- _displayVirtualDevices
- fi
- if "$DISPLAY_DEVICE"; then
- _displayDevices
- fi
- exit 0
- else
- _displayVirtualDevices
- _displayDevices
- exit 0
- fi
-fi
-
-
-# if device build found, run it first
-if "$USE_DEVICE"; then
- IOS_DEPLOY_MIN_VERSION="1.2.0"
- IOS_DEPLOY_LOCATION=$(which ios-deploy)
- if [ $? != 0 ]; then
- echo -e "\033[31mError: ios-deploy was not found. Please download, build and install version $IOS_DEPLOY_MIN_VERSION or greater from https://github.com/phonegap/ios-deploy into your path. Or 'npm install -g ios-deploy' using node.js: http://nodejs.org/\033[m" 1>&2;
- exit 1
- fi
-
- IOS_DEPLOY_VERSION=$(ios-deploy --version)
- if [[ "$IOS_DEPLOY_VERSION" < "$IOS_DEPLOY_MIN_VERSION" ]]; then
- echo "Cordova needs ios-deploy version $IOS_DEPLOY_MIN_VERSION or greater, you have version $IOS_DEPLOY_VERSION." 1>&2;
- exit 1
- fi
-
- DEVICE_CONNECTED=$(ios-deploy -c)
- if [ $? != 0 ]; then
- echo "No device is connected, trying Simulator." 1>&2;
- USE_SIMULATOR=true
- else
- # if we got here, we can deploy the app, then exit success
- if ! [ "$NO_BUILD" = true ]; then
- "$CORDOVA_PATH/build" --device || exit $?
- fi
- ios-deploy -d -b "$DEVICE_APP_PATH"
- exit 0
- fi
-fi
-
-if "$USE_SIMULATOR"; then
- IOS_SIM_MIN_VERSION="3.0"
- IOS_SIM_LOCATION=$(which ios-sim)
- 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 'npm install -g ios-sim' using node.js: http://nodejs.org/\033[m" 1>&2;
- 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." 1>&2;
- exit 1
- fi
-
- # launch using ios-sim
- if ! [ "$NO_BUILD" = true ]; then
- "$CORDOVA_PATH/build" --emulator || exit $?
- fi
- ios-sim launch "$SIMULATOR_APP_PATH" --stderr "$CORDOVA_PATH/console.log" --stdout "$CORDOVA_PATH/console.log" --devicetypeid com.apple.CoreSimulator.SimDeviceType.$TARGET --exit
-fi
-
+#!/usr/bin/env node
+
+/*
+ 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.
+*/
+
+var args = process.argv,
+ run = require('./lib/run');
+
+// Handle help flag
+if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(args[2]) > -1) {
+ run.help();
+} else {
+ run.run(args).done(function() {
+ console.log('** RUN SUCCEEDED **');
+ }, function (err) {
+ var errorMessage = (err && err.stack) ? err.stack : err;
+ console.error(errorMessage);
+ process.exit(2);
+ });
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/985fb6e9/bin/templates/scripts/cordova/run.bat
----------------------------------------------------------------------
diff --git a/bin/templates/scripts/cordova/run.bat b/bin/templates/scripts/cordova/run.bat
new file mode 100644
index 0000000..0d10321
--- /dev/null
+++ b/bin/templates/scripts/cordova/run.bat
@@ -0,0 +1,25 @@
+:: 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
+@ECHO OFF
+SET script_path="%~dp0run"
+IF EXIST %script_path% (
+ node %script_path% %*
+) ELSE (
+ ECHO.
+ ECHO ERROR: Could not find 'run' script in 'cordova' folder, aborting...>&2
+ EXIT /B 1
+)
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/985fb6e9/tests/spec/create.spec.js
----------------------------------------------------------------------
diff --git a/tests/spec/create.spec.js b/tests/spec/create.spec.js
index 48d6073..11a9062 100644
--- a/tests/spec/create.spec.js
+++ b/tests/spec/create.spec.js
@@ -108,10 +108,14 @@ describe('create', function() {
describe('end-to-end list validation', function(){
it('handles list parameter', function() {
shell.cp('-f', path.join(cordova_bin, 'check_reqs'), path.join(cordova_bin, 'templates', 'scripts', 'cordova', 'check_reqs'));
+ shell.cp('-f', path.join(cordova_bin, 'lib', 'check_reqs.js'), path.join(cordova_bin, 'templates', 'scripts', 'cordova', 'lib', 'check_reqs.js'));
+ shell.cp('-f', path.join(cordova_bin, 'lib', 'versions.js'), path.join(cordova_bin, 'templates', 'scripts', 'cordova', 'lib', 'versions.js'));
var command = '"' + path.join(cordova_bin, 'templates', 'scripts', 'cordova', 'run') + '" --list';
var output = shell.exec(command, {silent: true}).output;
expect(output).toMatch(/Available iOS Virtual Devices/);
expect(output).toMatch(/Available iOS Devices/);
shell.rm('-f', path.join(cordova_bin, 'templates', 'scripts', 'cordova', 'check_reqs'));
+ shell.rm('-f', path.join(cordova_bin, 'templates', 'scripts', 'cordova', 'lib', 'check_reqs.js'));
+ shell.rm('-f', path.join(cordova_bin, 'templates', 'scripts', 'cordova', 'lib', 'versions.js'));
});
});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org