You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/05/07 17:19:07 UTC
[30/30] git commit: Add leading slash to js-modules within
cordova_plugins.json
Add leading slash to js-modules within cordova_plugins.json
This fixes loading of modules from HTML files not in project root.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/ba8767ee
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/ba8767ee
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/ba8767ee
Branch: refs/heads/future
Commit: ba8767ee9b6af99bdba1922c08179e3dce40b3b5
Parents: a65d10e
Author: Hasan Ahmad <ha...@blackberry.com>
Authored: Thu Apr 25 14:56:22 2013 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Thu Apr 25 16:21:15 2013 -0400
----------------------------------------------------------------------
src/prepare.js | 42 +++++++++++++++++++++---------------------
1 files changed, 21 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ba8767ee/src/prepare.js
----------------------------------------------------------------------
diff --git a/src/prepare.js b/src/prepare.js
index 1d24726..1389e4f 100644
--- a/src/prepare.js
+++ b/src/prepare.js
@@ -50,48 +50,48 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir) {
var pluginDir = path.join(plugins_dir, plugin);
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);
-
+
});
-
+
// 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;
@@ -101,10 +101,10 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir) {
} 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) {
@@ -113,17 +113,17 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir) {
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),
+ 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') {
@@ -140,7 +140,7 @@ module.exports = function handlePrepare(project_dir, platform, plugins_dir) {
obj.runs = true;
}
});
-
+
// Add it to the list of module objects bound for cordova_plugins.json
moduleObjects.push(obj);
});