diff --git a/README.md b/README.md index 8beb8c6b..ea57b645 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ Options: --enable=ENABLE : Enable plugin by name --datauri=DATAURI : Output as Data URI string (base64, URI encoded or unencoded) --pretty : Make SVG pretty printed + --show-plugins : Show available plugins and exit Arguments: INPUT : Alias to --input diff --git a/README.ru.md b/README.ru.md index 7e795ab3..db72d6d0 100644 --- a/README.ru.md +++ b/README.ru.md @@ -78,6 +78,7 @@ $ [sudo] npm install -g svgo --enable=ENABLE : Включение плагина по имени --datauri=DATAURI : Результат в виде строки Data URI (base64, URI encoded или unencoded) --pretty : Удобочитаемое форматирование SVG + --show-plugins : доступные плагины Аргументы: INPUT : Аналогично --input diff --git a/lib/svgo/coa.js b/lib/svgo/coa.js index 5f1abb2d..1e0ee647 100644 --- a/lib/svgo/coa.js +++ b/lib/svgo/coa.js @@ -102,6 +102,11 @@ module.exports = require('coa').Cmd() .long('pretty') .flag() .end() + .opt() + .name('show-plugins').title('Show available plugins and exit') + .long('show-plugins') + .flag() + .end() .arg() .name('input').title('Alias to --input') .end() @@ -114,6 +119,14 @@ module.exports = require('coa').Cmd() output = args && args.output ? args.output : opts.output, config = {}; + // --show-plugins + if (opts['show-plugins']) { + + showAvailablePlugins(); + process.exit(0); + + } + // w/o anything if ( (!input || input === '-') && @@ -123,6 +136,7 @@ module.exports = require('coa').Cmd() process.stdin.isTTY ) return this.usage(); + // --config if (opts.config) { @@ -510,3 +524,23 @@ function optimizeFolder(dir, config, output) { }); } + + +var showAvailablePlugins = function () { + + var svgo = new SVGO(); + + console.log('Currently available plugins:'); + + svgo.config.plugins.forEach(function (plugins) { + + plugins.forEach(function (plugin) { + + console.log(' [ ' + plugin.name.green + ' ] ' + plugin.description); + + }); + + }); + + //console.log(JSON.stringify(svgo, null, 4)); +}; diff --git a/plugins/addClassesToSVGElement.js b/plugins/addClassesToSVGElement.js index cc9019af..1fe193f0 100644 --- a/plugins/addClassesToSVGElement.js +++ b/plugins/addClassesToSVGElement.js @@ -4,6 +4,8 @@ exports.type = 'full'; exports.active = false; +exports.description = 'Add classnames to an outer element.'; + /** * Add classnames to an outer element. * diff --git a/plugins/cleanupAttrs.js b/plugins/cleanupAttrs.js index 51effd8b..8d4a60ae 100644 --- a/plugins/cleanupAttrs.js +++ b/plugins/cleanupAttrs.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'cleanup attributes from newlines, trailing and repeating spaces'; + exports.params = { newlines: true, trim: true, diff --git a/plugins/cleanupEnableBackground.js b/plugins/cleanupEnableBackground.js index 119018c2..e6384ab5 100644 --- a/plugins/cleanupEnableBackground.js +++ b/plugins/cleanupEnableBackground.js @@ -4,6 +4,8 @@ exports.type = 'full'; exports.active = true; +exports.description = 'remove or cleanup enable-background attribute when possible'; + /** * Remove or cleanup enable-background attr which coincides with a width/height box. * diff --git a/plugins/cleanupIDs.js b/plugins/cleanupIDs.js index bfe907f1..f368da46 100644 --- a/plugins/cleanupIDs.js +++ b/plugins/cleanupIDs.js @@ -4,6 +4,8 @@ exports.type = 'full'; exports.active = true; +exports.description = 'remove unused and minify used IDs'; + exports.params = { remove: true, minify: true, diff --git a/plugins/cleanupListOfValues.js b/plugins/cleanupListOfValues.js index 5f617f0e..53d58e79 100644 --- a/plugins/cleanupListOfValues.js +++ b/plugins/cleanupListOfValues.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = false; +exports.description = 'Round list of values to the fixed precision'; + exports.params = { floatPrecision: 3, leadingZero: true, diff --git a/plugins/cleanupNumericValues.js b/plugins/cleanupNumericValues.js index a2865aa4..345bc7dd 100644 --- a/plugins/cleanupNumericValues.js +++ b/plugins/cleanupNumericValues.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'round numeric values to the fixed precision, remove default \'px\' units'; + exports.params = { floatPrecision: 3, leadingZero: true, diff --git a/plugins/collapseGroups.js b/plugins/collapseGroups.js index a751e40e..7d203a00 100644 --- a/plugins/collapseGroups.js +++ b/plugins/collapseGroups.js @@ -4,6 +4,8 @@ exports.type = 'perItemReverse'; exports.active = true; +exports.description = 'collapse useless groups'; + var animationElems = require('./_collections').elemsGroups.animation; /* diff --git a/plugins/convertColors.js b/plugins/convertColors.js index e1f6298a..413e6e9e 100644 --- a/plugins/convertColors.js +++ b/plugins/convertColors.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'convert colors (from rgb() to #rrggbb, from #rrggbb to #rgb)'; + exports.params = { names2hex: true, rgb2hex: true, diff --git a/plugins/convertPathData.js b/plugins/convertPathData.js index 13488e9b..9b7f6a9e 100644 --- a/plugins/convertPathData.js +++ b/plugins/convertPathData.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'convert Path data to relative or absolute whichever is shorter, convert one segment to another, trim useless delimiters, smart rounding and much more'; + exports.params = { applyTransforms: true, applyTransformsStroked: true, diff --git a/plugins/convertShapeToPath.js b/plugins/convertShapeToPath.js index c7527968..19a1eb97 100644 --- a/plugins/convertShapeToPath.js +++ b/plugins/convertShapeToPath.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'convert some basic shapes to path'; + var none = { value: 0 }, regNumber = /[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g; @@ -101,4 +103,4 @@ exports.fn = function(item) { .removeAttr('points'); } -}; \ No newline at end of file +}; diff --git a/plugins/convertStyleToAttrs.js b/plugins/convertStyleToAttrs.js index 8e5e246b..c8c5056b 100644 --- a/plugins/convertStyleToAttrs.js +++ b/plugins/convertStyleToAttrs.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'Convert style in attributes. Cleanups comments and illegal declarations (without colon) as a side effect'; + var EXTEND = require('whet.extend'), stylingProps = require('./_collections').stylingProps, rEscape = '\\\\(?:[0-9a-f]{1,6}\\s?|\\r\\n|.)', // Like \" or \2051. Code points consume one space. diff --git a/plugins/convertTransform.js b/plugins/convertTransform.js index 90daa01f..d141e11f 100644 --- a/plugins/convertTransform.js +++ b/plugins/convertTransform.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'collapse multiple transforms into one, convert matrices to the short aliases and much more'; + exports.params = { convertToShorts: true, // degPrecision: 3, // transformPrecision (or matrix precision) - 2 by default diff --git a/plugins/mergePaths.js b/plugins/mergePaths.js index a56e106f..d3cb9ddb 100644 --- a/plugins/mergePaths.js +++ b/plugins/mergePaths.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'merge multiple Paths into one'; + exports.params = { collapseRepeated: true, leadingZero: true, diff --git a/plugins/moveElemsAttrsToGroup.js b/plugins/moveElemsAttrsToGroup.js index 04d9ddf0..e333753d 100644 --- a/plugins/moveElemsAttrsToGroup.js +++ b/plugins/moveElemsAttrsToGroup.js @@ -4,6 +4,8 @@ exports.type = 'perItemReverse'; exports.active = true; +exports.description = 'move elements attributes to the existing group wrapper'; + var inheritableAttrs = require('./_collections').inheritableAttrs, pathElems = require('./_collections.js').pathElems; diff --git a/plugins/moveGroupAttrsToElems.js b/plugins/moveGroupAttrsToElems.js index c2682990..6d651947 100644 --- a/plugins/moveGroupAttrsToElems.js +++ b/plugins/moveGroupAttrsToElems.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'move some group attributes to the content elements'; + var collections = require('./_collections.js'), pathElems = collections.pathElems.concat(['g', 'text']), referencesProps = collections.referencesProps; diff --git a/plugins/removeComments.js b/plugins/removeComments.js index c53b997c..ae73627a 100644 --- a/plugins/removeComments.js +++ b/plugins/removeComments.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'remove comments'; + /** * Remove comments. * diff --git a/plugins/removeDesc.js b/plugins/removeDesc.js index a6066413..2b6a9136 100644 --- a/plugins/removeDesc.js +++ b/plugins/removeDesc.js @@ -8,6 +8,8 @@ exports.params = { removeAny: false }; +exports.description = 'remove (only non-meaningful by default)'; + var standardDescs = /^Created with/; /** diff --git a/plugins/removeDoctype.js b/plugins/removeDoctype.js index 180bd242..c257e680 100644 --- a/plugins/removeDoctype.js +++ b/plugins/removeDoctype.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'remove doctype declaration'; + /** * Remove DOCTYPE declaration. * diff --git a/plugins/removeEditorsNSData.js b/plugins/removeEditorsNSData.js index c1bbb203..7ac6ba57 100644 --- a/plugins/removeEditorsNSData.js +++ b/plugins/removeEditorsNSData.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'remove editors namespaces, elements and attributes'; + var editorNamespaces = require('./_collections').editorNamespaces, prefixes = []; diff --git a/plugins/removeEmptyAttrs.js b/plugins/removeEmptyAttrs.js index e4e072c3..492e6142 100644 --- a/plugins/removeEmptyAttrs.js +++ b/plugins/removeEmptyAttrs.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'remove empty attributes'; + /** * Remove attributes with empty values. * diff --git a/plugins/removeEmptyContainers.js b/plugins/removeEmptyContainers.js index d9efec08..1ade8d36 100644 --- a/plugins/removeEmptyContainers.js +++ b/plugins/removeEmptyContainers.js @@ -4,6 +4,8 @@ exports.type = 'perItemReverse'; exports.active = true; +exports.description = 'remove empty Container elements'; + var container = require('./_collections').elemsGroups.container; /** diff --git a/plugins/removeEmptyText.js b/plugins/removeEmptyText.js index ae314c6b..60119977 100644 --- a/plugins/removeEmptyText.js +++ b/plugins/removeEmptyText.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'remove empty Text elements'; + exports.params = { text: true, tspan: true, diff --git a/plugins/removeHiddenElems.js b/plugins/removeHiddenElems.js index 4b1a8260..652894f2 100644 --- a/plugins/removeHiddenElems.js +++ b/plugins/removeHiddenElems.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'remove hidden elements'; + exports.params = { displayNone: true, opacity0: true, diff --git a/plugins/removeMetadata.js b/plugins/removeMetadata.js index 7573a452..99c64f2c 100644 --- a/plugins/removeMetadata.js +++ b/plugins/removeMetadata.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'remove '; + /** * Remove . * diff --git a/plugins/removeNonInheritableGroupAttrs.js b/plugins/removeNonInheritableGroupAttrs.js index af7f0778..2c9b9123 100644 --- a/plugins/removeNonInheritableGroupAttrs.js +++ b/plugins/removeNonInheritableGroupAttrs.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'remove non-inheritable group\'s "presentation" attributes'; + var inheritableAttrs = require('./_collections').inheritableAttrs, attrsGroups = require('./_collections').attrsGroups, excludedAttrs = ['display', 'opacity']; diff --git a/plugins/removeRasterImages.js b/plugins/removeRasterImages.js index 2a272027..d068cbda 100644 --- a/plugins/removeRasterImages.js +++ b/plugins/removeRasterImages.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = false; +exports.description = 'remove raster images (disabled by default)'; + /** * Remove raster images references in . * diff --git a/plugins/removeTitle.js b/plugins/removeTitle.js index 3dd07f55..17930642 100644 --- a/plugins/removeTitle.js +++ b/plugins/removeTitle.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = false; +exports.description = 'remove (disabled by default)'; + /** * Remove <title>. * Disabled by default cause it may be used for accessibility. diff --git a/plugins/removeUnknownsAndDefaults.js b/plugins/removeUnknownsAndDefaults.js index 41cb7125..eb4514cf 100644 --- a/plugins/removeUnknownsAndDefaults.js +++ b/plugins/removeUnknownsAndDefaults.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'remove unknown elements content and attributes, remove attrs with default values'; + exports.params = { unknownContent: true, unknownAttrs: true, diff --git a/plugins/removeUnusedNS.js b/plugins/removeUnusedNS.js index 3e4985f3..f46f3782 100644 --- a/plugins/removeUnusedNS.js +++ b/plugins/removeUnusedNS.js @@ -4,6 +4,8 @@ exports.type = 'full'; exports.active = true; +exports.description = 'remove unused namespaces declaration'; + /** * Remove unused namespaces declaration. * diff --git a/plugins/removeUselessDefs.js b/plugins/removeUselessDefs.js index 00332e03..87eb1709 100644 --- a/plugins/removeUselessDefs.js +++ b/plugins/removeUselessDefs.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'remove elements of <defs> without id'; + var nonRendering = require('./_collections').elemsGroups.nonRendering, defs; diff --git a/plugins/removeUselessStrokeAndFill.js b/plugins/removeUselessStrokeAndFill.js index 9ae569fb..cc3bbb1f 100644 --- a/plugins/removeUselessStrokeAndFill.js +++ b/plugins/removeUselessStrokeAndFill.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'remove useless stroke and fill attrs'; + exports.params = { stroke: true, fill: true diff --git a/plugins/removeViewBox.js b/plugins/removeViewBox.js index d3578059..7fbdd362 100644 --- a/plugins/removeViewBox.js +++ b/plugins/removeViewBox.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = false; +exports.description = 'remove viewBox attribute when possible (disabled by default)'; + var regViewBox = /^0\s0\s([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)\s([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)$/, viewBoxElems = ['svg', 'pattern']; diff --git a/plugins/removeXMLProcInst.js b/plugins/removeXMLProcInst.js index 41938f1e..ec443b38 100644 --- a/plugins/removeXMLProcInst.js +++ b/plugins/removeXMLProcInst.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = true; +exports.description = 'remove XML processing instructions'; + /** * Remove XML Processing Instruction. * diff --git a/plugins/sortAttrs.js b/plugins/sortAttrs.js index 74f41c3e..70220547 100644 --- a/plugins/sortAttrs.js +++ b/plugins/sortAttrs.js @@ -4,6 +4,8 @@ exports.type = 'perItem'; exports.active = false; +exports.description = 'sort element attributes for epic readability (disabled by default)'; + exports.params = { order: [ 'xmlns', diff --git a/plugins/transformsWithOnePath.js b/plugins/transformsWithOnePath.js index f390dab3..05e49bf1 100644 --- a/plugins/transformsWithOnePath.js +++ b/plugins/transformsWithOnePath.js @@ -8,6 +8,8 @@ exports.type = 'full'; exports.active = false; +exports.description = 'apply transforms, crop by real width, center vertical alignment and resize SVG with one Path inside (disabled by default)'; + exports.params = { // width and height to resize SVG and rescale inner Path width: false,