incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [27/78] [abbrv] git commit: split out code into smaller modules, platform command now works. tweaked help txt.
Date Fri, 27 Jul 2012 00:29:15 GMT
split out code into smaller modules, platform command now works. tweaked help txt.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/794276ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/794276ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/794276ad

Branch: refs/heads/cordova-client
Commit: 794276adf94a4937f555d1a5c506d876b54ed632
Parents: 244fae1
Author: Fil Maj <maj.fil@gmail.com>
Authored: Tue Jul 17 11:41:51 2012 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Tue Jul 17 11:41:51 2012 -0700

----------------------------------------------------------------------
 .gitignore                 |   17 +------
 cordova.js                 |   34 ++++++++-------
 doc/help.txt               |   14 +++++--
 package.json               |    3 +-
 spec/config_parser.spec.js |   86 +++++++++++++++++++++++++++++++++++++++
 src/config_parser.js       |   36 ++++++++++++++++
 src/platforms.js           |    1 +
 templates/www/config.xml   |   51 ++++++++++++++++++++---
 8 files changed, 200 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/794276ad/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 7dccd97..4e7d8a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,15 +1,4 @@
-lib-cov
-*.seed
-*.log
-*.csv
-*.dat
-*.out
-*.pid
-*.gz
-
-pids
-logs
-results
-
 node_modules
