Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add script for generate typedoc declaration json file #2507

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ AUTHORS
stats.html
tsconfig.tsbuildinfo
api
docs/api
yarn.lock
e2e/videos/*
e2e/screenshots/*
Expand Down
28 changes: 28 additions & 0 deletions scripts/typedoc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -euo pipefail

# generate declaration files via typedoc

ENGINE_PATH="$(pwd)"

# Validate required environment variable
if [ -z "${TYPEDOC:-}" ]; then
echo "Error: TYPEDOC environment variable is not set" >&2
exit 1
fi
for directory in ${ENGINE_PATH}/packages/*
do
if [ -d $directory ]; then
bn=`basename $directory`;
echo "typedoc compiling $directory"
npx $TYPEDOC --version
npx $TYPEDOC --json api/$bn.json --tsconfig $directory/tsconfig.json $directory/src/index.ts;
SUCCESS+=("api/$bn.json")
fi
done
Comment on lines +13 to +22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve robustness of package processing.

The main loop needs several improvements for better error handling and robustness:

Apply these changes:

+# Initialize array and create output directory
+declare -a SUCCESS=()
+mkdir -p api
+
-for directory in ${ENGINE_PATH}/packages/*
+for directory in "${ENGINE_PATH}/packages/"*
 do
-  if [ -d $directory ]; then
-    bn=`basename $directory`;
+  if [ -d "$directory" ]; then
+    bn="$(basename "$directory")"
     echo "typedoc compiling $directory"
-    npx $TYPEDOC --version
-    npx $TYPEDOC --json api/$bn.json --tsconfig $directory/tsconfig.json $directory/src/index.ts;
-    SUCCESS+=("api/$bn.json")
+    if ! npx "$TYPEDOC" --json "api/${bn}.json" \
+         --tsconfig "${directory}/tsconfig.json" \
+         "${directory}/src/index.ts"; then
+      echo "Error: TypeDoc generation failed for ${bn}" >&2
+      continue
+    fi
+    SUCCESS+=("api/${bn}.json")
   fi
 done
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for directory in ${ENGINE_PATH}/packages/*
do
if [ -d $directory ]; then
bn=`basename $directory`;
echo "typedoc compiling $directory"
npx $TYPEDOC --version
npx $TYPEDOC --json api/$bn.json --tsconfig $directory/tsconfig.json $directory/src/index.ts;
SUCCESS+=("api/$bn.json")
fi
done
# Initialize array and create output directory
declare -a SUCCESS=()
mkdir -p api
for directory in "${ENGINE_PATH}/packages/"*
do
if [ -d "$directory" ]; then
bn="$(basename "$directory")"
echo "typedoc compiling $directory"
if ! npx "$TYPEDOC" --json "api/${bn}.json" \
--tsconfig "${directory}/tsconfig.json" \
"${directory}/src/index.ts"; then
echo "Error: TypeDoc generation failed for ${bn}" >&2
continue
fi
SUCCESS+=("api/${bn}.json")
fi
done


echo "============"
for f in ${SUCCESS[@]}; do
echo "[typedoc] $f";
done
echo "============"
Loading