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",
|
"htmlparser2": "^4.1.0",
|
||||||
"jest": "^26.4.2",
|
"jest": "^26.4.2",
|
||||||
"minimist": "^1.2.5",
|
"minimist": "^1.2.5",
|
||||||
"prettier": "^1.8.2",
|
"prettier": "1.17.1",
|
||||||
"rollup": "^2.7.3",
|
"rollup": "^2.7.3",
|
||||||
"rollup-plugin-commonjs": "^10.1.0",
|
"rollup-plugin-commonjs": "^10.1.0",
|
||||||
"rollup-plugin-license": "^2.0.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
|
* @param {string} content
|
||||||
*/
|
*/
|
||||||
export const writeSvgFile = (fileName, outputDirectory, 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
|
// This is a djb2 hashing function
|
||||||
export const hash = (string, seed = 5381) => {
|
export const hash = (string, seed = 5381) => {
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ const svgFiles = readSvgDirectory(ICONS_DIR);
|
|||||||
|
|
||||||
svgFiles.forEach(svgFile => {
|
svgFiles.forEach(svgFile => {
|
||||||
const content = fs.readFileSync(path.join(ICONS_DIR, 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 (
|
return (
|
||||||
optimize(svg)
|
optimize(svg)
|
||||||
.then(setAttrs)
|
.then(setAttrs)
|
||||||
.then(format)
|
.then(optimizedSvg => format(optimizedSvg, { parser: 'babel' }))
|
||||||
// remove semicolon inserted by prettier
|
// remove semicolon inserted by prettier
|
||||||
// because prettier thinks it's formatting JSX not HTML
|
// because prettier thinks it's formatting JSX not HTML
|
||||||
.then(svg => svg.replace(/;/g, ''))
|
.then(svg => svg.replace(/;/g, ''))
|
||||||
@@ -36,9 +36,7 @@ function optimize(svg) {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise(resolve => {
|
return svgo.optimize(svg).then(({ data }) => data);
|
||||||
svgo.optimize(svg, ({ data }) => resolve(data));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user