generated from mintlify/starter
-
Notifications
You must be signed in to change notification settings - Fork 9
/
generate-ts-doc.sh
executable file
·110 lines (83 loc) · 2.8 KB
/
generate-ts-doc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# npm install typedoc 0.25.13
# npm install "typedoc-plugin-markdown": "^4.0.0-next.25",
# Generate the documentation
SRC_DIR=../literalai-typescript
OUTPUT_DIR=typescript-client/api-reference
TMP_DIR=typescript-client/api-reference/tmp
# keep the dir of this script to use it as a base dir
BASEDIR=$(pwd)
# switch flags to change the src and output directories
for i in "$@"
do
case $i in
-s=*|--source-dir=*)
SRC_DIR="${i#*=}"
shift # past argument=value
;;
-o=*|--output-dir=*)
OUTPUT_DIR="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done
FILES=(
"api"
# "index"
# "thread"
# "step"
)
# if output directory does not exist, create it
if [ ! -d "$OUTPUT_DIR" ]; then
mkdir -p $OUTPUT_DIR
fi
# if tmp directory does not exist, create it
if [ ! -d "$TMP_DIR" ]; then
mkdir -p $TMP_DIR
fi
# get the absolute path of the output directory
OUTPUT_DIR=$(realpath $OUTPUT_DIR)
# echo the output dir to the console in yellow bold
echo "\033[1;33mOutput directory: $OUTPUT_DIR\033[0m"
# move to the src directory
cd $SRC_DIR
# echo the current directory to the console in yellow bold
echo "\033[1;33mCurrent directory: $(pwd)\033[0m"
# install the dependencies
npm install
for i in "${FILES[@]}"; do
echo "Writing docs for $i in $OUTPUT_DIR/$i.mdx"
# Generate the documentation
if [ "$i" = "api" ]; then
npx typedoc --out $TMP_DIR --tsconfig tsconfig.json src/$i.ts --name $i
else
npx typedoc --out $TMP_DIR --tsconfig tsconfig.json src/observability/$i.ts
fi
cp $TMP_DIR/README.md $OUTPUT_DIR/$i.mdx
done
rm -rf $TMP_DIR/README.md
cd $BASEDIR
for i in "${FILES[@]}"; do
# remove the 6 first lines (very bad solution, but removes useless auto-generated stuff)
sed -i '' '1,4d' $OUTPUT_DIR/$i.mdx
# remove the 2 last lines (very bad solution, but removes useless auto-generated stuff)
sed -i '' '$d' $OUTPUT_DIR/$i.mdx
sed -i '' '$d' $OUTPUT_DIR/$i.mdx
# replace arguments and returns from title 6 to bold plain text
sed -E -i '' -f "scripts/change_headers6_to_bold.txt" $OUTPUT_DIR/$i.mdx
# replace title 5 with title 3
sed -E -i '' -f "scripts/replace_title5_title3.txt" $OUTPUT_DIR/$i.mdx
# zoom_subtitles_special
sed -E -i '' -f "scripts/zoom_subtitles_special.txt" $OUTPUT_DIR/$i.mdx
python3 scripts/make_returns_tables.py $OUTPUT_DIR/$i.mdx
done
# for each file in the DOC_DIR, add its name without the extension to a files.txt file
for file in $OUTPUT_DIR/*.mdx; do
echo $(basename $file .mdx) >> $OUTPUT_DIR/files.txt
done
# call the python script to add the files to the mint.json
python3 scripts/update_api_reference.py -ts $OUTPUT_DIR/files.txt
# remove the files.txt file
rm $OUTPUT_DIR/files.txt