Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement exclude pattern cli option #1409

Merged
merged 6 commits into from
Mar 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/svgo/coa.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ module.exports = function makeProgram(program) {
.option('--indent <INTEGER>', 'Indent number when pretty printing SVGs')
.option(
'-r, --recursive',
"Use with '-f'. Optimizes *.svg files in folders recursively."
"Use with '--folder'. Optimizes *.svg files in folders recursively."
)
.option(
'--exclude <PATTERN...>',
"Use with '--folder'. Exclude files matching regular expression pattern."
)
.option(
'-q, --quiet',
Expand Down Expand Up @@ -156,6 +160,11 @@ async function action(args, opts, command) {
config.recursive = opts.recursive;
}

// --exclude
config.exclude = opts.exclude
? opts.exclude.map((pattern) => RegExp(pattern))
: [];

// --precision
if (opts.precision != null) {
var precision = Math.min(Math.max(0, opts.precision), 20);
Expand Down Expand Up @@ -291,7 +300,11 @@ function processDirectory(config, dir, files, output) {
*/
function getFilesDescriptions(config, dir, files, output) {
const filesInThisFolder = files
.filter((name) => regSVGFile.test(name))
.filter(
(name) =>
regSVGFile.test(name) &&
!config.exclude.some((regExclude) => regExclude.test(name))
)
.map((name) => ({
inputPath: PATH.resolve(dir, name),
outputPath: PATH.resolve(output, name),
Expand Down