Skip to content

Commit c74f82a

Browse files
authored
Merge pull request #48 from e2b-dev/generate-api-reference-for-code-interpreter-sdk-e2b-1235
Generate SDK reference
2 parents 8ea8003 + a154d0a commit c74f82a

File tree

19 files changed

+3721
-45
lines changed

19 files changed

+3721
-45
lines changed

.github/scripts/is_new_sdk_ref.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# This script checks for diffs in the js/ and python/ directory.
6+
# If there are diffs, it means we need to generate new SDK references.
7+
if git diff --name-only HEAD^ | grep -q '^js/\|^python/'; then
8+
echo "true"
9+
else
10+
echo "false"
11+
fi

.github/workflows/release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ jobs:
296296
run: pnpm run version
297297
env:
298298
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
299+
300+
- name: Generate SDK reference
301+
id: sdk-ref
302+
run: pnpm run --recursive generate-ref
303+
304+
- name: Show docs file structure
305+
run: tree ./sdk-reference
299306

300307
- name: Release new versions
301308
uses: changesets/action@v1
@@ -314,6 +321,7 @@ jobs:
314321
run: |
315322
git config user.name "github-actions[bot]"
316323
git config user.email "github-actions[bot]@users.noreply.github.com"
324+
git add ./sdk-reference
317325
git commit -am "[skip ci] Release new versions" || exit 0
318326
git push
319327
env:

js/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@e2b/code-interpreter",
33
"version": "1.0.4",
4+
"packageManager": "[email protected]",
45
"description": "E2B Code Interpreter - Stateful code execution",
56
"homepage": "https://e2b.dev",
67
"license": "MIT",
@@ -32,7 +33,8 @@
3233
"update-deps": "ncu -u && pnpm i",
3334
"example": "npx tsx example.mts",
3435
"test:bun": "bun test tests/runtimes/bun --env-file=.env",
35-
"test:deno": "deno test tests/runtimes/deno/ --allow-net --allow-read --allow-env --unstable-sloppy-imports --trace-leaks"
36+
"test:deno": "deno test tests/runtimes/deno/ --allow-net --allow-read --allow-env --unstable-sloppy-imports --trace-leaks",
37+
"generate-ref": "./scripts/generate_sdk_ref.sh"
3638
},
3739
"devDependencies": {
3840
"@types/node": "^18.18.6",
@@ -41,6 +43,8 @@
4143
"knip": "^5.25.1",
4244
"npm-check-updates": "^16.14.20",
4345
"tsup": "^8.1.0",
46+
"typedoc": "^0.26.8",
47+
"typedoc-plugin-markdown": "^4.2.7",
4448
"typescript": "^5.5.3",
4549
"vitest": "^2.0.1"
4650
},

