Fix optimizeSvgs script (#160)
This commit is contained in:
committed by
GitHub
parent
cf13cef475
commit
fc2fac9ca4
+1
-1
@@ -48,7 +48,7 @@
|
||||
"htmlparser2": "^4.1.0",
|
||||
"jest": "^26.4.2",
|
||||
"minimist": "^1.2.5",
|
||||
"prettier": "^1.8.2",
|
||||
"prettier": "1.17.1",
|
||||
"rollup": "^2.7.3",
|
||||
"rollup-plugin-commonjs": "^10.1.0",
|
||||
"rollup-plugin-license": "^2.0.0",
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ export const readSvg = (fileName, directory) => fs.readFileSync(path.join(direct
|
||||
* @param {string} content
|
||||
*/
|
||||
export const writeSvgFile = (fileName, outputDirectory, content) =>
|
||||
fs.appendFileSync(path.join(outputDirectory, fileName), content, 'utf-8');
|
||||
fs.writeFileSync(path.join(outputDirectory, fileName), content, 'utf-8');
|
||||
|
||||
// This is a djb2 hashing function
|
||||
export const hash = (string, seed = 5381) => {
|
||||
|
||||
@@ -11,5 +11,5 @@ const svgFiles = readSvgDirectory(ICONS_DIR);
|
||||
|
||||
svgFiles.forEach(svgFile => {
|
||||
const content = fs.readFileSync(path.join(ICONS_DIR, svgFile));
|
||||
processSvg(content).then(svg => writeSvgFile(svg, ICONS_DIR, content));
|
||||
processSvg(content).then(svg => writeSvgFile(svgFile, ICONS_DIR, svg));
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ function processSvg(svg) {
|
||||
return (
|
||||
optimize(svg)
|
||||
.then(setAttrs)
|
||||
.then(format)
|
||||
.then(optimizedSvg => format(optimizedSvg, { parser: 'babel' }))
|
||||
// remove semicolon inserted by prettier
|
||||
// because prettier thinks it's formatting JSX not HTML
|
||||
.then(svg => svg.replace(/;/g, ''))
|
||||
@@ -36,9 +36,7 @@ function optimize(svg) {
|
||||
],
|
||||
});
|
||||
|
||||
return new Promise(resolve => {
|
||||
svgo.optimize(svg, ({ data }) => resolve(data));
|
||||
});
|
||||
return svgo.optimize(svg).then(({ data }) => data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user