From 575ff876aac1381d9802a07e9718e8a1a8c0b12c Mon Sep 17 00:00:00 2001 From: Nikita Semenov Date: Sun, 26 Mar 2023 21:11:04 +0300 Subject: [PATCH] feat: general docs api --- .../Contents.swift | 2 + docs/api_doc.md | 7 ++ docs/tiuielements/placeholder.md | 2 + project-scripts/gen_api_doc.py | 73 +++++++++++++++++++ project-scripts/gen_docs_from_playgrounds.sh | 23 ++++-- 5 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 docs/api_doc.md create mode 100644 project-scripts/gen_api_doc.py diff --git a/TIUIElements/TIUIElements.app/Contents/MacOS/TIUIElements.playground/Pages/Placeholder.xcplaygroundpage/Contents.swift b/TIUIElements/TIUIElements.app/Contents/MacOS/TIUIElements.playground/Pages/Placeholder.xcplaygroundpage/Contents.swift index 4257d98c..132a48dc 100644 --- a/TIUIElements/TIUIElements.app/Contents/MacOS/TIUIElements.playground/Pages/Placeholder.xcplaygroundpage/Contents.swift +++ b/TIUIElements/TIUIElements.app/Contents/MacOS/TIUIElements.playground/Pages/Placeholder.xcplaygroundpage/Contents.swift @@ -392,3 +392,5 @@ placeholder.configure(with: .internetConnection) } ``` */ + +//: #### Others DefaultPlaceholderView diff --git a/docs/api_doc.md b/docs/api_doc.md new file mode 100644 index 00000000..c1235cf9 --- /dev/null +++ b/docs/api_doc.md @@ -0,0 +1,7 @@ +| Element Type | TI library name | Element Name | Example | Pull Request | Documentation | +| --- | --- | --- | --- | --- | --- | +| Button like elements | TIUIElements | RoundedStatefulButton | https://www.figma.com/file/90eBL1wq2By6z9ZrsBRpoR/iOS.Components?node-id=1-1608 | https://github.com/TouchInstinct/LeadKit/pull/342#issue-1583753852 | Doc is missing | +| Text like elements | TIUIElements | DefaultTitleSubtitleView | https://www.figma.com/file/90eBL1wq2By6z9ZrsBRpoR/iOS.Components?t=6YvNHHIicnvyFsB6-0 | https://github.com/TouchInstinct/LeadKit/pull/342#issue-1583753852 | Doc is missing | +| Others | TIUIElements | SkeletonLayer | https://www.figma.com/file/90eBL1wq2By6z9ZrsBRpoR/iOS.Components?node-id=202-2932&t=hv8FE52pKbXtRZQZ-0 | https://gitlab.ti/touchinstinct/LeadKit/-/merge_requests/1 | https://gitlab.ti/touchinstinct/LeadKit/-/blob/e3ae781f1d944905a6f035287cb354d3002ef2cb/docs/tiuielements/skeletons.md | +| Others | TIUIElements | DefaultPlaceholderView | https://www.figma.com/file/90eBL1wq2By6z9ZrsBRpoR/iOS.Components?node-id=0-1&t=CC3PgNPs7fdUjmBR-0 | | | +| Others | TIUIElements | DefaultPlaceholderView | | | | \ No newline at end of file diff --git a/docs/tiuielements/placeholder.md b/docs/tiuielements/placeholder.md index 37ea8aa3..bffbb4e8 100644 --- a/docs/tiuielements/placeholder.md +++ b/docs/tiuielements/placeholder.md @@ -407,3 +407,5 @@ placeholder.configure(with: .internetConnection) } } ``` + +#### Others DefaultPlaceholderView diff --git a/project-scripts/gen_api_doc.py b/project-scripts/gen_api_doc.py new file mode 100644 index 00000000..00ac49ff --- /dev/null +++ b/project-scripts/gen_api_doc.py @@ -0,0 +1,73 @@ +import sys +import os +from os.path import isfile, join + +from typing import Optional + + +SRCROOT = os.getenv("SRCROOT") +DOCROOT = SRCROOT + "/docs" +API_PATH = DOCROOT + "/api_doc.md" + + +# TODO: add url to documentation +def main(): + module_name = sys.argv[1] + rows = create_rows(module_name) + + if (rows): + append_row(rows) + + +def create_rows(module_name: str) -> list[str]: + path = DOCROOT + f"/{module_name.lower()}" + + files = [path + f"/{f}" for f in os.listdir(path) if isfile(join(path, f))] + info = [] + + for f in files: + type, name = get_element_info(f) + + if type and name: + row = create_row(type, name, module_name) + info.append(row) + + return info + + +def append_row(rows: list[str]): + with open(API_PATH, "a") as f: + for row in rows: + f.write(row) + + +def get_element_info(file_path: str) -> tuple[Optional[str], Optional[str]]: + line = _get_last_line(file_path) + + if not _validate(line): + return None, None + + words = line.split() + + if len(words) < 3: + print("‼️ Pass arguments like this: `#### ElementType ElementName`!") + return None, None + + return words[1], words[2] + + +def create_row(element_type: str, element_name: str, module_name: str) -> str: + return f"\n| {element_type} | {module_name} | {element_name} | | | |" + + +def _validate(line: str) -> bool: + return "####" in line + + +def _get_last_line(path: str) -> str: + with open(path, "r") as f: + return f.readlines()[-1] + + +if __name__ == "__main__": + main() diff --git a/project-scripts/gen_docs_from_playgrounds.sh b/project-scripts/gen_docs_from_playgrounds.sh index 1c5e3242..d9504102 100755 --- a/project-scripts/gen_docs_from_playgrounds.sh +++ b/project-scripts/gen_docs_from_playgrounds.sh @@ -7,10 +7,23 @@ # SRCROOT - path to project folder. # -PLAYGROUNDS="${SRCROOT}/TIFoundationUtils/TIFoundationUtils.app -${SRCROOT}/TIUIElements/TIUIElements.app" +if [ -z ${SRCROOT} ]; then + echo run \'source setup\ to set SRCROOT environment variable +fi -for playground_path in ${PLAYGROUNDS}; do - nef compile --project ${playground_path} - nef markdown --project ${playground_path} --output ${SRCROOT}/docs +for module_name in $(cat ${SRCROOT}/project-scripts/ordered_modules_list.txt); do + APP_FILE=${SRCROOT}/${module_name}/${module_name}.app + + if [ -d "$APP_FILE" ]; then + nef compile --project $APP_FILE + nef markdown --project $APP_FILE --output ${SRCROOT}/docs + python3 ${SRCROOT}/project-scripts/gen_api_doc.py $module_name + + # TODO: Open browser with figma ui documentation + # TODO: Open browser with git remote url + # TODO: Save state to run flow only if there are changes with documentation files + # TODO: Add a flag (like --no-doc) to skip api documentation flow + fi done + +open ${SRCROOT}/docs/api_doc.md