From 7f97ebd6bd6a0e26b1d58d8fe3d4e5ff7b34aaef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20Smyrek?=
Date: Mon, 25 Sep 2023 14:20:16 +0200
Subject: [PATCH] Added support to run `clean-up-svg-icons` script without
arguments to optimize the entire project.
---
scripts/clean-up-svg-icons.js | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/scripts/clean-up-svg-icons.js b/scripts/clean-up-svg-icons.js
index 669fe79f341..672b70c148b 100644
--- a/scripts/clean-up-svg-icons.js
+++ b/scripts/clean-up-svg-icons.js
@@ -12,10 +12,13 @@
// Usage:
// yarn run clean-up-svg-icons
//
+// yarn run clean-up-svg-icons
+//
// The can be either a direct path to a SVG file, or a path to a directory. Glob patterns in path are supported.
+// Multiple arguments (paths) in one call are supported.
//
// To optimize the entire project run:
-// yarn clean-up-svg-icons packages/**/theme/icons
+// yarn run clean-up-svg-icons
'use strict';
@@ -32,7 +35,10 @@ const EXCLUDED_ICONS = [
'project-logo.svg'
];
-const globPattern = minimist( process.argv.slice( 2 ) )._
+// A pattern to match all the icons.
+const ALL_ICONS_PATTERN = 'packages/**/theme/icons';
+
+const globPattern = parseArguments( process.argv.slice( 2 ) )
.map( pathToIcon => pathToIcon.endsWith( '.svg' ) ? pathToIcon : pathToIcon + '/*.svg' );
globSync( globPattern )
@@ -52,3 +58,13 @@ globSync( globPattern )
execSync( `svgo --config=./scripts/svgo.config.js -i ${ pathToIcon }` );
} );
+
+function parseArguments( args ) {
+ const paths = minimist( args )._;
+
+ if ( paths.length > 0 ) {
+ return paths;
+ }
+
+ return [ ALL_ICONS_PATTERN ];
+}