cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [65/91] [abbrv] git commit: Adding in bb10 support
Date Mon, 04 Mar 2013 19:32:51 GMT
Adding in bb10 support


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

Branch: refs/heads/master
Commit: 682895e792098900a968c6eb7a8855929dc4a462
Parents: 52892fd
Author: Tim Kim <timk@adobe.com>
Authored: Wed Jan 16 13:07:19 2013 -0800
Committer: Tim Kim <timk@adobe.com>
Committed: Wed Jan 16 15:22:11 2013 -0800

----------------------------------------------------------------------
 platforms/bb10.js |  146 ++++++++++++++++++++++++++++++++++++++++++++++++
 plugman.js        |    3 +-
 2 files changed, 148 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/682895e7/platforms/bb10.js
----------------------------------------------------------------------
diff --git a/platforms/bb10.js b/platforms/bb10.js
new file mode 100644
index 0000000..012df40
--- /dev/null
+++ b/platforms/bb10.js
@@ -0,0 +1,146 @@
+var fs = require('fs')  // use existsSync in 0.6.x
+   , path = require('path')
+   , shell = require('shelljs')
+   , et = require('elementtree')
+   , getConfigChanges = require('../util/config-changes')
+
+   , assetsDir = 'www'  // relative path to project's web assets
+   , sourceDir = 'src'
+   , xml_helpers = require(path.join(__dirname, '..', 'util', 'xml-helpers'));
+
+
+exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et) {
+    var plugin_id = plugin_et._root.attrib['id']
+      , version = plugin_et._root.attrib['version']
+      , external_hosts = []
+      , i = 0
+      // look for assets in the plugin 
+      , assets = plugin_et.findall('./asset')
+      , platformTag = plugin_et.find('./platform[@name="bb10"]')
+      , sourceFiles = platformTag.findall('./source-file')
+      , libFiles = platformTag.findall('./library-file')
+      , configChanges = getConfigChanges(platformTag);
+
+    // find which config-files we're interested in
+    Object.keys(configChanges).forEach(function (configFile) {
+        if (!fs.existsSync(path.resolve(project_dir, configFile))) {
+            delete configChanges[configFile];
+        }
+    });
+
+    // move asset files
+    assets.forEach(function (asset) {
+        var srcPath = path.resolve(
+                        plugin_dir,
+                        asset.attrib['src']);
+
+        var targetPath = path.resolve(
+                            project_dir,
+                            assetsDir,
+                            asset.attrib['target']);
+
+        var stats = fs.statSync(srcPath);
+        if (action == 'install') {
+            if(stats.isDirectory()) {
+                shell.mkdir('-p', targetPath);
+                shell.cp('-R', srcPath, path.join(project_dir, assetsDir));
+            } else {
+                shell.cp(srcPath, targetPath);
+            }
+        } else {
+            shell.rm('-rf', targetPath);
+        }
+    });
+
+    // move source files
+    sourceFiles.forEach(function (sourceFile) {
+        var srcDir = path.resolve(project_dir,
+                                sourceFile.attrib['target-dir'])
+          , destFile = path.resolve(srcDir,
+                                path.basename(sourceFile.attrib['src']));
+
+        if (action == 'install') {
+            shell.mkdir('-p', srcDir);
+            var srcFile = srcPath(plugin_dir, sourceFile.attrib['src']);
+            shell.cp(srcFile, destFile);
+        } else {
+            fs.unlinkSync(destFile);
+            // check if directory is empty
+            var curDir = srcDir;
+            while(curDir !== project_dir + '/src') {
+                if(fs.readdirSync(curDir).length == 0) {
+                    fs.rmdirSync(curDir);
+                    curDir = path.resolve(curDir + '/..');
+                } else {
+                    // directory not empty...do nothing
+                    break;
+                }
+            }
+        }
+    })
+
+    // move library files
+    libFiles.forEach(function (libFile) {
+        var libDir = path.resolve(project_dir,
+                                libFile.attrib['target-dir'])
+
+        if (action == 'install') {
+            shell.mkdir('-p', libDir);
+            var src = path.resolve(plugin_dir, 'src/BlackBerry10',
+                                        libFile.attrib['src']),
+                dest = path.resolve(libDir,
+                                path.basename(libFile.attrib['src']));
+            
+            shell.cp(src, dest);
+        } else {
+            var destFile = path.resolve(libDir,
+                            path.basename(libFile.attrib['src']));
+
+            fs.unlinkSync(destFile);
+            // check if directory is empty
+            var files = fs.readdirSync(libDir);
+            if(files.length == 0) {
+                shell.rm('-rf', libDir);
+            }
+        }
+    })
+
+
+    // edit configuration files
+    Object.keys(configChanges).forEach(function (filename) {
+        var filepath = path.resolve(project_dir, filename),
+            xmlDoc = xml_helpers.parseElementtreeSync(filepath),
+            output;
+
+        configChanges[filename].forEach(function (configNode) {
+            var selector = configNode.attrib["parent"],
+                children = configNode.findall('*');
+
+            if( action == 'install') {
+                if (!xml_helpers.graftXML(xmlDoc, children, selector)) {
+                    throw new Error('failed to add children to ' + filename);
+                }
+            } else {
+                if (!xml_helpers.pruneXML(xmlDoc, children, selector)) {
+                    throw new Error('failed to remove children from' + filename);
+                }
+            }
+        });
+
+        output = xmlDoc.write({indent: 4});
+        output = output.replace(/\$PACKAGE_NAME/g, PACKAGE_NAME);
+        fs.writeFileSync(filepath, output);
+    });
+}
+
+
+function srcPath(pluginPath, filename) {
+    var prefix = /^src\/BlackBerry10/;
+
+    if (prefix.test(filename)) {
+        return path.resolve(pluginPath, filename);
+    } else {
+        return path.resolve(pluginPath, 'src/BlackBerry10', filename);
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/682895e7/plugman.js
----------------------------------------------------------------------
diff --git a/plugman.js b/plugman.js
index 2d44077..652396c 100755
--- a/plugman.js
+++ b/plugman.js
@@ -11,10 +11,11 @@ var fs = require('fs')
   , platform_modules = {
         'android': require('./platforms/android'),
         'ios': require('./platforms/ios'),
+        //'bb10': require('./platforms/bb10'),
         'www': require('./platforms/www')
     };
 
-var known_opts = { 'platform' : [ 'ios', 'android', 'www' ]
+var known_opts = { 'platform' : [ 'ios', 'android', 'bb10' ,'www' ]
             , 'project' : path
             , 'plugin' : [String, path, url]
             , 'remove' : Boolean


Mime
View raw message