Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize bot is now a part of the build script #624

Merged
merged 2 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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