Skip to content

Commit

Permalink
Support comma list of plugins for --disable, --enable options. (svg#1019
Browse files Browse the repository at this point in the history
)

support comma list of plugins for --disable, --enable options
  • Loading branch information
jmwebservices authored and GreLI committed Feb 24, 2019
1 parent 416fcdf commit f84bff3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ Options:
-o OUTPUT, --output=OUTPUT : Output file or folder (by default the same as the input), "-" for STDOUT
-p PRECISION, --precision=PRECISION : Set number of digits in the fractional part, overrides plugins params
--config=CONFIG : Config file or JSON string to extend or replace default
--disable=PLUGIN : Disable plugin by name, "--disable={PLUGIN1,PLUGIN2}" for multiple plugins (*nix)
--enable=PLUGIN : Enable plugin by name, "--enable={PLUGIN3,PLUGIN4}" for multiple plugins (*nix)
--disable=PLUGIN : Disable plugin by name, "--disable=PLUGIN1,PLUGIN2" for multiple plugins
--enable=PLUGIN : Enable plugin by name, "--enable=PLUGIN3,PLUGIN4" for multiple plugins
--datauri=DATAURI : Output as Data URI string (base64, URI encoded or unencoded)
--multipass : Enable multipass
--pretty : Make SVG pretty printed
Expand Down
21 changes: 21 additions & 0 deletions lib/svgo/coa.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ module.exports = require('coa').Cmd()
* @return {Object} changed config
*/
function changePluginsState(names, state, config) {
names.forEach(flattenPluginsCbk);

// extend config
if (config.plugins) {
for (var name of names) {
Expand Down Expand Up @@ -347,6 +349,25 @@ function changePluginsState(names, state, config) {
return config;
}

/**
* Flatten an array of plugins by invoking this callback on each element
* whose value may be a comma separated list of plugins.
*
* @param {String} name Plugin name
* @param {Number} index Plugin index
* @param {Array} names Plugins being traversed
*/
function flattenPluginsCbk(name, index, names)
{
var split = name.split(',');

if(split.length > 1) {
names[index] = split.shift();
names.push.apply(names, split);
}

}

/**
* Optimize SVG files in a directory.
* @param {Object} config options
Expand Down

0 comments on commit f84bff3

Please sign in to comment.