mirror of
https://github.com/konpa/devicon.git
synced 2025-08-01 20:30:18 +02:00
Optimize bot is now a part of the build script (#624)
Co-authored-by: Clemens Bastian <8781699+amacado@users.noreply.github.com>
This commit is contained in:
17
.github/scripts/icomoon_build.py
vendored
17
.github/scripts/icomoon_build.py
vendored
@@ -1,6 +1,8 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
from selenium.common.exceptions import TimeoutException
|
from selenium.common.exceptions import TimeoutException
|
||||||
|
import subprocess
|
||||||
|
import json
|
||||||
|
|
||||||
# pycharm complains that build_assets is an unresolved ref
|
# pycharm complains that build_assets is an unresolved ref
|
||||||
# don't worry about it, the script still runs
|
# don't worry about it, the script still runs
|
||||||
@@ -20,11 +22,22 @@ def main():
|
|||||||
|
|
||||||
runner = None
|
runner = None
|
||||||
try:
|
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,
|
runner = SeleniumRunner(args.download_path,
|
||||||
args.geckodriver_path, args.headless)
|
args.geckodriver_path, args.headless)
|
||||||
runner.upload_icomoon(args.icomoon_json_path)
|
runner.upload_icomoon(args.icomoon_json_path)
|
||||||
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path, True)
|
runner.upload_svgs(icon_svgs)
|
||||||
runner.upload_svgs(svgs)
|
|
||||||
|
|
||||||
zip_name = "devicon-v1.0.zip"
|
zip_name = "devicon-v1.0.zip"
|
||||||
zip_path = Path(args.download_path, zip_name)
|
zip_path = Path(args.download_path, zip_name)
|
||||||
|
26
gulpfile.js
26
gulpfile.js
@@ -160,35 +160,15 @@ function cleanUp() {
|
|||||||
* This must be passed through the commandline arguments.
|
* This must be passed through the commandline arguments.
|
||||||
*/
|
*/
|
||||||
function optimizeSvg() {
|
function optimizeSvg() {
|
||||||
let svgPaths = getAddedModifiedSvg(yargs.argv.filesAddedJson,
|
let svgGlob = JSON.parse(yargs.argv.svgFiles)
|
||||||
yargs.argv.filesModifiedJson)
|
console.log("Optimizing these files: ", svgGlob)
|
||||||
|
return gulp.src(svgGlob)
|
||||||
return gulp.src(svgPaths)
|
|
||||||
.pipe(svgmin(configOptionCallback))
|
.pipe(svgmin(configOptionCallback))
|
||||||
.pipe(gulp.dest(file => {
|
.pipe(gulp.dest(file => {
|
||||||
return file.base
|
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.
|
* Create a config option for each file.
|
||||||
* @param {Object} file - Gulp Vinyl instance of the file
|
* @param {Object} file - Gulp Vinyl instance of the file
|
||||||
|
Reference in New Issue
Block a user