You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by be...@apache.org on 2013/08/26 23:50:20 UTC

[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   : <emulator_name>,
+       path   : <path_to_emulator_image>,
+       target : <api_target>,
+       abi    : <cpu>,
+       skin   : <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 <name> --target <targetID>\' ');
+            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 <name> --target <targetID>' 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<args.length; i++) {
+        if (args[i] == '--debug') {
+            build_type = '--debug';
+        } else if (args[i] == '--release') {
+            build_type = '--release';
+        } else if (args[i] == '--nobuild') {
+            build_type = '--nobuild';
+        } else if (args[i] == '--device') {
+            install_target = '--device';
+        } else if (args[i] == '--emulator') {
+            install_target = '--emulator';
+        } else if (args[i].substring(0, 9) == '--target=') {
+            install_target = args[i].substring(9, args[i].length);
+        } else {
+            console.error('ERROR : Run option \'' + args[i] + '\' not recognized.');
+            process.exit(2);
+        }
+    }
+    build.run(build_type);
+    if (install_target == '--device') {
+        device.install();
+    } else if (install_target == '--emulator') {
+        if (emulator.list_started() == 0) {
+            emulator.start();
+        }
+        emulator.install();
+    } else if (install_target) {
+        var devices = device.list();
+        var started_emulators = emulator.list_started();
+        var avds = emulator.list_images();
+        if (devices.indexOf(install_target) > -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=<target_id> : 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 <name> --target <targetID>' 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=<targetID> ] 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
+)


[2/2] android commit: [CB-3542] rewrote cli tooling scripts in node

Posted by be...@apache.org.
[CB-3542] rewrote cli tooling scripts in node


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

Branch: refs/heads/master
Commit: 1bd490098127543cf89b02735ea29757a11aab0c
Parents: e6812f1
Author: Benn Mapes <be...@gmail.com>
Authored: Mon Aug 12 17:07:23 2013 -0700
Committer: Benn Mapes <be...@gmail.com>
Committed: Mon Aug 26 14:45:28 2013 -0700

----------------------------------------------------------------------
 VERSION                                         |   2 +-
 bin/check_reqs                                  |  60 +-
 bin/check_reqs.bat                              |   8 +-
 bin/check_reqs.js                               | 102 ----
 bin/create                                      | 191 +-----
 bin/create.bat                                  |  46 +-
 bin/create.js                                   | 214 -------
 bin/lib/check_reqs.js                           |  85 +++
 bin/lib/create.js                               | 265 ++++++++
 bin/package.json                                |  32 +
 bin/templates/cordova/build                     |  70 +--
 bin/templates/cordova/build.bat                 |  10 +-
 bin/templates/cordova/clean                     |  54 +-
 bin/templates/cordova/clean.bat                 |  10 +-
 bin/templates/cordova/cordova.bat               |  31 -
 bin/templates/cordova/lib/build.js              |  89 +++
 bin/templates/cordova/lib/clean.js              |  43 ++
 bin/templates/cordova/lib/cordova.js            | 612 -------------------
 bin/templates/cordova/lib/device.js             | 101 +++
 bin/templates/cordova/lib/emulator.js           | 342 +++++++++++
 bin/templates/cordova/lib/install-device        |  83 ++-
 bin/templates/cordova/lib/install-device.bat    |  13 +-
 bin/templates/cordova/lib/install-emulator      |  84 ++-
 bin/templates/cordova/lib/install-emulator.bat  |  13 +-
 bin/templates/cordova/lib/list-devices          |  56 +-
 bin/templates/cordova/lib/list-devices.bat      |  13 +-
 bin/templates/cordova/lib/list-emulator-images  |  59 +-
 .../cordova/lib/list-emulator-images.bat        |   9 +-
 .../cordova/lib/list-started-emulators          |  59 +-
 .../cordova/lib/list-started-emulators.bat      |  13 +-
 bin/templates/cordova/lib/log.js                |  43 ++
 bin/templates/cordova/lib/run.js                | 123 ++++
 bin/templates/cordova/lib/start-emulator        | 149 ++---
 bin/templates/cordova/lib/start-emulator.bat    |  13 +-
 bin/templates/cordova/lib/version.js            |  53 ++
 bin/templates/cordova/log                       |  51 +-
 bin/templates/cordova/log.bat                   |  10 +-
 bin/templates/cordova/run                       | 106 +---
 bin/templates/cordova/run.bat                   |  10 +-
 bin/templates/cordova/version                   |  48 +-
 bin/templates/cordova/version.bat               |  10 +-
 41 files changed, 1684 insertions(+), 1701 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/VERSION
----------------------------------------------------------------------
diff --git a/VERSION b/VERSION
index 38f8e88..9001211 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-dev
+dev
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/check_reqs
----------------------------------------------------------------------
diff --git a/bin/check_reqs b/bin/check_reqs
index cdc3fda..d50c78d 100755
--- a/bin/check_reqs
+++ b/bin/check_reqs
@@ -1,34 +1,26 @@
-#! /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.
-#
-ROOT="$( cd "$( dirname "$0" )/.." && pwd )"
-cmd=`android list target`
-if [[ $? != 0 ]]; then
-    echo "The command \"android\" failed. Make sure you have the latest Android SDK installed, and the \"android\" command (inside the tools/ folder) added to your path."
-    exit 2
-elif [[ ! $cmd =~ "android-18" ]]; then
-    echo "Please install Android target 18 (the Android 4.3 SDK). Make sure you have the latest Android tools installed as well. Run \"android\" from your command-line to install/update any missing SDKs or tools."
-    exit 2
-else
-    cmd="android update project -p $ROOT -t android-18 1> /dev/null 2>&1"
-    eval $cmd
-    if [[ $? != 0 ]]; then
-        echo "Error updating the Cordova library to work with your Android environment."
-        exit 2
-    fi
-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 check_reqs = require('./lib/check_reqs');
+
+if(!check_reqs.run()) {
+      process.exit(2);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/check_reqs.bat
----------------------------------------------------------------------
diff --git a/bin/check_reqs.bat b/bin/check_reqs.bat
index 12da1e7..cb2c6f5 100644
--- a/bin/check_reqs.bat
+++ b/bin/check_reqs.bat
@@ -16,11 +16,11 @@
 :: under the License.
 
 @ECHO OFF
-SET full_path=%~dp0
-IF EXIST %full_path%check_reqs.js (
-        cscript "%full_path%check_reqs.js" //nologo
+SET script_path="%~dp0check_reqs"
+IF EXIST %script_path% (
+        node "%script_path%" %*
 ) ELSE (
     ECHO.
-    ECHO ERROR: Could not find 'check_reqs.js' in 'bin' folder, aborting...>&2
+    ECHO ERROR: Could not find 'check_reqs' script in 'bin' folder, aborting...>&2
     EXIT /B 1
 )

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/check_reqs.js b/bin/check_reqs.js
deleted file mode 100644
index 4a724a6..0000000
--- a/bin/check_reqs.js
+++ /dev/null
@@ -1,102 +0,0 @@
-// 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 ROOT  = WScript.ScriptFullName.split('\\bin\\check_reqs.js').join(''),
-    shell = WScript.CreateObject("WScript.Shell"),
-    fso   = WScript.CreateObject('Scripting.FileSystemObject');
-
-
-// executes a command in the shell, returns stdout or stderr if error
-function exec_out(command) {
-    var oExec=shell.Exec(command);
-    var output = new String();
-    while (oExec.Status == 0) {
-        if (!oExec.StdOut.AtEndOfStream) {
-            var line = oExec.StdOut.ReadAll();
-            // XXX: Change to verbose mode 
-            // WScript.StdOut.WriteLine(line);
-            output += line;
-        }
-        WScript.sleep(100);
-    }
-    //Check to make sure our scripts did not encounter an error
-    if (!oExec.StdErr.AtEndOfStream) {
-        var line = oExec.StdErr.ReadAll();
-        return {'error' : true, 'output' : line};
-    } else if (!oExec.StdOut.AtEndOfStream) {
-            var line = oExec.StdOut.ReadAll();
-            // XXX: Change to verbose mode 
-            // WScript.StdOut.WriteLine(line);
-            output += line;
-    }
-    return {'error' : false, 'output' : output};
-}
-
-// log to stdout or stderr
-function Log(msg, error) {
-    if (error) {
-        WScript.StdErr.WriteLine(msg);
-    }
-    else {
-        WScript.StdOut.WriteLine(msg);
-    }
-}
-
-// checks that android requirements are met
-function check_requirements() {
-    var target = get_target();
-    if(target==null) {
-        Log('Unable to find android target in project.properties');
-        WScript.Quit(2);
-    }
-    var result = exec_out('%comspec% /c android list target');
-    if(result.error) {
-        Log('The command `android` failed. Make sure you have the latest Android SDK installed, and the `android` command (inside the tools/ folder) added to your path. Output: ' + result.output, true);
-        WScript.Quit(2);
-    }
-    else if(result.output.indexOf(target) == -1) {
-        Log(result.output.indexOf(target));
-        Log('Please install the latest Android target (' + target + '). Make sure you have the latest Android tools installed as well. Run `android` from your command-line to install/update any missing SDKs or tools.', true);
-        Log(result.output);
-        WScript.Quit(2);
-    }
-    else {
-        var cmd = '%comspec% /c android update project -p ' + ROOT + '\\framework -t ' + target;
-        result = exec_out(cmd);
-        if(result.error) {
-            Log('Error updating the Cordova library to work with your Android environment. Command run: "' + cmd + '", output: ' + result.output, true);
-            WScript.Quit(2);  
-        }
-    }
-}
-
-function get_target() {
-    var fso=WScript.CreateObject("Scripting.FileSystemObject");
-    var f=fso.OpenTextFile(ROOT + '\\framework\\project.properties', 1);
-    var s=f.ReadAll();
-    var lines = s.split('\n');
-    for (var line in lines) {
-        if(lines[line].match(/target=/))
-        {
-            return lines[line].split('=')[1].replace(' ', '').replace('\r', '');
-        }
-    }
-    return null;
-}
-
-check_requirements();
-

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/create
----------------------------------------------------------------------
diff --git a/bin/create b/bin/create
index 6a49dc9..0c2b796 100755
--- a/bin/create
+++ b/bin/create
@@ -1,159 +1,32 @@
-#! /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.
-#
-# create a cordova/android project
-# 
-# USAGE
-#   ./create [path package activity]
-#
-set -e
-
-if [ -z "$1" ] || [ "$1" == "-h" ]
-then
-    echo "Usage: $0 <path_to_new_project> <package_name> <project_name>"
-    echo "Make sure the Android SDK tools folder is in your PATH!"
-    echo "    <path_to_new_project>: Path to your new Cordova iOS project"
-    echo "    <package_name>: Package name, following reverse-domain style convention"
-    echo "    <project_name>: Project name"
-    exit 0
-fi
-
-BUILD_PATH="$( cd "$( dirname "$0" )/.." && pwd )"
-VERSION=$(cat "$BUILD_PATH"/VERSION)
-
-PROJECT_PATH="${1:-'./example'}"
-PACKAGE=${2:-"org.apache.cordova.example"}
-ACTIVITY=$(echo ${3:-"cordovaExample"} | tr -d '[:blank:][:punct:]')
-APP_LABEL=${3:-"Cordova Example"};
-PROJECT_TEMPLATE_DIR=${4:-"$BUILD_PATH/bin/templates/project"};
-
-# clobber any existing example
-if [ -d "$PROJECT_PATH" ]
-then
-    echo "Project already exists! Delete and recreate"
-    exit 1
-fi
-
-function createAppInfoJar {
-    pushd "$BUILD_PATH"/bin/templates/cordova/ApplicationInfo > /dev/null
-    javac ApplicationInfo.java
-    jar -cfe ../appinfo.jar ApplicationInfo ApplicationInfo.class
-    popd > /dev/null
-}
-
-function on_error {
-    echo "An unexpected error occurred: $previous_command exited with $?"
-    echo "Deleting project..."
-    [ -d "$PROJECT_PATH" ] && rm -rf "$PROJECT_PATH"
-    exit 1
-}
-
-function replace {
-    local pattern=$1
-    local filename=$2
-    # Mac OS X requires -i argument
-    if [[ "$OSTYPE" =~ "darwin" ]]
-    then
-        /usr/bin/sed -i '' -e "$pattern" "$filename"
-    elif [[ "$OSTYPE" =~ "linux" ]]
-    then
-        /bin/sed -i -e $pattern "$filename"
-    fi
-}
-
-# we do not want the script to silently fail
-trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
-trap on_error ERR
-
-ANDROID_BIN="${ANDROID_BIN:=$( which android )}"
-PACKAGE_AS_PATH=$(echo $PACKAGE | sed 's/\./\//g')
-ACTIVITY_PATH="$PROJECT_PATH"/src/$PACKAGE_AS_PATH/$ACTIVITY.java
-MANIFEST_PATH="$PROJECT_PATH"/AndroidManifest.xml
-STRINGS_PATH="$PROJECT_PATH"/res/values/strings.xml
-
-TARGET=$("$ANDROID_BIN" list targets -c | grep '^android-' | tail -1 )
-API_LEVEL=${TARGET##android-}
-
-# check that build targets exist
-if [ -z "$TARGET" ] || [ -z "$API_LEVEL" ]
-then
-    echo "No Android Targets are installed. Please install at least one via the android SDK"
-    exit 1
-fi
-
-# if this a distribution release no need to build a jar
-if [ ! -e "$BUILD_PATH"/cordova-$VERSION.jar ] && [ -d "$BUILD_PATH"/framework ]
-then
-    # update the cordova-android framework for the desired target
-    "$ANDROID_BIN" update project --target $TARGET --path "$BUILD_PATH"/framework &> /dev/null
-
-    # compile cordova.js and cordova.jar
-    pushd "$BUILD_PATH"/framework > /dev/null
-    ant jar > /dev/null
-    popd > /dev/null
-fi
-
-# create new android project
-"$ANDROID_BIN" create project --target $TARGET --path "$PROJECT_PATH" --package $PACKAGE --activity $ACTIVITY &> /dev/null
-
-# copy project template
-cp -r "$PROJECT_TEMPLATE_DIR"/assets "$PROJECT_PATH"
-cp -r "$PROJECT_TEMPLATE_DIR"/res "$PROJECT_PATH"
-
-# copy cordova.js, cordova.jar and res/xml
-if [ -d "$BUILD_PATH"/framework ]
-then
-    cp -r "$BUILD_PATH"/framework/res/xml "$PROJECT_PATH"/res
-    cp "$BUILD_PATH"/framework/assets/www/cordova.js "$PROJECT_PATH"/assets/www/cordova.js
-    cp "$BUILD_PATH"/framework/cordova-$VERSION.jar "$PROJECT_PATH"/libs/cordova-$VERSION.jar
-else
-    cp -r "$BUILD_PATH"/xml "$PROJECT_PATH"/res/xml
-    cp "$BUILD_PATH"/cordova.js "$PROJECT_PATH"/assets/www/cordova.js
-    cp "$BUILD_PATH"/cordova-$VERSION.jar "$PROJECT_PATH"/libs/cordova-$VERSION.jar
-fi
-
-# interpolate the activity name and package
-cp "$PROJECT_TEMPLATE_DIR"/Activity.java "$ACTIVITY_PATH"
-replace "s/__ACTIVITY__/${ACTIVITY}/g" "$ACTIVITY_PATH"
-replace "s/__ID__/${PACKAGE}/g" "$ACTIVITY_PATH"
-
-# interpolate the app name into strings.xml
-replace "s/>${ACTIVITY}</>${APP_LABEL}</g" "$STRINGS_PATH"
-
-cp "$PROJECT_TEMPLATE_DIR"/AndroidManifest.xml "$MANIFEST_PATH"
-replace "s/__ACTIVITY__/${ACTIVITY}/g" "$MANIFEST_PATH"
-replace "s/__PACKAGE__/${PACKAGE}/g" "$MANIFEST_PATH"
-replace "s/__APILEVEL__/${API_LEVEL}/g" "$MANIFEST_PATH"
-
-# creating cordova folder and copying run/build/log/launch scripts
-mkdir "$PROJECT_PATH"/cordova
-mkdir "$PROJECT_PATH"/cordova/lib
-createAppInfoJar
-cp "$BUILD_PATH"/bin/templates/cordova/appinfo.jar "$PROJECT_PATH"/cordova/appinfo.jar
-cp "$BUILD_PATH"/bin/templates/cordova/build "$PROJECT_PATH"/cordova/build
-cp "$BUILD_PATH"/bin/templates/cordova/clean "$PROJECT_PATH"/cordova/clean
-cp "$BUILD_PATH"/bin/templates/cordova/log "$PROJECT_PATH"/cordova/log
-cp "$BUILD_PATH"/bin/templates/cordova/run "$PROJECT_PATH"/cordova/run
-cp "$BUILD_PATH"/bin/templates/cordova/version "$PROJECT_PATH"/cordova/version
-cp "$BUILD_PATH"/bin/templates/cordova/lib/install-device "$PROJECT_PATH"/cordova/lib/install-device
-cp "$BUILD_PATH"/bin/templates/cordova/lib/install-emulator "$PROJECT_PATH"/cordova/lib/install-emulator
-cp "$BUILD_PATH"/bin/templates/cordova/lib/list-devices "$PROJECT_PATH"/cordova/lib/list-devices
-cp "$BUILD_PATH"/bin/templates/cordova/lib/list-emulator-images "$PROJECT_PATH"/cordova/lib/list-emulator-images
-cp "$BUILD_PATH"/bin/templates/cordova/lib/list-started-emulators "$PROJECT_PATH"/cordova/lib/list-started-emulators
-cp "$BUILD_PATH"/bin/templates/cordova/lib/start-emulator "$PROJECT_PATH"/cordova/lib/start-emulator
-
+#!/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 create = require('./lib/create');
+var args  = process.argv;
+
+// Support basic help commands
+if(args.length < 3 || (args[2] == '--help' || args[2] == '/?' || args[2] == '-h' ||
+                    args[2] == 'help' || args[2] == '-help' || args[2] == '/help')) {
+    create.help();
+} else {
+    create.run(args[2], args[3], args[4]);
+    process.exit(0);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/create.bat
----------------------------------------------------------------------
diff --git a/bin/create.bat b/bin/create.bat
index 7f0346f..4b475a2 100644
--- a/bin/create.bat
+++ b/bin/create.bat
@@ -1,5 +1,3 @@
-@ECHO OFF
-GOTO BEGIN
 :: 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
@@ -17,38 +15,12 @@ GOTO BEGIN
 :: specific language governing permissions and limitations
 :: under the License.
 
-:BEGIN
-        IF NOT DEFINED JAVA_HOME GOTO MISSING_JAVA_HOME
-
-        FOR %%X in (java.exe javac.exe ant.bat android.bat) do (
-            IF [%%~$PATH:X]==[] (
-              ECHO Cannot locate %%X using the PATH environment variable.
-              ECHO Retry after adding directory containing %%X to the PATH variable.
-              ECHO Remember to open a new command window after updating the PATH variable.
-              IF "%%X"=="java.exe" GOTO GET_JAVA
-              IF "%%X"=="javac.exe" GOTO GET_JAVA
-              IF "%%X"=="ant.bat" GOTO GET_ANT
-              IF "%%X"=="android.bat" GOTO GET_ANDROID
-              GOTO ERROR
-            )
-        )
-        cscript "%~dp0\create.js" %* //nologo
-        GOTO END
-:MISSING_JAVA_HOME
-        ECHO The JAVA_HOME environment variable is not set.
-        ECHO Set JAVA_HOME to an existing JRE directory.
-        ECHO Remember to also add JAVA_HOME to the PATH variable.
-        ECHO After updating system variables, open a new command window and retry.
-        GOTO ERROR
-:GET_JAVA
-        ECHO Visit http://java.oracle.com if you need to install Java (JDK).
-        GOTO ERROR
-:GET_ANT
-        ECHO Visit http://ant.apache.org if you need to install Apache Ant.
-        GOTO ERROR
-:GET_ANDROID
-        ECHO Visit http://developer.android.com if you need to install the Android SDK.
-        GOTO ERROR
-:ERROR
-EXIT /B 1
-:END
+@ECHO OFF
+SET script_path="%~dp0create"
+IF EXIST %script_path% (
+    node %script_path% %*
+) ELSE (
+    ECHO.
+    ECHO ERROR: Could not find 'create' script in 'bin' 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/create.js
----------------------------------------------------------------------
diff --git a/bin/create.js b/bin/create.js
deleted file mode 100644
index c723b12..0000000
--- a/bin/create.js
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
-       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.
-*/
-
-/*
- * create a cordova/android project
- *
- * USAGE
- *  ./create [path package activity]
- */
-
-var args = WScript.Arguments, PROJECT_PATH="example", 
-    PACKAGE="org.apache.cordova.example", ACTIVITY="cordovaExample",
-    shell=WScript.CreateObject("WScript.Shell"),
-    fso = WScript.CreateObject('Scripting.FileSystemObject');
-
-function Usage() {
-    Log("Usage: create PathTONewProject [ PackageName AppName ]");
-    Log("    PathTONewProject : The path to where you wish to create the project");
-    Log("    PackageName      : The package for the project (default is org.apache.cordova.example)")
-    Log("    AppName          : The name of the application/activity (default is cordovaExample)");
-    Log("examples:");
-    Log("    create C:\\Users\\anonymous\\Desktop\\MyProject");
-    Log("    create C:\\Users\\anonymous\\Desktop\\MyProject io.Cordova.Example AnApp");
-}
-
-// logs messaged to stdout and stderr
-function Log(msg, error) {
-    if (error) {
-        WScript.StdErr.WriteLine(msg);
-    }
-    else {
-        WScript.StdOut.WriteLine(msg);
-    }
-}
-
-function read(filename) {
-    var fso=WScript.CreateObject("Scripting.FileSystemObject");
-    var f=fso.OpenTextFile(filename, 1);
-    var s=f.ReadAll();
-    f.Close();
-    return s;
-}
-
-function checkTargets(targets) {
-    if(!targets) {
-        Log("You do not have any android targets setup. Please create at least one target with the `android` command", true);
-        WScript.Quit(69);
-    }
-}
-
-function setTarget() {
-    var targets = shell.Exec('android.bat list targets').StdOut.ReadAll().match(/id:\s\d+/g);
-    checkTargets(targets);
-    return targets[targets.length - 1].replace(/id: /, ""); // TODO: give users the option to set their target 
-}
-function setApiLevel() {
-    var targets = shell.Exec('android.bat list targets').StdOut.ReadAll().match(/API level:\s\d+/g);
-    checkTargets(targets);
-    return targets[targets.length - 1].replace(/API level: /, "");
-}
-function write(filename, contents) {
-    var fso=WScript.CreateObject("Scripting.FileSystemObject");
-    var f=fso.OpenTextFile(filename, 2, true);
-    f.Write(contents);
-    f.Close();
-}
-function replaceInFile(filename, regexp, replacement) {
-    write(filename, read(filename).replace(regexp, replacement));
-}
-function exec(command) {
-    var oShell=shell.Exec(command);
-    while (oShell.Status == 0) {
-        if(!oShell.StdOut.AtEndOfStream) {
-            var line = oShell.StdOut.ReadLine();
-            // XXX: Change to verbose mode 
-            // WScript.StdOut.WriteLine(line);
-        }
-        WScript.sleep(100);
-    }
-}
-
-function createAppInfoJar() {
-    if(!fso.FileExists(ROOT+"\\bin\\templates\\cordova\\appinfo.jar")) {
-        Log("Creating appinfo.jar...");
-        var cur = shell.CurrentDirectory;
-        shell.CurrentDirectory = ROOT+"\\bin\\templates\\cordova\\ApplicationInfo";
-        exec("javac ApplicationInfo.java");
-        exec("jar -cfe ..\\appinfo.jar ApplicationInfo ApplicationInfo.class");
-        shell.CurrentDirectory = cur;
-    }
-}
-
-// working dir
-var ROOT = WScript.ScriptFullName.split('\\bin\\create.js').join('');
-if (args.Count() > 0) {
-    // support help flags
-    if (args(0) == "--help" || args(0) == "/?" ||
-            args(0) == "help" || args(0) == "-help" || args(0) == "/help" || args(0) == "-h") {
-        Usage();
-        WScript.Quit(2);
-    }
-
-    PROJECT_PATH=args(0);
-    if (args.Count() > 1) {
-        PACKAGE = args(1);
-    }
-    if (args.Count() > 2) {
-        ACTIVITY = args(2);
-    }
-}
-else {
-    Log("Error : No project path provided.");
-    Usage();
-    WScript.Quit(2);
-}
-
-if(fso.FolderExists(PROJECT_PATH)) {
-    Log("Project path already exists!", true);
-    WScript.Quit(2);
-}
-
-var PACKAGE_AS_PATH=PACKAGE.replace(/\./g, '\\');
-var ACTIVITY_DIR=PROJECT_PATH + '\\src\\' + PACKAGE_AS_PATH;
-var SAFE_ACTIVITY = ACTIVITY.replace(/\W/g, '');
-var ACTIVITY_PATH=ACTIVITY_DIR+'\\'+SAFE_ACTIVITY+'.java';
-var MANIFEST_PATH=PROJECT_PATH+'\\AndroidManifest.xml';
-var STRINGS_PATH=PROJECT_PATH+'\\res\\values\\strings.xml';
-var TARGET=setTarget();
-var API_LEVEL=setApiLevel();
-var VERSION=read(ROOT+'\\VERSION').replace(/\r\n/,'').replace(/\n/,'');
-// create the project
-Log("Creating new android project...");
-exec('android.bat create project --target "'+TARGET+'" --path "'+PROJECT_PATH+'" --package "'+PACKAGE+'" --activity "'+SAFE_ACTIVITY+'"');
-
-// build from source. distro should have these files
-if (!fso.FileExists(ROOT+'\\cordova-'+VERSION+'.jar') &&
-    !fso.FileExists(ROOT+'\\cordova.js')) {
-    Log("Building jar and js files...");
-    // update the cordova framework project to a target that exists on this machine
-    exec('android.bat update project --target "'+TARGET+'" --path "'+ROOT+'\\framework"');
-    exec('ant.bat -f "'+ ROOT +'\\framework\\build.xml" jar');
-}
-
-// copy in the project template
-Log("Copying template files...");
-exec('%comspec% /c xcopy "'+ ROOT + '\\bin\\templates\\project\\res" "'+PROJECT_PATH+'\\res\\" /E /Y');
-exec('%comspec% /c xcopy "'+ ROOT + '\\bin\\templates\\project\\assets" "'+PROJECT_PATH+'\\assets\\" /E /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\project\\AndroidManifest.xml" "' + PROJECT_PATH + '\\AndroidManifest.xml" /Y');
-exec('%comspec% /c mkdir "' + ACTIVITY_DIR + '"');
-exec('%comspec% /c copy "' + ROOT + '"\\bin\\templates\\project\\Activity.java "' + ACTIVITY_PATH + '" /Y');
-
-// check if we have the source or the distro files
-Log("Copying js, jar & config.xml files...");
-if(fso.FolderExists(ROOT + '\\framework')) {
-    exec('%comspec% /c copy "'+ROOT+'\\framework\\assets\\www\\cordova.js" "'+PROJECT_PATH+'\\assets\\www\\cordova.js" /Y');
-    exec('%comspec% /c copy "'+ROOT+'\\framework\\cordova-'+VERSION+'.jar" "'+PROJECT_PATH+'\\libs\\cordova-'+VERSION+'.jar" /Y');
-    fso.CreateFolder(PROJECT_PATH + '\\res\\xml');
-    exec('%comspec% /c copy "'+ROOT+'\\framework\\res\\xml\\config.xml" "' + PROJECT_PATH + '\\res\\xml\\config.xml" /Y');
-} else {
-    // copy in cordova.js
-    exec('%comspec% /c copy "'+ROOT+'\\cordova.js" "'+PROJECT_PATH+'\\assets\\www\\cordova.js" /Y');
-    // copy in cordova.jar
-    exec('%comspec% /c copy "'+ROOT+'\\cordova-'+VERSION+'.jar" "'+PROJECT_PATH+'\\libs\\cordova-'+VERSION+'.jar" /Y');
-    // copy in xml
-    fso.CreateFolder(PROJECT_PATH + '\\res\\xml');
-    exec('%comspec% /c copy "'+ROOT+'\\xml\\config.xml" "' + PROJECT_PATH + '\\res\\xml\\config.xml" /Y');
-}
-
-// copy cordova scripts
-fso.CreateFolder(PROJECT_PATH + '\\cordova');
-fso.CreateFolder(PROJECT_PATH + '\\cordova\\lib');
-createAppInfoJar();
-Log("Copying cordova command tools...");
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\appinfo.jar" "' + PROJECT_PATH + '\\cordova\\appinfo.jar" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\lib\\cordova.js" "' + PROJECT_PATH + '\\cordova\\lib\\cordova.js" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\lib\\install-device.bat" "' + PROJECT_PATH + '\\cordova\\lib\\install-device.bat" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\lib\\install-emulator.bat" "' + PROJECT_PATH + '\\cordova\\lib\\install-emulator.bat" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\lib\\list-emulator-images.bat" "' + PROJECT_PATH + '\\cordova\\lib\\list-emulator-images.bat" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\lib\\list-devices.bat" "' + PROJECT_PATH + '\\cordova\\lib\\list-devices.bat" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\lib\\list-started-emulators.bat" "' + PROJECT_PATH + '\\cordova\\lib\\list-started-emulators.bat" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\lib\\start-emulator.bat" "' + PROJECT_PATH + '\\cordova\\lib\\start-emulator.bat" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\cordova.bat" "' + PROJECT_PATH + '\\cordova\\cordova.bat" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\clean.bat" "' + PROJECT_PATH + '\\cordova\\clean.bat" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\build.bat" "' + PROJECT_PATH + '\\cordova\\build.bat" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\log.bat" "' + PROJECT_PATH + '\\cordova\\log.bat" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\run.bat" "' + PROJECT_PATH + '\\cordova\\run.bat" /Y');
-exec('%comspec% /c copy "'+ROOT+'\\bin\\templates\\cordova\\version.bat" "' + PROJECT_PATH + '\\cordova\\version.bat" /Y');
-
-// interpolate the activity name and package
-Log("Updating AndroidManifest.xml and Main Activity...");
-replaceInFile(ACTIVITY_PATH, /__ACTIVITY__/, ACTIVITY);
-replaceInFile(ACTIVITY_PATH, /__ID__/, PACKAGE);
-
-replaceInFile(MANIFEST_PATH, /__ACTIVITY__/, ACTIVITY);
-replaceInFile(MANIFEST_PATH, /__PACKAGE__/, PACKAGE);
-replaceInFile(MANIFEST_PATH, /__APILEVEL__/, API_LEVEL);
-
-replaceInFile(STRINGS_PATH, new RegExp('>' + SAFE_ACTIVITY + '<'), '>' + ACTIVITY + '<');
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
new file mode 100644
index 0000000..eb0c477
--- /dev/null
+++ b/bin/lib/check_reqs.js
@@ -0,0 +1,85 @@
+#!/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'),
+    fs    = require('fs'),
+    ROOT  = path.join(__dirname, '..', '..');
+
+// Get valid target from framework/project.properties
+module.exports.get_target = function() {
+    if(fs.existsSync(path.join(ROOT, 'framework', 'project.properties'))) {
+        var target = shell.grep(/target=android-[\d+]/, path.join(ROOT, 'framework', 'project.properties'));
+        return target.split('=')[1].replace('\n', '').replace('\r', '').replace(' ', '');
+    } else if (fs.existsSync(path.join(ROOT, 'project.properties'))) {
+        // if no target found, we're probably in a project and project.properties is in ROOT.
+        var target = shell.grep(/target=android-[\d+]/, path.join(ROOT, 'project.properties'));
+        return target.split('=')[1].replace('\n', '').replace('\r', '').replace(' ', '');
+    }
+}
+
+module.exports.check_ant = function() {
+    var test = shell.exec('ant -version', {silent:true, async:false});
+    if(test.code > 0) {
+        console.error('ERROR : executing command \'ant\', make sure you have ant installed and added to your path.');
+        return false;
+    }
+    return true;
+}
+
+module.exports.check_java = function() {
+    if(process.env.JAVA_HOME) {
+        var test = shell.exec('java', {silent:true, async:false});
+        if(test.code > 0) {
+            console.error('ERROR : executing command \'java\', make sure you java environment is set up. Including your JDK and JRE.');
+            return false;
+        }
+        return true;
+    } else {
+        console.error('ERROR : Make sure JAVA_HOME is set, as well as paths to your JDK and JRE for java.');
+        return false;
+    }
+}
+
+module.exports.check_android = function() {
+    var valid_target = this.get_target();
+    var targets = shell.exec('android list targets', {silent:true, async:false});
+
+    if(targets.code > 0 && targets.output.match(/command\snot\sfound/)) {
+        console.error('The command \"android\" failed. Make sure you have the latest Android SDK installed, and the \"android\" command (inside the tools/ folder) is added to your path.');
+        return false;
+    } else if(!targets.output.match(valid_target)) {
+        console.error('Please install Android target ' + valid_target.split('-')[1] + ' (the Android newest SDK). Make sure you have the latest Android tools installed as well. Run \"android\" from your command-line to install/update any missing SDKs or tools.');
+        return false;
+    } else {
+        var cmd = 'android update project -p ' + ROOT + ' -t ' + valid_target + ' 1> /dev/null 2>&1';
+        var result = shell.exec(cmd, {silent:false, async:true});
+        if(result.code > 0) {
+          console.error('Error updating the Cordova library to work with your Android environment.');
+          return false;
+        }
+    }
+    return true;
+}
+
+module.exports.run = function() {
+    return this.check_ant() && this.check_java && this.check_android();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
new file mode 100755
index 0000000..4a7294c
--- /dev/null
+++ b/bin/lib/create.js
@@ -0,0 +1,265 @@
+#!/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.
+*/
+try {
+    require.resolve("shelljs");
+} catch(e) {
+    console.error('Shelljs module was not found, please run \'npm install\' from the bin folder.');
+    process.exit(e.code);
+}
+
+var shell = require('shelljs'),
+    path  = require('path'),
+    fs    = require('fs'),
+    check_reqs = require('./check_reqs'),
+    ROOT    = path.join(__dirname, '..', '..');
+
+
+/**
+ * $ create [options]
+ *
+ * Creates an android application with the given options.
+ *
+ * Options:
+ *
+ *   - `project_path` 	{String} Path to the new Cordova android project.
+ *   - `package_name`{String} Package name, following reverse-domain style convention.
+ *   - `project_name` 	{String} Project name.
+ */
+
+module.exports.run = function(project_path, package_name, project_name) {
+
+    var VERSION = fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf-8');
+    var project_template_dir = path.join(ROOT, 'bin', 'templates', 'project');
+
+    // Set default values for path, package and name
+    project_path = typeof project_path !== 'undefined' ? project_path : "CordovaExample";
+    package_name = typeof package_name !== 'undefined' ? package_name : 'my.cordova.project';
+    project_name = typeof project_name !== 'undefined' ? project_name : 'CordovaExample';
+
+    var safe_activity_name = project_name.replace(/\W/, '');
+    var package_as_path = package_name.replace(/\./g, path.sep);
+    var activity_dir    = path.join(project_path, 'src', package_as_path);
+    var activity_path   = path.join(activity_dir, safe_activity_name + '.java');
+    var target_api      = check_reqs.get_target();
+    var strings_path    = path.join(project_path, 'res', 'values', 'strings.xml');
+    var manifest_path   = path.join(project_path, 'AndroidManifest.xml');
+
+    // Check if project already exists
+    if(fs.existsSync(project_path)) {
+        console.error('Project already exists! Delete and recreate');
+        process.exit(2);
+    }
+
+    // Check that requirements are met and proper targets are installed
+    if(!check_reqs.run()) {
+        console.error('Please make sure you meeet the software requirements in order to build an android cordova project');
+        process.exit(2);
+    }
+
+    // Log the given values for the project
+    console.log('Creating Cordova project for the Android platform :');
+    console.log('\tPath : ' + path.relative(process.cwd(), project_path));
+    console.log('\tPackage : ' + package_name);
+    console.log('\tName : ' + project_name);
+    console.log('\tAndroid target : ' + target_api);
+
+    // build from source. distro should have these files
+    if(!fs.existsSync(path.join(ROOT, 'cordova-' + VERSION + '.jar')) && fs.existsSync(path.join(ROOT, 'framework'))) {
+        console.log('Building jar and js files...');
+        // update the cordova-android framework for the desired target
+        exec('android update project --target ' + target_api + ' --path ' + path.join(ROOT, 'framework'));
+
+        // compile cordova.js and cordova.jar
+        var cwd = process.cwd();
+        process.chdir(path.join(ROOT, 'framework'));
+        exec('ant jar');
+        process.chdir(cwd);
+    }
+
+    // create new android project
+    var create_cmd = 'android create project --target "'+target_api+'" --path "'+path.relative(process.cwd(), project_path)+'" --package "'+package_name+'" --activity "'+safe_activity_name+'"';
+    exec(create_cmd);
+
+    console.log('Copying template files...');
+
+    // copy project template
+    shell.cp('-r', path.join(project_template_dir, 'assets'), project_path);
+    shell.cp('-r', path.join(project_template_dir, 'res'), project_path);
+
+    // copy cordova.js, cordova.jar and res/xml
+    if(fs.existsSync(path.join(ROOT, 'framework'))) {
+        shell.cp('-r', path.join(ROOT, 'framework', 'res', 'xml'), path.join(project_path, 'res'));
+        shell.cp(path.join(ROOT, 'framework', 'assets', 'www', 'cordova.js'), path.join(project_path, 'assets', 'www', 'cordova.js'));
+        shell.cp(path.join(ROOT, 'framework', 'cordova-' + VERSION + '.jar'), path.join(project_path, 'libs', 'cordova-' + VERSION + '.jar'));
+    } else {
+        shell.cp('-r', path.join(ROOT, 'xml'), path.join(project_path, 'res'));
+        shell.cp(path.join(ROOT, 'cordova.js'), path.join(project_path, 'assets', 'www', 'cordova.js'));
+        shell.cp(path.join(ROOT, 'cordova-' + VERSION + '.jar'), path.join(project_path, 'libs', 'cordova-' + VERSION + '.jar'));
+    }
+
+    // interpolate the activity name and package
+    shell.mkdir('-p', activity_dir);
+    shell.cp('-f', path.join(project_template_dir, 'Activity.java'), activity_path);
+    replaceInFile(activity_path, /__ACTIVITY__/, safe_activity_name);
+    replaceInFile(activity_path, /__ID__/, package_name);
+
+    // interpolate the app name into strings.xml
+    replaceInFile(strings_path, />Cordova</, '>' + project_name + '<');
+
+    shell.cp('-f', path.join(project_template_dir, 'AndroidManifest.xml'), manifest_path);
+    replaceInFile(manifest_path, /__ACTIVITY__/, safe_activity_name);
+    replaceInFile(manifest_path, /__PACKAGE__/, package_name);
+    replaceInFile(manifest_path, /__APILEVEL__/, target_api.split('-')[1]);
+
+    var cordova_path = path.join(ROOT, 'bin', 'templates', 'cordova');
+    // create app info jar
+    if(!fs.existsSync(path.join(cordova_path, 'appinfo.jar'))) {
+        console.log('Creating appinfo.jar...');
+        var cwd = process.cwd();
+        process.chdir(path.join(cordova_path, 'ApplicationInfo'));
+        exec('javac ApplicationInfo.java');
+        exec('jar -cfe ' + path.join(cordova_path, 'appinfo.jar') + ' ApplicationInfo ApplicationInfo.class');
+        process.chdir(cwd);
+    }
+
+    // creating cordova folder and copying run/build/log/launch/check_reqs scripts
+    var lib_path = path.join(cordova_path, 'lib');
+    shell.mkdir(path.join(project_path, 'cordova'));
+    shell.mkdir(path.join(project_path, 'cordova', 'lib'));
+
+    shell.cp(path.join(cordova_path, 'appinfo.jar'), path.join(project_path, 'cordova', 'appinfo.jar'));
+    shell.cp(path.join(cordova_path, 'build'), path.join(project_path, 'cordova', 'build'));
+    shell.chmod(755, path.join(project_path, 'cordova', 'build'));
+    shell.cp(path.join(cordova_path, 'clean'), path.join(project_path, 'cordova', 'clean'));
+    shell.chmod(755, path.join(project_path, 'cordova', 'clean'));
+    shell.cp(path.join(cordova_path, 'log'), path.join(project_path, 'cordova', 'log'));
+    shell.chmod(755, path.join(project_path, 'cordova', 'log'));
+    shell.cp(path.join(cordova_path, 'run'), path.join(project_path, 'cordova', 'run'));
+    shell.chmod(755, path.join(project_path, 'cordova', 'run'));
+    shell.cp(path.join(cordova_path, 'version'), path.join(project_path, 'cordova', 'version'));
+    shell.chmod(755, path.join(project_path, 'cordova', 'version'));
+    shell.cp(path.join(ROOT, 'bin', 'check_reqs'), path.join(project_path, 'cordova', 'check_reqs'));
+    shell.chmod(755, path.join(project_path, 'cordova', 'check_reqs'));
+
+    shell.cp(path.join(lib_path, 'build.js'), path.join(project_path, 'cordova', 'lib', 'build.js'));
+    shell.cp(path.join(ROOT, 'bin', 'lib', 'check_reqs.js'), path.join(project_path, 'cordova', 'lib', 'check_reqs.js'));
+    shell.cp(path.join(lib_path, 'clean.js'), path.join(project_path, 'cordova', 'lib', 'clean.js'));
+    shell.cp(path.join(lib_path, 'device.js'), path.join(project_path, 'cordova', 'lib', 'device.js'));
+    shell.cp(path.join(lib_path, 'emulator.js'), path.join(project_path, 'cordova', 'lib', 'emulator.js'));
+    shell.cp(path.join(lib_path, 'log.js'), path.join(project_path, 'cordova', 'lib', 'log.js'));
+    shell.cp(path.join(lib_path, 'run.js'), path.join(project_path, 'cordova', 'lib', 'run.js'));
+    shell.cp(path.join(lib_path, 'version.js'), path.join(project_path, 'cordova', 'lib', 'version.js'));
+    shell.cp(path.join(lib_path, 'install-device'), path.join(project_path, 'cordova', 'lib', 'install-device'));
+    shell.chmod(755, path.join(project_path, 'cordova', 'lib', 'install-device'));
+    shell.cp(path.join(lib_path, 'install-emulator'), path.join(project_path, 'cordova', 'lib', 'install-emulator'));
+    shell.chmod(755, path.join(project_path, 'cordova', 'lib', 'install-emulator'));
+    shell.cp(path.join(lib_path, 'list-devices'), path.join(project_path, 'cordova', 'lib', 'list-devices'));
+    shell.chmod(755, path.join(project_path, 'cordova', 'lib', 'list-devices'));
+    shell.cp(path.join(lib_path, 'list-emulator-images'), path.join(project_path, 'cordova', 'lib', 'list-emulator-images'));
+    shell.chmod(755, path.join(project_path, 'cordova', 'lib', 'list-emulator-images'));
+    shell.cp(path.join(lib_path, 'list-started-emulators'), path.join(project_path, 'cordova', 'lib', 'list-started-emulators'));
+    shell.chmod(755, path.join(project_path, 'cordova', 'lib', 'list-started-emulators'));
+    shell.cp(path.join(lib_path, 'start-emulator'), path.join(project_path, 'cordova', 'lib', 'start-emulator'));
+    shell.chmod(755, path.join(project_path, 'cordova', 'lib', 'start-emulator'));
+
+    // if on windows, copy .bat scripts
+    // TODO : make these not nessesary, they clutter the scripting folder.
+    if(process.platform == 'win32' || process.platform == 'win64') {
+        shell.cp(path.join(cordova_path, 'build.bat'), path.join(project_path, 'cordova', 'build.bat'));
+        shell.cp(path.join(cordova_path, 'clean.bat'), path.join(project_path, 'cordova', 'clean.bat'));
+        shell.cp(path.join(cordova_path, 'log.bat'), path.join(project_path, 'cordova', 'log.bat'));
+        shell.cp(path.join(cordova_path, 'run.bat'), path.join(project_path, 'cordova', 'run.bat'));
+        shell.cp(path.join(cordova_path, 'version.bat'), path.join(project_path, 'cordova', 'version.bat'));
+        shell.cp(path.join(ROOT, 'bin', 'check_reqs.bat'), path.join(project_path, 'cordova', 'check_reqs.bat'));
+
+        // lib scripts
+        shell.cp(path.join(lib_path, 'install-device.bat'), path.join(project_path, 'cordova', 'lib', 'install-device.bat'));
+        shell.cp(path.join(lib_path, 'install-emulator.bat'), path.join(project_path, 'cordova', 'lib', 'install-emulator.bat'));
+        shell.cp(path.join(lib_path, 'list-devices.bat'), path.join(project_path, 'cordova', 'lib', 'list-devices.bat'));
+        shell.cp(path.join(lib_path, 'list-emulator-images.bat'), path.join(project_path, 'cordova', 'lib', 'list-emulator-images.bat'));
+        shell.cp(path.join(lib_path, 'list-started-emulators.bat'), path.join(project_path, 'cordova', 'lib', 'list-started-emulators.bat'));
+        shell.cp(path.join(lib_path, 'start-emulator.bat'), path.join(project_path, 'cordova', 'lib', 'start-emulator.bat'));
+    }
+
+    // copy node related files
+    shell.cp(path.join(ROOT, 'bin', 'package.json'), path.join(project_path, 'cordova', 'package.json'));
+    shell.cp('-r', path.join(ROOT, 'bin', 'node_modules'), path.join(project_path, 'cordova'));
+
+    /*
+     * HELPER FUNCTIONS
+     */
+
+    function exec(command) {
+        var result;
+        try {
+            result = shell.exec(command, {silent:false, async:false});
+        } catch(e) {
+            console.error('Command error on execuation : ' + command);
+            console.error(e);
+            process.exit(2);
+        }
+        if(result && result.code > 0) {
+            console.error('Command failed to execute : ' + command);
+            console.error(result.output);
+            process.exit(2);
+        } else {
+            return result;
+        }
+    }
+
+    function replaceInFile(filename, regex, replacement) {
+        write(filename, read(filename).replace(regex, replacement));
+    }
+
+    function read(filename) {
+        if(fs.existsSync(filename)) {
+            if(fs.lstatSync(filename).isFile()) {
+                return fs.readFileSync(filename, 'utf-8');
+            } else {
+                console.error('Uanble to read directory : ' + filename);
+                process.exit(1);
+            }
+        } else {
+            console.error('Uanble to read file, not found : ' + filename);
+            process.exit(1);
+        }
+    }
+
+    function write(filename, content) {
+        fs.writeFileSync(filename, content, 'utf-8');
+    }
+}
+
+/**
+ * Usage information.
+ **/
+
+module.exports.help = function() {
+    console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'bin', 'create')) + ' <path_to_new_project> <package_name> <project_name>');
+    console.log('Make sure the Android SDK tools folder is in your PATH!');
+    console.log('    <path_to_new_project>: Path to your new Cordova Android project');
+    console.log('    <package_name>: Package name, following reverse-domain style convention');
+    console.log('    <project_name>: Project name');
+    process.exit(0);
+}
+
+
+

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/package.json
----------------------------------------------------------------------
diff --git a/bin/package.json b/bin/package.json
new file mode 100644
index 0000000..cceb151
--- /dev/null
+++ b/bin/package.json
@@ -0,0 +1,32 @@
+{
+    "name": "cordova-android",
+    "description": "Cordova tooling for the android platform.",
+    "version": "0.0.0",
+    "homepage": "http://github.com/apache/cordova-android",
+    "repository": {
+        "type": "git",
+        "url": "https://git-wip-us.apache.org/repos/asf/cordova-andorid.git"
+    },
+    "keywords": [
+        "cli",
+        "cordova",
+        "tooling"
+    ],
+    "engineStrict": "true",
+    "engines": {
+        "node": ">=0.10.0"
+    },
+    "dependencies": {
+        "shelljs" : "0.1.4"
+    },
+    "devDependencies": {
+    },
+    "optionalDependencies": {
+    },
+    "author": {
+        "name": "Benn Mapes",
+        "email": "bennmapes@gmail.com"
+    },
+    "contributors": [
+    ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/build
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/build b/bin/templates/cordova/build
index 5ba36c0..752945f 100755
--- a/bin/templates/cordova/build
+++ b/bin/templates/cordova/build
@@ -1,39 +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
 
-if [[ "$#" -eq 1 ]] ; then
-    if [[ $1 == "--debug" ]] ; then
-        $DIR/clean
-        ant debug -f "$PROJECT_PATH"/build.xml
-    elif [[ $1 == "--release" ]] ; then
-        $DIR/clean
-        ant release -f "$PROJECT_PATH"/build.xml
-    elif [[ $1 == "--nobuild" ]] ; then
-        echo "Skipping build..."
-    else
-        echo "Error : Build command '$1' not recognized."
-        exit 2
-    fi
-else
-    echo "Warning : [ --debug | --release | --nobuild ] not specified, defaulting to --debug"
-    $DIR/clean
-    ant debug -f "$PROJECT_PATH"/build.xml
-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 build = require('./lib/build'),
+    reqs  = require('./lib/check_reqs'),
+    args  = process.argv;
+
+// Support basic help commands
+if(args[2] == '--help' || args[2] == '/?' || args[2] == '-h' ||
+                    args[2] == 'help' || args[2] == '-help' || args[2] == '/help') {
+    build.help();
+} else if(reqs.run()) {
+    build.run(args[2]);
+    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/build.bat
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/build.bat b/bin/templates/cordova/build.bat
index 392f374..2f317e3 100644
--- a/bin/templates/cordova/build.bat
+++ b/bin/templates/cordova/build.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 build %*
+SET script_path="%~dp0build"
+IF EXIST %script_path% (
+        node "%script_path%" %*
+) ELSE (
+    ECHO.
+    ECHO ERROR: Could not find 'build' 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/clean
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/clean b/bin/templates/cordova/clean
index b943b47..6b72e71 100755
--- a/bin/templates/cordova/clean
+++ b/bin/templates/cordova/clean
@@ -1,22 +1,34 @@
-#!/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 )
-echo "Cleaning project..."
-ant -f "$PROJECT_PATH/build.xml" clean
+/*
+       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 clean = require('./lib/clean'),
+    reqs  = require('./lib/check_reqs'),
+    args  = process.argv;
+
+// Usage support for when args are given
+if(args.length > 2) {
+    clean.help();
+} else if(reqs.run()) {
+    clean.run();
+    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/clean.bat
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/clean.bat b/bin/templates/cordova/clean.bat
index 643c8d5..fa1f669 100644
--- a/bin/templates/cordova/clean.bat
+++ b/bin/templates/cordova/clean.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 clean %*
+SET script_path="%~dp0clean"
+IF EXIST %script_path% (
+        node "%script_path%" %*
+) ELSE (
+    ECHO.
+    ECHO ERROR: Could not find 'clean' 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/cordova.bat
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/cordova.bat b/bin/templates/cordova/cordova.bat
deleted file mode 100644
index 6235fdb..0000000
--- a/bin/templates/cordova/cordova.bat
+++ /dev/null
@@ -1,31 +0,0 @@
-:: 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
-IF NOT DEFINED JAVA_HOME GOTO MISSING
-FOR %%X in (java.exe ant.bat android.bat) do (
-    SET FOUND=%%~$PATH:X
-    IF NOT DEFINED FOUND GOTO MISSING
-)
-cscript %~dp0\lib\cordova.js %* //nologo
-GOTO END
-:MISSING
-ECHO Missing one of the following:
-ECHO JDK: http://java.oracle.com
-ECHO Android SDK: http://developer.android.com
-ECHO Apache ant: http://ant.apache.org
-EXIT /B 1
-:END

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/1bd49009/bin/templates/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/build.js b/bin/templates/cordova/lib/build.js
new file mode 100644
index 0000000..84e4e02
--- /dev/null
+++ b/bin/templates/cordova/lib/build.js
@@ -0,0 +1,89 @@
+#!/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'),
+    clean   = require('./clean'),
+    path    = require('path'),
+    fs      = require('fs'),
+    ROOT    = path.join(__dirname, '..', '..');
+
+/*
+ * Builds the project with ant.
+ */
+module.exports.run = function(build_type) {
+    //default build type
+    build_type = typeof build_type !== 'undefined' ? build_type : "--debug";
+    var cmd;
+    switch(build_type) {
+        case '--debug' :
+            clean.run();
+            cmd = 'ant debug -f ' + path.join(ROOT, 'build.xml');
+            break;
+        case '--release' :
+            clean.run();
+            cmd = 'ant release -f ' + path.join(ROOT, 'build.xml');
+            break;
+        case '--nobuild' :
+            console.log('Skipping build...');
+            break;
+        default :
+           console.error('Build option \'' + build_type + '\' not recognized.');
+           process.exit(2);
+           break;
+    }
+    if(cmd) {
+        var result = shell.exec(cmd, {silent:false, async:false});
+        if(result.code > 0) {
+            console.error('ERROR: Failed to build android project.');
+            console.error(result.output);
+            process.exit(2);
+        }
+    }
+}
+
+/*
+ * Gets the path to the apk file, if not such file exists then
+ * the script will error out. (should we error or just return undefined?)
+ */
+module.exports.get_apk = function() {
+    if(fs.existsSync(path.join(ROOT, 'bin'))) {
+        var bin_files = fs.readdirSync(path.join(ROOT, 'bin'));
+        for (file in bin_files) {
+            if(path.extname(bin_files[file]) == '.apk') {
+                return path.join(ROOT, 'bin', bin_files[file]);
+            }
+        }
+        console.error('ERROR : No .apk found in \'bin\' folder');
+        process.exit(2);
+    } else {
+        console.error('ERROR : unable to find project bin folder, could not locate .apk');
+        process.exit(2);
+    }
+}
+
+module.exports.help = function() {
+    console.log('Usage: ' + path.relative(process.cwd(), path.join(ROOT, 'corodva', 'build')) + ' [build_type]');
+    console.log('Build Types : ');
+    console.log('    \'--debug\': Default build, will build project in using ant debug');
+    console.log('    \'--release\': will build project using ant release');
+    console.log('    \'--nobuild\': will skip build process (can be used with run command)');
+    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/clean.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/clean.js b/bin/templates/cordova/lib/clean.js
new file mode 100644
index 0000000..579a5fa
--- /dev/null
+++ b/bin/templates/cordova/lib/clean.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, '..', '..');
+
+/*
+ * Cleans the project using ant
+ */
+module.exports.run = function() {
+    var cmd = 'ant clean -f ' + path.join(ROOT, 'build.xml');
+    var result = shell.exec(cmd, {silent:false, async:false});
+    if (result.code > 0) {
+        console.error('ERROR: Failed to clean android project.');
+        console.error(result.output);
+        process.exit(2);
+    }
+}
+
+module.exports.help = function() {
+    console.log('Usage: ' + path.relative(process.cwd(), process.argv[1]));
+    console.log('Cleans the project directory.');
+    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/cordova.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/cordova.js b/bin/templates/cordova/lib/cordova.js
deleted file mode 100644
index 2d0195a..0000000
--- a/bin/templates/cordova/lib/cordova.js
+++ /dev/null
@@ -1,612 +0,0 @@
-// 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 ROOT  = WScript.ScriptFullName.split('\\cordova\\lib\\cordova.js').join(''),
-    shell = WScript.CreateObject("WScript.Shell"),
-    fso   = WScript.CreateObject('Scripting.FileSystemObject');
-//device_id for targeting specific device
-var device_id;
-//build types
-var NONE = 0,
-    DEBUG = '--debug',
-    RELEASE = '--release',
-    NO_BUILD = '--nobuild';
-var build_type = NONE;
-
-//deploy tpyes
-var NONE = 0,
-    EMULATOR = 1,
-    DEVICE = 2,
-    TARGET = 3;
-var deploy_type = NONE;
-
-
-// log to stdout or stderr
-function Log(msg, error) {
-    if (error) {
-        WScript.StdErr.WriteLine(msg);
-    }
-    else {
-        WScript.StdOut.WriteLine(msg);
-    }
-} 
-
-// executes a commmand in the shell, returning stdout
-function exec(command) {
-    var oExec=shell.Exec(command);
-    var output = new String();
-    while (oExec.Status == 0) {
-        if (!oExec.StdOut.AtEndOfStream) {
-            var line = oExec.StdOut.ReadLine();
-            output += line;
-        }
-        WScript.sleep(100);
-    }
-    return output;
-}
-
-// executes a command in the shell, returns stdout or stderr if error
-function exec_out(command) {
-    var oExec=shell.Exec(command);
-    var output = new String();
-    while (oExec.Status == 0) {
-        if (!oExec.StdOut.AtEndOfStream) {
-            var line = oExec.StdOut.ReadLine();
-            // XXX: Change to verbose mode 
-            // WScript.StdOut.WriteLine(line);
-            output += line;
-        }
-        WScript.sleep(100);
-    }
-    //Check to make sure our scripts did not encounter an error
-    if (!oExec.StdErr.AtEndOfStream) {
-        var line = oExec.StdErr.ReadAll();
-        return {'error' : true, 'output' : line};
-    }
-    return {'error' : false, 'output' : output};
-}
-
-// executes a commmand in the shell and outputs stdout and fails on stderr
-function exec_verbose(command) {
-    //Log("Command: " + command);
-    var oShell=shell.Exec(command);
-    while (oShell.Status == 0) {
-        //Wait a little bit so we're not super looping
-        WScript.sleep(100);
-        //Print any stdout output from the script
-        if (!oShell.StdOut.AtEndOfStream) {
-            var line = oShell.StdOut.ReadLine();
-            Log(line);
-        }
-    }
-    //Check to make sure our scripts did not encounter an error
-    if (!oShell.StdErr.AtEndOfStream) {
-        var line = oShell.StdErr.ReadAll();
-        Log(line, true);
-        WScript.Quit(2);
-    }
-}
-
-function version(path) {
-    var cordovajs_path = path + "\\assets\\www\\cordova.js";
-    if(fso.FileExists(cordovajs_path)) {
-        var f = fso.OpenTextFile(cordovajs_path, 1,2);
-        var cordovajs = f.ReadAll();
-        f.Close();
-        var version_regex = /^.*CORDOVA_JS_BUILD_LABEL.*$/m;
-        var version_line = cordovajs.match(version_regex) + "";
-        var version = version_line.match(/(\d+)\.(\d+)\.(\d+)(rc\d)?/) + "";
-        // TODO : figure out why this isn't matching properly so we can remove this substring workaround.
-        Log(version.substr(0, ((version.length/2) -1)));
-    } else {
-        Log("Error : Could not find cordova js.", true);
-        Log("Expected Location : " + cordovajs_path, true);
-        WScript.Quit(2);
-    }
-
-}
-
-function get_devices() {
-    var device_list = []
-    var local_devices = shell.Exec("%comspec% /c adb devices").StdOut.ReadAll();
-    if (local_devices.match(/\w+\tdevice/)) {
-        devices = local_devices.split('\r\n');
-        //format (ID DESCRIPTION)
-        for (i in devices) {
-            if (devices[i].match(/\w+\tdevice/) && !devices[i].match(/emulator/)) {
-                device_list.push(devices[i].replace(/\t/, ' '));
-            }
-        }
-    }
-    return device_list
-}
-
-function list_devices() {
-    var devices = get_devices();
-    if (devices.length > 0) {
-        for (i in devices) {
-            Log(devices[i]);
-        }
-    }
-    else {
-        Log('No devices found, if your device is connected and not showing,');
-        Log(' then try and install the drivers for your device.');
-        Log(' http://developer.android.com/tools/extras/oem-usb.html');
-    }
-
-}
-
-function get_emulator_images() {
-    var avd_list = [];
-    var local_emulators = shell.Exec("%comspec% /c android list avds").StdOut.ReadAll();
-    if (local_emulators.match(/Name\:/)) {
-        emulators = local_emulators.split('\n');
-        var count = 0;
-        var output = '';
-        for (i in emulators) {
-            // Find the line with the emulator name.
-            if (emulators[i].match(/Name\:/)) {
-                // strip description
-                var emulator_name = emulators[i].replace(/\s*Name\:\s/, '') + ' ';
-                avd_list.push(emulator_name);
-            }
-        }
-    }
-    return avd_list;
-}
-
-function list_emulator_images() {
-    var images = get_emulator_images();
-    if (images.length > 0) {
-        for(i in images) {
-            Log(images[i]);
-        }
-    }
-    else {
-        Log('No emulators found, if you would like to create an emulator follow the instructions');
-        Log(' provided here : http://developer.android.com/tools/devices/index.html');
-        Log(' Or run \'android create avd --name <name> --target <targetID>\' in on the command line.');
-    }
-}
-
-function get_started_emulators() {
-    var started_emulators = [];
-    var local_devices = shell.Exec("%comspec% /c adb devices").StdOut.ReadAll();
-    if (local_devices.match(/emulator/)) {
-        devices = local_devices.split('\r\n');
-        //format (ID DESCRIPTION)
-        for (i in devices) {
-            if (devices[i].match(/\w+\tdevice/) && devices[i].match(/emulator/)) {
-                started_emulators.push(devices[i].replace(/\t/, ' '));
-            }
-        }
-    }
-    return started_emulators
-}
-
-function list_started_emulators() {
-    var images = get_started_emulators();
-    if (images.length > 0) {
-        for(i in images) {
-            Log(images[i]);
-        }
-    }
-    else {
-        Log('No started emulators found, if you would like to start an emulator call ');
-        Log('\'list-emulator-images\'');
-        Log(' to get the name of an emulator and then start the emulator with');
-        Log('\'start-emulator <Name>\'');
-    }
-}
-
-function create_emulator() {
-    //get targets
-    var targets = shell.Exec('android.bat list targets').StdOut.ReadAll().match(/id:\s\d+/g);
-    if(targets) {
-        exec('%comspec% /c android create avd --name cordova_emulator --target ' + targets[targets.length - 1].replace(/id: /, ""));
-    } else {
-        Log("You do not have any android targets setup. Please create at least one target with the `android` command so that an emulator can be created.", true);
-        WScript.Quit(69);
-    }
-}
-
-function start_emulator(name) {  
-    var emulators = get_emulator_images();
-    var started_emulators = get_started_emulators();
-    var num_started = started_emulators.length;
-    var emulator_name;
-    var started = false;
-    if (name) {
-        for (i in emulators) {
-            if (emulators[i].substr(0,name.length) == name) {
-                Log("Starting emulator : " + name);
-                shell.Exec("%comspec% /c emulator -avd " + name + " &");
-                //shell.Run("%comspec% /c start cmd /c emulator -cpu-delay 0 -no-boot-anim -cache %Temp%\cache -avd " + name);
-                started = true;
-            }
-        }
-    }
-    else {
-        if (emulators.length > 0 && started_emulators.length == 0) {
-            emulator_name = emulators[0].split(' ', 1)[0];
-            start_emulator(emulator_name);
-            return;
-        } else if (started_emulators.length > 0) {
-            Log("Emulator already started : " + started_emulators[0].split(' ', 1));
-            return;
-        } else {
-            Log("Error : unable to start emulator, ensure you have emulators availible by checking \'list-emulator-images\'", true);
-            WScript.Quit(2);
-        }
-    }
-    if (!started) {
-        Log("Error : unable to start emulator, ensure you have emulators availible by checking \'list-emulator-images\'", true);
-        WScript.Quit(2);
-    }
-    else { 
-        // wait for emulator to get the ID
-        Log('Waiting for emulator...');
-        var boot_anim = null;
-        var emulator_ID = null;
-        var new_started = null;
-        var i = 0;
-        while(emulator_ID == null && i < 10) {
-            new_started = get_started_emulators();
-            if(new_started.length > started_emulators.length) {
-                // find new emulator that was just started to get it's ID
-                for(var i = 0; i < new_started.length; i++) {
-                    if (new_started[i] != started_emulators[i]) {
-                        emulator_ID = new_started[i].split(' ', 1)[0];
-                        boot_anim = exec_out('%comspec% /c adb -s ' + emulator_ID + ' shell getprop init.svc.bootanim');
-                        break;
-                    }
-                }
-            }
-        }
-        if (i == 10) {
-             Log('\nEmulator start timed out.');
-             WScript.Quit(2);
-        }
-        i = 0;
-        WScript.Stdout.Write('Booting up emulator (this may take a while).');
-        // use boot animation property to tell when boot is complete.
-        while (!boot_anim.output.match(/stopped/) && i < 100) {
-            boot_anim = exec_out('%comspec% /c adb -s ' + emulator_ID + ' shell getprop init.svc.bootanim');
-            i++;
-            WScript.Stdout.Write('.');
-            WScript.Sleep(2000);
-        }
-
-        if (i < 100) {
-            Log('\nBoot Complete!');
-            // Unlock the device
-            shell.Exec("%comspec% /c adb -s " + emulator_ID + " shell input keyevent 82");
-        } else {
-             Log('\nEmulator boot timed out. Failed to load emulator');
-             WScript.Quit(2);
-        }
-    }
-}
-
-function get_apk(path) {
-    // check if file .apk has been created
-    if (fso.FolderExists(path + '\\bin')) {
-        var path_to_apk;
-        var out_folder = fso.GetFolder(path + '\\bin');
-        var out_files = new Enumerator(out_folder.Files);
-        for (;!out_files.atEnd(); out_files.moveNext()) {
-            var path = out_files.item() + '';
-            if (fso.GetExtensionName(path) == 'apk' && !path.match(/unaligned/)) {
-                path_to_apk = out_files.item();
-                break;
-            }
-        }
-        if (path_to_apk) {
-            return path_to_apk;
-        }
-        else {
-            Log('Failed to find apk, make sure you project is built and there is an ', true);
-            Log(' apk in <project>\\bin\\.  To build your project use \'<project>\\cordova\\build\'', true);
-            WScript.Quit(2);
-        }
-    }
-}
-
-function install_device(path) {
-    var devices = get_devices();
-    var use_target = false;
-    if (devices.length < 1) {
-        Log("Error : No devices found to install to, make sure there are devices", true);
-        Log(" availible by checking \'<project_dir>\\cordova\\lib\\list-devices\'", true);
-        WScript.Quit(2);
-    }
-    launch(path, devices[0].split(' ', 1)[0], true);
-}
-
-function install_emulator(path) {
-    var emulators = get_started_emulators();
-    var use_target = false;
-    if (emulators.length < 1) {
-        Log("Error : No emulators found to install to, make sure there are emulators", true);
-        Log(" availible by checking \'<project_dir>\\cordova\\lib\\list-started-emulators\'", true);
-        WScript.Quit(2);
-    }
-    launch(path, emulators[0].split(' ', 1)[0], false);
-}
-
-function install_target(path) {
-    if(device_id) {
-        var device = false;
-        var emulators = get_started_emulators();
-        var devices = get_devices();
-        var exists = false;
-        for (i in emulators) {
-            if (emulators[i].substr(0,device_id.length) == device_id) {
-                exists = true;
-                break;
-            }
-        }
-        for (i in devices) {
-            if (devices[i].substr(0,device_id.length) == device_id) {
-                exists = true;
-                device = true
-                break;
-            }
-        }
-        if (!exists) {
-            Log("Error : Unable to find target " + device_id, true);
-            Log("Please ensure the target exists by checking \'<project>\\cordova\\lib\\list-started-emulators'");
-            Log(" Or  \'<project>\\cordova\\lib\\list-devices'");
-        }
-        launch(path, device_id, device);
-    }
-    else {
-        Log("You cannot install to a target without providing a valid target ID.", true);
-        WScript.Quit(2);
-    }
-}
-
-function launch(path, id, device) {
-     if(id) {
-        var path_to_apk = get_apk(path);
-        if (path_to_apk) {
-            var launch_name = exec_out("%comspec% /c java -jar "+path+"\\cordova\\appinfo.jar "+path+"\\AndroidManifest.xml");
-            if (launch_name.error) {
-                Log("Failed to get application name from appinfo.jar + AndroidManifest : ", true);
-                Log("Output : " + launch_name.output, true);
-                WScript.Quit(2);
-            }
-            if (device) {
-                // install on device (-d)
-                Log("Installing app on device...");
-            } else {
-                // install on emulator (-e)
-                Log("Installing app on emulator...");
-            }
-            var cmd = '%comspec% /c adb -s ' + id + ' install -r ' + path_to_apk;
-            var install = exec_out(cmd);
-            if ( install.error && install.output.match(/Failure/)) {
-                Log("Error : Could not install apk to emulator : ", true);
-                Log(install.output, true);
-                WScript.Quit(2);
-            }
-            else {
-                Log(install.output);
-            }
-            // launch the application
-            Log("Launching application...");
-            cmd = '%comspec% /c adb -s ' + id + ' shell am start -W -a android.intent.action.MAIN -n ' + launch_name.output;
-            exec_verbose(cmd);
-        }
-        else {
-            Log('Failed to find apk, make sure you project is built and there is an ', true);
-            Log(' apk in <project>\\bin\\.  To build your project use \'<project>\\cordova\\build\'', true);
-            WScript.Quit(2);
-        }
-    }
-    else {
-        Log("You cannot install to a target without providing a valid target ID.", true);
-        WScript.Quit(2);
-    }
-}
-
-function clean(path) {
-    Log("Cleaning project...");
-    exec("%comspec% /c ant.bat clean -f "+path+"\\build.xml 2>&1");
-}
-
-function log() {
-    // filter out nativeGetEnabledTags spam from latest sdk bug.
-    shell.Run("%comspec% /c adb logcat | grep -v nativeGetEnabledTags");
-}
-
-function build(path) {
-    switch (build_type) {
-        case DEBUG :
-            clean(path);
-            Log("Building project...");
-            exec_verbose("%comspec% /c ant.bat debug -f "+path+"\\build.xml 2>&1");
-            break;
-        case RELEASE :
-            clean(path);
-            Log("Building project...");
-            exec_verbose("%comspec% /c ant.bat release -f "+path+"\\build.xml 2>&1");
-            break;
-        case NO_BUILD :
-            Log("Skipping build process.");
-            break;
-        case NONE :
-            clean(path);
-            Log("WARNING: [ --debug | --release | --nobuild ] not specified, defaulting to --debug.");
-            exec_verbose("%comspec% /c ant.bat debug -f "+path+"\\build.xml 2>&1");
-            break;
-        default :
-            Log("Build option not recognized: " + build_type, true);
-            WScript.Quit(2);
-            break;
-    }
-}
-
-function run(path) {
-    switch(deploy_type) {
-        case EMULATOR :
-            build(path);
-            if(get_started_emulators().length == 0) {
-                start_emulator();
-            }
-            //TODO : Start emulator if one isn't started, and create one if none exists.
-            install_emulator(path);
-            break;
-        case DEVICE :
-            build(path);
-            install_device(path);
-            break;
-        case TARGET :
-            build(path);
-            install_target(path);
-            break;
-        case NONE :
-            if (get_devices().length > 0) {
-                Log("WARNING: [ --target=<ID> | --emulator | --device ] not specified, defaulting to --device");
-                deploy_type = DEVICE;
-            } else {
-                Log("WARNING: [ --target=<ID> | --emulator | --device ] not specified, defaulting to --emulator");
-                deploy_type = EMULATOR;
-            }
-            run(path);
-            break;
-        default :
-            Log("Deploy option not recognized: " + deploy_type, true);
-            WScript.Quit(2);
-            break;
-    }
-}
-
-
-var args = WScript.Arguments;
-if (args.count() == 0) {
-    Log("Error: no args provided.");
-    WScript.Quit(2);
-}
-else {
-    // parse command
-    switch(args(0)) {
-        case "version" :
-            version(ROOT);
-            break;
-        case "build" :
-            if(args.Count() > 1) {
-                if (args(1) == "--release") {
-                    build_type = RELEASE;
-                }
-                else if (args(1) == "--debug") {
-                    build_type = DEBUG;
-                }
-                else if (args(1) == "--nobuild") {
-                    build_type = NO_BUILD;
-                }
-                else {
-                    Log('Error: \"' + args(i) + '\" is not recognized as a build option', true);
-                    WScript.Quit(2);
-                }
-            }
-            build(ROOT);
-            break;
-        case "clean" :
-            clean();
-            break;
-        case "log" :
-            log();
-            break;
-        case "list-devices" :
-            list_devices();
-            break;
-        case "list-emulator-images" :
-            list_emulator_images();
-            break;
-        case "list-started-emulators" :
-            list_started_emulators();
-            break;
-        case "start-emulator" :
-            if (args.Count() > 1) {
-                start_emulator(args(1))
-            } else {
-                start_emulator();
-            }
-            break;
-        case "install-emulator" :
-            if (args.Count() == 2) {
-                if (args(1).substr(0,9) == "--target=") {
-                    device_id = args(1).split('--target=').join('');
-                    install_emulator(ROOT);
-                } else {
-                    Log('Error: \"' + args(1) + '\" is not recognized as an install option', true);
-                    WScript.Quit(2);
-                }
-            } else {
-                install_emulator(ROOT);
-            }
-            break;
-        case "install-device" :
-            if (args.Count() == 2) {
-                if (args(1).substr(0,9) == "--target=") {
-                    device_id = args(1).split('--target=').join('');
-                    install_target(ROOT);
-                } else {
-                    Log('Error: \"' + args(1) + '\" is not recognized as an install option', true);
-                    WScript.Quit(2);
-                }
-            } else {
-                install_device(ROOT);
-            }
-            break;
-        case "run" :
-            //parse args
-            for(var i = 1; i < args.Count(); i++) {
-                if (args(i) == "--release") {
-                    build_type = RELEASE;
-                }
-                else if (args(i) == "--debug") {
-                    build_type = DEBUG;
-                }
-                else if (args(i) == "--nobuild") {
-                    build_type = NO_BUILD;
-                }
-                else if (args(i) == "--emulator" || args(i) == "-e") {
-                    deploy_type = EMULATOR;
-                }
-                else if (args(i) == "--device" || args(i) == "-d") {
-                    deploy_type = DEVICE;
-                }
-                else if (args(i).substr(0,9) == "--target=") {
-                    device_id = args(i).split("--target=").join("");
-                    deploy_type = TARGET;
-                }
-                else {
-                    Log('Error: \"' + args(i) + '\" is not recognized as a run option', true);
-                    WScript.Quit(2);
-                }
-            }
-            run(ROOT);
-            break;
-        default :
-            Log("Cordova does not regognize the command " + args(0), true);
-            WScript.Quit(2);
-            break;
-    }
-}
-