Skip to content

Commit 48ebd6a

Browse files
Thomas-Boiamacado
andauthored
Optimize bot is now a part of the build script (#624)
Co-authored-by: Clemens Bastian <8781699+amacado@users.noreply.github.com>
1 parent 1e01930 commit 48ebd6a

2 files changed

Lines changed: 18 additions & 25 deletions

File tree

.github/scripts/icomoon_build.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from pathlib import Path
22
import sys
33
from selenium.common.exceptions import TimeoutException
4+
import subprocess
5+
import json
46

57
# pycharm complains that build_assets is an unresolved ref
68
# don't worry about it, the script still runs
@@ -20,11 +22,22 @@ def main():
2022

2123
runner = None
2224
try:
25+
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path, icon_versions_only=False)
26+
# optimizes the files
27+
# do in each batch in case the command
28+
# line complains there's too many characters
29+
start = 0
30+
step = 10
31+
for i in range(start, len(svgs), step):
32+
batch = svgs[i:i + step]
33+
subprocess.run(["npm", "run", "optimize-svg", "--", f"--svgFiles={json.dumps(batch)}"], shell=True)
34+
35+
icon_svgs = filehandler.get_svgs_paths(
36+
new_icons, args.icons_folder_path, icon_versions_only=True)
2337
runner = SeleniumRunner(args.download_path,
2438
args.geckodriver_path, args.headless)
2539
runner.upload_icomoon(args.icomoon_json_path)
26-
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path, True)
27-
runner.upload_svgs(svgs)
40+
runner.upload_svgs(icon_svgs)
2841

2942
zip_name = "devicon-v1.0.zip"
3043
zip_path = Path(args.download_path, zip_name)

gulpfile.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -160,35 +160,15 @@ function cleanUp() {
160160
* This must be passed through the commandline arguments.
161161
*/
162162
function optimizeSvg() {
163-
let svgPaths = getAddedModifiedSvg(yargs.argv.filesAddedJson,
164-
yargs.argv.filesModifiedJson)
165-
166-
return gulp.src(svgPaths)
163+
let svgGlob = JSON.parse(yargs.argv.svgFiles)
164+
console.log("Optimizing these files: ", svgGlob)
165+
return gulp.src(svgGlob)
167166
.pipe(svgmin(configOptionCallback))
168167
.pipe(gulp.dest(file => {
169168
return file.base
170169
}))
171170
}
172171

173-
/**
174-
* Get the svgs added and modified from the '/icons' folder only.
175-
* @param {*} filesAddedJson - the files that were added in this commit.
176-
* @param {*} filesModifiedJson - the files that were modified in this commit.
177-
* @returns a list of the svg file paths that were added/modified in this pr as Path.
178-
* It will only return icons in '/icons' path (see https://github.com/devicons/devicon/issues/505)
179-
*/
180-
function getAddedModifiedSvg(filesAddedJson, filesModifiedJson) {
181-
const filesAdded = JSON.parse(filesAddedJson),
182-
filesModified = JSON.parse(filesModifiedJson)
183-
184-
files = filesAdded.concat(filesModified)
185-
return files.filter(filename => {
186-
if (path.extname(filename) == ".svg"
187-
&& path.dirname(filename).includes('icons/'))
188-
return filename
189-
})
190-
}
191-
192172
/**
193173
* Create a config option for each file.
194174
* @param {Object} file - Gulp Vinyl instance of the file

0 commit comments

Comments
 (0)