From 3a998b4598e551f398ba66c1c1d1be4b10db306e Mon Sep 17 00:00:00 2001 From: Wen Junhua Date: Mon, 25 Dec 2023 22:17:25 +0900 Subject: [PATCH 1/7] feat: add script to auto update icons --- scripts/update_icon.py | 127 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 scripts/update_icon.py diff --git a/scripts/update_icon.py b/scripts/update_icon.py new file mode 100644 index 00000000..a7159b06 --- /dev/null +++ b/scripts/update_icon.py @@ -0,0 +1,127 @@ +import argparse +import bs4 +import re +import logging +import requests +import os + +from typing import Tuple + + +DEFAULT_FONTAWESOME_VERSION = "v6.5.1" +DEFAULT_BASE_URL = ( + "https://site-assets.fontawesome.com/releases/%s/svgs/brands/" + % DEFAULT_FONTAWESOME_VERSION + + "%s.svg" +) +DEFAULT_ICON_PATH = os.path.join( + os.getcwd(), + "..", + "assets", + "icons", +) +DEFAULT_SVG_ATTR = {"fill": "currentColor"} + + +def download_icon(download_url: str) -> None: + """Downloads the icon based on the URL""" + with requests.Session() as s: + return s.get(download_url).content + + +def update_svg_to_theme(svg: bytes) -> bytes: + """Update the current color of SVG to match theme""" + soup = bs4.BeautifulSoup(svg, features="html.parser") + + # Update attrs + svg_elem = soup.find("svg").find("path") + for k, v in DEFAULT_SVG_ATTR.items(): + svg_elem[k] = v + + # Remove comments + return re.sub(r'','', str(soup)) + + + +def save_file(name: str, svg: str) -> None: + file_name = f"{name}.svg" + logging.debug(f"saving icon to {file_name}") + with open( + os.path.join( + DEFAULT_ICON_PATH, + file_name, + ), + "w", + ) as file: + file.write(svg) + + +def parse_args() -> Tuple[str, str, int]: + """ + Parse arguments. + Returns the following: + 1. Icon URL: str + 2. Icon Representation :str + 3. Log Level: int + """ + parser = argparse.ArgumentParser() + parser.add_argument( + "-v", + "--verbose", + help="show debug messages during script execution", + required=False, + default=False, + action="store_true", + ) + + parser.add_argument( + "-u", + "--url", + help="full url of the icon svg, defaults to fortawesome url", + required=False, + nargs=1, + ) + + parser.add_argument( + "name", + help="name of the icon to be added. EG: `github`", + ) + + parse_res = parser.parse_args() + url = DEFAULT_BASE_URL % parse_res.name + if parse_res.url is not None: + if len(parse_res.url) != 1: + raise ValueError("Invalid URL arguments. Use -h for help.") + url = parse_res.url[0] + + log_level = logging.DEBUG if parse_res.verbose else logging.INFO + return url, parse_res.name, log_level + + +if __name__ == "__main__": + icon_url, icon_name, log_level = parse_args() + + # Setup logging + logging.basicConfig( + level=log_level, + format="%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", + ) + logging.debug(f"Using default base URL: {DEFAULT_BASE_URL}") + logging.info(f"Using Log Level: {logging.getLevelName(log_level)}") + logging.info(f"Using URL: {icon_url}") + logging.info(f"Using Icon Name: {icon_name}") + + # Download Icon + logging.debug(f"fetching icon at {icon_url}") + svg_content = download_icon(icon_url) + + # Patch svg attrs + logging.debug(f"updating svg attrs") + final_svg = update_svg_to_theme(svg_content) + + # Save file + logging.debug("saving icon to assets") + save_file(icon_name, final_svg) + + # Write to docs (TODO) From eb527de54bb989bf1938dc09e402710f4594bc33 Mon Sep 17 00:00:00 2001 From: Wen Junhua Date: Mon, 25 Dec 2023 23:13:32 +0900 Subject: [PATCH 2/7] feat: add docs update --- scripts/update_icon.py | 63 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/scripts/update_icon.py b/scripts/update_icon.py index a7159b06..2b52319e 100644 --- a/scripts/update_icon.py +++ b/scripts/update_icon.py @@ -5,7 +5,7 @@ import logging import requests import os -from typing import Tuple +from typing import Tuple, List DEFAULT_FONTAWESOME_VERSION = "v6.5.1" @@ -14,13 +14,17 @@ DEFAULT_BASE_URL = ( % DEFAULT_FONTAWESOME_VERSION + "%s.svg" ) +DEFAULT_BASE_PATH = os.path.join(os.getcwd(), "..") DEFAULT_ICON_PATH = os.path.join( - os.getcwd(), - "..", + DEFAULT_BASE_PATH, "assets", "icons", ) DEFAULT_SVG_ATTR = {"fill": "currentColor"} +DEFAULT_ICON_DOCS = os.path.join( + DEFAULT_BASE_PATH, "exampleSite", "content", "samples", "icons" +) +DEFAULT_TABLE_DELIMITER = "| -------------------- | --------------------------------- |" def download_icon(download_url: str) -> None: @@ -39,9 +43,56 @@ def update_svg_to_theme(svg: bytes) -> bytes: svg_elem[k] = v # Remove comments - return re.sub(r'','', str(soup)) + return re.sub(r"", "", str(soup)) +def update_docs(icon_name: str) -> None: + """Update icon to docs""" + files = get_folder_md(DEFAULT_ICON_DOCS) + for file in files: + # Parse Table + logging.debug(f"reading {file}") + with open(file) as f: + file_data = f.read() + table_fmt, table = parse_table(file_data) + table.append(str(table[0]).replace("amazon", icon_name)) + + # Write Doc + print(table_fmt) + with open(file, "w") as f: + f.write( + "\n".join( + ( + table_fmt, + DEFAULT_TABLE_DELIMITER, + "\n".join(sorted(table)), + ) + ) + ) + + +def get_folder_md(dir_path: str) -> List[str]: + return list( + map( + lambda path: os.path.join(dir_path, path), + filter(lambda x: x.endswith(".md"), os.listdir(dir_path)), + ) + ) + + +def parse_table(table_str: str) -> Tuple[str, List[str]]: + """Parse the table to a list of (article_fmt, (icon_name, icon_shortcode))""" + headers, table = table_str.split(DEFAULT_TABLE_DELIMITER) + return headers.strip(), list( + filter( + lambda x: len(x.strip()) > 0, + map( + lambda x: x.strip(), + table.split("\n"), + ), + ) + ) + def save_file(name: str, svg: str) -> None: file_name = f"{name}.svg" @@ -125,3 +176,7 @@ if __name__ == "__main__": save_file(icon_name, final_svg) # Write to docs (TODO) + logging.debug("updating") + update_docs(icon_name) + + logging.info("done!") From 3c81e00bedd9463c64b358a28678f3ed5f44f892 Mon Sep 17 00:00:00 2001 From: Wen Junhua Date: Mon, 25 Dec 2023 23:17:40 +0900 Subject: [PATCH 3/7] chore: clean up code --- scripts/update_icon.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/update_icon.py b/scripts/update_icon.py index 2b52319e..ccb76877 100644 --- a/scripts/update_icon.py +++ b/scripts/update_icon.py @@ -15,7 +15,7 @@ DEFAULT_BASE_URL = ( + "%s.svg" ) DEFAULT_BASE_PATH = os.path.join(os.getcwd(), "..") -DEFAULT_ICON_PATH = os.path.join( +DEFAULT_ICON_DIR_PATH = os.path.join( DEFAULT_BASE_PATH, "assets", "icons", @@ -99,7 +99,7 @@ def save_file(name: str, svg: str) -> None: logging.debug(f"saving icon to {file_name}") with open( os.path.join( - DEFAULT_ICON_PATH, + DEFAULT_ICON_DIR_PATH, file_name, ), "w", @@ -141,8 +141,6 @@ def parse_args() -> Tuple[str, str, int]: parse_res = parser.parse_args() url = DEFAULT_BASE_URL % parse_res.name if parse_res.url is not None: - if len(parse_res.url) != 1: - raise ValueError("Invalid URL arguments. Use -h for help.") url = parse_res.url[0] log_level = logging.DEBUG if parse_res.verbose else logging.INFO @@ -175,7 +173,7 @@ if __name__ == "__main__": logging.debug("saving icon to assets") save_file(icon_name, final_svg) - # Write to docs (TODO) + # Write to docs logging.debug("updating") update_docs(icon_name) From db07288d0128a5504f680cd19e64430d44eb507d Mon Sep 17 00:00:00 2001 From: Wen Junhua Date: Mon, 25 Dec 2023 23:24:47 +0900 Subject: [PATCH 4/7] chore: clean up code --- scripts/update_icon.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/scripts/update_icon.py b/scripts/update_icon.py index ccb76877..22450a6f 100644 --- a/scripts/update_icon.py +++ b/scripts/update_icon.py @@ -21,7 +21,7 @@ DEFAULT_ICON_DIR_PATH = os.path.join( "icons", ) DEFAULT_SVG_ATTR = {"fill": "currentColor"} -DEFAULT_ICON_DOCS = os.path.join( +DEFAULT_ICON_DOCS_DIR = os.path.join( DEFAULT_BASE_PATH, "exampleSite", "content", "samples", "icons" ) DEFAULT_TABLE_DELIMITER = "| -------------------- | --------------------------------- |" @@ -48,7 +48,7 @@ def update_svg_to_theme(svg: bytes) -> bytes: def update_docs(icon_name: str) -> None: """Update icon to docs""" - files = get_folder_md(DEFAULT_ICON_DOCS) + files = get_folder_md(DEFAULT_ICON_DOCS_DIR) for file in files: # Parse Table logging.debug(f"reading {file}") @@ -58,7 +58,6 @@ def update_docs(icon_name: str) -> None: table.append(str(table[0]).replace("amazon", icon_name)) # Write Doc - print(table_fmt) with open(file, "w") as f: f.write( "\n".join( @@ -161,20 +160,25 @@ if __name__ == "__main__": logging.info(f"Using URL: {icon_url}") logging.info(f"Using Icon Name: {icon_name}") - # Download Icon - logging.debug(f"fetching icon at {icon_url}") - svg_content = download_icon(icon_url) + try: + # Download Icon + logging.debug(f"fetching icon at {icon_url}") + svg_content = download_icon(icon_url) - # Patch svg attrs - logging.debug(f"updating svg attrs") - final_svg = update_svg_to_theme(svg_content) + # Patch svg attrs + logging.debug( + f"remove svg comments and update svg attrs with {DEFAULT_SVG_ATTR}" + ) + final_svg = update_svg_to_theme(svg_content) - # Save file - logging.debug("saving icon to assets") - save_file(icon_name, final_svg) + # Save file + logging.debug(f"saving icon to {DEFAULT_ICON_DIR_PATH}") + save_file(icon_name, final_svg) - # Write to docs - logging.debug("updating") - update_docs(icon_name) - - logging.info("done!") + # Write to docs + logging.debug(f"updating docs from {DEFAULT_ICON_DOCS_DIR} dir") + update_docs(icon_name) + except Exception as e: + logging.critical(f"error adding icon {str(e)}") + else: + logging.info(f"{icon_name} added successfully") From 679898570c8c1d09c2e2312ca19ad1bc4201902b Mon Sep 17 00:00:00 2001 From: Wen Junhua Date: Mon, 25 Dec 2023 23:27:14 +0900 Subject: [PATCH 5/7] docs: update script docs --- scripts/update_icon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_icon.py b/scripts/update_icon.py index 22450a6f..24664101 100644 --- a/scripts/update_icon.py +++ b/scripts/update_icon.py @@ -114,7 +114,7 @@ def parse_args() -> Tuple[str, str, int]: 2. Icon Representation :str 3. Log Level: int """ - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser(description="This script adds an icon to this congo theme and updates the relevant documentation.") parser.add_argument( "-v", "--verbose", From 97a3f0064c5cc7ba7fad122171d40bcc9bdd1183 Mon Sep 17 00:00:00 2001 From: Wen Junhua Date: Sun, 31 Dec 2023 13:24:02 +0800 Subject: [PATCH 6/7] feat: port script to node --- package-lock.json | 743 ++++++++++++++++++++++++++++++++++++++++- package.json | 4 +- scripts/index.js | 11 + scripts/update_icon.js | 98 ++++++ scripts/update_icon.py | 184 ---------- 5 files changed, 841 insertions(+), 199 deletions(-) create mode 100644 scripts/index.js create mode 100644 scripts/update_icon.js delete mode 100644 scripts/update_icon.py diff --git a/package-lock.json b/package-lock.json index b9ff1cc0..4e00ef91 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@tailwindcss/typography": "^0.5.10", "chart.js": "^4.4.1", "fuse.js": "^7.0.0", + "jsdom": "^23.0.1", "katex": "^0.16.9", "mermaid": "^10.6.1", "prettier": "^3.1.1", @@ -233,6 +234,18 @@ "integrity": "sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==", "dev": true }, + "node_modules/agent-base": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz", + "integrity": "sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==", + "dev": true, + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/ansi-regex": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", @@ -282,6 +295,12 @@ "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==", "dev": true }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -406,6 +425,18 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "8.3.0", "resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz", @@ -456,6 +487,18 @@ "node": ">=4" } }, + "node_modules/cssstyle": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-3.0.0.tgz", + "integrity": "sha512-N4u2ABATi3Qplzf0hWbVCdjenim8F3ojEXpBDF5hBpjzW182MjNGLqfmQ0SkSPeQ+V86ZXgeH8aXj6kayd4jgg==", + "dev": true, + "dependencies": { + "rrweb-cssom": "^0.6.0" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/cytoscape": { "version": "3.23.0", "resolved": "https://registry.npmjs.org/cytoscape/-/cytoscape-3.23.0.tgz", @@ -968,6 +1011,19 @@ "lodash-es": "^4.17.21" } }, + "node_modules/data-urls": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", + "integrity": "sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==", + "dev": true, + "dependencies": { + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/dayjs": { "version": "1.11.7", "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.7.tgz", @@ -991,6 +1047,12 @@ } } }, + "node_modules/decimal.js": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz", + "integrity": "sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==", + "dev": true + }, "node_modules/decode-named-character-reference": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/decode-named-character-reference/-/decode-named-character-reference-1.0.2.tgz", @@ -1013,6 +1075,15 @@ "robust-predicates": "^3.0.0" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/dequal": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", @@ -1067,6 +1138,18 @@ "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", "dev": true }, + "node_modules/entities": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", + "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "dev": true, + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/fast-glob": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz", @@ -1132,6 +1215,20 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -1219,6 +1316,44 @@ "integrity": "sha512-2bsegYkkHO+h/9MGbn6KWcE45cHZgPANo5LXF7EvWdT0yT2EguSVO1nDgU5c8+ZOPwp2vMNa7YFsJhVcDR9Sdg==", "dev": true }, + "node_modules/html-encoding-sniffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-4.0.0.tgz", + "integrity": "sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==", + "dev": true, + "dependencies": { + "whatwg-encoding": "^3.1.1" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/http-proxy-agent": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.0.tgz", + "integrity": "sha512-+ZT+iBxVUQ1asugqnD6oWoRiS25AkjNfG085dKJGtGxkdwLQrMKU5wJr2bOOFAXzKcTuqq+7fZlTMgG3SRfIYQ==", + "dev": true, + "dependencies": { + "agent-base": "^7.1.0", + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/https-proxy-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.2.tgz", + "integrity": "sha512-NmLNjm6ucYwtcUmL7JQC1ZQ57LmHP4lT15FQ8D61nak1rO6DH+fz5qNK2Ap5UN4ZapYICE3/0KodcLYSPsPbaA==", + "dev": true, + "dependencies": { + "agent-base": "^7.0.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", @@ -1319,6 +1454,12 @@ "node": ">=0.12.0" } }, + "node_modules/is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==", + "dev": true + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -1359,6 +1500,46 @@ "dev": true, "peer": true }, + "node_modules/jsdom": { + "version": "23.0.1", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-23.0.1.tgz", + "integrity": "sha512-2i27vgvlUsGEBO9+/kJQRbtqtm+191b5zAZrU/UezVmnC2dlDAFLgDYJvAEi94T4kjsRKkezEtLQTgsNEsW2lQ==", + "dev": true, + "dependencies": { + "cssstyle": "^3.0.0", + "data-urls": "^5.0.0", + "decimal.js": "^10.4.3", + "form-data": "^4.0.0", + "html-encoding-sniffer": "^4.0.0", + "http-proxy-agent": "^7.0.0", + "https-proxy-agent": "^7.0.2", + "is-potential-custom-element-name": "^1.0.1", + "nwsapi": "^2.2.7", + "parse5": "^7.1.2", + "rrweb-cssom": "^0.6.0", + "saxes": "^6.0.0", + "symbol-tree": "^3.2.4", + "tough-cookie": "^4.1.3", + "w3c-xmlserializer": "^5.0.0", + "webidl-conversions": "^7.0.0", + "whatwg-encoding": "^3.1.1", + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0", + "ws": "^8.14.2", + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "canvas": "^2.11.2" + }, + "peerDependenciesMeta": { + "canvas": { + "optional": true + } + } + }, "node_modules/katex": { "version": "0.16.9", "resolved": "https://registry.npmjs.org/katex/-/katex-0.16.9.tgz", @@ -1993,6 +2174,27 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "9.0.3", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", @@ -2044,9 +2246,9 @@ } }, "node_modules/nanoid": { - "version": "3.3.6", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", - "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", + "version": "3.3.7", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", + "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", "dev": true, "funding": [ { @@ -2085,6 +2287,12 @@ "node": ">=0.10.0" } }, + "node_modules/nwsapi": { + "version": "2.2.7", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.7.tgz", + "integrity": "sha512-ub5E4+FBPKwAZx0UwIQOjYWGHTEq5sPqHQNRN8Z9e4A7u3Tj1weLJsL59yH9vmvqEtBHaOmT6cYQKIZOxp35FQ==", + "dev": true + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -2112,6 +2320,18 @@ "wrappy": "1" } }, + "node_modules/parse5": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.1.2.tgz", + "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==", + "dev": true, + "dependencies": { + "entities": "^4.4.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, "node_modules/path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", @@ -2189,9 +2409,9 @@ } }, "node_modules/postcss": { - "version": "8.4.23", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.23.tgz", - "integrity": "sha512-bQ3qMcpF6A/YjR55xtoTr0jGOlnPOKAIMdOWiv0EIT6HVPEaJiJB4NLljSbiHoC2RX7DN5Uvjtpbg1NPdwv1oA==", + "version": "8.4.32", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.32.tgz", + "integrity": "sha512-D/kj5JNu6oo2EIy+XL/26JEDTlIbB8hw85G8StOE6L74RQAVVP5rej6wxCNqyMbR4RkPfqvezVbPw81Ngd6Kcw==", "dev": true, "funding": [ { @@ -2208,7 +2428,7 @@ } ], "dependencies": { - "nanoid": "^3.3.6", + "nanoid": "^3.3.7", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" }, @@ -2443,6 +2663,27 @@ "react-is": "^16.13.1" } }, + "node_modules/psl": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", + "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==", + "dev": true + }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/querystringify": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==", + "dev": true + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -2545,6 +2786,12 @@ "node": ">=6" } }, + "node_modules/requires-port": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", + "dev": true + }, "node_modules/resolve": { "version": "1.22.2", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.2.tgz", @@ -2608,6 +2855,12 @@ "node": ">= 6" } }, + "node_modules/rrweb-cssom": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.6.0.tgz", + "integrity": "sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==", + "dev": true + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -2655,6 +2908,18 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, + "node_modules/saxes": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", + "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "dev": true, + "dependencies": { + "xmlchars": "^2.2.0" + }, + "engines": { + "node": ">=v12.22.7" + } + }, "node_modules/scheduler": { "version": "0.19.1", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.19.1.tgz", @@ -2895,6 +3160,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/symbol-tree": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", + "dev": true + }, "node_modules/tailwindcss": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.0.tgz", @@ -2987,6 +3258,33 @@ "node": ">=8.0" } }, + "node_modules/tough-cookie": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz", + "integrity": "sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==", + "dev": true, + "dependencies": { + "psl": "^1.1.33", + "punycode": "^2.1.1", + "universalify": "^0.2.0", + "url-parse": "^1.5.3" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/tr46": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.0.0.tgz", + "integrity": "sha512-tk2G5R2KRwBd+ZN0zaEXpmzdKyOYksXwywulIX95MBODjSzMIuQnQ3m8JxgbhnL1LeVo7lqQKsYa1O3Htl7K5g==", + "dev": true, + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/ts-dedent": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/ts-dedent/-/ts-dedent-2.2.0.tgz", @@ -3024,6 +3322,25 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/universalify": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz", + "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==", + "dev": true, + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/url-parse": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", + "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "dev": true, + "dependencies": { + "querystringify": "^2.1.1", + "requires-port": "^1.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -3072,12 +3389,67 @@ "node": ">=12" } }, + "node_modules/w3c-xmlserializer": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", + "integrity": "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==", + "dev": true, + "dependencies": { + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/web-worker": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.2.0.tgz", "integrity": "sha512-PgF341avzqyx60neE9DD+XS26MMNMoUQRz9NOZwW32nPQrF6p77f1htcnjBSEV8BGMKZ16choqUG4hyI0Hx7mA==", "dev": true }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "dev": true, + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-encoding": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", + "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==", + "dev": true, + "dependencies": { + "iconv-lite": "0.6.3" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-mimetype": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", + "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", + "dev": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-url": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.0.0.tgz", + "integrity": "sha512-1lfMEm2IEr7RIV+f4lUNPOqfFL+pO+Xw3fJSqmjX9AbXcXcYOkCe1P6+9VBZB6n94af16NfZf+sSk0JCBZC9aw==", + "dev": true, + "dependencies": { + "tr46": "^5.0.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -3190,6 +3562,42 @@ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "dev": true }, + "node_modules/ws": { + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz", + "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==", + "dev": true, + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/xml-name-validator": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", + "integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==", + "dev": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", + "dev": true + }, "node_modules/yaml": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.2.2.tgz", @@ -3376,6 +3784,15 @@ "integrity": "sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==", "dev": true }, + "agent-base": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz", + "integrity": "sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==", + "dev": true, + "requires": { + "debug": "^4.3.4" + } + }, "ansi-regex": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", @@ -3410,6 +3827,12 @@ "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==", "dev": true }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true + }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -3503,6 +3926,15 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, "commander": { "version": "8.3.0", "resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz", @@ -3541,6 +3973,15 @@ "integrity": "sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==", "dev": true }, + "cssstyle": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-3.0.0.tgz", + "integrity": "sha512-N4u2ABATi3Qplzf0hWbVCdjenim8F3ojEXpBDF5hBpjzW182MjNGLqfmQ0SkSPeQ+V86ZXgeH8aXj6kayd4jgg==", + "dev": true, + "requires": { + "rrweb-cssom": "^0.6.0" + } + }, "cytoscape": { "version": "3.23.0", "resolved": "https://registry.npmjs.org/cytoscape/-/cytoscape-3.23.0.tgz", @@ -3940,6 +4381,16 @@ "lodash-es": "^4.17.21" } }, + "data-urls": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", + "integrity": "sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==", + "dev": true, + "requires": { + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0" + } + }, "dayjs": { "version": "1.11.7", "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.7.tgz", @@ -3955,6 +4406,12 @@ "ms": "2.1.2" } }, + "decimal.js": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz", + "integrity": "sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==", + "dev": true + }, "decode-named-character-reference": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/decode-named-character-reference/-/decode-named-character-reference-1.0.2.tgz", @@ -3973,6 +4430,12 @@ "robust-predicates": "^3.0.0" } }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true + }, "dequal": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", @@ -4021,6 +4484,12 @@ "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", "dev": true }, + "entities": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", + "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "dev": true + }, "fast-glob": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz", @@ -4073,6 +4542,17 @@ "signal-exit": "^4.0.1" } }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -4135,6 +4615,35 @@ "integrity": "sha512-2bsegYkkHO+h/9MGbn6KWcE45cHZgPANo5LXF7EvWdT0yT2EguSVO1nDgU5c8+ZOPwp2vMNa7YFsJhVcDR9Sdg==", "dev": true }, + "html-encoding-sniffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-4.0.0.tgz", + "integrity": "sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==", + "dev": true, + "requires": { + "whatwg-encoding": "^3.1.1" + } + }, + "http-proxy-agent": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.0.tgz", + "integrity": "sha512-+ZT+iBxVUQ1asugqnD6oWoRiS25AkjNfG085dKJGtGxkdwLQrMKU5wJr2bOOFAXzKcTuqq+7fZlTMgG3SRfIYQ==", + "dev": true, + "requires": { + "agent-base": "^7.1.0", + "debug": "^4.3.4" + } + }, + "https-proxy-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.2.tgz", + "integrity": "sha512-NmLNjm6ucYwtcUmL7JQC1ZQ57LmHP4lT15FQ8D61nak1rO6DH+fz5qNK2Ap5UN4ZapYICE3/0KodcLYSPsPbaA==", + "dev": true, + "requires": { + "agent-base": "^7.0.2", + "debug": "4" + } + }, "iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", @@ -4211,6 +4720,12 @@ "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", "dev": true }, + "is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==", + "dev": true + }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -4240,6 +4755,35 @@ "dev": true, "peer": true }, + "jsdom": { + "version": "23.0.1", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-23.0.1.tgz", + "integrity": "sha512-2i27vgvlUsGEBO9+/kJQRbtqtm+191b5zAZrU/UezVmnC2dlDAFLgDYJvAEi94T4kjsRKkezEtLQTgsNEsW2lQ==", + "dev": true, + "requires": { + "cssstyle": "^3.0.0", + "data-urls": "^5.0.0", + "decimal.js": "^10.4.3", + "form-data": "^4.0.0", + "html-encoding-sniffer": "^4.0.0", + "http-proxy-agent": "^7.0.0", + "https-proxy-agent": "^7.0.2", + "is-potential-custom-element-name": "^1.0.1", + "nwsapi": "^2.2.7", + "parse5": "^7.1.2", + "rrweb-cssom": "^0.6.0", + "saxes": "^6.0.0", + "symbol-tree": "^3.2.4", + "tough-cookie": "^4.1.3", + "w3c-xmlserializer": "^5.0.0", + "webidl-conversions": "^7.0.0", + "whatwg-encoding": "^3.1.1", + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0", + "ws": "^8.14.2", + "xml-name-validator": "^5.0.0" + } + }, "katex": { "version": "0.16.9", "resolved": "https://registry.npmjs.org/katex/-/katex-0.16.9.tgz", @@ -4631,6 +5175,21 @@ "picomatch": "^2.3.1" } }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, + "requires": { + "mime-db": "1.52.0" + } + }, "minimatch": { "version": "9.0.3", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", @@ -4670,9 +5229,9 @@ } }, "nanoid": { - "version": "3.3.6", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", - "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", + "version": "3.3.7", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", + "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", "dev": true }, "ncp": { @@ -4693,6 +5252,12 @@ "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", "dev": true }, + "nwsapi": { + "version": "2.2.7", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.7.tgz", + "integrity": "sha512-ub5E4+FBPKwAZx0UwIQOjYWGHTEq5sPqHQNRN8Z9e4A7u3Tj1weLJsL59yH9vmvqEtBHaOmT6cYQKIZOxp35FQ==", + "dev": true + }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -4714,6 +5279,15 @@ "wrappy": "1" } }, + "parse5": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.1.2.tgz", + "integrity": "sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==", + "dev": true, + "requires": { + "entities": "^4.4.0" + } + }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", @@ -4767,12 +5341,12 @@ "dev": true }, "postcss": { - "version": "8.4.23", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.23.tgz", - "integrity": "sha512-bQ3qMcpF6A/YjR55xtoTr0jGOlnPOKAIMdOWiv0EIT6HVPEaJiJB4NLljSbiHoC2RX7DN5Uvjtpbg1NPdwv1oA==", + "version": "8.4.32", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.32.tgz", + "integrity": "sha512-D/kj5JNu6oo2EIy+XL/26JEDTlIbB8hw85G8StOE6L74RQAVVP5rej6wxCNqyMbR4RkPfqvezVbPw81Ngd6Kcw==", "dev": true, "requires": { - "nanoid": "^3.3.6", + "nanoid": "^3.3.7", "picocolors": "^1.0.0", "source-map-js": "^1.0.2" } @@ -4878,6 +5452,24 @@ "react-is": "^16.13.1" } }, + "psl": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", + "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==", + "dev": true + }, + "punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true + }, + "querystringify": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==", + "dev": true + }, "queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -4950,6 +5542,12 @@ "integrity": "sha512-6IQpFBv6e5vz1QAqI+V4k8P2e/3gRrqfCJ9FI+O1FLQTO+Uz6RXZEZOPmTJ6hlGj7gkERzY5BRCv09whKP96/g==", "dev": true }, + "requires-port": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", + "dev": true + }, "resolve": { "version": "1.22.2", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.2.tgz", @@ -4991,6 +5589,12 @@ "regexparam": "^1.3.0" } }, + "rrweb-cssom": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.6.0.tgz", + "integrity": "sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==", + "dev": true + }, "run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -5021,6 +5625,15 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, + "saxes": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", + "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "dev": true, + "requires": { + "xmlchars": "^2.2.0" + } + }, "scheduler": { "version": "0.19.1", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.19.1.tgz", @@ -5198,6 +5811,12 @@ "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", "dev": true }, + "symbol-tree": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", + "dev": true + }, "tailwindcss": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.0.tgz", @@ -5273,6 +5892,27 @@ "is-number": "^7.0.0" } }, + "tough-cookie": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz", + "integrity": "sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==", + "dev": true, + "requires": { + "psl": "^1.1.33", + "punycode": "^2.1.1", + "universalify": "^0.2.0", + "url-parse": "^1.5.3" + } + }, + "tr46": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.0.0.tgz", + "integrity": "sha512-tk2G5R2KRwBd+ZN0zaEXpmzdKyOYksXwywulIX95MBODjSzMIuQnQ3m8JxgbhnL1LeVo7lqQKsYa1O3Htl7K5g==", + "dev": true, + "requires": { + "punycode": "^2.3.1" + } + }, "ts-dedent": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/ts-dedent/-/ts-dedent-2.2.0.tgz", @@ -5300,6 +5940,22 @@ "@types/unist": "^2.0.0" } }, + "universalify": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz", + "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==", + "dev": true + }, + "url-parse": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", + "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "dev": true, + "requires": { + "querystringify": "^2.1.1", + "requires-port": "^1.0.0" + } + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -5333,12 +5989,52 @@ "ncp": "^2.0.0" } }, + "w3c-xmlserializer": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", + "integrity": "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==", + "dev": true, + "requires": { + "xml-name-validator": "^5.0.0" + } + }, "web-worker": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.2.0.tgz", "integrity": "sha512-PgF341avzqyx60neE9DD+XS26MMNMoUQRz9NOZwW32nPQrF6p77f1htcnjBSEV8BGMKZ16choqUG4hyI0Hx7mA==", "dev": true }, + "webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "dev": true + }, + "whatwg-encoding": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", + "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==", + "dev": true, + "requires": { + "iconv-lite": "0.6.3" + } + }, + "whatwg-mimetype": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", + "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", + "dev": true + }, + "whatwg-url": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.0.0.tgz", + "integrity": "sha512-1lfMEm2IEr7RIV+f4lUNPOqfFL+pO+Xw3fJSqmjX9AbXcXcYOkCe1P6+9VBZB6n94af16NfZf+sSk0JCBZC9aw==", + "dev": true, + "requires": { + "tr46": "^5.0.0", + "webidl-conversions": "^7.0.0" + } + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -5419,6 +6115,25 @@ "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "dev": true }, + "ws": { + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz", + "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==", + "dev": true, + "requires": {} + }, + "xml-name-validator": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", + "integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==", + "dev": true + }, + "xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", + "dev": true + }, "yaml": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.2.2.tgz", diff --git a/package.json b/package.json index 14199a2d..ce6e01c4 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "dev": "NODE_ENV=development ./node_modules/tailwindcss/lib/cli.js -i ./assets/css/main.css -o ./assets/css/compiled/main.css --jit -w", "build": "NODE_ENV=production ./node_modules/tailwindcss/lib/cli.js -i ./assets/css/main.css -o ./assets/css/compiled/main.css --jit", "example": "hugo server --bind 0.0.0.0 -p 8008 --source exampleSite --themesDir ../.. --buildDrafts -b http://localhost/congo/ ", - "lighthouse": "lhci autorun" + "lighthouse": "lhci autorun", + "add-icon": "node scripts/index.js add-icon" }, "repository": { "type": "git", @@ -32,6 +33,7 @@ "@tailwindcss/typography": "^0.5.10", "chart.js": "^4.4.1", "fuse.js": "^7.0.0", + "jsdom": "^23.0.1", "katex": "^0.16.9", "mermaid": "^10.6.1", "prettier": "^3.1.1", diff --git a/scripts/index.js b/scripts/index.js new file mode 100644 index 00000000..a22fb4ae --- /dev/null +++ b/scripts/index.js @@ -0,0 +1,11 @@ +#!/usr/bin/env node +const { program } = require("commander"); +const { add_icon_to_congo } = require("./update_icon"); + +// Adds an icon to the project. +program + .command("add-icon ") + .description("Add icon to the project") + .action(add_icon_to_congo); + +program.parse(process.argv); diff --git a/scripts/update_icon.js b/scripts/update_icon.js new file mode 100644 index 00000000..fe64f3c7 --- /dev/null +++ b/scripts/update_icon.js @@ -0,0 +1,98 @@ +const jsdom = require("jsdom"); +const fs = require("fs"); + +const DOC_DIR = "./exampleSite/content/samples/icons"; +const FONTAWESOME_VERSION = "v6.5.1"; +const DEFAULT_TABLE_DELIMITER = "| -------------------- | --------------------------------- |"; + +/** + * Saves an icon to the congo project and update documentation. + * @param {string} icon_name Icon name from Font Awesome to download + * @returns null + */ +const add_icon_to_congo = async (icon_name) => { + try { + const icon_url = create_icon_url(icon_name, FONTAWESOME_VERSION); + const file = await get_file(icon_url); + const final_svg = modify_svg_string(file); + const icon_download_path = create_icon_download_path(icon_name); + save_file(icon_download_path, final_svg); + add_documentation(icon_name); + } catch (e) { + console.log(e); + return; + } +}; + +const modify_svg_string = (svg_string) => { + try { + dom = new jsdom.JSDOM(svg_string); + svg = dom.window.document.documentElement.querySelector("svg"); + svg.querySelector("path").setAttribute("fill", "currentColor"); + return svg.outerHTML; + } catch (e) { + throw new Error("Invalid SVG file"); + } +}; + +const create_icon_url = (icon_name, fontawesome_version) => { + return `https://site-assets.fontawesome.com/releases/${fontawesome_version}/svgs/brands/${icon_name}.svg`; +}; + +const create_icon_download_path = (icon_name) => { + return `./assets/icons/${icon_name}.svg`; +}; + +const get_file = async (url) => { + console.log("Getting file at " + url + "..."); + const response = await fetch(url); + if (response.status >= 400) { + throw new Error("Could not download icon / icon not found"); + } + return response.text(); +}; + +const save_file = (file_path, file) => { + console.log("Saving file at " + file_path + "..."); + fs.writeFile(file_path, file, function (err) { + if (err) throw err; + console.log("File saved!"); + }); +}; + +const add_documentation = async (icon_name) => { + files = get_md_docs(); + + for (const file of files) { + const file_path = `${DOC_DIR}/${file}`; + const file_contents = fs.readFileSync(file_path, "utf8"); + const file_result = process_file(file_contents, icon_name); + console.log(file_result); + // Save file_result to file_path + fs.writeFile(file_path, file_result, function (err) { + if (err) throw err; + }); + console.log(`Updated ${file_path}`); + } +}; + +/** + * Process the file contents to include the icon name. + * @param {string} file_contents contents of the documentation files. + * @returns {string} processed file contents. + */ +const process_file = (file_contents, icon_name) => { + const [headers, table] = file_contents.split(DEFAULT_TABLE_DELIMITER); + const table_rows = table.split("\n").map((x) => x.trim()).filter((row) => row !== ""); + console.log(table_rows); + table_rows.push(table_rows[0].replace("amazon", icon_name)); + table_rows.sort(); + const new_table = table_rows.join("\n"); + return `${headers.trimEnd()}\n${DEFAULT_TABLE_DELIMITER}\n${new_table}\n`; +}; + +const get_md_docs = () => { + return fs.readdirSync(DOC_DIR).filter((file) => file.endsWith(".md")); +}; + +module.exports = { add_icon_to_congo }; diff --git a/scripts/update_icon.py b/scripts/update_icon.py deleted file mode 100644 index 24664101..00000000 --- a/scripts/update_icon.py +++ /dev/null @@ -1,184 +0,0 @@ -import argparse -import bs4 -import re -import logging -import requests -import os - -from typing import Tuple, List - - -DEFAULT_FONTAWESOME_VERSION = "v6.5.1" -DEFAULT_BASE_URL = ( - "https://site-assets.fontawesome.com/releases/%s/svgs/brands/" - % DEFAULT_FONTAWESOME_VERSION - + "%s.svg" -) -DEFAULT_BASE_PATH = os.path.join(os.getcwd(), "..") -DEFAULT_ICON_DIR_PATH = os.path.join( - DEFAULT_BASE_PATH, - "assets", - "icons", -) -DEFAULT_SVG_ATTR = {"fill": "currentColor"} -DEFAULT_ICON_DOCS_DIR = os.path.join( - DEFAULT_BASE_PATH, "exampleSite", "content", "samples", "icons" -) -DEFAULT_TABLE_DELIMITER = "| -------------------- | --------------------------------- |" - - -def download_icon(download_url: str) -> None: - """Downloads the icon based on the URL""" - with requests.Session() as s: - return s.get(download_url).content - - -def update_svg_to_theme(svg: bytes) -> bytes: - """Update the current color of SVG to match theme""" - soup = bs4.BeautifulSoup(svg, features="html.parser") - - # Update attrs - svg_elem = soup.find("svg").find("path") - for k, v in DEFAULT_SVG_ATTR.items(): - svg_elem[k] = v - - # Remove comments - return re.sub(r"", "", str(soup)) - - -def update_docs(icon_name: str) -> None: - """Update icon to docs""" - files = get_folder_md(DEFAULT_ICON_DOCS_DIR) - for file in files: - # Parse Table - logging.debug(f"reading {file}") - with open(file) as f: - file_data = f.read() - table_fmt, table = parse_table(file_data) - table.append(str(table[0]).replace("amazon", icon_name)) - - # Write Doc - with open(file, "w") as f: - f.write( - "\n".join( - ( - table_fmt, - DEFAULT_TABLE_DELIMITER, - "\n".join(sorted(table)), - ) - ) - ) - - -def get_folder_md(dir_path: str) -> List[str]: - return list( - map( - lambda path: os.path.join(dir_path, path), - filter(lambda x: x.endswith(".md"), os.listdir(dir_path)), - ) - ) - - -def parse_table(table_str: str) -> Tuple[str, List[str]]: - """Parse the table to a list of (article_fmt, (icon_name, icon_shortcode))""" - headers, table = table_str.split(DEFAULT_TABLE_DELIMITER) - return headers.strip(), list( - filter( - lambda x: len(x.strip()) > 0, - map( - lambda x: x.strip(), - table.split("\n"), - ), - ) - ) - - -def save_file(name: str, svg: str) -> None: - file_name = f"{name}.svg" - logging.debug(f"saving icon to {file_name}") - with open( - os.path.join( - DEFAULT_ICON_DIR_PATH, - file_name, - ), - "w", - ) as file: - file.write(svg) - - -def parse_args() -> Tuple[str, str, int]: - """ - Parse arguments. - Returns the following: - 1. Icon URL: str - 2. Icon Representation :str - 3. Log Level: int - """ - parser = argparse.ArgumentParser(description="This script adds an icon to this congo theme and updates the relevant documentation.") - parser.add_argument( - "-v", - "--verbose", - help="show debug messages during script execution", - required=False, - default=False, - action="store_true", - ) - - parser.add_argument( - "-u", - "--url", - help="full url of the icon svg, defaults to fortawesome url", - required=False, - nargs=1, - ) - - parser.add_argument( - "name", - help="name of the icon to be added. EG: `github`", - ) - - parse_res = parser.parse_args() - url = DEFAULT_BASE_URL % parse_res.name - if parse_res.url is not None: - url = parse_res.url[0] - - log_level = logging.DEBUG if parse_res.verbose else logging.INFO - return url, parse_res.name, log_level - - -if __name__ == "__main__": - icon_url, icon_name, log_level = parse_args() - - # Setup logging - logging.basicConfig( - level=log_level, - format="%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s", - datefmt="%Y-%m-%d %H:%M:%S", - ) - logging.debug(f"Using default base URL: {DEFAULT_BASE_URL}") - logging.info(f"Using Log Level: {logging.getLevelName(log_level)}") - logging.info(f"Using URL: {icon_url}") - logging.info(f"Using Icon Name: {icon_name}") - - try: - # Download Icon - logging.debug(f"fetching icon at {icon_url}") - svg_content = download_icon(icon_url) - - # Patch svg attrs - logging.debug( - f"remove svg comments and update svg attrs with {DEFAULT_SVG_ATTR}" - ) - final_svg = update_svg_to_theme(svg_content) - - # Save file - logging.debug(f"saving icon to {DEFAULT_ICON_DIR_PATH}") - save_file(icon_name, final_svg) - - # Write to docs - logging.debug(f"updating docs from {DEFAULT_ICON_DOCS_DIR} dir") - update_docs(icon_name) - except Exception as e: - logging.critical(f"error adding icon {str(e)}") - else: - logging.info(f"{icon_name} added successfully") From 2cf1371c3e60530089e2f31191d2f13451ca6c5e Mon Sep 17 00:00:00 2001 From: Wen Junhua Date: Sun, 31 Dec 2023 13:26:09 +0800 Subject: [PATCH 7/7] fix: remove debug logs --- scripts/update_icon.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/update_icon.js b/scripts/update_icon.js index fe64f3c7..2dbe43be 100644 --- a/scripts/update_icon.js +++ b/scripts/update_icon.js @@ -49,6 +49,7 @@ const get_file = async (url) => { if (response.status >= 400) { throw new Error("Could not download icon / icon not found"); } + console.log("File retrieved!"); return response.text(); }; @@ -67,7 +68,6 @@ const add_documentation = async (icon_name) => { const file_path = `${DOC_DIR}/${file}`; const file_contents = fs.readFileSync(file_path, "utf8"); const file_result = process_file(file_contents, icon_name); - console.log(file_result); // Save file_result to file_path fs.writeFile(file_path, file_result, function (err) { if (err) throw err; @@ -84,7 +84,6 @@ const add_documentation = async (icon_name) => { const process_file = (file_contents, icon_name) => { const [headers, table] = file_contents.split(DEFAULT_TABLE_DELIMITER); const table_rows = table.split("\n").map((x) => x.trim()).filter((row) => row !== ""); - console.log(table_rows); table_rows.push(table_rows[0].replace("amazon", icon_name)); table_rows.sort(); const new_table = table_rows.join("\n");