CB-11205 Respect saved variables when installing plugin This closes #471
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/acb7b0a0 Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/acb7b0a0 Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/acb7b0a0 Branch: refs/heads/common-1.4.x Commit: acb7b0a0e68499f589cf585830bfb6461d0e9f39 Parents: 29382ca Author: Nikita Matrosov <nikita.matro...@rp.ru> Authored: Fri Jul 29 14:47:44 2016 +0300 Committer: Vladimir Kotikov <v-vlk...@microsoft.com> Committed: Fri Jul 29 17:06:55 2016 +0300 ---------------------------------------------------------------------- cordova-lib/spec-cordova/save.spec.js | 27 +++++++++++++++++++++++++++ cordova-lib/src/cordova/plugin.js | 6 ++++++ 2 files changed, 33 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/acb7b0a0/cordova-lib/spec-cordova/save.spec.js ---------------------------------------------------------------------- diff --git a/cordova-lib/spec-cordova/save.spec.js b/cordova-lib/spec-cordova/save.spec.js index e2be5a5..b5ece83 100644 --- a/cordova-lib/spec-cordova/save.spec.js +++ b/cordova-lib/spec-cordova/save.spec.js @@ -412,6 +412,33 @@ describe('(save flag)', function () { }); }, TIMEOUT); + it('spec.14.1 should restore plugin with variables', function (done) { + platform('add', platformLocalPathNewer) + .then(function () { + return cordova.raw.plugin('add', variablePluginUrl, { + 'save': true, + 'cli_variables': { + 'APP_ID':'123456789', + 'APP_NAME':'myApplication' + } + }); + }).then(function () { + expect(helpers.getPluginVariable(appPath, variablePluginName, 'APP_ID')).toBe('123456789'); + expect(helpers.getPluginVariable(appPath, variablePluginName, 'APP_NAME')).toBe('myApplication'); + return cordova.raw.plugin('rm', variablePluginName); + }).then(function() { + expect(path.join(appPath, 'plugins', variablePluginName)).not.toExist(); + return cordova.raw.plugin('add', variablePluginName); + }).then(function() { + expect(path.join(appPath, 'plugins', variablePluginName)).toExist(); + done(); + }).catch(function (err) { + console.log(err.message); + expect(true).toBe(false); + done(); + }); + }, TIMEOUT); + it('spec.15 save git url as spec', function (done) { platform('add', platformLocalPathNewer) .then(function () { http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/acb7b0a0/cordova-lib/src/cordova/plugin.js ---------------------------------------------------------------------- diff --git a/cordova-lib/src/cordova/plugin.js b/cordova-lib/src/cordova/plugin.js index e8d6acb..d803425 100644 --- a/cordova-lib/src/cordova/plugin.js +++ b/cordova-lib/src/cordova/plugin.js @@ -155,6 +155,12 @@ module.exports = function plugin(command, targets, opts) { .then(function(pluginInfo) { // Validate top-level required variables var pluginVariables = pluginInfo.getPreferences(); + opts.cli_variables = opts.cli_variables || {}; + var pluginEntry = cfg.getPlugin(pluginInfo.id); + var pluginEntryVariables = pluginEntry ? pluginEntry.variables : {}; + Object.keys(pluginVariables).forEach(function(varName) { + opts.cli_variables[varName] = opts.cli_variables[varName] || pluginEntryVariables[varName]; + }); var missingVariables = Object.keys(pluginVariables) .filter(function (variableName) { // discard variables with default value --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org