diff --git a/lib/Api.js b/lib/Api.js index a7fced475..95f8dec3c 100644 --- a/lib/Api.js +++ b/lib/Api.js @@ -51,6 +51,19 @@ function getVariableSpec (spec, options) { return spec.includes('$') ? options.cli_variables[spec.replace('$', '')] : spec; } +// Replaces all pod specs available +function replacePodSpecVariables (pod, options) { + const podSpecs = ['spec', 'tag', 'git', 'commit', 'branch']; + + podSpecs.filter(e => pod[e]) + .forEach(obj => { + const value = pod[obj]; + pod[obj] = getVariableSpec(value, options); + }); + + return pod; +} + class Api { /** * Creates a new PlatformApi instance. @@ -379,10 +392,8 @@ class Api { // libraries if (obj.libraries) { Object.keys(obj.libraries).forEach(key => { - const podJson = Object.assign({}, obj.libraries[key]); - if (podJson.spec) { - podJson.spec = getVariableSpec(podJson.spec, installOptions); - } + let podJson = Object.assign({}, obj.libraries[key]); + podJson = replacePodSpecVariables(podJson, installOptions); const val = podsjsonFile.getLibrary(key); if (val) { events.emit('warn', `${plugin.id} depends on ${podJson.name}, which may conflict with another plugin. ${podJson.name}@${val.spec} is already installed and was not overwritten.`); @@ -472,10 +483,8 @@ class Api { }); // libraries Object.keys(obj.libraries).forEach(key => { - const podJson = Object.assign({}, obj.libraries[key]); - if (podJson.spec) { - podJson.spec = getVariableSpec(podJson.spec, uninstallOptions); - } + let podJson = Object.assign({}, obj.libraries[key]); + podJson = replacePodSpecVariables(podJson, uninstallOptions); const val = podsjsonFile.getLibrary(key); if (val) { podsjsonFile.decrementLibrary(key);