CB-10138 Adds missing plugin metadata to plugin_list module. This closes #254

This commit is contained in:
Vladimir Kotikov 2016-01-27 15:39:11 +03:00
parent 7669378c6e
commit e08d0671ab

View File

@ -431,6 +431,11 @@ Api.prototype._addModulesInfo = function(plugin, targetDir) {
});
this._platformJson.root.modules = installedModules.concat(modulesToInstall);
if (!this._platformJson.root.plugin_metadata) {
this._platformJson.root.plugin_metadata = {};
}
this._platformJson.root.plugin_metadata[plugin.id] = plugin.version;
this._writePluginModules(targetDir);
this._platformJson.save();
};
@ -457,6 +462,10 @@ Api.prototype._removeModulesInfo = function(plugin, targetDir) {
});
this._platformJson.root.modules = updatedModules;
if (this._platformJson.root.plugin_metadata) {
delete this._platformJson.root.plugin_metadata[plugin.id];
}
this._writePluginModules(targetDir);
this._platformJson.save();
};
@ -470,20 +479,13 @@ Api.prototype._removeModulesInfo = function(plugin, targetDir) {
* directories.
*/
Api.prototype._writePluginModules = function (targetDir) {
var self = this;
// Write out moduleObjects as JSON wrapped in a cordova module to cordova_plugins.js
var final_contents = 'cordova.define(\'cordova/plugin_list\', function(require, exports, module) {\n';
final_contents += 'module.exports = ' + JSON.stringify(this._platformJson.root.modules, null, ' ') + ';\n';
final_contents += 'module.exports.metadata = \n';
final_contents += '// TOP OF METADATA\n';
var pluginMetadata = Object.keys(this._platformJson.root.installed_plugins)
.reduce(function (metadata, plugin) {
metadata[plugin] = self._platformJson.root.installed_plugins[plugin].version;
return metadata;
}, {});
final_contents += JSON.stringify(pluginMetadata, null, 4) + '\n';
final_contents += JSON.stringify(this._platformJson.root.plugin_metadata, null, 4) + ';\n';
final_contents += '// BOTTOM OF METADATA\n';
final_contents += '});'; // Close cordova.define.