Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AD51710635 for ; Mon, 26 Aug 2013 21:50:21 +0000 (UTC) Received: (qmail 5986 invoked by uid 500); 26 Aug 2013 21:50:21 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 5970 invoked by uid 500); 26 Aug 2013 21:50:21 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 5956 invoked by uid 99); 26 Aug 2013 21:50:20 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Aug 2013 21:50:20 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 65AD58C5DF2; Mon, 26 Aug 2013 21:50:20 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bennmapes@apache.org To: commits@cordova.apache.org Date: Mon, 26 Aug 2013 21:50:20 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] [CB-3542] rewrote cli tooling scripts in node Updated Branches: refs/heads/master e6812f18a -> 1bd490098 http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/device.js ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/device.js b/bin/templates/cordova/lib/device.js new file mode 100644 index 0000000..900baf4 --- /dev/null +++ b/bin/templates/cordova/lib/device.js @@ -0,0 +1,101 @@ +#!/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 shell = require('shelljs'), + path = require('path'), + build = require('./build'), + exec = require('child_process').exec, + ROOT = path.join(__dirname, '..', '..'); + +/** + * Returns a list of the device ID's found + */ +module.exports.list = function() { + var cmd = 'adb devices'; + var result = shell.exec(cmd, {silent:true, async:false}); + if (result.code > 0) { + console.error('Failed to execute android command \'' + cmd + '\'.'); + process.exit(2); + } else { + var response = result.output.split('\n'); + var device_list = []; + for (var i = 1; i < response.length; i++) { + if (response[i].match(/\w+\tdevice/) && !response[i].match(/emulator/)) { + device_list.push(response[i].replace(/\tdevice/, '').replace('\r', '')); + } + } + return device_list; + } +} + +/* + * Installs a previously built application on the device + * and launches it. + */ +module.exports.install = function(target) { + var device_list = this.list(); + if (device_list.length > 0) { + // default device + target = typeof target !== 'undefined' ? target : device_list[0]; + if (device_list.indexOf(target) > -1) { + var apk_path = build.get_apk(); + var cmd = 'java -jar ' + path.join(ROOT, 'cordova', 'appinfo.jar') + ' ' + path.join(ROOT, 'AndroidManifest.xml'); + var launch_name = shell.exec(cmd, {silent:true, async:false}); + if (launch_name.error) { + console.log('ERROR : Failed to get application name from appinfo.jar + AndroidManifest : '); + console.log("Output : " + launch_name.output); + process.exit(2); + } + + console.log('Installing app on device...'); + cmd = 'adb -s ' + target + ' install -r ' + apk_path; + var install = shell.exec(cmd, {silent:false, async:false}); + if (install.error || install.output.match(/Failure/)) { + console.error('ERROR : Failed to install apk to device : '); + console.error(install.output); + process.exit(2); + } + + //unlock screen + cmd = 'adb -s ' + target + ' shell input keyevent 82'; + shell.exec(cmd, {silent:true, async:false}); + + // launch the application + console.log('Launching application...'); + cmd = 'adb -s ' + target + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output.replace('\r', '').replace('\n', ''); + var launch = shell.exec(cmd, {silent:true, async:false}); + if(launch.code > 0) { + console.error('ERROR : Failed to launch application on emulator : ' + launch.error); + console.error(launch.output); + process.exit(2); + } else { + console.log('LANCH SUCCESS'); + } + } else { + console.error('ERROR : Unable to find target \'' + target + '\'.'); + console.error('Failed to deploy to device.'); + process.exit(2); + } + } else { + console.error('ERROR : Failed to deploy to device, no devices found.'); + process.exit(2); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/emulator.js ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js new file mode 100644 index 0000000..579c898 --- /dev/null +++ b/bin/templates/cordova/lib/emulator.js @@ -0,0 +1,342 @@ +#!/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 shell = require('shelljs'), + path = require('path'), + build = require('./build'), + ROOT = path.join(__dirname, '..', '..'), + new_emulator = 'cordova_emulator'; + +/** + * Returns a list of emulator images in the form of objects + * { + name : , + path : , + target : , + abi : , + skin : + } + */ +module.exports.list_images = function() { + var cmd = 'android list avds'; + var result = shell.exec(cmd, {silent:true, async:false}); + if (result.code > 0) { + console.error('Failed to execute android command \'' + cmd + '\'.'); + process.exit(2); + } else { + var response = result.output.split('\n'); + var emulator_list = []; + for (var i = 1; i < response.length; i++) { + // To return more detailed information use img_obj + var img_obj = {}; + if (response[i].match(/Name:\s/)) { + img_obj['name'] = response[i].split('Name: ')[1].replace('\r', ''); + if (response[i + 1].match(/Path:\s/)) { + i++; + img_obj['path'] = response[i].split('Path: ')[1].replace('\r', ''); + } + if (response[i + 1].match(/\(API\slevel\s/)) { + i++; + img_obj['target'] = response[i].replace('\r', ''); + } + if (response[i + 1].match(/ABI:\s/)) { + i++; + img_obj['abi'] = response[i].split('ABI: ')[1].replace('\r', ''); + } + if (response[i + 1].match(/Skin:\s/)) { + i++; + img_obj['skin'] = response[i].split('Skin: ')[1].replace('\r', ''); + } + + emulator_list.push(img_obj); + } + /* To just return a list of names use this + if (response[i].match(/Name:\s/)) { + emulator_list.push(response[i].split('Name: ')[1].replace('\r', ''); + }*/ + + } + return emulator_list; + } +} + +/** + * Will return the closest avd to the projects target + * or undefined if no avds exist. + */ +module.exports.best_image = function() { + var project_target = this.get_target().replace('android-', ''); + var images = this.list_images(); + var closest = 9999; + var best = images[0]; + for (i in images) { + var target = images[i].target; + if(target) { + var num = target.split('(API level ')[1].replace(')', ''); + if (num == project_target) { + return images[i]; + } else if (project_target - num < closest && project_target > num) { + var closest = project_target - num; + best = images[i]; + } + } + } + return best; +} + +module.exports.list_started = function() { + var cmd = 'adb devices'; + var result = shell.exec(cmd, {silent:true, async:false}); + if (result.code > 0) { + console.error('Failed to execute android command \'' + cmd + '\'.'); + process.exit(2); + } else { + var response = result.output.split('\n'); + var started_emulator_list = []; + for (var i = 1; i < response.length; i++) { + if (response[i].match(/device/) && response[i].match(/emulator/)) { + started_emulator_list.push(response[i].replace(/\tdevice/, '').replace('\r', '')); + } + } + return started_emulator_list; + } +} + +module.exports.get_target = function() { + var target = shell.grep(/target=android-[\d+]/, path.join(ROOT, 'project.properties')); + return target.split('=')[1].replace('\n', '').replace('\r', '').replace(' ', ''); +} + +module.exports.list_targets = function() { + var target_out = shell.exec('android list targets', {silent:true, async:false}).output.split('\n'); + var targets = []; + for (var i = target_out.length; i >= 0; i--) { + if(target_out[i].match(/id:/)) { + targets.push(targets[i].split(' ')[1]); + } + } + return targets; +} + +/* + * Starts an emulator with the given ID, + * and returns the started ID of that emulator. + * If no ID is given it will used the first image availible, + * if no image is availible it will error out (maybe create one?). + */ +module.exports.start = function(emulator_ID) { + var started_emulators = this.list_started(); + var num_started = started_emulators.length; + if (typeof emulator_ID === 'undefined') { + var emulator_list = this.list_images(); + if (emulator_list.length > 0) { + emulator_ID = this.best_image().name; + console.log('WARNING : no emulator specified, defaulting to ' + emulator_ID); + } else { + console.error('ERROR : No emulator images (avds) found, if you would like to create an'); + console.error(' avd follow the instructions provided here : '); + console.error(' http://developer.android.com/tools/devices/index.html') + console.error(' Or run \'android create avd --name --target \' '); + console.error(' in on the command line.'); + process.exit(2); + /*console.log('WARNING : no emulators availible, creating \'' + new_emulator + '\'.'); + this.create_image(new_emulator, this.get_target()); + emulator_ID = new_emulator;*/ + } + } + + var pipe_null = (process.platform == 'win32' || process.platform == 'win64'? '> NUL' : '> /dev/null'); + var cmd = 'emulator -avd ' + emulator_ID + ' ' + pipe_null + ' &'; + if(process.platform == 'win32' || process.platform == 'win64') { + cmd = '%comspec% /c start cmd /c ' + cmd; + } + var result = shell.exec(cmd, {silent:true, async:false}, function(code, output) { + if (code > 0) { + console.error('Failed to execute android command \'' + cmd + '\'.'); + console.error(output); + process.exit(2); + } + }); + + // wait for emulator to start + console.log('Waiting for emulator...'); + var new_started = this.wait_for_emulator(num_started); + var emulator_id; + if (new_started.length > 1) { + for (i in new_started) { + console.log(new_started[i]); + console.log(started_emulators.indexOf(new_started[i])); + if (started_emulators.indexOf(new_started[i]) < 0) { + emulator_id = new_started[i]; + } + } + } else { + emulator_id = new_started[0]; + } + if (!emulator_id) { + console.error('ERROR : Failed to start emulator, could not find new emulator'); + process.exit(2); + } + + //wait for emulator to boot up + process.stdout.write('Booting up emulator (this may take a while)...'); + this.wait_for_boot(emulator_id); + console.log('BOOT COMPLETE'); + + //unlock screen + cmd = 'adb -s ' + emulator_id + ' shell input keyevent 82'; + shell.exec(cmd, {silent:false, async:false}); + + //return the new emulator id for the started emulators + return emulator_id; +} + +/* + * Waits for the new emulator to apear on the started-emulator list. + */ +module.exports.wait_for_emulator = function(num_running) { + var new_started = this.list_started(); + if (new_started.length > num_running) { + return new_started; + } else { + this.sleep(1); + return this.wait_for_emulator(num_running); + } +} + +/* + * Waits for the boot animation property of the emulator to switch to 'stopped' + */ +module.exports.wait_for_boot = function(emulator_id) { + var cmd; + // ShellJS opens a lot of file handles, and the default on OS X is too small. + // TODO : This is not working, need to find a better way to increese the ulimit. + if(process.platform == 'win32' || process.platform == 'win64') { + cmd = 'adb -s ' + emulator_id + ' shell getprop init.svc.bootanim'; + } else { + cmd = 'ulimit -S -n 4096; adb -s ' + emulator_id + ' shell getprop init.svc.bootanim'; + } + var boot_anim = shell.exec(cmd, {silent:true, async:false}); + if (boot_anim.output.match(/stopped/)) { + return; + } else { + process.stdout.write('.'); + this.sleep(3); + return this.wait_for_boot(emulator_id); + } +} + +/* + * TODO : find a better way to wait for the emulator (maybe using async methods?) + */ +module.exports.sleep = function(time_sec) { + if (process.platform == 'win32' || process.platform == 'win64') { + shell.exec('ping 127.0.0.1 -n ' + time_sec, {silent:true, async:false}); + } else { + shell.exec('sleep ' + time_sec, {silent:true, async:false}); + } +} + +/* + * Create avd + * TODO : Enter the stdin input required to complete the creation of an avd. + */ +module.exports.create_image = function(name, target) { + console.log('Creating avd named ' + name); + if (target) { + var cmd = 'android create avd --name ' + name + ' --target ' + target; + var create = shell.exec(cmd, {sient:false, async:false}); + if (create.error) { + console.error('ERROR : Failed to create emulator image : '); + console.error(' Do you have the latest android targets including ' + target + '?'); + console.error(create.output); + process.exit(2); + } + } else { + console.log('WARNING : Project target not found, creating avd with a different target but the project may fail to install.'); + var cmd = 'android create avd --name ' + name + ' --target ' + this.list_targets()[0]; + var create = shell.exec(cmd, {sient:false, async:false}); + if (create.error) { + console.error('ERROR : Failed to create emulator image : '); + console.error(create.output); + process.exit(2); + } + console.error('ERROR : Unable to create an avd emulator, no targets found.'); + console.error('Please insure you have targets availible by runing the "android" command'). + process.exit(2); + } +} + +/* + * Installs a previously built application on the emulator and launches it. + * If no target is specified, then it picks one. + * If no started emulators are found, error out. + */ +module.exports.install = function(target) { + var emulator_list = this.list_started(); + if (emulator_list.length < 1) { + console.error('ERROR : No started emulators found, please start an emultor before deploying your project.'); + process.exit(2); + /*console.log('WARNING : No started emulators found, attemting to start an avd...'); + this.start(this.best_image().name);*/ + } + // default emulator + target = typeof target !== 'undefined' ? target : emulator_list[0]; + if (emulator_list.indexOf(target) > -1) { + console.log('Installing app on emulator...'); + var apk_path = build.get_apk(); + var cmd = 'adb -s ' + target + ' install -r ' + apk_path; + var install = shell.exec(cmd, {sient:false, async:false}); + if (install.error || install.output.match(/Failure/)) { + console.error('ERROR : Failed to install apk to emulator : '); + console.error(install.output); + process.exit(2); + } + + //unlock screen + cmd = 'adb -s ' + target + ' shell input keyevent 82'; + shell.exec(cmd, {silent:true, async:false}); + + // launch the application + console.log('Launching application...'); + cmd = 'java -jar ' + path.join(ROOT, 'cordova', 'appinfo.jar') + ' ' + path.join(ROOT, 'AndroidManifest.xml'); + var launch_name = shell.exec(cmd, {silent:true, async:false}); + if (launch_name.error) { + console.log('ERROR : Failed to get application name from appinfo.jar + AndroidManifest : '); + console.log("Output : " + launch_name.output); + process.exit(2); + } + cmd = 'adb -s ' + target + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output.replace('\r', '').replace('\n', ''); + console.log(cmd); + var launch = shell.exec(cmd, {silent:false, async:false}); + if(launch.code > 0) { + console.error('ERROR : Failed to launch application on emulator : ' + launch.error); + console.error(launch.output); + process.exit(2); + } else { + console.log('LANCH SUCCESS'); + } + } else { + console.error('ERROR : Unable to find target \'' + target + '\'.'); + console.error('Failed to deploy to emulator.'); + process.exit(2); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/install-device ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/install-device b/bin/templates/cordova/lib/install-device index e70bef7..cf53918 100755 --- a/bin/templates/cordova/lib/install-device +++ b/bin/templates/cordova/lib/install-device @@ -1,49 +1,38 @@ -#!/bin/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. +#!/usr/bin/env node -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_PATH=$( cd "$DIR/../.." && pwd ) -device_list=$("$DIR/list-devices") -if [ $? != 0 ]; then - echo "No devices found to deploy to. Please make sure your device is connected" - echo " and you can view it using the 'cordova/lib/list-devices' command." - exit 2 -fi +/* + 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 -apks=`find $PROJECT_PATH/bin -type f -maxdepth 1 | egrep '\.apk$'` -apk_list=($apks) -if [[ ${#apk_list[@]} > 0 ]] ; then - # handle target - read -ra device_array <<< "$device_list" - if [[ "$#" -eq 1 ]] ; then - # deploy to given target - target=${1/--target=/} - else - # delete trailing space and 'device' after device ID - target=${device_array[0]} - fi - echo "Installing ${apk_list[0]} onto device $target..." - adb -s $target install -r ${apk_list[0]}; - echo "Launching application..." - launch_str=$(java -jar "$PROJECT_PATH"/cordova/appinfo.jar "$PROJECT_PATH"/AndroidManifest.xml) - adb -s $target shell am start -W -a android.intent.action.MAIN -n $launch_str -else - echo "Application package not found, could not install to device" - echo " make sure your application is built before deploying." - exit 2 -fi + 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 device = require('./device'), + args = process.argv; + +if(args.length > 2) { + var install_target; + if (args[2].substring(0, 9) == '--target=') { + install_target = args[2].substring(9, args[2].length); + device.install(install_target); + process.exit(0); + } else { + console.error('ERROR : argument \'' + args[2] + '\' not recognized.'); + process.exit(2); + } +} else { + device.install(); + process.exit(0); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/install-device.bat ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/install-device.bat b/bin/templates/cordova/lib/install-device.bat index b00e757..ac7214a 100644 --- a/bin/templates/cordova/lib/install-device.bat +++ b/bin/templates/cordova/lib/install-device.bat @@ -14,12 +14,13 @@ :: KIND, either express or implied. See the License for the :: specific language governing permissions and limitations :: under the License. + @ECHO OFF -SET full_path=%~dp0 -IF EXIST %full_path%cordova.js ( - cscript "%full_path%cordova.js" install-device %* //nologo +SET script_path="%~dp0install-device" +IF EXIST %script_path% ( + node "%script_path%" %* ) ELSE ( - ECHO. - ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2 + ECHO. + ECHO ERROR: Could not find 'install-device' script in 'cordova\lib' folder, aborting...>&2 EXIT /B 1 -) +) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/install-emulator ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/install-emulator b/bin/templates/cordova/lib/install-emulator index d4bffa4..70421be 100755 --- a/bin/templates/cordova/lib/install-emulator +++ b/bin/templates/cordova/lib/install-emulator @@ -1,50 +1,38 @@ -#!/bin/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. +#!/usr/bin/env node -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_PATH=$( cd "$DIR/../.." && pwd ) -emulator_list=$("$DIR/list-started-emulators") -if [ $? != 0 ]; then - echo "No emulators found to deploy to. Please make sure your emulator is started" - echo " You can view it using the 'cordova/lib/list-started-emulators' command." - echo " You can view created emulator images using the 'cordova/lib/list-emulator-images' command." - echo " You can start an emulator image using the 'cordova/lib/start-emulator' command." - exit 2 -fi +/* + 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 -apks=`find $PROJECT_PATH/bin -type f -maxdepth 1 | egrep '\.apk$'` -apk_list=($apks) -if [[ ${#apk_list[@]} > 0 ]] ; then - # handle target emulator - if [[ "$#" -eq 1 ]] ; then - # deploy to given target - target=${1/--target=/} - else - # delete trailing space and 'device' after emulator ID - target=${emulator_list[0]} - fi - echo "Installing ${apk_list[0]} onto emulator $target..." - adb -s $target install -r ${apk_list[0]}; - echo "Launching application..." - launch_str=$(java -jar "$PROJECT_PATH"/cordova/appinfo.jar "$PROJECT_PATH"/AndroidManifest.xml) - adb -s $target shell am start -W -a android.intent.action.MAIN -n $launch_str -else - echo "Application package not found, could not install to device" - echo " make sure your application is built before deploying." - exit 2 -fi + 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 emulator = require('./emulator'), + args = process.argv; + +if(args.length > 2) { + var install_target; + if (args[2].substring(0, 9) == '--target=') { + install_target = args[2].substring(9, args[2].length); + emulator.install(install_target); + process.exit(0); + } else { + console.error('ERROR : argument \'' + args[2] + '\' not recognized.'); + process.exit(2); + } +} else { + emulator.install(); + process.exit(0); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/install-emulator.bat ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/install-emulator.bat b/bin/templates/cordova/lib/install-emulator.bat index 2b88630..1ec6779 100644 --- a/bin/templates/cordova/lib/install-emulator.bat +++ b/bin/templates/cordova/lib/install-emulator.bat @@ -14,12 +14,13 @@ :: KIND, either express or implied. See the License for the :: specific language governing permissions and limitations :: under the License. + @ECHO OFF -SET full_path=%~dp0 -IF EXIST %full_path%cordova.js ( - cscript "%full_path%cordova.js" install-emulator %* //nologo +SET script_path="%~dp0install-emulator" +IF EXIST %script_path% ( + node "%script_path%" %* ) ELSE ( - ECHO. - ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2 + ECHO. + ECHO ERROR: Could not find 'install-emulator' script in 'cordova\lib' folder, aborting...>&2 EXIT /B 1 -) +) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/list-devices ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/list-devices b/bin/templates/cordova/lib/list-devices index 86d0054..bdd0abd 100755 --- a/bin/templates/cordova/lib/list-devices +++ b/bin/templates/cordova/lib/list-devices @@ -1,30 +1,28 @@ -#!/bin/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. +#!/usr/bin/env node -devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep 'device' | grep -v 'emulator' | awk '{ print $1; }'` -device_list=($devices) -if [[ ${#device_list[@]} > 0 ]] ; then - for i in ${devices[@]} - do - echo $i - done - exit 0 -else - echo "No devices found." - exit 2 -fi +/* + 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 devices = require('./device'); + +// Usage support for when args are given +var device_list = devices.list(); +for(device in device_list) { + console.log(device_list[device]); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/list-devices.bat ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/list-devices.bat b/bin/templates/cordova/lib/list-devices.bat index 3840d12..c0bcdd9 100644 --- a/bin/templates/cordova/lib/list-devices.bat +++ b/bin/templates/cordova/lib/list-devices.bat @@ -14,12 +14,13 @@ :: KIND, either express or implied. See the License for the :: specific language governing permissions and limitations :: under the License. + @ECHO OFF -SET full_path=%~dp0 -IF EXIST %full_path%cordova.js ( - cscript "%full_path%cordova.js" list-devices //nologo +SET script_path="%~dp0list-devices" +IF EXIST %script_path% ( + node "%script_path%" %* ) ELSE ( - ECHO. - ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2 + ECHO. + ECHO ERROR: Could not find 'list-devices' script in 'cordova\lib' folder, aborting...>&2 EXIT /B 1 -) +) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/list-emulator-images ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/list-emulator-images b/bin/templates/cordova/lib/list-emulator-images index 202d0e5..69f4789 100755 --- a/bin/templates/cordova/lib/list-emulator-images +++ b/bin/templates/cordova/lib/list-emulator-images @@ -1,32 +1,29 @@ -#!/bin/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. +#!/usr/bin/env node -emulator_images=`android list avds | grep "Name:" | cut -f 2 -d ":"` -emulator_list=($emulator_images) -if [[ ${#emulator_list[@]} > 0 ]] ; then - for i in ${emulator_list[@]} - do - echo $i - done - exit 0 -else - echo "No emulators found, if you would like to create an emulator follow the instructions" - echo " provided here : http://developer.android.com/tools/devices/index.html" - echo " Or run 'android create avd --name --target ' in on the command line." - exit 2 -fi +/* + 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 emulators = require('./emulator'); + +// Usage support for when args are given +var emulator_list = emulators.list_images(); +for(emulator in emulator_list) { + console.log(emulator_list[emulator].name); + process.exit(0); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/list-emulator-images.bat ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/list-emulator-images.bat b/bin/templates/cordova/lib/list-emulator-images.bat index e21aafe..661cbf9 100644 --- a/bin/templates/cordova/lib/list-emulator-images.bat +++ b/bin/templates/cordova/lib/list-emulator-images.bat @@ -14,12 +14,13 @@ :: KIND, either express or implied. See the License for the :: specific language governing permissions and limitations :: under the License. + @ECHO OFF -SET full_path=%~dp0 -IF EXIST %full_path%cordova.js ( - cscript "%full_path%cordova.js" list-emulator-images //nologo +SET script_path="%~dp0list-emulator-images" +IF EXIST %script_path% ( + node "%script_path%" %* ) ELSE ( ECHO. - ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2 + ECHO ERROR: Could not find 'list-emulator-images' script in 'cordova\lib' folder, aborting...>&2 EXIT /B 1 ) http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/list-started-emulators ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/list-started-emulators b/bin/templates/cordova/lib/list-started-emulators index 2aa6e99..3e69b2f 100755 --- a/bin/templates/cordova/lib/list-started-emulators +++ b/bin/templates/cordova/lib/list-started-emulators @@ -1,32 +1,29 @@ -#!/bin/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. +#!/usr/bin/env node -devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print $1;}}' | grep 'emulator' | grep -v 'offline'` -read -ra emulator_list <<< "$devices" -if [[ ${#emulator_list[@]} > 0 ]] ; then - for i in ${emulator_list[@]} - do - # remove space and 'device' - echo $i - done - exit 0 -else - echo "No started emulators found (it may still be booting up), you can start an emulator by using the command" - echo " 'cordova/lib/start-emulator'" - exit 2 -fi +/* + 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 emulators = require('./emulator'); + +// Usage support for when args are given +var emulator_list = emulators.list_started(); +for(emulator in emulator_list) { + console.log(emulator_list[emulator]); + process.exit(0); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/list-started-emulators.bat ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/list-started-emulators.bat b/bin/templates/cordova/lib/list-started-emulators.bat index eb9f3b6..a4e88f7 100644 --- a/bin/templates/cordova/lib/list-started-emulators.bat +++ b/bin/templates/cordova/lib/list-started-emulators.bat @@ -14,12 +14,13 @@ :: KIND, either express or implied. See the License for the :: specific language governing permissions and limitations :: under the License. + @ECHO OFF -SET full_path=%~dp0 -IF EXIST %full_path%cordova.js ( - cscript "%full_path%cordova.js" list-started-emulators //nologo +SET script_path="%~dp0list-started-emulators" +IF EXIST %script_path% ( + node "%script_path%" %* ) ELSE ( - ECHO. - ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2 + ECHO. + ECHO ERROR: Could not find 'list-started-emulators' script in 'cordova\lib' folder, aborting...>&2 EXIT /B 1 -) +) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/log.js ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/log.js b/bin/templates/cordova/lib/log.js new file mode 100644 index 0000000..ff14e46 --- /dev/null +++ b/bin/templates/cordova/lib/log.js @@ -0,0 +1,43 @@ +#!/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 shell = require('shelljs'), + path = require('path'), + ROOT = path.join(__dirname, '..', '..'); + +/* + * Starts running logcat in the shell. + */ +module.exports.run = function() { + var cmd = 'adb logcat | grep -v nativeGetEnabledTags'; + var result = shell.exec(cmd, {silent:false, async:false}); + if (result.code > 0) { + console.error('ERROR: Failed to run logcat command.'); + console.error(result.output); + process.exit(2); + } +} + +module.exports.help = function() { + console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'corodva', 'log'))); + console.log('Gives the logcat output on the command line.'); + process.exit(0); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/run.js ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/run.js b/bin/templates/cordova/lib/run.js new file mode 100644 index 0000000..b1c8b2b --- /dev/null +++ b/bin/templates/cordova/lib/run.js @@ -0,0 +1,123 @@ +#!/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 path = require('path'), + build = require('./build'), + emulator = require('./emulator'), + device = require('./device'); + +/* + * Runs the application on a device if availible. + * If not device is found, it will use a started emulator. + * If no started emulators are found it will attempt to start an avd. + * If no avds are found it will error out. + */ + module.exports.run = function(args) { + var build_type; + var install_target; + + for (var i=2; i -1) { + device.install(install_target); + } else if (started_emulators.indexOf(install_target) > -1) { + emulator.install(install_target); + } else { + // if target emulator isn't started, then start it. + var emulator_ID; + for(avd in avds) { + if(avds[avd].name == install_target) { + emulator_ID = emulator.start(install_target); + emulator.install(emulator_ID); + break; + } + } + if(!emulator_ID) { + console.error('ERROR : Target \'' + install_target + '\' not found, unalbe to run project'); + process.exit(2); + } + } + } else { + // no target given, deploy to device if availible, otherwise use the emulator. + var device_list = device.list(); + if (device_list.length > 0) { + console.log('WARNING : No target specified, deploying to device \'' + device_list[0] + '\'.'); + device.install(device_list[0]) + } else { + var emulator_list = emulator.list_started(); + if (emulator_list.length > 0) { + console.log('WARNING : No target specified, deploying to emulator \'' + emulator_list[0] + '\'.'); + emulator.install(emulator_list[0]); + } else { + console.log('WARNING : No started emulators found, starting an emulator.'); + var best_avd = emulator.best_image(); + if(best_avd) { + var emulator_ID = emulator.start(best_avd.name); + console.log('WARNING : No target specified, deploying to emulator \'' + emulator_ID + '\'.'); + emulator.install(emulator_ID); + } else { + emulator.start(); + } + } + } + } +} + +module.exports.help = function() { + console.log('Usage: ' + path.relative(process.cwd(), args[0]) + ' [options]'); + console.log('Build options :'); + console.log(' --debug : Builds project in debug mode'); + console.log(' --release : Builds project in release mode'); + console.log(' --nobuild : Runs the currently built project without recompiling'); + console.log('Deploy options :'); + console.log(' --device : Will deploy the built project to a device'); + console.log(' --emulator : Will deploy the built project to an emulator if one exists'); + console.log(' --target= : Installs to the target with the specified id.'); + process.exit(0); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/start-emulator ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/start-emulator b/bin/templates/cordova/lib/start-emulator index c7ce01a..8ea6d3f 100755 --- a/bin/templates/cordova/lib/start-emulator +++ b/bin/templates/cordova/lib/start-emulator @@ -1,111 +1,38 @@ -#!/bin/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. - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_PATH=$( cd "$( dirname "$0" )/../.." && pwd ) - -function dot { - sleep 1 - echo -n "." -} - -function wait_for_emulator() { - local emulator_log_path="$1" - local error_string - local status - - # Try to detect fatal errors early - sleep 1.5 - error_string=$(grep -F "ERROR: " ${emulator_log_path}) - status=$? - - if [ $status -eq 0 ]; then - echo "Emulator failed to start, fatal error detected" - echo "Error: ${error_string}" - echo "Full log available at: ${emulator_log_path}" - echo "Exiting..." - exit 1 - fi - - local i="0" - echo -n "Waiting for emulator" - emulator_string=$($DIR/list-started-emulators) - while [ $? != 0 ] - do - dot - i=$[i+1] - emulator_string=$($DIR/list-started-emulators) - done - read -ra target <<< "$emulator_string" - echo "" - echo -n "Waiting for it to boot up (this can take a while)" - while [ $i -lt 300 ] - do - boot_anim=$(adb -s $target shell getprop init.svc.bootanim 2>&1) - if [[ "$boot_anim" =~ "stopped" ]] ; then - break - else - i=$[i+1] - dot - fi - done - # Device timeout: emulator has not started in time - if [ $i -eq 300 ] - then - echo "" - echo "Emulator timeout!" - exit 69 - else - echo "" - echo "Connected!" - fi - # Unlock the device - adb -s $target shell input keyevent 82 - exit 0 -} - -emulator_images=$("$DIR/list-emulator-images") -if [ $? != 0 ]; then - echo "No emulators found, if you would like to create an emulator follow the instructions" - echo " provided here : http://developer.android.com/tools/devices/index.html" - echo " Or run 'android create avd --name --target ' in on the command line." - exit 2 -fi - -# start first emulator -log_path=$(mktemp -t android_emulator) - -# if target emulator is provided -if [[ "$#" -eq 1 ]] ; then - # check that it exists - if [[ $emulator_images =~ $1 ]] ; then - #xterm -e emulator -avd $1 & - emulator -avd $1 1> "${log_path}" 2>&1 & - else - echo "Could not find the provided emulator '$1', make sure the emulator exists" - echo " by checking 'cordova/lib/list-emulator-images'" - exit 2 - fi -else - read -ra emulator_list <<< "$emulator_images" - #xterm -e emulator -avd ${emulator_list[0]} & - emulator -avd ${emulator_list[0]} 1> "${log_path}" 2>&1 & -fi - -echo "Saving emulator log to: ${log_path}" -wait_for_emulator "$log_path" +#!/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 emulator = require('./emulator'), + args = process.argv; + +if(args.length > 2) { + var install_target; + if (args[2].substring(0, 9) == '--target=') { + install_target = args[2].substring(9, args[2].length); + emulator.start(install_target); + process.exit(0); + } else { + console.error('ERROR : argument \'' + args[2] + '\' not recognized.'); + process.exit(2); + } +} else { + emulator.start(); + process.exit(0); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/start-emulator.bat ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/start-emulator.bat b/bin/templates/cordova/lib/start-emulator.bat index 758c854..9329d95 100644 --- a/bin/templates/cordova/lib/start-emulator.bat +++ b/bin/templates/cordova/lib/start-emulator.bat @@ -14,12 +14,13 @@ :: KIND, either express or implied. See the License for the :: specific language governing permissions and limitations :: under the License. + @ECHO OFF -SET full_path=%~dp0 -IF EXIST %full_path%cordova.js ( - cscript "%full_path%cordova.js" start-emulator %* //nologo +SET script_path="%~dp0start-emulator" +IF EXIST %script_path% ( + node "%script_path%" %* ) ELSE ( - ECHO. - ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2 + ECHO. + ECHO ERROR: Could not find 'start-emulator' script in 'cordova\lib' folder, aborting...>&2 EXIT /B 1 -) +) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/version.js ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/lib/version.js b/bin/templates/cordova/lib/version.js new file mode 100644 index 0000000..f28b672 --- /dev/null +++ b/bin/templates/cordova/lib/version.js @@ -0,0 +1,53 @@ +#!/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 shell = require('shelljs'), + fs = require('fs'), + path = require('path'), + ROOT = path.join(__dirname, '..', '..'); + +/* + * Displays the version, gotten from cordova.js + */ +module.exports.run = function() { + var cordovajs_path = path.join(ROOT, 'assets', 'www', 'cordova.js'); + if (fs.existsSync(cordovajs_path)) { + var version_line = shell.grep(/^.*CORDOVA_JS_BUILD_LABEL.*$/, cordovajs_path); + var version = version_line.match(/(\d+)\.(\d+)\.(\d+)(rc\d)?/)[0]; + if (version) { + console.log(version); + return version; + } else { + console.error("ERROR : Unable to find version in cordova.js"); + process.exit(2); + } + } else { + console.error("ERROR : Could not find cordova.js"); + console.error('Expected Location : ' + cordovajs_path); + process.exit(2); + } +} + +module.exports.help = function() { + console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'corodva', 'version'))); + console.log('Returns the version of Cordova.'); + process.exit(0); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/log ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/log b/bin/templates/cordova/log index f8df9cc..514f69c 100755 --- a/bin/templates/cordova/log +++ b/bin/templates/cordova/log @@ -1,20 +1,33 @@ -#!/bin/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. +#!/usr/bin/env node -# filter out nativeGetEnabledTags spam from latest sdk bug. -adb logcat | grep -v nativeGetEnabledTags +/* + 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 log = require('./lib/log'), + reqs = require('./lib/check_reqs'), + args = process.argv; + +// Usage support for when args are given +if(args.length > 2) { + log.help(); +} else if(reqs.run()) { + log.run(); +} else { + process.exit(2); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/log.bat ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/log.bat b/bin/templates/cordova/log.bat index c259802..875982f 100644 --- a/bin/templates/cordova/log.bat +++ b/bin/templates/cordova/log.bat @@ -14,5 +14,13 @@ :: KIND, either express or implied. See the License for the :: specific language governing permissions and limitations :: under the License. + @ECHO OFF -%~dp0\cordova.bat log %* +SET script_path="%~dp0log" +IF EXIST %script_path% ( + node "%script_path%" %* +) ELSE ( + ECHO. + ECHO ERROR: Could not find 'log' script in 'cordova' folder, aborting...>&2 + EXIT /B 1 +) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/run ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/run b/bin/templates/cordova/run index 4772058..c3a5772 100755 --- a/bin/templates/cordova/run +++ b/bin/templates/cordova/run @@ -1,81 +1,35 @@ -#!/bin/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. +#!/usr/bin/env node -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PROJECT_PATH=$( cd "$DIR/.." && pwd ) +/* + 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 -function run_on_device_or_emulator { - devices=`$DIR/lib/list-devices` - if [ $? = 0 ]; then - $DIR/lib/install-device - else - run_on_emulator - fi -} + http://www.apache.org/licenses/LICENSE-2.0 -function run_on_emulator { - emulators=`$DIR/lib/list-started-emulators` - if [ $? = 0 ] ; then - $DIR/lib/install-emulator - else - images=`$DIR/lib/list-emulator-images` - if [ $? = 0 ] ; then - $DIR/lib/start-emulator - $DIR/lib/install-emulator - else - echo "No devices/emulators started nor images available to start. How are we supposed to do this, then?" - exit 2 - fi - fi -} + 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 run = require('./lib/run'), + reqs = require('./lib/check_reqs'), + args = process.argv; - -if [[ "$#" -eq 2 ]] ; then - # TODO: the order of arguments here may be reversed from the assumption below - $DIR/build $2 - if [[ $1 == "--device" ]] ; then - $DIR/lib/install-device - elif [[ $1 == "--emulator" ]] ; then - run_on_emulator - elif [[ $1 =~ "--target=" ]]; then - $DIR/lib/install-device $1 - else - echo "Error : '$1' is not recognized as an install option" - fi -elif [[ "$#" -eq 1 ]] ; then - if [[ $1 == "--debug" || $1 == "--release" || $1 == "--nobuild" ]] ; then - $DIR/build $1 - run_on_device_or_emulator - elif [[ $1 == "--device" ]] ; then - $DIR/build - $DIR/lib/install-device - elif [[ $1 == "--emulator" ]] ; then - $DIR/build - run_on_emulator - elif [[ $1 =~ "--target=" ]]; then - $DIR/build - $DIR/lib/install-device $1 - else - echo "Error : '$1' is not recognized as an install option" - fi -else - echo "Warning : [ --device | --emulate | --target= ] not specified, using defaults." - $DIR/build - run_on_device_or_emulator -fi +// Support basic help commands +if (args[2] == '--help' || args[2] == '/?' || args[2] == '-h' || + args[2] == 'help' || args[2] == '-help' || args[2] == '/help') { + run.help(); +} else if(reqs.run()) { + run.run(args); + process.exit(0); +} else { + process.exit(2); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/run.bat ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/run.bat b/bin/templates/cordova/run.bat index f191f67..0aad853 100644 --- a/bin/templates/cordova/run.bat +++ b/bin/templates/cordova/run.bat @@ -14,5 +14,13 @@ :: KIND, either express or implied. See the License for the :: specific language governing permissions and limitations :: under the License. + @ECHO OFF -%~dp0\cordova.bat run %* +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 +) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/version ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/version b/bin/templates/cordova/version index 0ba1457..f280e13 100755 --- a/bin/templates/cordova/version +++ b/bin/templates/cordova/version @@ -1,19 +1,31 @@ -#!/bin/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. +#!/usr/bin/env node -echo "3.1.0-dev" +/* + 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 version = require('./lib/version'); +var args = process.argv; + +// Usage support for when args are given +if(args.length > 2) { + version.help(); +} else { + console.log(version.run()); + process.exit(0); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/version.bat ---------------------------------------------------------------------- diff --git a/bin/templates/cordova/version.bat b/bin/templates/cordova/version.bat index e70769f..d589002 100644 --- a/bin/templates/cordova/version.bat +++ b/bin/templates/cordova/version.bat @@ -14,5 +14,13 @@ :: KIND, either express or implied. See the License for the :: specific language governing permissions and limitations :: under the License. + @ECHO OFF -%~dp0\cordova.bat version %* \ No newline at end of file +SET script_path="%~dp0version" +IF EXIST %script_path% ( + node "%script_path%" %* +) ELSE ( + ECHO. + ECHO ERROR: Could not find 'version' script in 'cordova' folder, aborting...>&2 + EXIT /B 1 +)