Skip to content

Commit 36be8c4

Browse files
authored
Merge pull request #14 from devicons/fix_build
fix build issues by removing style elements with svgo
2 parents b71900d + 50a4973 commit 36be8c4

File tree

3 files changed

+582
-422
lines changed

3 files changed

+582
-422
lines changed

index.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fsAsync from "fs/promises";
44
import { JSDOM } from "jsdom";
55
import { exec } from "child_process";
66
import svgtojsx from "svg-to-jsx";
7+
import svgo from "svgo";
78

89
interface ConfigEntry {
910
name: string;
@@ -28,9 +29,7 @@ interface ConfigEntry {
2829
fs.rmSync(`${__dirname}/dist`, { recursive: true });
2930
fsAsync.mkdir(`${__dirname}/tmp`);
3031

31-
await degit("https://github.com/devicons/devicon.git").clone(
32-
`${__dirname}/tmp/devicon`
33-
);
32+
await degit("devicons/devicon").clone(`${__dirname}/tmp/devicon`);
3433

3534
const deviconConfig: ConfigEntry[] = JSON.parse(
3635
(await fsAsync.readFile(`${__dirname}/tmp/devicon/devicon.json`)).toString()
@@ -55,7 +54,18 @@ interface ConfigEntry {
5554
const icon = await fsAsync.readFile(
5655
`${__dirname}/tmp/devicon/icons/${entry.name}/${name}.svg`
5756
);
58-
const { document } = new JSDOM(icon).window;
57+
const optimizedIcon = svgo.optimize(icon, {
58+
plugins: [
59+
{
60+
name: "inlineStyles",
61+
params: {
62+
onlyMatchedOnce: false,
63+
},
64+
},
65+
"removeStyleElement",
66+
],
67+
}) as svgo.OptimizedSvg;
68+
const { document } = new JSDOM(optimizedIcon.data).window;
5969
const dir = `${__dirname}/tmp/dist/${entry.name}/${version}`;
6070
const reactName =
6171
name
@@ -110,10 +120,9 @@ module.exports = function ${reactName}({size = "1em", ${
110120
}
111121
}
112122
}
113-
return (${(await svgtojsx(svg.outerHTML)).replace(
114-
"<svg",
115-
"<svg {...props}"
116-
)});
123+
return (${(
124+
await svgtojsx(svg.outerHTML)
125+
).replace("<svg", "<svg {...props}")});
117126
}`
118127
);
119128
const definitions = `import React from "react";

package.json

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,28 @@
77
"release": "ts-node publish.ts"
88
},
99
"devDependencies": {
10-
"@babel/cli": "^7.17.6",
11-
"@babel/core": "^7.17.8",
12-
"@babel/plugin-syntax-jsx": "^7.16.7",
13-
"@babel/plugin-transform-parameters": "^7.16.7",
14-
"@babel/preset-react": "^7.16.7",
15-
"@octokit/core": "^3.6.0",
10+
"@babel/cli": "^7.18.9",
11+
"@babel/core": "^7.18.9",
12+
"@babel/plugin-syntax-jsx": "^7.18.6",
13+
"@babel/plugin-transform-parameters": "^7.18.8",
14+
"@babel/preset-react": "^7.18.6",
15+
"@octokit/core": "^4.0.4",
1616
"@types/degit": "^2.8.3",
17-
"@types/jsdom": "^16.2.14",
18-
"@types/node": "^17.0.23",
19-
"@types/react": "^17.0.42",
20-
"axios": "^0.26.1",
21-
"babel-preset-minify": "^0.5.1",
17+
"@types/jsdom": "^16.2.15",
18+
"@types/node": "^18.0.6",
19+
"@types/react": "^18.0.15",
20+
"@types/svgo": "^2.6.3",
21+
"axios": "^0.27.2",
22+
"babel-preset-minify": "^0.5.2",
2223
"degit": "^2.8.4",
23-
"dotenv": "^16.0.0",
24-
"jsdom": "^19.0.0",
24+
"dotenv": "^16.0.1",
25+
"jsdom": "^20.0.0",
2526
"svg-to-jsx": "^1.0.4",
26-
"ts-node": "^10.7.0",
27-
"typescript": "^4.6.2"
27+
"svgo": "^2.8.0",
28+
"ts-node": "^10.9.1",
29+
"typescript": "^4.7.4"
2830
},
2931
"dependencies": {
30-
"react": "^17.0.2"
32+
"react": "^18.2.0"
3133
}
3234
}

0 commit comments

Comments
 (0)