doc: use code snippet for typescript examples (#880)

The typescript code is in a fully function file, that will be run via the CI.
This commit is contained in:
Lei Xu
2024-01-27 22:52:37 -08:00
committed by Weston Pace
parent 545a03d7f9
commit d811b89de2
12 changed files with 281 additions and 49 deletions

View File

@@ -9,7 +9,10 @@ const excludedGlobs = [
"../src/embedding.md",
"../src/examples/*.md",
"../src/guides/tables.md",
"../src/guides/storage.md",
"../src/embeddings/*.md",
"../src/javascript/**/*.md",
"../src/basic.md",
];
const nodePrefix = "javascript";
@@ -47,8 +50,11 @@ for (const file of files.filter((file) => !excludedFiles.includes(file))) {
if (lines.length > 0) {
const fileName = path.basename(file, ".md");
const outPath = path.join(nodeFolder, fileName, `${fileName}${nodeFile}`);
console.log(outPath)
console.log(outPath);
fs.mkdirSync(path.dirname(outPath), { recursive: true });
fs.writeFileSync(outPath, asyncPrefix + "\n" + lines.join("\n") + asyncSuffix);
fs.writeFileSync(
outPath,
asyncPrefix + "\n" + lines.join("\n") + asyncSuffix
);
}
}
}