Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace variables in Podfile #754

Merged
merged 2 commits into from
Dec 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions bin/templates/scripts/cordova/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function setupEvents (externalEventEmitter) {
}
}

function getVariableSpec (spec, options) {
return spec.includes('$') ? options.cli_variables[spec.replace('$', '')] : spec;
}

/**
* Creates a new PlatformApi instance.
*
Expand Down Expand Up @@ -268,7 +272,7 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
const frameworkPods = frameworkTags.filter(function (obj) {
return (obj.type === 'podspec');
});
return self.addPodSpecs(plugin, podSpecs, frameworkPods);
return self.addPodSpecs(plugin, podSpecs, frameworkPods, installOptions);
}
})
// CB-11022 return non-falsy value to indicate
Expand Down Expand Up @@ -322,7 +326,7 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
const frameworkPods = frameworkTags.filter(function (obj) {
return (obj.type === 'podspec');
});
return self.removePodSpecs(plugin, podSpecs, frameworkPods);
return self.removePodSpecs(plugin, podSpecs, frameworkPods, uninstallOptions);
}
})
// CB-11022 return non-falsy value to indicate
Expand All @@ -340,7 +344,7 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) {
* @return {Promise} Return a promise
*/

Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods) {
Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods, installOptions) {
const self = this;

const project_dir = self.locations.root;
Expand Down Expand Up @@ -389,6 +393,9 @@ Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods) {
// libraries
Object.keys(obj.libraries).forEach(function (key) {
const podJson = Object.assign({}, obj.libraries[key]);
if (podJson.spec) {
podJson.spec = getVariableSpec(podJson.spec, 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.');
Expand All @@ -406,10 +413,11 @@ Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods) {
events.emit('warn', '"framework" tag with type "podspec" is deprecated and will be removed. Please use the "podspec" tag.');
events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type="podspec"');
frameworkPods.forEach(function (obj) {
const spec = getVariableSpec(obj.spec, installOptions);
const podJson = {
name: obj.src,
type: obj.type,
spec: obj.spec
spec
};

const val = podsjsonFile.getLibrary(podJson.name);
Expand Down Expand Up @@ -459,7 +467,7 @@ Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods) {
* @return {Promise} Return a promise
*/

Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods) {
Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods, uninstallOptions) {
const self = this;

const project_dir = self.locations.root;
Expand Down Expand Up @@ -511,6 +519,9 @@ Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods) {
// libraries
Object.keys(obj.libraries).forEach(function (key) {
const podJson = Object.assign({}, obj.libraries[key]);
if (podJson.spec) {
podJson.spec = getVariableSpec(podJson.spec, uninstallOptions);
}
const val = podsjsonFile.getLibrary(key);
if (val) {
podsjsonFile.decrementLibrary(key);
Expand All @@ -529,10 +540,11 @@ Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods) {
events.emit('warn', '"framework" tag with type "podspec" is deprecated and will be removed. Please use the "podspec" tag.');
events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type=\"podspec\"'); /* eslint no-useless-escape : 0 */
frameworkPods.forEach(function (obj) {
const spec = getVariableSpec(obj.spec, uninstallOptions);
const podJson = {
name: obj.src,
type: obj.type,
spec: obj.spec
spec
};

const val = podsjsonFile.getLibrary(podJson.name);
Expand Down