Skip to content

Commit

Permalink
Optimize bot is now a part of the build script (#624)
Browse files Browse the repository at this point in the history
Co-authored-by: Clemens Bastian <8781699+amacado@users.noreply.github.com>
  • Loading branch information
Thomas-Boi and amacado authored May 27, 2021
1 parent 1e01930 commit 48ebd6a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
17 changes: 15 additions & 2 deletions .github/scripts/icomoon_build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path
import sys
from selenium.common.exceptions import TimeoutException
import subprocess
import json

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

runner = None
try:
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path, icon_versions_only=False)
# optimizes the files
# do in each batch in case the command
# line complains there's too many characters
start = 0
step = 10
for i in range(start, len(svgs), step):
batch = svgs[i:i + step]
subprocess.run(["npm", "run", "optimize-svg", "--", f"--svgFiles={json.dumps(batch)}"], shell=True)

icon_svgs = filehandler.get_svgs_paths(
new_icons, args.icons_folder_path, icon_versions_only=True)
runner = SeleniumRunner(args.download_path,
args.geckodriver_path, args.headless)
runner.upload_icomoon(args.icomoon_json_path)
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path, True)
runner.upload_svgs(svgs)
runner.upload_svgs(icon_svgs)

zip_name = "devicon-v1.0.zip"
zip_path = Path(args.download_path, zip_name)
Expand Down
26 changes: 3 additions & 23 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,35 +160,15 @@ function cleanUp() {
* This must be passed through the commandline arguments.
*/
function optimizeSvg() {
let svgPaths = getAddedModifiedSvg(yargs.argv.filesAddedJson,
yargs.argv.filesModifiedJson)

return gulp.src(svgPaths)
let svgGlob = JSON.parse(yargs.argv.svgFiles)
console.log("Optimizing these files: ", svgGlob)
return gulp.src(svgGlob)
.pipe(svgmin(configOptionCallback))
.pipe(gulp.dest(file => {
return file.base
}))
}

/**
* Get the svgs added and modified from the '/icons' folder only.
* @param {*} filesAddedJson - the files that were added in this commit.
* @param {*} filesModifiedJson - the files that were modified in this commit.
* @returns a list of the svg file paths that were added/modified in this pr as Path.
* It will only return icons in '/icons' path (see https://github.com/devicons/devicon/issues/505)
*/
function getAddedModifiedSvg(filesAddedJson, filesModifiedJson) {
const filesAdded = JSON.parse(filesAddedJson),
filesModified = JSON.parse(filesModifiedJson)

files = filesAdded.concat(filesModified)
return files.filter(filename => {
if (path.extname(filename) == ".svg"
&& path.dirname(filename).includes('icons/'))
return filename
})
}

/**
* Create a config option for each file.
* @param {Object} file - Gulp Vinyl instance of the file
Expand Down

0 comments on commit 48ebd6a

Please sign in to comment.