Made sure to check for directory

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

Branch: refs/heads/future
Commit: b256b9fb43c9f899d7d7906f8a0b80ed10beab63
Parents: 570f922
Author: Tim Kim <[email protected]>
Authored: Thu Apr 4 15:09:36 2013 -0700
Committer: Tim Kim <[email protected]>
Committed: Tue Apr 9 14:01:02 2013 -0700

----------------------------------------------------------------------
 util/plugin_loader.js |  189 ++++++++++++++++++++++----------------------
 1 files changed, 96 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/b256b9fb/util/plugin_loader.js
----------------------------------------------------------------------
diff --git a/util/plugin_loader.js b/util/plugin_loader.js
index b14a640..5ea6f93 100644
--- a/util/plugin_loader.js
+++ b/util/plugin_loader.js
@@ -45,103 +45,106 @@ exports.handlePrepare = function(projectRoot, 
plugins_dir, wwwDir, platform) {
     // This array holds all the metadata for each module and ends up in 
cordova_plugins.json
     var moduleObjects = [];
 
+    //console.log('plugins_dir ' + fs.readdirSync(plugins_dir));
     plugins && plugins.forEach(function(plugin) {
         var pluginDir = path.join(plugins_dir, plugin);
-        var xml = new 
et.ElementTree(et.XML(fs.readFileSync(path.join(pluginDir, 'plugin.xml'), 
'utf-8')));
-
-        var plugin_id = xml.getroot().attrib.id;
-
-        // Copy all the <asset>s into the platform's www/
-        var assets = xml.findall('./asset');
-        assets && assets.forEach(function(asset) {
-            var target = asset.attrib.target;
-           
-            var lastSlash = target.lastIndexOf('/');
-            var dirname  = lastSlash < 0 ? ''     : target.substring(0, 
lastSlash);
-            var basename = lastSlash < 0 ? target : target.substring(lastSlash 
+ 1);
-
-            var targetDir = path.join(wwwDir, dirname);
-             
-            shell.mkdir('-p', targetDir);
-
-            var srcFile = path.join(pluginDir, asset.attrib.src);
-            var targetFile = path.join(targetDir, basename);
-
-            var cpOptions = '-f';
-            
-            if(fs.statSync(srcFile).isDirectory()){
-                shell.mkdir('-p',targetFile);
-                srcFile = srcFile+'/*';
-                cpOptions = '-Rf';
-            }
-
-            shell.cp(cpOptions, [srcFile], targetFile);
-            
-        });
-
-        // And then add the plugins dir to the platform's www.
-        var platformPluginsDir = path.join(wwwDir, 'plugins');
-        shell.mkdir('-p', platformPluginsDir);
-
-        var generalModules = xml.findall('./js-module');
-        var platformTag = xml.find(util.format('./platform[@name="%s"]', 
platform));
-
-        generalModules = generalModules || [];
-        var platformModules = platformTag ? platformTag.findall('./js-module') 
: [];
-        var allModules = generalModules.concat(platformModules);
-
-        allModules.forEach(function(module) {
-            // Copy the plugin's files into the www directory.
-            var dirname = module.attrib.src;
-            var lastSlash = dirname.lastIndexOf('/');
-            if (lastSlash >= 0) {
-                dirname = dirname.substring(0, lastSlash);
-            } else {
-                dirname = ''; // Just the file, no subdir.
-            }
-
-            var dir = path.join(platformPluginsDir, plugin_id, dirname);
-            shell.mkdir('-p', dir);
-
-            // Read in the file, prepend the cordova.define, and write it back 
out.
-            var moduleName = plugin_id + '.';
-            if (module.attrib.name) {
-                moduleName += module.attrib.name;
-            } else {
-                var result = module.attrib.src.match(/([^\/]+)\.js/);
-                moduleName += result[1];
-            }
-
-            var scriptContent = fs.readFileSync(path.join(pluginDir, 
module.attrib.src), 'utf-8');
-            scriptContent = 'cordova.define("' + moduleName + '", 
function(require, exports, module) {' + scriptContent + '});\n';
-            fs.writeFileSync(path.join(platformPluginsDir, plugin_id, 
module.attrib.src), scriptContent, 'utf-8');
-
-            // Prepare the object for cordova_plugins.json.
-            var obj = {
-                file: path.join('plugins', plugin_id, module.attrib.src),
-                id: moduleName
-            };
-
-            // Loop over the children of the js-module tag, collecting 
clobbers, merges and runs.
-            module.getchildren().forEach(function(child) {
-                if (child.tag.toLowerCase() == 'clobbers') {
-                    if (!obj.clobbers) {
-                        obj.clobbers = [];
-                    }
-                    obj.clobbers.push(child.attrib.target);
-                } else if (child.tag.toLowerCase() == 'merges') {
-                    if (!obj.merges) {
-                        obj.merges = [];
-                    }
-                    obj.merges.push(child.attrib.target);
-                } else if (child.tag.toLowerCase() == 'runs') {
-                    obj.runs = true;
+        if(fs.statSync(pluginDir).isDirectory()){
+            var xml = new 
et.ElementTree(et.XML(fs.readFileSync(path.join(pluginDir, 'plugin.xml'), 
'utf-8')));
+    
+            var plugin_id = xml.getroot().attrib.id;
+    
+            // Copy all the <asset>s into the platform's www/
+            var assets = xml.findall('./asset');
+            assets && assets.forEach(function(asset) {
+                var target = asset.attrib.target;
+               
+                var lastSlash = target.lastIndexOf('/');
+                var dirname  = lastSlash < 0 ? ''     : target.substring(0, 
lastSlash);
+                var basename = lastSlash < 0 ? target : 
target.substring(lastSlash + 1);
+    
+                var targetDir = path.join(wwwDir, dirname);
+                 
+                shell.mkdir('-p', targetDir);
+    
+                var srcFile = path.join(pluginDir, asset.attrib.src);
+                var targetFile = path.join(targetDir, basename);
+    
+                var cpOptions = '-f';
+                
+                if(fs.statSync(srcFile).isDirectory()){
+                    shell.mkdir('-p',targetFile);
+                    srcFile = srcFile+'/*';
+                    cpOptions = '-Rf';
                 }
+    
+                shell.cp(cpOptions, [srcFile], targetFile);
+                
             });
-
-            // Add it to the list of module objects bound for 
cordova_plugins.json
-            moduleObjects.push(obj);
-        });
+    
+            // And then add the plugins dir to the platform's www.
+            var platformPluginsDir = path.join(wwwDir, 'plugins');
+            shell.mkdir('-p', platformPluginsDir);
+    
+            var generalModules = xml.findall('./js-module');
+            var platformTag = xml.find(util.format('./platform[@name="%s"]', 
platform));
+    
+            generalModules = generalModules || [];
+            var platformModules = platformTag ? 
platformTag.findall('./js-module') : [];
+            var allModules = generalModules.concat(platformModules);
+    
+            allModules.forEach(function(module) {
+                // Copy the plugin's files into the www directory.
+                var dirname = module.attrib.src;
+                var lastSlash = dirname.lastIndexOf('/');
+                if (lastSlash >= 0) {
+                    dirname = dirname.substring(0, lastSlash);
+                } else {
+                    dirname = ''; // Just the file, no subdir.
+                }
+    
+                var dir = path.join(platformPluginsDir, plugin_id, dirname);
+                shell.mkdir('-p', dir);
+    
+                // Read in the file, prepend the cordova.define, and write it 
back out.
+                var moduleName = plugin_id + '.';
+                if (module.attrib.name) {
+                    moduleName += module.attrib.name;
+                } else {
+                    var result = module.attrib.src.match(/([^\/]+)\.js/);
+                    moduleName += result[1];
+                }
+    
+                var scriptContent = fs.readFileSync(path.join(pluginDir, 
module.attrib.src), 'utf-8');
+                scriptContent = 'cordova.define("' + moduleName + '", 
function(require, exports, module) {' + scriptContent + '});\n';
+                fs.writeFileSync(path.join(platformPluginsDir, plugin_id, 
module.attrib.src), scriptContent, 'utf-8');
+    
+                // Prepare the object for cordova_plugins.json.
+                var obj = {
+                    file: path.join('plugins', plugin_id, module.attrib.src),
+                    id: moduleName
+                };
+    
+                // Loop over the children of the js-module tag, collecting 
clobbers, merges and runs.
+                module.getchildren().forEach(function(child) {
+                    if (child.tag.toLowerCase() == 'clobbers') {
+                        if (!obj.clobbers) {
+                            obj.clobbers = [];
+                        }
+                        obj.clobbers.push(child.attrib.target);
+                    } else if (child.tag.toLowerCase() == 'merges') {
+                        if (!obj.merges) {
+                            obj.merges = [];
+                        }
+                        obj.merges.push(child.attrib.target);
+                    } else if (child.tag.toLowerCase() == 'runs') {
+                        obj.runs = true;
+                    }
+                });
+    
+                // Add it to the list of module objects bound for 
cordova_plugins.json
+                moduleObjects.push(obj);
+            });
+        }
     });
 
     // Write out moduleObjects as JSON to cordova_plugins.json

Reply via email to