forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
66 changed files
with
1,005 additions
and
619 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
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,74 @@ | ||
const { Project, SyntaxKind } = require("ts-morph"); | ||
const fs = require("fs"); | ||
|
||
/** | ||
* | ||
* @param {string} relativePath | ||
* @param {any} updateFunction | ||
*/ | ||
const updateJsonFile = (relativePath, updateFunction) => { | ||
const contents = fs.readFileSync(relativePath).toString(); | ||
const res = updateFunction(JSON.parse(contents)); | ||
fs.writeFileSync(relativePath, JSON.stringify(res, null, 2) + "\n"); | ||
}; | ||
|
||
function main() { | ||
const project = new Project(); | ||
const entrypointFiles = [ | ||
"../../langchain/scripts/create-entrypoints.js", | ||
"../../langchain-core/scripts/create-entrypoints.js", | ||
"../../libs/langchain-community/scripts/create-entrypoints.js", | ||
"../../libs/langchain-anthropic/scripts/create-entrypoints.js", | ||
"../../libs/langchain-google-genai/scripts/create-entrypoints.js", | ||
"../../libs/langchain-openai/scripts/create-entrypoints.js", | ||
"../../libs/langchain-mistralai/scripts/create-entrypoints.js", | ||
]; | ||
|
||
const entrypoints = new Set([]); | ||
entrypointFiles.forEach((entrypointFile) => { | ||
// load file contents from ts-morph | ||
const file = project.addSourceFileAtPath(entrypointFile); | ||
// extract the variable named entrypoints | ||
const entrypointVar = file.getVariableDeclarationOrThrow("entrypoints"); | ||
// extract the `deprecatedNodeOnly` if it exists | ||
const deprecatedNodeOnlyVar = | ||
file.getVariableDeclaration("deprecatedNodeOnly"); | ||
/** | ||
* @type {string[]} | ||
*/ | ||
let deprecatedNodeOnly = []; | ||
if (deprecatedNodeOnlyVar) { | ||
const deprecatedNodeOnlyKeys = deprecatedNodeOnlyVar | ||
.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression) | ||
.getElements() | ||
.map((element) => element.getText().replaceAll('"', "")); | ||
deprecatedNodeOnly = deprecatedNodeOnlyKeys; | ||
} | ||
// get all keys from the entrypoints object | ||
const entrypointKeys = entrypointVar | ||
.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression) | ||
.getProperties() | ||
.map((property) => property.getText()); | ||
const entrypointKeysArray = entrypointKeys.map((kv) => | ||
kv.split(":").map((part) => part.trim().replace(/^"|"$/g, "")) | ||
); | ||
|
||
/** | ||
* @type {Record<string, string>} | ||
*/ | ||
const entrypointsObject = Object.fromEntries(entrypointKeysArray); | ||
const entrypointDir = entrypointFile.split( | ||
"/scripts/create-entrypoints.js" | ||
)[0]; | ||
|
||
Object.values(entrypointsObject) | ||
.filter((key) => !deprecatedNodeOnly.includes(key)) | ||
.map((key) => entrypoints.add(`${entrypointDir}/src/${key}.ts`)); | ||
}); | ||
|
||
updateJsonFile("./typedoc.json", (json) => ({ | ||
...json, | ||
entryPoints: Array.from(entrypoints), | ||
})); | ||
} | ||
main(); |
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
Oops, something went wrong.