refactoring windows scripts

This commit is contained in:
Anis Kadri 2012-11-20 18:49:16 -08:00
parent 3f3a0b9140
commit d9107bcac6
2 changed files with 33 additions and 18 deletions

View File

@ -198,10 +198,9 @@ exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\appinfo.jar ' + PRO
exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\cordova.js ' + PROJECT_PATH + '\\cordova\\cordova.js /Y'); exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\cordova.js ' + PROJECT_PATH + '\\cordova\\cordova.js /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\\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\\clean.bat ' + PROJECT_PATH + '\\cordova\\clean.bat /Y');
exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\debug.bat ' + PROJECT_PATH + '\\cordova\\debug.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\\log.bat ' + PROJECT_PATH + '\\cordova\\log.bat /Y');
exec('%comspec% /c copy "'+ROOT+'"\\bin\\templates\\cordova\\emulate.bat ' + PROJECT_PATH + '\\cordova\\emulate.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\\BOOM.bat ' + PROJECT_PATH + '\\cordova\\BOOM.bat /Y');
// interpolate the activity name and package // interpolate the activity name and package
WScript.Echo("Updating AndroidManifest.xml and Main Activity..."); WScript.Echo("Updating AndroidManifest.xml and Main Activity...");

View File

@ -34,17 +34,19 @@ function exec(command) {
return output; return output;
} }
function emulator_running() { function device_running() {
var local_devices = shell.Exec("%comspec% /c adb devices").StdOut.ReadAll(); var local_devices = shell.Exec("%comspec% /c adb devices").StdOut.ReadAll();
if(local_devices.match(/emulator/)) { if(local_devices.match(/\w+\tdevice/)) {
WScript.Echo("Yes");
return true; return true;
} }
WScript.Echo("No");
return false; return false;
} }
function emulate() { function emulate() {
// don't run emulator if a device is plugged in or if emulator is already running // don't run emulator if a device is plugged in or if emulator is already running
if(emulator_running()) { if(device_running()) {
WScript.Echo("Device or Emulator already running!"); //WScript.Echo("Device or Emulator already running!");
return; return;
} }
var oExec = shell.Exec("%comspec% /c android.bat list avd"); var oExec = shell.Exec("%comspec% /c android.bat list avd");
@ -84,18 +86,18 @@ function emulate() {
} }
function clean() { function clean() {
WScript.Echo("Cleaning project...");
exec("%comspec% /c ant.bat clean -f "+ROOT+"\\build.xml 2>&1"); exec("%comspec% /c ant.bat clean -f "+ROOT+"\\build.xml 2>&1");
} }
function debug() { function build() {
if(emulator_running()) { WScript.Echo("Building project...");
exec("%comspec% /c ant.bat debug install -f "+ROOT+"\\build.xml 2>&1"); exec("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1");
} else { }
exec("%comspec% /c ant.bat debug -f "+ROOT+"\\build.xml 2>&1");
WScript.Echo("##################################################################"); function install() {
WScript.Echo("# Plug in your device or launch an emulator with cordova/emulate #"); WScript.Echo("Building/Installing project...");
WScript.Echo("##################################################################"); exec("%comspec% /c ant.bat debug install -f "+ROOT+"\\build.xml 2>&1");
}
} }
function log() { function log() {
@ -103,14 +105,28 @@ function log() {
} }
function launch() { function launch() {
WScript.Echo("Launching app...");
var launch_str=exec("%comspec% /c java -jar "+ROOT+"\\cordova\\appinfo.jar "+ROOT+"\\AndroidManifest.xml"); var launch_str=exec("%comspec% /c java -jar "+ROOT+"\\cordova\\appinfo.jar "+ROOT+"\\AndroidManifest.xml");
//WScript.Echo(launch_str); //WScript.Echo(launch_str);
exec("%comspec% /c adb shell am start -n "+launch_str+" 2>&1"); exec("%comspec% /c adb shell am start -n "+launch_str+" 2>&1");
} }
function BOOM() { function run() {
var i=0;
clean(); clean();
debug(); emulate();
WScript.Stdout.Write('Waiting for device...');
while(!device_running() && i < 300) {
WScript.Stdout.Write('.');
WScript.sleep(1000);
i += 1;
}
if(i == 300) {
WScript.Stderr.WriteLine("device/emulator timeout!");
} else {
WScript.Stdout.WriteLine("connected!");
}
install();
launch(); launch();
} }
var args = WScript.Arguments; var args = WScript.Arguments;