mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-17 14:28:25 +00:00
Fixes pre-commit git hook to ensure the optimisation of staged icons (#958)
* testing * Fixes pre-commit hook * Removing checkIcons from pre commit hook because it might result in false positives and negatives on an unclean local repository * Added checkIcons Github action --------- Co-authored-by: Karsa <karsa@karsa.org>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { optimize } from 'svgo';
|
||||
import {optimize} from 'svgo';
|
||||
import prettier from 'prettier';
|
||||
import { parseSync, stringify } from 'svgson';
|
||||
import {parseSync, stringify} from 'svgson';
|
||||
import DEFAULT_ATTRS from './default-attrs.json' assert { type: 'json' };
|
||||
|
||||
/**
|
||||
@@ -8,8 +8,9 @@ import DEFAULT_ATTRS from './default-attrs.json' assert { type: 'json' };
|
||||
* @param {string} svg - An SVG string.
|
||||
* @returns {Promise<string>} An optimized svg
|
||||
*/
|
||||
async function optimizeSvg(svg) {
|
||||
async function optimizeSvg(svg, path) {
|
||||
const result = optimize(svg, {
|
||||
path,
|
||||
plugins: [
|
||||
{
|
||||
name: 'preset-default',
|
||||
@@ -17,12 +18,15 @@ async function optimizeSvg(svg) {
|
||||
overrides: {
|
||||
convertShapeToPath: false,
|
||||
mergePaths: false,
|
||||
removeAttrs: {
|
||||
attrs: '(fill|stroke.*)',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'removeAttrs',
|
||||
params: {
|
||||
attrs: '(fill|stroke.*)',
|
||||
}
|
||||
}
|
||||
],
|
||||
});
|
||||
|
||||
@@ -47,12 +51,12 @@ function setAttrs(svg) {
|
||||
* @param {string} svg An SVG string.
|
||||
* @returns {Promise<string>} An optimized svg
|
||||
*/
|
||||
function processSvg(svg) {
|
||||
function processSvg(svg, path) {
|
||||
return (
|
||||
optimizeSvg(svg)
|
||||
optimizeSvg(svg, path)
|
||||
.then(setAttrs)
|
||||
.then((optimizedSvg) =>
|
||||
prettier.format(optimizedSvg, { parser: 'babel' }),
|
||||
prettier.format(optimizedSvg, {parser: 'babel'}),
|
||||
)
|
||||
// remove semicolon inserted by prettier
|
||||
// because prettier thinks it's formatting JSX not HTML
|
||||
|
||||
Reference in New Issue
Block a user