Skip to content

Commit

Permalink
Merge pull request #14764 from ckeditor/ck/14762
Browse files Browse the repository at this point in the history
Internal: Rewritten the `clean-up-svg-icons` script from shell script to JavaScript and fixed handling excluded icons. Closes #14762.
  • Loading branch information
psmyrek authored and pomek committed Aug 8, 2023
1 parent 048ed18 commit 84e7755
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"release:publish-packages": "node ./scripts/release/publishpackages.js",
"release:switch-latest": "node ./scripts/release/switchlatest.js",
"release:clean": "node ./scripts/release/clean.js",
"clean-up-svg-icons": "sh ./scripts/clean-up-svg-icons.sh",
"clean-up-svg-icons": "node ./scripts/clean-up-svg-icons.js",
"collect-svg-icons": "node scripts/collect-svg-icons.js",
"check-dependencies": "ckeditor5-dev-dependency-checker",
"check-dependencies:versions-match": "node ./scripts/ci/check-dependencies-versions-match.js"
Expand Down
54 changes: 54 additions & 0 deletions scripts/clean-up-svg-icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env node

/**
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* eslint-env node */

// Cleans up and optimizes SVG files using the SVGO utility. The configuration file is located in svgo.config.json.
//
// Usage:
// yarn run clean-up-svg-icons <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.
//
// To optimize the entire project run:
// yarn clean-up-svg-icons packages/**/theme/icons

'use strict';

const chalk = require( 'chalk' );
const upath = require( 'upath' );
const minimist = require( 'minimist' );
const { globSync } = require( 'glob' );
const { execSync } = require( 'child_process' );

// A list of icons that should not NOT be cleaned up. Their internal structure should not be changed
// because, for instance, CSS animations may depend on it.
const EXCLUDED_ICONS = [
'return-arrow.svg',
'project-logo.svg'
];

const globPattern = minimist( process.argv.slice( 2 ) )._
.map( pathToIcon => pathToIcon.endsWith( '.svg' ) ? pathToIcon : pathToIcon + '/*.svg' );

globSync( globPattern )
.map( upath.toUnix )
.filter( pathToIcon => {
const iconName = upath.basename( pathToIcon );
const isExcluded = EXCLUDED_ICONS.includes( iconName );

if ( isExcluded ) {
console.log( chalk.yellow( `The "${ pathToIcon }" icon is excluded.` ) );
}

return !isExcluded;
} )
.forEach( pathToIcon => {
console.log( chalk.green( `Processing "${ pathToIcon }" icon...` ) );

execSync( `svgo --config=./scripts/svgo.config.js -i ${ pathToIcon }` );
} );
27 changes: 0 additions & 27 deletions scripts/clean-up-svg-icons.sh

This file was deleted.

0 comments on commit 84e7755

Please sign in to comment.