1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00

Add --show-plugins option

This commit is contained in:
Yoshiya Hinosawa
2015-06-07 19:35:49 +09:00
parent e9d00c5c57
commit 8e6b365c40
38 changed files with 107 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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));
};

View File

@ -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.
*

View File

@ -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,

View File

@ -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.
*

View File

@ -4,6 +4,8 @@ exports.type = 'full';
exports.active = true;
exports.description = 'remove unused and minify used IDs';
exports.params = {
remove: true,
minify: true,

View File

@ -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,

View File

@ -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,

View File

@ -4,6 +4,8 @@ exports.type = 'perItemReverse';
exports.active = true;
exports.description = 'collapse useless groups';
var animationElems = require('./_collections').elemsGroups.animation;
/*

View File

@ -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,

View File

@ -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,

View File

@ -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');
}
};
};

View File

@ -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.

View File

@ -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

View File

@ -4,6 +4,8 @@ exports.type = 'perItem';
exports.active = true;
exports.description = 'merge multiple Paths into one';
exports.params = {
collapseRepeated: true,
leadingZero: true,

View File

@ -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;

View File

@ -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;

View File

@ -4,6 +4,8 @@ exports.type = 'perItem';
exports.active = true;
exports.description = 'remove comments';
/**
* Remove comments.
*

View File

@ -8,6 +8,8 @@ exports.params = {
removeAny: false
};
exports.description = 'remove <desc> (only non-meaningful by default)';
var standardDescs = /^Created with/;
/**

View File

@ -4,6 +4,8 @@ exports.type = 'perItem';
exports.active = true;
exports.description = 'remove doctype declaration';
/**
* Remove DOCTYPE declaration.
*

View File

@ -4,6 +4,8 @@ exports.type = 'perItem';
exports.active = true;
exports.description = 'remove editors namespaces, elements and attributes';
var editorNamespaces = require('./_collections').editorNamespaces,
prefixes = [];

View File

@ -4,6 +4,8 @@ exports.type = 'perItem';
exports.active = true;
exports.description = 'remove empty attributes';
/**
* Remove attributes with empty values.
*

View File

@ -4,6 +4,8 @@ exports.type = 'perItemReverse';
exports.active = true;
exports.description = 'remove empty Container elements';
var container = require('./_collections').elemsGroups.container;
/**

View File

@ -4,6 +4,8 @@ exports.type = 'perItem';
exports.active = true;
exports.description = 'remove empty Text elements';
exports.params = {
text: true,
tspan: true,

View File

@ -4,6 +4,8 @@ exports.type = 'perItem';
exports.active = true;
exports.description = 'remove hidden elements';
exports.params = {
displayNone: true,
opacity0: true,

View File

@ -4,6 +4,8 @@ exports.type = 'perItem';
exports.active = true;
exports.description = 'remove <metadata>';
/**
* Remove <metadata>.
*

View File

@ -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'];

View File

@ -4,6 +4,8 @@ exports.type = 'perItem';
exports.active = false;
exports.description = 'remove raster images (disabled by default)';
/**
* Remove raster images references in <image>.
*

View File

@ -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.

View File

@ -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,

View File

@ -4,6 +4,8 @@ exports.type = 'full';
exports.active = true;
exports.description = 'remove unused namespaces declaration';
/**
* Remove unused namespaces declaration.
*

View File

@ -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;

View File

@ -4,6 +4,8 @@ exports.type = 'perItem';
exports.active = true;
exports.description = 'remove useless stroke and fill attrs';
exports.params = {
stroke: true,
fill: true

View File

@ -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'];

View File

@ -4,6 +4,8 @@ exports.type = 'perItem';
exports.active = true;
exports.description = 'remove XML processing instructions';
/**
* Remove XML Processing Instruction.
*

View File

@ -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',

View File

@ -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,