Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Auto-generate API reference markdown files for the js-sdk (#447)

0div4059a95e928c
diff --git a/packages/js-sdk/package.json b/packages/js-sdk/package.json
index 6aa6b3376..d3943a4b1 100644
--- a/packages/js-sdk/package.json
+++ b/packages/js-sdk/package.json
@@ -46,6 +46,8 @@
"npm-check-updates": "^16.14.20",
"openapi-typescript": "^6.7.6",
"tsup": "^8.0.2",
+ "typedoc": "^0.26.7",
+ "typedoc-plugin-markdown": "^4.2.7",
"typescript": "^5.4.5",
"vitest": "^1.6.0"
},
diff --git a/packages/js-sdk/scripts/CustomMarkdownTheme.js b/packages/js-sdk/scripts/CustomMarkdownTheme.js
new file mode 100644
index 000000000..263bec658
--- /dev/null
+++ b/packages/js-sdk/scripts/CustomMarkdownTheme.js
@@ -0,0 +1,45 @@
+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(removeLinesWithConditions(page.contents), 6));
+ });
+}
+
+// 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 not removed, add the line to filteredLines
+ filteredLines.push(lines[i]);
+ }
+
+ // Join the filtered lines back into a single string
+ return filteredLines.join('\n');
+}
+
+// Export the load function
+module.exports = { load };
diff --git a/packages/js-sdk/scripts/generate_api_ref.sh b/packages/js-sdk/scripts/generate_api_ref.sh
new file mode 100755
index 000000000..dfd0926b2
--- /dev/null
+++ b/packages/js-sdk/scripts/generate_api_ref.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# This script generates the JS SDK API reference markdown files
+# Run it in the `js-sdk/` directory
+
+# generate raw api reference markdown files
+npx typedoc
+
+# move to docs (for later use)
+#mkdir -p ../../apps/web/src/app/\(docs\)/docs/api-reference/js-sdk/sandbox
+#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
+#
+#rm -rf api_ref
diff --git a/packages/js-sdk/typedoc.json b/packages/js-sdk/typedoc.json
new file mode 100644
index 000000000..9019be986
--- /dev/null
+++ b/packages/js-sdk/typedoc.json
@@ -0,0 +1,22 @@
+{
+ "out": "api_ref",
+ "plugin": ["typedoc-plugin-markdown", "./scripts/CustomMarkdownTheme.js"],
+ "exclude": ["**/*.spec.ts"],
+ "entryPoints": [
+ "src/sandbox/index.ts",
+ "src/sandbox/filesystem/index.ts",
+ "src/sandbox/process/index.ts",
+ "src/sandbox/process/index.ts",
+ "src/sandbox/pty.ts",
+ "src/errors.ts"
+ ],
+ "excludeExternals": true,
+ "excludePrivate": true,
+ "excludeProtected": true,
+ "navigation": {
+ "includeGroups": false,
+ "includeCategories": false
+ },
+ "outputFileStrategy": "modules",
+ "readme": "none"
+}