From c6e2cb737a4df6ffac6499224829fdf6b7d21dac Mon Sep 17 00:00:00 2001 From: 0div Date: Tue, 24 Sep 2024 17:57:42 +0200 Subject: [PATCH] fixed js-sdk script --- .github/workflows/generate_api_ref.yml | 1 - .gitignore | 3 ++ packages/js-sdk/scripts/generate_api_ref.sh | 41 ++++++++++--------- packages/python-sdk/api_ref/sandbox_sync.mdx | 0 .../python-sdk/scripts/generate_api_ref.sh | 10 ++--- 5 files changed, 30 insertions(+), 25 deletions(-) delete mode 100644 packages/python-sdk/api_ref/sandbox_sync.mdx diff --git a/.github/workflows/generate_api_ref.yml b/.github/workflows/generate_api_ref.yml index b11a27bb4..93428b5cd 100644 --- a/.github/workflows/generate_api_ref.yml +++ b/.github/workflows/generate_api_ref.yml @@ -102,7 +102,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - git status git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add apps/web/src/app/\(docs\)/docs/api-reference diff --git a/.gitignore b/.gitignore index 8e12639e8..d2dd8fc7e 100644 --- a/.gitignore +++ b/.gitignore @@ -287,3 +287,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ + +# API reference artifacts +api_ref/ diff --git a/packages/js-sdk/scripts/generate_api_ref.sh b/packages/js-sdk/scripts/generate_api_ref.sh index 0ec8edbba..bd822ed2e 100755 --- a/packages/js-sdk/scripts/generate_api_ref.sh +++ b/packages/js-sdk/scripts/generate_api_ref.sh @@ -9,25 +9,28 @@ set -euo pipefail npx typedoc PKG_VERSION="v$(node -p "require('./package.json').version")" - +ROUTES_DIR="../../apps/web/src/app/(docs)/docs/api-reference/js-sdk/${PKG_VERSION}" # move to docs web app -mkdir -p ../../apps/web/src/app/\(docs\)/docs/api-reference/js-sdk/${PKG_VERSION} - -mv api_ref/* ../../apps/web/src/app/\(docs\)/docs/api-reference/js-sdk/${PKG_VERSION}/ - -#mv api_ref/sandbox.md ../../apps/web/src/app/\(docs\)/docs/api-reference/js-sdk/sandbox/page.mdx -# -#mkdir -p ../../apps/web/src/app/\(docs\)/docs/api-reference/js-sdk/errors -#mv api_ref/errors.md ../../apps/web/src/app/\(docs\)/docs/api-reference/js-sdk/errors/page.mdx -# -#mkdir -p ../../apps/web/src/app/\(docs\)/docs/api-reference/js-sdk/filesystem -#mv api_ref/sandbox/filesystem.md ../../apps/web/src/app/\(docs\)/docs/api-reference/js-sdk/filesystem/page.mdx -# -#mkdir -p ../../apps/web/src/app/\(docs\)/docs/api-reference/js-sdk/process -#mv api_ref/sandbox/process.md ../../apps/web/src/app/\(docs\)/docs/api-reference/js-sdk/process/page.mdx -# -#mkdir -p ../../apps/web/src/app/\(docs\)/docs/api-reference/js-sdk/pty -#mv api_ref/sandbox/pty.md ../../apps/web/src/app/\(docs\)/docs/api-reference/js-sdk/pty/page.mdx -# +mkdir -p "${ROUTES_DIR}" + +rm -rf api_ref/README.md + +# Flatten the api_ref directory by moving all nested files to the root level and remove empty subdirectories +find api_ref -mindepth 2 -type f | while read -r file; do + mv "$file" api_ref/ +done +find api_ref -type d -empty -delete + +# Transfrom top level MD files into folders of the same name with page.mdx inside +find api_ref -maxdepth 1 -type f -name "*.md" | while read -r file; do + # Extract the filename without extension + filename=$(basename "$file" .md) + # Create the directory of the same name in api_ref + mkdir -p "api_ref/${filename}" + # Move the file inside the newly created directory + mv "$file" "api_ref/${filename}/page.mdx" +done + +cp -r api_ref/* "${ROUTES_DIR}" rm -rf api_ref diff --git a/packages/python-sdk/api_ref/sandbox_sync.mdx b/packages/python-sdk/api_ref/sandbox_sync.mdx deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/python-sdk/scripts/generate_api_ref.sh b/packages/python-sdk/scripts/generate_api_ref.sh index 2f848775a..c174fd644 100755 --- a/packages/python-sdk/scripts/generate_api_ref.sh +++ b/packages/python-sdk/scripts/generate_api_ref.sh @@ -15,14 +15,14 @@ mkdir -p api_ref for package in "${packages[@]}"; do # generate raw api reference markdown file - pydoc-markdown -p e2b.${package} >api_ref/${package}.mdx + pydoc-markdown -p e2b."${package}" >api_ref/"${package}".mdx # remove package path display - sed -i '/]*>.*<\/a>/d' api_ref/${package}.mdx + sed -i '/]*>.*<\/a>/d' api_ref/"${package}".mdx # remove empty hyperlinks - sed -i '/^# /d' api_ref/${package}.mdx + sed -i '/^# /d' "api_ref/${package}.mdx" # move to docs - mkdir -p ../../apps/web/src/app/\(docs\)/docs/api-reference/python-sdk/${PKG_VERSION}/${package} - mv api_ref/${package}.mdx ../../apps/web/src/app/\(docs\)/docs/api-reference/python-sdk/${PKG_VERSION}/${package}/page.mdx + mkdir -p "../../apps/web/src/app/(docs)/docs/api-reference/python-sdk/${PKG_VERSION}/${package}" + mv "api_ref/${package}.mdx" "../../apps/web/src/app/(docs)/docs/api-reference/python-sdk/${PKG_VERSION}/${package}/page.mdx" done rm -rf api_ref