-npm-debug.log
\ No newline at end of file
+npm-debug.log
+temp
+lib/**

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/794276ad/cordova.js
----------------------------------------------------------------------
diff --git a/cordova.js b/cordova.js
index 74ae6ec..03050a1 100755
--- a/cordova.js
+++ b/cordova.js
@@ -1,11 +1,11 @@
-var fs        = require('fs')
-,   path      = require('path')
-,   util      = require('util')
-,   exec      = require('child_process').exec
-,   platforms = ['ios', 'android']
-,   dist      = process.env.CORDOVA_HOME != undefined ? process.env.CORDOVA_HOME : path.join(__dirname,
'lib', 'cordova-1.9.0')
-,   colors    = require('colors')
-,   wrench    = require('wrench')
+var fs            = require('fs')
+,   path          = require('path')
+,   util          = require('util')
+,   exec          = require('child_process').exec
+,   dist          = process.env.CORDOVA_HOME != undefined ? process.env.CORDOVA_HOME : path.join(__dirname,
'lib', 'cordova-1.9.0')
+,   colors        = require('colors')
+,   wrench        = require('wrench')
+,   config_parser = require('./src/config_parser')
 
 // Runs up the directory chain looking for a .cordova directory.
 // IF it is found we are in a Cordova project.
@@ -25,7 +25,6 @@ function isCordova(dir) {
 }
 
 module.exports = {
-
     help: function help () {
         var raw = fs.readFileSync(path.join(__dirname, 'doc', 'help.txt')).toString('utf8').split("\n")
         console.log(raw.map(function(line) {
@@ -101,29 +100,32 @@ module.exports = {
     ,
     platform: function platform(command, target) {
         var projectRoot = isCordova(process.cwd());
+
         if (!projectRoot) {
             console.error('Current working directory is not a Cordova-based project.');
             return;
         }
         if (arguments.length === 0) command = 'ls';
 
+        var xml = path.join(projectRoot, 'www', 'config.xml');
+        var cfg = new config_parser(xml);
+
         switch(command) {
             case 'ls':
-                var contents = fs.readdirSync(path.join(projectRoot, 'platforms'));
-                if (contents.length) {
-                    contents.map(function(p) {
+                var platforms = cfg.ls_platforms();
+                if (platforms.length) {
+                    platforms.map(function(p) {
                         console.log(p);
                     });
-                } else {
-                    console.log('No platforms. Use `cordova platform add <platform>`.');
-                }
+                } else console.log('No platforms added. Use `cordova platforms add <platform>`.');
                 break;
             case 'add':
                 break;
             case 'remove':
+
                 break;
             default:
-                console.error('Unrecognized command "' + command '". Use either `add`, `remove`,
or `ls`.');
+                console.error('Unrecognized command "' + command + '". Use either `add`,
`remove`, or `ls`.');
                 break;
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/794276ad/doc/help.txt
----------------------------------------------------------------------
diff --git a/doc/help.txt b/doc/help.txt
index 73e63ee..4a7ea82 100644
--- a/doc/help.txt
+++ b/doc/help.txt
@@ -1,18 +1,24 @@
 
 Synopsis
     
-    cordova cmd [options]
+    cordova command [options]
 
-Available commands
+Global Commands
 
-    create [platform package name] .... creates a cordova project
+    create ............................ creates a cordova project
+
+Project-Level Commands
+
+    platform [add|remove|ls [name]] ... adds or removes a platform, or lists all currently-added
platforms
+    plugin [add|remove|ls [path]] ..... adds or removes a plugin (from the specified path),
or lists all currently-added plugins
     build ............................. builds a cordova project
     emulate ........................... starts emulator for cordova project
     docs .............................. serves docs at http://localhost:2222
 
 Example usage
 
-    $ cordova create ios com.foobar Baz
+    $ cordova create Baz
     $ cd Baz
+    $ cordova platform add android
     $ codova build && cordova emulate 
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/794276ad/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index eb95ca5..5e234bf 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,8 @@
   ],
   "dependencies": {
     "colors":">=0.6.0",
-    "wrench":""
+    "wrench":"",
+    "elementtree":""
   },
   "devDependencies": {
     "jasmine-node":">=1.0.0"

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/794276ad/spec/config_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/config_parser.spec.js b/spec/config_parser.spec.js
new file mode 100644
index 0000000..ba39e0a
--- /dev/null
+++ b/spec/config_parser.spec.js
@@ -0,0 +1,86 @@
+var cordova = require('../cordova'),
+    wrench = require('wrench'),
+    mkdirp = wrench.mkdirSyncRecursive,
+    path = require('path'),
+    rmrf = wrench.rmdirSyncRecursive,
+    fs = require('fs'),
+    config_parser = require('../src/config_parser'),
+    tempDir = path.join(__dirname, '..', 'temp'),
+    et = require('elementtree'),
+    xml = path.join(tempDir, 'www', 'config.xml');
+
+describe('config parser', function () {
+    beforeEach(function() {
+        // Make a temp directory
+        try { rmrf(tempDir); } catch(e) {}
+        mkdirp(tempDir);
+        cordova.create(tempDir);
+    });
+
+    it('should create an instance based on an xml file', function() {
+        var cfg;
+        expect(function () {
+            cfg = new config_parser(xml);
+        }).not.toThrow();
+        expect(cfg).toBeDefined();
+        expect(cfg.doc).toBeDefined();
+    });
+
+    describe('platforms', function() {
+        describe('ls command', function() {
+            it('should return an empty array if there are no platforms specified in the document',
function() {
+                var cfg = new config_parser(xml);
+
+                expect(cfg.ls_platforms().length).toBe(0);
+            });
+            it('should return a populated array if there are platforms specified in the document',
function() {
+                var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
+                var p = new et.Element('platform');
+                p.attrib['name'] = 'android';
+                doc.find('platforms').append(p);
+                fs.writeFileSync(xml, doc.write(), 'utf-8');
+
+                var cfg = new config_parser(xml);
+                expect(cfg.ls_platforms().length).toBe(1);
+                expect(cfg.ls_platforms()[0]).toEqual('android');
+            });
+        });
+
+        describe('add command', function() {
+            it('should add a platform element to the platforms element', function() {
+                var cfg = new config_parser(xml);
+                cfg.add_platform('android');
+                
+                var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
+                expect(doc.find('platforms').getchildren()[0].attrib['name']).toEqual('android');
+            });
+            it('should ignore existing platforms', function() {
+                var cfg = new config_parser(xml);
+                cfg.add_platform('android');
+                cfg.add_platform('android');
+                
+                var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
+                expect(doc.find('platforms').getchildren().length).toEqual(1);
+            });
+            it('should ignore garbage platforms', function() {
+                var cfg = new config_parser(xml);
+                cfg.add_platform('bat country');
+                
+                var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
+                expect(doc.find('platforms').getchildren().length).toEqual(0);
+            });
+        });
+
+        describe('remove command', function() {
+            it('should remove a platform element from the platforms element', function()
{
+                var cfg = new config_parser(xml);
+                cfg.add_platform('ios');
+
+                cfg.remove_platform('ios');
+
+                var doc = new et.ElementTree(et.XML(fs.readFileSync(xml, 'utf-8')));
+                expect(doc.find('platforms').getchildren().length).toEqual(0);
+            });
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/794276ad/src/config_parser.js
----------------------------------------------------------------------
diff --git a/src/config_parser.js b/src/config_parser.js
new file mode 100644
index 0000000..bfef967
--- /dev/null
+++ b/src/config_parser.js
@@ -0,0 +1,36 @@
+var et = require('elementtree'),
+    platforms = require('./platforms'),
+    fs = require('fs');
+
+function config_parser(xmlPath) {
+    this.path = xmlPath;
+    this.doc = new et.ElementTree(et.XML(fs.readFileSync(xmlPath, 'utf-8')));
+}
+
+config_parser.prototype = {
+    ls_platforms:function() {
+        return this.doc.find('platforms').getchildren().map(function(p) {
+            return p.attrib['name'];
+        });
+    },
+    add_platform:function(platform) {
+        if ((platforms.indexOf(platform) == -1) || this.doc.find('platforms/platform[@name="'
+ platform + '"]')) return;
+        else {
+            var p = new et.Element('platform');
+            p.attrib['name'] = platform;
+            this.doc.find('platforms').append(p);
+            fs.writeFileSync(this.path, this.doc.write(), 'utf-8');
+        }
+    },
+    remove_platform:function(platform) {
+        if ((platforms.indexOf(platform) == -1) || !(this.doc.find('platforms/platform[@name="'
+ platform + '"]'))) return;
+        else {
+            var psEl = this.doc.find('platforms');
+            var pEl = psEl.find('platform[@name="' + platform + '"]');
+            psEl.remove(null, pEl);
+            fs.writeFileSync(this.path, this.doc.write(), 'utf-8');
+        }
+    }
+};
+
+module.exports = config_parser;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/794276ad/src/platforms.js
----------------------------------------------------------------------
diff --git a/src/platforms.js b/src/platforms.js
new file mode 100644
index 0000000..c6c5601
--- /dev/null
+++ b/src/platforms.js
@@ -0,0 +1 @@
+module.exports = ['ios','android'];

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/794276ad/templates/www/config.xml
----------------------------------------------------------------------
diff --git a/templates/www/config.xml b/templates/www/config.xml
index 3847bfb..400c377 100644
--- a/templates/www/config.xml
+++ b/templates/www/config.xml
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<widget xmlns=     "http://www.w3.org/ns/widgets"
-        xmlns:gap= "http://phonegap.com/ns/1.0"
-        id=        "org.apache.cordova.sampleapp"
-        version=   "1.0.0">
+<widget xmlns="http://www.w3.org/ns/widgets"
+        xmlns:rim="http://www.blackberry.com/ns/widgets"
+        id="org.apache.cordova.sampleapp"
+        version="1.0.0">
 
   <name>Cordova Sample Application</name>
 
@@ -14,8 +14,45 @@
     Anonymous
   </author>
 
-  <gap:platforms>
-	</gap:platforms>
+  <platforms>
+  </platforms>
 
-  <icon src="blurry.png" />
+  <!-- Cordova API -->
+  <feature id="org.apache.cordova" required="true" version="1.0.0" />
+  <!-- BlackBerry-specific -->
+  <feature id="blackberry.system" required="true" version="1.0.0.0" />
+  <feature id="blackberry.find" required="true" version="1.0.0.0" />
+  <feature id="blackberry.identity" required="true" version="1.0.0.0" />
+  <feature id="blackberry.pim.Address" required="true" version="1.0.0.0" />
+  <feature id="blackberry.pim.Contact" required="true" version="1.0.0.0" />
+  <feature id="blackberry.io.file" required="true" version="1.0.0.0" />
+  <feature id="blackberry.utils" required="true" version="1.0.0.0" />
+  <feature id="blackberry.io.dir" required="true" version="1.0.0.0" />
+  <feature id="blackberry.app" required="true" version="1.0.0.0" />
+  <feature id="blackberry.app.event" required="true" version="1.0.0.0" />
+  <feature id="blackberry.system.event" required="true" version="1.0.0.0"/>
+  <feature id="blackberry.widgetcache" required="true" version="1.0.0.0"/>
+  <feature id="blackberry.media.camera" />
+  <feature id="blackberry.ui.dialog" />
+  <feature id="blackberry.media.microphone" required="true" version="1.0.0.0"/>
+  
+  <!-- Cordova API -->
+  <access subdomains="true" uri="file:///store/home" />
+  <access subdomains="true" uri="file:///SDCard" />
+  <!-- Expose access to all URIs, including the file and http protocols -->
+  <access subdomains="true" uri="*" />
+
+  <!-- potential icon stuff
+  <icon src="blurry.png" /> -->
+
+  <!-- Starting Page -->
+  <content src="index.html" />
+
+  <rim:permissions>
+    <rim:permit>use_camera</rim:permit>
+    <rim:permit>read_device_identifying_information</rim:permit>
+    <rim:permit>access_shared</rim:permit>
+    <rim:permit>read_geolocation</rim:permit>
+    <rim:permit>record_audio</rim:permit> 
+  </rim:permissions>
 </widget>


Mime
View raw message