Skip to content

Commit

Permalink
Merge pull request svg#380 from kt3k/feature/show-plugins
Browse files Browse the repository at this point in the history
Add --show-plugins option
  • Loading branch information
GreLI committed Jun 7, 2015
2 parents e9d00c5 + 8e6b365 commit 7bba483
Show file tree
Hide file tree
Showing 38 changed files with 107 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions lib/svgo/coa.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 === '-') &&
Expand All @@ -123,6 +136,7 @@ module.exports = require('coa').Cmd()
process.stdin.isTTY
) return this.usage();


// --config
if (opts.config) {

Expand Down Expand Up @@ -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));
};
2 changes: 2 additions & 0 deletions plugins/addClassesToSVGElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'full';

exports.active = false;

exports.description = 'Add classnames to an outer <svg> element.';

/**
* Add classnames to an outer <svg> element.
*
Expand Down
2 changes: 2 additions & 0 deletions plugins/cleanupAttrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions plugins/cleanupEnableBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 2 additions & 0 deletions plugins/cleanupIDs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'full';

exports.active = true;

exports.description = 'remove unused and minify used IDs';

exports.params = {
remove: true,
minify: true,
Expand Down
2 changes: 2 additions & 0 deletions plugins/cleanupListOfValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions plugins/cleanupNumericValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions plugins/collapseGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItemReverse';

exports.active = true;

exports.description = 'collapse useless groups';

var animationElems = require('./_collections').elemsGroups.animation;

/*
Expand Down
2 changes: 2 additions & 0 deletions plugins/convertColors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions plugins/convertPathData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion plugins/convertShapeToPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -101,4 +103,4 @@ exports.fn = function(item) {
.removeAttr('points');
}

};
};
2 changes: 2 additions & 0 deletions plugins/convertStyleToAttrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions plugins/convertTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions plugins/mergePaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItem';

exports.active = true;

exports.description = 'merge multiple Paths into one';

exports.params = {
collapseRepeated: true,
leadingZero: true,
Expand Down
2 changes: 2 additions & 0 deletions plugins/moveElemsAttrsToGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions plugins/moveGroupAttrsToElems.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeComments.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItem';

exports.active = true;

exports.description = 'remove comments';

/**
* Remove comments.
*
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeDesc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ exports.params = {
removeAny: false
};

exports.description = 'remove <desc> (only non-meaningful by default)';

var standardDescs = /^Created with/;

/**
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeDoctype.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItem';

exports.active = true;

exports.description = 'remove doctype declaration';

/**
* Remove DOCTYPE declaration.
*
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeEditorsNSData.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItem';

exports.active = true;

exports.description = 'remove editors namespaces, elements and attributes';

var editorNamespaces = require('./_collections').editorNamespaces,
prefixes = [];

Expand Down
2 changes: 2 additions & 0 deletions plugins/removeEmptyAttrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItem';

exports.active = true;

exports.description = 'remove empty attributes';

/**
* Remove attributes with empty values.
*
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeEmptyContainers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItemReverse';

exports.active = true;

exports.description = 'remove empty Container elements';

var container = require('./_collections').elemsGroups.container;

/**
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeEmptyText.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItem';

exports.active = true;

exports.description = 'remove empty Text elements';

exports.params = {
text: true,
tspan: true,
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeHiddenElems.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItem';

exports.active = true;

exports.description = 'remove hidden elements';

exports.params = {
displayNone: true,
opacity0: true,
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItem';

exports.active = true;

exports.description = 'remove <metadata>';

/**
* Remove <metadata>.
*
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeNonInheritableGroupAttrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeRasterImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItem';

exports.active = false;

exports.description = 'remove raster images (disabled by default)';

/**
* Remove raster images references in <image>.
*
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItem';

exports.active = false;

exports.description = 'remove <title> (disabled by default)';

/**
* Remove <title>.
* Disabled by default cause it may be used for accessibility.
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeUnknownsAndDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeUnusedNS.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'full';

exports.active = true;

exports.description = 'remove unused namespaces declaration';

/**
* Remove unused namespaces declaration.
*
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeUselessDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions plugins/removeUselessStrokeAndFill.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItem';

exports.active = true;

exports.description = 'remove useless stroke and fill attrs';

exports.params = {
stroke: true,
fill: true
Expand Down
2 changes: 2 additions & 0 deletions plugins/removeViewBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
2 changes: 2 additions & 0 deletions plugins/removeXMLProcInst.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports.type = 'perItem';

exports.active = true;

exports.description = 'remove XML processing instructions';

/**
* Remove XML Processing Instruction.
*
Expand Down
2 changes: 2 additions & 0 deletions plugins/sortAttrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions plugins/transformsWithOnePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7bba483

Please sign in to comment.