You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/05/18 23:12:43 UTC

[9/9] android commit: [CB-659] create script should work on android

[CB-659] create script should work on android


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

Branch: refs/heads/463
Commit: 7eb3e5d13955725f44f72cb816c2fc2b2f376e18
Parents: fc50a0d
Author: filmaj <ma...@gmail.com>
Authored: Wed May 16 19:38:11 2012 -0700
Committer: filmaj <ma...@gmail.com>
Committed: Wed May 16 19:38:11 2012 -0700

----------------------------------------------------------------------
 bin/create.bat                           |    2 +-
 bin/create.js                            |   67 +++++++++++++++++-------
 bin/templates/project/cordova/create.bat |    2 +
 bin/templates/project/cordova/create.js  |   70 +++++++++++++++++++++++++
 4 files changed, 120 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/7eb3e5d1/bin/create.bat
----------------------------------------------------------------------
diff --git a/bin/create.bat b/bin/create.bat
index b9c9392..7182d21 100644
--- a/bin/create.bat
+++ b/bin/create.bat
@@ -1 +1 @@
-cscript create.js
\ No newline at end of file
+cscript bin\create.js %*
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/7eb3e5d1/bin/create.js
----------------------------------------------------------------------
diff --git a/bin/create.js b/bin/create.js
index 24e7032..96e61ec 100644
--- a/bin/create.js
+++ b/bin/create.js
@@ -25,8 +25,9 @@
  */
 
 function read(filename) {
+    WScript.Echo('Reading in ' + filename);
     var fso=WScript.CreateObject("Scripting.FileSystemObject");
-    var f=fso.OpenTextFile(filename, 1, true);
+    var f=fso.OpenTextFile(filename, 1);
     var s=f.ReadAll();
     f.Close();
     return s;
@@ -40,8 +41,24 @@ function write(filename, contents) {
 function replaceInFile(filename, regexp, replacement) {
     write(filename, read(filename).replace(regexp, replacement));
 }
-function exec(s) {
+function exec(s, output) {
+    WScript.Echo('Executing ' + s);
     var o=shell.Exec(s);
+    while (o.Status == 0) {
+        WScript.Sleep(100);
+    }
+    WScript.Echo("Command exited with code " + o.Status);
+}
+
+function fork(s) {
+    WScript.Echo('Executing ' + s);
+    var o=shell.Exec(s);
+    while (o.Status != 1) {
+        WScript.Sleep(100);
+    }
+    WScript.Echo(o.StdOut.ReadAll());
+    WScript.Echo(o.StdErr.ReadAll());
+    WScript.Echo("Command exited with code " + o.Status);
 }
 
 var args = WScript.Arguments, PROJECT_PATH="example", 
@@ -61,6 +78,14 @@ var MANIFEST_PATH=PROJECT_PATH+'\\AndroidManifest.xml';
 var TARGET=shell.Exec('android.bat list targets').StdOut.ReadAll().match(/id:\s([0-9]).*/)[1];
 var VERSION=read('VERSION').replace(/\r\n/,'').replace(/\n/,'');
 
+WScript.Echo("Project path: " + PROJECT_PATH);
+WScript.Echo("Package: " + PACKAGE);
+WScript.Echo("Activity: " + ACTIVITY);
+WScript.Echo("Package as path: " + PACKAGE_AS_PATH);
+WScript.Echo("Activity path: " + ACTIVITY_PATH);
+WScript.Echo("Manifest path: " + MANIFEST_PATH);
+WScript.Echo("Cordova version: " + VERSION);
+
 // clobber any existing example
 
 /*
@@ -84,24 +109,26 @@ exec('ant.bat -f framework\\build.xml jar');
 // copy in the project template
 exec('cmd /c xcopy bin\\templates\\project '+PROJECT_PATH+' /S /Y');
 
+// copy example www assets
+exec('cmd /c xcopy ' + PROJECT_PATH + '\\cordova\\assets ' + PROJECT_PATH + ' /S /Y');
+
 // copy in cordova.js
-exec('cmd /c copy framework\\assets\\www\\cordova-'+VERSION+'.js '+PROJECT_PATH+'\\assets\\www\\cordova-'+VERSION+'.js /Y');
+exec('cmd /c copy framework\\assets\\js\\cordova.android.js '+PROJECT_PATH+'\\.cordova\\android\\cordova-'+VERSION+'.js /Y');
 
 // copy in cordova.jar
-exec('cmd /c copy framework\\cordova-'+VERSION+'.jar '+PROJECT_PATH+'\\libs\\cordova-'+VERSION+'.jar /Y');
-
-// copy in default activity
-exec('cmd /c copy bin\\templates\\Activity.java '+ACTIVITY_PATH+' /Y');
-
-// interpolate the activity name and package
-replaceInFile(ACTIVITY_PATH, /__ACTIVITY__/, ACTIVITY);
-replaceInFile(ACTIVITY_PATH, /__ID__/, PACKAGE);
-
-replaceInFile(MANIFEST_PATH, /__ACTIVITY__/, ACTIVITY);
-replaceInFile(MANIFEST_PATH, /__PACKAGE__/, PACKAGE);
-
-/*
-# leave the id for launching
-touch $PROJECT_PATH/package-activity
-echo $PACKAGE/$PACKAGE.$ACTIVITY >  $PROJECT_PATH/package-activity 
-*/
+exec('cmd /c copy framework\\cordova-'+VERSION+'.jar '+PROJECT_PATH+'\\.cordova\\android\\cordova-'+VERSION+'.jar /Y');
+
+// copy in xml
+exec('cmd /c copy framework\\res\\xml\\cordova.xml ' + PROJECT_PATH + '\\.cordova\\android\\cordova.xml /Y');
+exec('cmd /c copy framework\\res\\xml\\plugins.xml ' + PROJECT_PATH + '\\.cordova\\android\\plugins.xml /Y');
+
+// write out config file
+write(PROJECT_PATH + '\\.cordova\\config',
+  'VERSION=' + VERSION + '\r\n' +
+  'PROJECT_PATH=' + PROJECT_PATH + '\r\n' +
+  'PACKAGE=' + PACKAGE + '\r\n' +
+  'ACTIVITY=' + ACTIVITY + '\r\n' +
+  'TARGET=' + TARGET);
+
+// run project-specific create process
+fork('cscript.exe ' + PROJECT_PATH + '\\cordova\\create.js');
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/7eb3e5d1/bin/templates/project/cordova/create.bat
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/create.bat b/bin/templates/project/cordova/create.bat
new file mode 100644
index 0000000..cfde65a
--- /dev/null
+++ b/bin/templates/project/cordova/create.bat
@@ -0,0 +1,2 @@
+echo "BALLS"
+cscript cordova\create.js
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/7eb3e5d1/bin/templates/project/cordova/create.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/create.js b/bin/templates/project/cordova/create.js
new file mode 100644
index 0000000..b87f0a1
--- /dev/null
+++ b/bin/templates/project/cordova/create.js
@@ -0,0 +1,70 @@
+var shell=WScript.CreateObject("WScript.Shell");
+
+function exec(s, output) {
+    WScript.Echo('Executing ' + s);
+    var o=shell.Exec(s);
+    while (o.Status == 0) {
+        WScript.Sleep(100);
+    }
+    WScript.Echo("Command exited with code " + o.Status);
+}
+function read(filename) {
+    WScript.Echo('Reading in ' + filename);
+    var fso=WScript.CreateObject("Scripting.FileSystemObject");
+    var f=fso.OpenTextFile(filename, 1);
+    var s=f.ReadAll();
+    f.Close();
+    return s;
+}
+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));
+}
+
+// working dir
+var PWD = WScript.ScriptFullName.split('\\cordova\\create.js').join('');
+
+var fso=WScript.CreateObject("Scripting.FileSystemObject");
+var f=fso.OpenTextFile(PWD + '\\.cordova\\config', 1);
+while (!f.AtEndOfStream) {
+  var prop = f.ReadLine().split('=');
+  var line = 'var ' + prop[0] + '=' + "'" + prop[1] + "';";
+  eval(line); // hacky shit to load config but whatevs
+}
+
+var PACKAGE_AS_PATH=PACKAGE.replace(/\./g, '\\');
+var ACTIVITY_PATH=PWD+'\\src\\'+PACKAGE_AS_PATH+'\\'+ACTIVITY+'.java';
+var MANIFEST_PATH=PWD+'\\AndroidManifest.xml';
+
+exec('android.bat create project --target ' + TARGET + ' --path ' + PWD + ' --package ' + PACKAGE + ' --activity ' + ACTIVITY);
+
+// copy in activity and other android assets
+exec('cmd /c xcopy ' + PWD + '\\cordova\\templates\project\* ' + PWD +' /Y /S');
+
+// copy in cordova.js
+exec('cmd /c copy ' + PWD + '\\.cordova\\android\\cordova-' + VERSION + '.js ' + PWD + '\\assets\\www /Y');
+
+// copy in cordova.jar
+exec('cmd /c copy ' + PWD + '\\.cordova\\android\\cordova-' + VERSION + '.jar ' + PWD + '\\libs /Y');
+
+// copy in res/xml
+exec('cmd /c md ' + PWD + '\\res\\xml');
+exec('cmd /c copy ' + PWD + '\\.cordova\\android\\cordova.xml ' + PWD + '\\res\\xml /Y');
+exec('cmd /c copy ' + PWD + '\\.cordova\\android\\plugins.xml ' + PWD + '\\res\\xml /Y');
+
+// copy in default activity
+exec('cmd /c copy ' + PWD + '\\cordova\\templates\\Activity.java ' + ACTIVITY_PATH + ' /Y');
+
+// interpolate the activity name and package
+replaceInFile(ACTIVITY_PATH, /__ACTIVITY__/, ACTIVITY);
+replaceInFile(ACTIVITY_PATH, /__ID__/, PACKAGE);
+
+replaceInFile(MANIFEST_PATH, /__ACTIVITY__/, ACTIVITY);
+replaceInFile(MANIFEST_PATH, /__PACKAGE__/, PACKAGE);
+
+WScript.Echo('DONE!');
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/7eb3e5d1/bin/templates/project/cordova/debug.bat
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/debug.bat b/bin/templates/project/cordova/debug.bat
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/7eb3e5d1/bin/templates/project/cordova/emulate.bat
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/emulate.bat b/bin/templates/project/cordova/emulate.bat
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/7eb3e5d1/bin/templates/project/cordova/log.bat
----------------------------------------------------------------------
diff --git a/bin/templates/project/cordova/log.bat b/bin/templates/project/cordova/log.bat
new file mode 100644
index 0000000..e69de29