cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hermw...@apache.org
Subject [2/3] git commit: Merge pull request #4 from rodms10/autoPermission
Date Fri, 25 Apr 2014 20:45:37 GMT
Merge pull request #4 from rodms10/autoPermission

CB-5416 - Need to auto generate manifest.webapp with appropriate plugin permissions


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

Branch: refs/heads/master
Commit: b4febd7c102fcfcb30774d894bab824de9e0bfd3
Parents: 7012448
Author: Piotr Zalewa <piotr@zalewa.info>
Authored: Thu Apr 17 20:19:37 2014 +0200
Committer: hermwong <herm.wong@gmail.com>
Committed: Fri Apr 25 13:45:10 2014 -0700

----------------------------------------------------------------------
 src/metadata/firefoxos_parser.js | 85 ++++++++++++++++++-----------------
 1 file changed, 45 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/b4febd7c/src/metadata/firefoxos_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/firefoxos_parser.js b/src/metadata/firefoxos_parser.js
index 8ba44a3..1d41916 100644
--- a/src/metadata/firefoxos_parser.js
+++ b/src/metadata/firefoxos_parser.js
@@ -22,8 +22,7 @@ var fs = require('fs'),
     util = require('../util'),
     events = require('../events'),
     Q = require('q'),
-    ConfigParser = require('../ConfigParser'),
-    config = require('../config');
+    ConfigParser = require('../ConfigParser');
 
 module.exports = function firefoxos_parser(project) {
     this.path = project;
@@ -36,15 +35,8 @@ module.exports.check_requirements = function(project_root) {
 
 module.exports.prototype = {
     // Returns a promise.
-    update_from_config: function(config) {
-        if (!(config instanceof ConfigParser)) {
-            return Q.reject(new Error('update_from_config requires a ConfigParser object'));
-        }
-
-        var name = config.name();
-        var pkg = config.packageName();
-        var version = config.version();
-
+    update_from_config: function() {
+        var config = new ConfigParser(this.config_xml());
         var manifestPath = path.join(this.www_dir(), 'manifest.webapp');
         var manifest;
 
@@ -58,30 +50,43 @@ module.exports.prototype = {
             };
         }
 
-        // Update icons
-        var icons = config.getIcons('firefoxos');
-        var platformRoot = this.path;
-        var appRoot = util.isCordova(platformRoot);
-
-        // http://www.mozilla.org/en-US/styleguide/products/firefox-os/icons/
-        var platformIcons = [
-            {dest: "www/img/logo.png", width: 60, height: 60}
-        ];
-
-        platformIcons.forEach(function (item) {
-            icon = icons.getIconBySize(item.width, item.height) || icons.getDefault();
-            if (icon){
-                var src = path.join(appRoot, icon.src),
-                    dest = path.join(platformRoot, item.dest);
-                events.emit('verbose', 'Copying icon from ' + src + ' to ' + dest);
-                shell.cp('-f', src, dest);
-            }
-        });
-
-        manifest.version = version;
-        manifest.name = name;
-        manifest.pkgName = pkg;
-        fs.writeFileSync(manifestPath, JSON.stringify(manifest));
+        manifest.version = config.version();
+        manifest.name = config.name();
+        manifest.pkgName = config.packageName();
+        manifest.description = config.description();
+        manifest.developer = {
+            name: config.author()
+        };
+
+        var authorNode = config.doc.find('author');
+        var authorUrl = authorNode.attrib['href'];
+
+        if (authorUrl) {
+            manifest.developer.url = authorUrl;
+        }
+
+        var permissionNodes = config.doc.findall('permission');
+
+        if (permissionNodes.length) {
+            manifest.permissions = manifest.permissions || {};
+
+            permissionNodes.forEach(function(node) {
+                var permissionName = node.attrib['name'];
+
+                // Don't change if it was already created
+                if (!manifest.permissions[permissionName]) {
+                    manifest.permissions[permissionName] = {
+                        description: node.attrib['description']
+                    };
+
+                    if (node.attrib['access']) {
+                        manifest.permissions[permissionName].access = node.attrib['access'];
+                    }
+                }
+            });
+        }
+
+        fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 4));
 
         return Q();
     },
@@ -126,10 +131,10 @@ module.exports.prototype = {
 
     // Returns a promise.
     update_project: function(cfg) {
-        return this.update_from_config(cfg)
-        .then(function(){
-            this.update_overrides();
-            util.deleteSvnFolders(this.www_dir());
-        }.bind(this));
+        return this.update_from_config()
+            .then(function(){
+                this.update_overrides();
+                util.deleteSvnFolders(this.www_dir());
+            }.bind(this));
     }
 };


Mime
View raw message