js/scripts/CustomMarkdownTheme.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const { MarkdownTheme, MarkdownPageEvent } = require('typedoc-plugin-markdown')
2+
3+
function load(app) {
4+
// Listen to the render event
5+
app.renderer.on(MarkdownPageEvent.END, (page) => {
6+
// Remove Markdown links from the document contents
7+
page.contents = removeMarkdownLinks(
8+
removeFirstNLines(
9+
convertH5toH3(removeLinesWithConditions(page.contents)),
10+
6
11+
)
12+
)
13+
})
14+
}
15+
16+
// this is a hacky way to make methods in the js-sdk sdk reference look more prominent
17+
function convertH5toH3(text) {
18+
return text.replace(/^##### (.*)$/gm, '### $1')
19+
}
20+
21+
// Function to remove Markdown-style links
22+
function removeMarkdownLinks(text) {
23+
// Regular expression to match Markdown links [text](url)
24+
return text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1') // Replace with just the link text
25+
}
26+
27+
function removeFirstNLines(text, n, condition) {
28+
// Split the text into lines, then join back excluding the first four lines
29+
return text.split('\n').slice(n).join('\n')
30+
}
31+
32+
// Function to remove lines based on conditions
33+
function removeLinesWithConditions(text) {
34+
const lines = text.split('\n')
35+
const filteredLines = []
36+
37+
for (let i = 0; i < lines.length; i++) {
38+
// Check if the current line starts with "#### Extends" or "###### Overrides"
39+
if (
40+
lines[i].startsWith('#### Extends') ||
41+
lines[i].startsWith('###### Overrides') ||
42+
lines[i].startsWith('###### Inherited from')
43+
) {
44+
// If it does, skip this line and the next three lines
45+
i += 3 // Skip this line and the next three
46+
continue
47+
}
48+
49+
if (lines[i].startsWith('##### new')) {
50+
// avoid promoting constructors
51+
i += 1
52+
continue
53+
}
54+
55+
// If not removed, add the line to filteredLines
56+
filteredLines.push(convertH5toH3(lines[i]))
57+
}
58+
59+
// Join the filtered lines back into a single string
60+
return filteredLines.join('\n')
61+
}
62+
63+
// Export the load function
64+
module.exports = { load }

js/scripts/generate_sdk_ref.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# This script generates the Code Interpreter JS SDK reference markdown files
6+
# Run it in the `js/` directory
7+
8+
# generate raw SDK reference markdown files
9+
npx typedoc
10+
11+
PKG_VERSION="v$(node -p "require('./package.json').version")"
12+
ROUTES_DIR="../sdk-reference/code-interpreter-js-sdk/${PKG_VERSION}"
13+
mkdir -p "${ROUTES_DIR}"
14+
15+
rm -rf sdk_ref/README.md
16+
17+
# Flatten the sdk_ref directory by moving all nested files to the root level and remove empty subdirectories
18+
find sdk_ref -mindepth 2 -type f | while read -r file; do
19+
mv "$file" sdk_ref/
20+
done
21+
find sdk_ref -type d -empty -delete
22+
23+
# Transfrom top level MD files into folders of the same name with page.mdx inside
24+
find sdk_ref -maxdepth 1 -type f -name "*.md" | while read -r file; do
25+
# Extract the filename without extension
26+
filename=$(basename "$file" .md)
27+
# Create the directory of the same name in sdk_ref
28+
mkdir -p "sdk_ref/${filename}"
29+
# Move the file inside the newly created directory
30+
mv "$file" "sdk_ref/${filename}/page.mdx"
31+
done
32+
33+
cp -r sdk_ref/* "${ROUTES_DIR}"
34+
35+
rm -rf sdk_ref

js/typedoc.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"out": "sdk_ref",
3+
"plugin": ["typedoc-plugin-markdown", "./scripts/CustomMarkdownTheme.js"],
4+
"exclude": ["**/*.spec.ts"],
5+
"entryPoints": [
6+
"src/index.ts",
7+
"src/charts.ts",
8+
"src/consts.ts",
9+
"src/messaging.ts",
10+
"src/sandbox.ts"
11+
],
12+
"excludeExternals": true,
13+
"excludePrivate": true,
14+
"excludeProtected": true,
15+
"navigation": {
16+
"includeGroups": false,
17+
"includeCategories": false
18+
},
19+
"outputFileStrategy": "modules",
20+
"readme": "none",
21+
"disableSources": true,
22+
// typedoc-plugin-markdown options
23+
"classPropertiesFormat": "table",
24+
"typeDeclarationFormat": "table",
25+
"enumMembersFormat": "table",
26+
"parametersFormat": "table",
27+
"expandParameters": true,
28+
"useCodeBlocks": true,
29+
"hidePageTitle": true,
30+
"hideBreadcrumbs": true
31+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"changeset": "^0.2.6"
1414
},
1515
"engines": {
16-
"pnpm": ">=9.0.0 <10"
16+
"pnpm": ">=9.0.0 <10"
1717
}
1818
}

0 commit comments

Comments
 (0)