Skip to content

Commit

Permalink
Merge pull request #15055 from ckeditor/ck/14912
Browse files Browse the repository at this point in the history
Other: Added support to execute `yarn run clean-up-svg-icons` script without arguments to optimize all icons in the entire project. Closes #14912.
  • Loading branch information
pomek committed Sep 25, 2023
2 parents 7acb67d + 7f97ebd commit ba1bcba
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions scripts/clean-up-svg-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
// Usage:
// yarn run clean-up-svg-icons <path/to/icons>
//
// yarn run clean-up-svg-icons <path/to/icons> <another/path/to/icons>
//
// The <path/to/icons> 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';

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

0 comments on commit ba1bcba

Please sign in to comment.