You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2015/03/16 16:49:02 UTC
cordova-lib git commit: CB-8521 Cleans up plugin metadata save method
Repository: cordova-lib
Updated Branches:
refs/heads/master 3e89cb8b4 -> 497a199fe
CB-8521 Cleans up plugin metadata save method
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/497a199f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/497a199f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/497a199f
Branch: refs/heads/master
Commit: 497a199fe54ebef207c5b80c627c3694d9cc177c
Parents: 3e89cb8
Author: Vladimir Kotikov <v-...@microsoft.com>
Authored: Mon Mar 16 18:48:08 2015 +0300
Committer: Vladimir Kotikov <v-...@microsoft.com>
Committed: Mon Mar 16 18:48:08 2015 +0300
----------------------------------------------------------------------
cordova-lib/src/cordova/plugin.js | 79 ++++++++++++++-------------
cordova-lib/src/plugman/util/metadata.js | 2 +-
2 files changed, 41 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/497a199f/cordova-lib/src/cordova/plugin.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/plugin.js b/cordova-lib/src/cordova/plugin.js
index 5346585..8bdeb6a 100644
--- a/cordova-lib/src/cordova/plugin.js
+++ b/cordova-lib/src/cordova/plugin.js
@@ -288,7 +288,7 @@ module.exports = function plugin(command, targets, opts) {
// Remove plugin from fetch.json
events.emit('verbose', 'Removing plugin ' + target + ' from fetch.json');
var pluginsDir = path.join(projectRoot, 'plugins');
- metadata.remove_plugin(pluginsDir, target);
+ metadata.remove_fetch_metadata(pluginsDir, target);
});
}, Q());
}).then(function() {
@@ -323,52 +323,53 @@ function save(projectRoot, opts){
cfg.removePlugin(plugin);
});
- // It might be the case that fetch.json file is not yet existent.
- // for example: when we have never ran the command 'cordova plugin add foo' on the project
- // in that case, there's nothing to do except bubble up the error
- function onFileNotFoundException(err){
+ // Then, save top-level plugins and their sources
+ var jsonFile = path.join(projectRoot, 'plugins', 'fetch.json');
+ var plugins;
+ try {
+ // It might be the case that fetch.json file is not yet existent.
+ // for example: when we have never ran the command 'cordova plugin add foo' on the project
+ // in that case, there's nothing to do except bubble up the error
+ plugins = JSON.parse(fs.readFileSync(jsonFile, 'utf-8'));
+ } catch (err) {
return Q.reject(err.message);
}
- // Then, save top-level plugins and their sources
- return Q().then(function(){
- var jsonFile = path.join(projectRoot, 'plugins', 'fetch.json');
- return JSON.parse(fs.readFileSync(jsonFile, 'utf-8'));
- }).fail(onFileNotFoundException).then(function(plugins){
- Object.keys(plugins).forEach(function(pluginName){
- var plugin = plugins[pluginName];
- var pluginSource = plugin.source;
-
- // If not a top-level plugin, skip it, don't save it to config.xml
- if(!plugin.is_top_level){
- return;
- }
+ Object.keys(plugins).forEach(function(pluginName){
+ var plugin = plugins[pluginName];
+ var pluginSource = plugin.source;
+
+ // If not a top-level plugin, skip it, don't save it to config.xml
+ if(!plugin.is_top_level){
+ return;
+ }
- var attribs = {name: pluginName};
+ var attribs = {name: pluginName};
- // Retrieve appropriate property: 'src' or 'version'
- var src = (function(){
- if(pluginSource.hasOwnProperty('url') || pluginSource.hasOwnProperty('path')){
- return { src: (pluginSource.url || pluginSource.path) };
+ // Retrieve appropriate property: 'src' or 'version'
+ var src = (function(){
+ if(pluginSource.hasOwnProperty('url') || pluginSource.hasOwnProperty('path')){
+ return { src: (pluginSource.url || pluginSource.path) };
+ }
+ if(pluginSource.hasOwnProperty('id')){
+ var parts = pluginSource.id.split('@');
+ var version = parts[1];
+ if(version){
+ return { version: version };
}
- if(pluginSource.hasOwnProperty('id')){
- var parts = pluginSource.id.split('@');
- var version = parts[1];
- if(version){
- return { version: version };
- }
- }
- // If there's an id, but no version
- // If there's no valid property('url', 'path', 'id')
- return {};
- }());
- _.extend(attribs, src);
- var variables = getPluginVariables(plugin.variables);
- cfg.addPlugin(attribs, variables);
- });
- cfg.write();
+ }
+ // If there's an id, but no version
+ // If there's no valid property('url', 'path', 'id')
+ return {};
+ }());
+ _.extend(attribs, src);
+ var variables = getPluginVariables(plugin.variables);
+ cfg.addPlugin(attribs, variables);
});
+ cfg.write();
+
+ return Q.resolve();
}
function getPluginVariables(variables){
http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/497a199f/cordova-lib/src/plugman/util/metadata.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/util/metadata.js b/cordova-lib/src/plugman/util/metadata.js
index 2707d13..33b0c2a 100644
--- a/cordova-lib/src/plugman/util/metadata.js
+++ b/cordova-lib/src/plugman/util/metadata.js
@@ -59,7 +59,7 @@ exports.save_fetch_metadata = function(pluginsDir, pluginId, data) {
fs.writeFileSync(fetchJsonPath, JSON.stringify(metadataJson, null, 4), 'utf-8');
};
-exports.remove_plugin = function(pluginsDir, pluginId){
+exports.remove_fetch_metadata = function(pluginsDir, pluginId){
var metadataJson = getJson(pluginsDir);
delete metadataJson[pluginId];
var fetchJsonPath = path.join(pluginsDir, 'fetch.json');
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org