1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-14 10:34:14 +02:00

Added __pycache__ to gitignore. Documented geckodriver. Invalid path now throws error

This commit is contained in:
Thomas Bui
2020-09-02 09:29:39 -07:00
parent 83378fa698
commit 33b07225bf
9 changed files with 13 additions and 132 deletions

View File

@@ -78,7 +78,7 @@ class SeleniumRunner:
def upload_icomoon(self): def upload_icomoon(self):
""" """
Upload the icomoon_test.json to icomoon.io. Upload the icomoon.json to icomoon.io.
:raises TimeoutException: happens when elements are not found. :raises TimeoutException: happens when elements are not found.
""" """
print("Uploading JSON file...") print("Uploading JSON file...")
@@ -89,7 +89,6 @@ class SeleniumRunner:
) )
import_btn.send_keys(self.icomoon_json_path) import_btn.send_keys(self.icomoon_json_path)
except Exception as e: except Exception as e:
print("hi")
self.close() self.close()
raise e raise e
@@ -100,8 +99,8 @@ class SeleniumRunner:
confirm_btn.click() confirm_btn.click()
except SeleniumTimeoutException as e: except SeleniumTimeoutException as e:
print(e.stacktrace) print(e.stacktrace)
print("Cannot find the confirm button when uploading the icomoon_test.json", print("Cannot find the confirm button when uploading the icomoon.json",
"Ensure that the icomoon_test.json is in the correct format for Icomoon.io", "Ensure that the icomoon.json is in the correct format for Icomoon.io",
sep='\n') sep='\n')
self.close() self.close()

View File

@@ -56,9 +56,8 @@ def get_svgs_paths(new_icons: List[dict], icons_folder_path: str) -> List[str]:
for icon_info in new_icons: for icon_info in new_icons:
folder_path = Path(icons_folder_path, icon_info['name']) folder_path = Path(icons_folder_path, icon_info['name'])
if not (folder_path.exists() and folder_path.is_dir()): if not folder_path.is_dir():
print(f"Invalid path. This is not a directory: {folder_path}\nSkipping entry...") raise ValueError(f"Invalid path. This is not a directory: {folder_path}.")
continue
try: try:
aliases = icon_info["aliases"] aliases = icon_info["aliases"]
@@ -74,6 +73,8 @@ def get_svgs_paths(new_icons: List[dict], icons_folder_path: str) -> List[str]:
if path.exists(): if path.exists():
file_paths.append(str(path)) file_paths.append(str(path))
else:
raise ValueError(f"This path doesn't exist: {path}")
return file_paths return file_paths

View File

@@ -0,0 +1 @@
This folder was taken from: https://github.com/mozilla/geckodriver/releases/tag/v0.27.0

Binary file not shown.

View File

@@ -1,14 +1,5 @@
name: Build Icons name: Build Icons
on: on: push
# Trigger the workflow on push or pull request,
# but only for the master branch
push:
branches:
- master
pull_request:
branches:
- master
jobs: jobs:
build: build:
name: Get Fonts From Icomoon name: Get Fonts From Icomoon
@@ -25,7 +16,8 @@ jobs:
pip install -r ./.github/scripts/requirements.txt pip install -r ./.github/scripts/requirements.txt
- name: Run icomoon_upload.py - name: Run icomoon_upload.py
run: > run: >
python ./.github/scripts/icomoon_upload.py ./.github/scripts/build_assets/geckodriver.exe python ./.github/scripts/icomoon_upload.py
./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe
./icomoon.json ./devicon.json ./icons ./built_files --headless ./icomoon.json ./devicon.json ./icons ./built_files --headless
- name: Commit changes - name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4 uses: stefanzweifel/git-auto-commit-action@v4

3
.gitignore vendored
View File

@@ -1,4 +1,5 @@
node_modules node_modules
.DS_Store .DS_Store
.idea .idea
geckodriver.log geckodriver.log
__pycache__

View File

@@ -1,39 +0,0 @@
/* Parse the devicon-colors.css and convert it to devicon-colors.json*/
const fs = require("fs");
const path = require('path');
function main() {
let filePath = path.join(__dirname, "..", "css", "devicon-colors.css");
fs.readFile(filePath, "utf8", (err, css) => {
if (err) {
console.log(err);
return;
}
let key = null;
let deviconColors = {};
css.split("\n").forEach(line => {
if (key) {
// since have key, now look for line
// that contains color: ###
if (line.match(/color: /)) {
deviconColors[key] = line.match(/#\w+/)[0];
key = null;
}
return;
}
if (line.match(/devicon/)) {
key = line.match(/-\w+/)[0].slice(1);
}
});
let deviconColorsFile = path.join(__dirname, "deviconColors.json");
fs.writeFile(deviconColorsFile, JSON.stringify(deviconColors), err => {
console.log(err ? err : "File successfully created");
})
});
}
main();

View File

@@ -1,74 +0,0 @@
const path = require("path");
const fs = require("fs");
/**
* Parse through the input.json and get all the
* svg files within the new folder(s) as listed.
* @param {{
* folderName: string,
* "originalSameAsPlain": boolean,
"color": string
}[]} input, an array of icon objects
*/
async function parseInput(input) {
let svgFontFilePaths = [];
let colors = [];
input.forEach(async iconObj => {
let {folderName, originalSameAsPlain, color} = iconObj;
colors.push(color);
// if original is same as plain (aka true), we use
// the original version. else, we use plain.
let allowedFontVers = [
parseInt(originalSameAsPlain) ? "original" : "plain",
"line",
];
await getFolderFontFiles(folderName, allowedFontVers, svgFontFilePaths)
})
return {
svgFontFilePaths,
colors
};
}
/**
* Get the eligible SVG files from the folder.
* @param {String} folderName, the name of the folder
* @param {String[]} allowedFontVers, an array of allowed
* font version. This makes sure that we only add the
* appropriate files to the svgFilePaths.
* @param {String[]} svgFilePaths, an array of filepaths
* to eligible svg files that can be used as fonts.
*/
async function getFolderFontFiles(folderName, allowedFontVers, svgFilePaths) {
// the new folder(s) must be in the icons folder
let folderPath = path.join(__dirname, "icons", folderName);
let dir = await new Promise((resolve, reject) => {
fs.opendir(folderPath, (err, dir) => {
if (err) reject(err);
else resolve(dir);
});
});
let dirEntry;
while (dirEntry = await dir.read()) {
// check if it's an SVG file
let entryName = dirEntry.name;
if (dirEntry.isFile() && entryName.match(/\.svg$/)) {
// check if it has the correct type to use as a font
if (allowedFontVers.some(allowedVer =>
entryName.match(new RegExp(allowedVer)))) {
svgFilePaths.push(path.join(folderPath, dirEntry.name));
}
}
}
}
module.exports = parseInput;