diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..eae764c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +repos: + - repo: https://github.com/prettier/prettier + # Use old version until https://github.com/prettier/prettier/issues/4637 is fixed + rev: 1.12.1 + hooks: + - id: prettier + - repo: https://github.com/ambv/black + rev: stable + hooks: + - id: black + language_version: python3.6 diff --git a/package.json b/package.json index cab0cfb..e112576 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "name": "fonticon", "version": "1.0.0", - "description": "Tool for creating favicons and images from [Font Awesome](http://fontawesome.io/) icons. The generated icon can be previewed live in the browser.", + "description": + "Tool for creating favicons and images from [Font Awesome](http://fontawesome.io/) icons. The generated icon can be previewed live in the browser.", "private": true, "directories": { "lib": "src", @@ -12,18 +13,13 @@ "build": "webpack --display-modules", "start:dev": "webpack-dev-server", "build:prod": "webpack --display-modules --mode=production", - "precommit": "pretty-quick --staged" + "postinstall": "pip install pre-commit && pre-commit install" }, "repository": { "type": "git", "url": "git+https://github.com/devgg/fonticon.git" }, - "keywords": [ - "favicon", - "Font Awesome", - "icon", - "fonticon" - ], + "keywords": ["favicon", "Font Awesome", "icon", "fonticon"], "author": "Florian Gauger", "license": "MIT", "bugs": { @@ -35,9 +31,6 @@ "css-loader": "^0.28.11", "file-loader": "^1.1.11", "html-webpack-plugin": "^3.2.0", - "husky": "^0.14.3", - "prettier": "^1.13.7", - "pretty-quick": "^1.6.0", "style-loader": "^0.21.0", "uglifyjs-webpack-plugin": "^1.2.7", "webpack": "^4.12.1", diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..55ec8d7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.black] +line-length = 120 diff --git a/util/import_icon_data.py b/util/import_icon_data.py index 45ca581..5a4f90d 100644 --- a/util/import_icon_data.py +++ b/util/import_icon_data.py @@ -9,8 +9,11 @@ import tempfile from PIL import ImageFont -css_url = 'https://use.fontawesome.com/releases/v5.1.0/css/all.css' -icons_json_url = 'https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/advanced-options/metadata/icons.json' +css_url = "https://use.fontawesome.com/releases/v5.1.0/css/all.css" +icons_json_url = ( + "https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/advanced-options/metadata/icons.json" +) + def load_fonts(css_url): with urllib.request.urlopen(css_url) as url: @@ -20,36 +23,38 @@ def load_fonts(css_url): font_solid = None font_regular = None for rule in rules: - if rule.type == 'at-rule' and rule.at_keyword == 'font-face': + if rule.type == "at-rule" and rule.at_keyword == "font-face": for component in rule.content: - if component.type == 'url' and component.value.endswith('.woff'): + if component.type == "url" and component.value.endswith(".woff"): font_url = urllib.parse.urljoin(css_url, component.value) fd = urllib.request.urlopen(font_url) font = fd.read() - if 'fa-solid-900' in component.value: + if "fa-solid-900" in component.value: font_solid = font - elif 'fa-regular-400' in component.value: + elif "fa-regular-400" in component.value: font_regular = font else: - print('Warning font "{0}" found in import but unused.'.format(font_url)); + print('Warning font "{0}" found in import but unused.'.format(font_url)) if font_solid == None or font_regular == None: - print('Error one of the required fonts was not found') + print("Error one of the required fonts was not found") sys.exit() return (font_solid, font_regular) + font_solid, font_regular = load_fonts(css_url) + def get_style(style): - if style == 'solid': - return ('fas', font_solid_path) - elif style == 'regular': - return ('far', font_regular_path) + if style == "solid": + return ("fas", font_solid_path) + elif style == "regular": + return ("far", font_regular_path) else: - print('Warning: style {0} unkown.'.format(style)) + print("Warning: style {0} unkown.".format(style)) def get_max_size(font, icon): - font_size = 1200; + font_size = 1200 max_size = 1024 width = max_size + 1 height = max_size + 1 @@ -67,12 +72,13 @@ def get_max_size(font, icon): width, height = f.getsize(icon) return font_size + with tempfile.TemporaryDirectory() as tmp_dir: - font_solid_path = tmp_dir + 'solid.woff' - with open(font_solid_path, 'wb') as output: + font_solid_path = tmp_dir + "solid.woff" + with open(font_solid_path, "wb") as output: output.write(font_solid) - font_regular_path = tmp_dir + 'regular.woff' - with open(font_regular_path, 'wb') as output: + font_regular_path = tmp_dir + "regular.woff" + with open(font_regular_path, "wb") as output: output.write(font_regular) with urllib.request.urlopen(icons_json_url) as url: @@ -81,27 +87,21 @@ with tempfile.TemporaryDirectory() as tmp_dir: result = [] idx = 0 for i, (icon_name, icon) in enumerate(icons_json.items()): - if icon_name != 'font-awesome-logo-full': - for style in icon['styles']: - if style != 'brands': + if icon_name != "font-awesome-logo-full": + for style in icon["styles"]: + if style != "brands": style, font = get_style(style) font - uni = ('\\u' + icon['unicode']).encode().decode('unicode-escape') - result_icon = { - 'ix': idx, - 'id': icon_name, - 'st': style, - 'uc': uni, - 'si': get_max_size(font, uni), - } - search_terms = icon['search']['terms'] + uni = ("\\u" + icon["unicode"]).encode().decode("unicode-escape") + result_icon = {"ix": idx, "id": icon_name, "st": style, "uc": uni, "si": get_max_size(font, uni)} + search_terms = icon["search"]["terms"] if search_terms: - result_icon['se'] = search_terms + result_icon["se"] = search_terms result.append(result_icon) idx += 1 - print('{0}/{1} icons processed.'.format(i + 1, len(icons_json)), end="\r") + print("{0}/{1} icons processed.".format(i + 1, len(icons_json)), end="\r") - js_icons = 'export default ' + json.dumps(result, separators=(',', ':')) + js_icons = "export default " + json.dumps(result, separators=(",", ":")) - with open('src/js/generated/icons.js', 'w') as f: + with open("src/js/generated/icons.js", "w") as f: f.write(js_icons)