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 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/svgo/coa.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ module.exports = function makeProgram(program) {
'-r, --recursive',
"Use with '-f'. Optimizes *.svg files in folders recursively."
)
.option(
'-e, --exclude <PATTERN...>',
"Use with '-f'. Exclude files matching regular expression pattern."
)
.option(
'-q, --quiet',
'Only output error messages, not regular status messages'
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