diff --git a/bin/create.js b/bin/create.js index 9f704430..fcce4786 100644 --- a/bin/create.js +++ b/bin/create.js @@ -33,6 +33,10 @@ function read(filename) { f.Close(); return s; } +function setTarget() { + var targets = shell.Exec('android.bat list targets').StdOut.ReadAll().match(/id:\s\d+/g); + return targets[targets.length - 1].replace(/id: /, ""); // TODO: give users the option to set their target +} function write(filename, contents) { var fso=WScript.CreateObject("Scripting.FileSystemObject"); var f=fso.OpenTextFile(filename, 2, true); @@ -42,12 +46,11 @@ function write(filename, contents) { function replaceInFile(filename, regexp, replacement) { write(filename, read(filename).replace(regexp, replacement)); } -function exec(s, output) { - var o=shell.Exec(s); - while (o.Status == 0) { - WScript.Sleep(100); +function exec(command) { + var oShell=shell.Exec(command); + while (oShell.Status == 0) { + WScript.sleep(100); } - //WScript.Echo("Command exited with code " + o.Status); } function cleanup() { @@ -125,9 +128,8 @@ if(fso.FolderExists(PROJECT_PATH)) { var PACKAGE_AS_PATH=PACKAGE.replace(/\./g, '\\'); var ACTIVITY_PATH=PROJECT_PATH+'\\src\\'+PACKAGE_AS_PATH+'\\'+ACTIVITY+'.java'; var MANIFEST_PATH=PROJECT_PATH+'\\AndroidManifest.xml'; -var TARGET=shell.Exec('android.bat list targets').StdOut.ReadAll().match(/id:\s([0-9]).*/)[1]; +var TARGET=setTarget(); var VERSION=read(ROOT+'\\VERSION').replace(/\r\n/,'').replace(/\n/,''); - // create the project exec('android.bat create project --target '+TARGET+' --path '+PROJECT_PATH+' --package '+PACKAGE+' --activity '+ACTIVITY); @@ -140,7 +142,10 @@ downloadCommonsCodec(); exec('ant.bat -f '+ ROOT +'\\framework\\build.xml jar'); // copy in the project template -exec('cmd /c xcopy '+ ROOT + '\\bin\\templates\\project\\* '+PROJECT_PATH+' /S /Y'); +exec('cmd /c xcopy '+ ROOT + '\\bin\\templates\\project\\res '+PROJECT_PATH+'\\res\\ /E /Y'); +exec('cmd /c xcopy '+ ROOT + '\\bin\\templates\\project\\assets '+PROJECT_PATH+'\\assets\\ /E /Y'); +exec('cmd /c copy '+ROOT+'\\bin\\templates\\project\\AndroidManifest.xml ' + PROJECT_PATH + '\\AndroidManifest.xml /Y'); +exec('cmd /c copy '+ROOT+'\\bin\\templates\\project\\Activity.java '+ ACTIVITY_PATH +' /Y'); // copy in cordova.js exec('cmd /c copy '+ROOT+'\\framework\\assets\\www\\cordova-'+VERSION+'.js '+PROJECT_PATH+'\\assets\\www\\cordova-'+VERSION+'.js /Y'); @@ -153,6 +158,17 @@ fso.CreateFolder(PROJECT_PATH + '\\res\\xml'); exec('cmd /c copy '+ROOT+'\\framework\\res\\xml\\cordova.xml ' + PROJECT_PATH + '\\res\\xml\\cordova.xml /Y'); exec('cmd /c copy '+ROOT+'\\framework\\res\\xml\\plugins.xml ' + PROJECT_PATH + '\\res\\xml\\plugins.xml /Y'); +// copy cordova scripts +fso.CreateFolder(PROJECT_PATH + '\\cordova'); +exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\appinfo.jar ' + PROJECT_PATH + '\\cordova\\appinfo.jar /Y'); +exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\cordova.js ' + PROJECT_PATH + '\\cordova\\cordova.js /Y'); +exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\cordova.bat ' + PROJECT_PATH + '\\cordova\\cordova.bat /Y'); +exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\clean.bat ' + PROJECT_PATH + '\\cordova\\clean.bat /Y'); +exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\debug.bat ' + PROJECT_PATH + '\\cordova\\debug.bat /Y'); +exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\log.bat ' + PROJECT_PATH + '\\cordova\\log.bat /Y'); +exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\emulate.bat ' + PROJECT_PATH + '\\cordova\\emulate.bat /Y'); +exec('cmd /c copy '+ROOT+'\\bin\\templates\\cordova\\BOOM.bat ' + PROJECT_PATH + '\\cordova\\BOOM.bat /Y'); + // interpolate the activity name and package replaceInFile(ACTIVITY_PATH, /__ACTIVITY__/, ACTIVITY); replaceInFile(ACTIVITY_PATH, /__ID__/, PACKAGE); diff --git a/bin/tests/test_create_win.js b/bin/tests/test_create_win.js index 76dd6aab..e8202dec 100644 --- a/bin/tests/test_create_win.js +++ b/bin/tests/test_create_win.js @@ -91,8 +91,43 @@ create_project.on('exit', function(code) { assert(exists, 'cordova.js did not get added'); }); - // check that project compiles && creates a cordovaExample-debug.apk - // XXX: !@##!@# WINDOWS + // make sure cordova master script was added + path.exists(util.format('%s/cordova/cordova.bat', project_path), function(exists) { + assert(exists, 'cordova script did not get added'); + }); + + // make sure debug script was added + path.exists(util.format('%s/cordova/debug.bat', project_path), function(exists) { + assert(exists, 'debug script did not get added'); + }); + + // make sure BOOM script was added + path.exists(util.format('%s/cordova/BOOM.bat', project_path), function(exists) { + assert(exists, 'BOOM script did not get added'); + }); + + // make sure log script was added + path.exists(util.format('%s/cordova/log.bat', project_path), function(exists) { + assert(exists, 'log script did not get added'); + }); + + // make sure clean script was added + path.exists(util.format('%s/cordova/clean.bat', project_path), function(exists) { + assert(exists, 'clean script did not get added'); + }); + + // make sure emulate script was added + path.exists(util.format('%s/cordova/emulate.bat', project_path), function(exists) { + assert(exists, 'emulate script did not get added'); + }); + + // make sure appinfo.jar script was added + path.exists(util.format('%s/cordova/appinfo.jar', project_path), function(exists) { + assert(exists, 'appinfo.jar script did not get added'); + }); + + // check that project compiles && creates a cordovaExample-debug.apk + // XXX: !@##!@# WINDOWS exec('ant debug -f ' + project_path + "\\build.xml", function(error, stdout, stderr) { assert(error == null, "Cordova Android Project does not compile"); path.exists(util.format('%s/bin/%s-debug.apk', project_path, project_name),