Skip to content

Commit

Permalink
lib/config: add setPluginActiveState function
Browse files Browse the repository at this point in the history
  • Loading branch information
vithar authored and GreLI committed Jul 13, 2019
1 parent b533063 commit 357de5f
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions lib/svgo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,8 @@ function preparePluginsArray(plugins) {

} else {

plugin = Object.assign({}, require('../../plugins/' + key));

// name: {}
if (typeof item[key] === 'object') {
plugin.params = Object.assign({}, plugin.params || {}, item[key]);
plugin.active = true;

// name: false
} else if (item[key] === false) {
plugin.active = false;

// name: true
} else if (item[key] === true) {
plugin.active = true;
}

plugin.name = key;
plugin = setPluginActiveState(Object.assign({}, require('../../plugins/' + key)), item, key);
plugin.name = key;
}

// name
Expand Down Expand Up @@ -138,19 +123,7 @@ function extendConfig(defaults, config) {
defaults.plugins.forEach(function(plugin) {

if (plugin.name === key) {
// name: {}
if (typeof item[key] === 'object') {
plugin.params = Object.assign({}, plugin.params || {}, item[key]);
plugin.active = true;

// name: false
} else if (item[key] === false) {
plugin.active = false;

// name: true
} else if (item[key] === true) {
plugin.active = true;
}
plugin = setPluginActiveState(plugin, item, key);
}
});
}
Expand Down Expand Up @@ -212,3 +185,29 @@ function optimizePluginsArray(plugins) {
}, []);

}

/**
* Sets plugin to active or inactive state.
*
* @param {Object} plugin
* @param {Object} item
* @param {Object} key
* @return {Object} plugin
*/
function setPluginActiveState(plugin, item, key) {
// name: {}
if (typeof item[key] === 'object') {
plugin.params = Object.assign({}, plugin.params || {}, item[key]);
plugin.active = true;

// name: false
} else if (item[key] === false) {
plugin.active = false;

// name: true
} else if (item[key] === true) {
plugin.active = true;
}

return plugin;
}

0 comments on commit 357de5f

Please sign in to comment.