Skip to content

Commit

Permalink
Add hook to optimize staged SVGs before commit (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
csandman authored Jan 14, 2021
1 parent 4352e98 commit 3bedf3b
Show file tree
Hide file tree
Showing 3 changed files with 319 additions and 5 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
"eslint-plugin-prettier": "^2.5.0",
"html-minifier": "^3.5.8",
"htmlparser2": "^4.1.0",
"husky": "^4.3.6",
"jest": "^26.4.2",
"lint-staged": "^10.5.3",
"minimist": "^1.2.5",
"prettier": "1.17.1",
"rollup": "^2.7.3",
Expand All @@ -57,5 +59,13 @@
"rollup-plugin-terser": "^5.2.0",
"rollup-plugin-visualizer": "^4.1.0",
"svgo": "^1.3.2"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"icons/*.svg": "npx babel-node ./scripts/optimizeStagedSvgs.js --presets @babel/env"
}
}
10 changes: 10 additions & 0 deletions scripts/optimizeStagedSvgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import fs from 'fs';
import processSvg from './render/processSvg';

const svgFiles = process.argv.slice(4);

svgFiles.forEach(async svgFile => {
const content = fs.readFileSync(svgFile);
const svg = await processSvg(content);
fs.writeFileSync(svgFile, svg, 'utf-8');
});
Loading

0 comments on commit 3bedf3b

Please sign in to comment.