-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from e2b-dev/generate-api-reference-for-code-i…
…nterpreter-sdk-e2b-1235 Generate SDK reference
- Loading branch information
Showing
19 changed files
with
3,721 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# This script checks for diffs in the js/ and python/ directory. | ||
# If there are diffs, it means we need to generate new SDK references. | ||
if git diff --name-only HEAD^ | grep -q '^js/\|^python/'; then | ||
echo "true" | ||
else | ||
echo "false" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const { MarkdownTheme, MarkdownPageEvent } = require('typedoc-plugin-markdown') | ||
|
||
function load(app) { | ||
// Listen to the render event | ||
app.renderer.on(MarkdownPageEvent.END, (page) => { | ||
// Remove Markdown links from the document contents | ||
page.contents = removeMarkdownLinks( | ||
removeFirstNLines( | ||
convertH5toH3(removeLinesWithConditions(page.contents)), | ||
6 | ||
) | ||
) | ||
}) | ||
} | ||
|
||
// this is a hacky way to make methods in the js-sdk sdk reference look more prominent | ||
function convertH5toH3(text) { | ||
return text.replace(/^##### (.*)$/gm, '### $1') | ||
} | ||
|
||
// Function to remove Markdown-style links | ||
function removeMarkdownLinks(text) { | ||
// Regular expression to match Markdown links [text](url) | ||
return text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1') // Replace with just the link text | ||
} | ||
|
||
function removeFirstNLines(text, n, condition) { | ||
// Split the text into lines, then join back excluding the first four lines | ||
return text.split('\n').slice(n).join('\n') | ||
} | ||
|
||
// Function to remove lines based on conditions | ||
function removeLinesWithConditions(text) { | ||
const lines = text.split('\n') | ||
const filteredLines = [] | ||
|
||
for (let i = 0; i < lines.length; i++) { | ||
// Check if the current line starts with "#### Extends" or "###### Overrides" | ||
if ( | ||
lines[i].startsWith('#### Extends') || | ||
lines[i].startsWith('###### Overrides') || | ||
lines[i].startsWith('###### Inherited from') | ||
) { | ||
// If it does, skip this line and the next three lines | ||
i += 3 // Skip this line and the next three | ||
continue | ||
} | ||
|
||
if (lines[i].startsWith('##### new')) { | ||
// avoid promoting constructors | ||
i += 1 | ||
continue | ||
} | ||
|
||
// If not removed, add the line to filteredLines | ||
filteredLines.push(convertH5toH3(lines[i])) | ||
} | ||
|
||
// Join the filtered lines back into a single string | ||
return filteredLines.join('\n') | ||
} | ||
|
||
// Export the load function | ||
module.exports = { load } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# This script generates the Code Interpreter JS SDK reference markdown files | ||
# Run it in the `js/` directory | ||
|
||
# generate raw SDK reference markdown files | ||
npx typedoc | ||
|
||
PKG_VERSION="v$(node -p "require('./package.json').version")" | ||
ROUTES_DIR="../sdk-reference/code-interpreter-js-sdk/${PKG_VERSION}" | ||
mkdir -p "${ROUTES_DIR}" | ||
|
||
rm -rf sdk_ref/README.md | ||
|
||
# Flatten the sdk_ref directory by moving all nested files to the root level and remove empty subdirectories | ||
find sdk_ref -mindepth 2 -type f | while read -r file; do | ||
mv "$file" sdk_ref/ | ||
done | ||
find sdk_ref -type d -empty -delete | ||
|
||
# Transfrom top level MD files into folders of the same name with page.mdx inside | ||
find sdk_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 sdk_ref | ||
mkdir -p "sdk_ref/${filename}" | ||
# Move the file inside the newly created directory | ||
mv "$file" "sdk_ref/${filename}/page.mdx" | ||
done | ||
|
||
cp -r sdk_ref/* "${ROUTES_DIR}" | ||
|
||
rm -rf sdk_ref |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"out": "sdk_ref", | ||
"plugin": ["typedoc-plugin-markdown", "./scripts/CustomMarkdownTheme.js"], | ||
"exclude": ["**/*.spec.ts"], | ||
"entryPoints": [ | ||
"src/index.ts", | ||
"src/charts.ts", | ||
"src/consts.ts", | ||
"src/messaging.ts", | ||
"src/sandbox.ts" | ||
], | ||
"excludeExternals": true, | ||
"excludePrivate": true, | ||
"excludeProtected": true, | ||
"navigation": { | ||
"includeGroups": false, | ||
"includeCategories": false | ||
}, | ||
"outputFileStrategy": "modules", | ||
"readme": "none", | ||
"disableSources": true, | ||
// typedoc-plugin-markdown options | ||
"classPropertiesFormat": "table", | ||
"typeDeclarationFormat": "table", | ||
"enumMembersFormat": "table", | ||
"parametersFormat": "table", | ||
"expandParameters": true, | ||
"useCodeBlocks": true, | ||
"hidePageTitle": true, | ||
"hideBreadcrumbs": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,6 @@ | |
"changeset": "^0.2.6" | ||
}, | ||
"engines": { | ||
"pnpm": ">=9.0.0 <10" | ||
"pnpm": ">=9.0.0 <10" | ||
} | ||
} |
Oops, something went wrong.