|
1 |
| -import { writeFileSync } from "fs"; |
| 1 | +import { mkdir } from "node:fs/promises"; |
| 2 | +import { $, file, write } from "bun"; |
2 | 3 | import { TypeScriptSymbolExtractor } from "./typescript-symbol-extractor";
|
| 4 | +import { GoSymbolExtractor } from "./go-symbol-extractor"; |
| 5 | +import { PythonSymbolExtractor } from "./python-symbol-extractor"; |
| 6 | +import { SymbolExtractor, Symbol } from "./types"; |
3 | 7 |
|
4 |
| -const extractor = new TypeScriptSymbolExtractor(); |
| 8 | +type Repository = { |
| 9 | + url: string; |
| 10 | + files: { path: string; module: string }[]; |
| 11 | + name: string; |
| 12 | + language: "typescript" | "go" | "python"; |
| 13 | +}; |
| 14 | + |
| 15 | +type IndexDocument = { |
| 16 | + name: string; |
| 17 | + type: "function" | "class" | "variable" | "type"; |
| 18 | + meta: Record<string, unknown>; |
| 19 | + content: string; |
| 20 | + file: string; |
| 21 | + line: number; |
| 22 | +}; |
| 23 | + |
| 24 | +(async () => { |
| 25 | + const repositories: Repository[] = []; |
| 26 | + const documents: IndexDocument[] = []; |
| 27 | + |
| 28 | + try { |
| 29 | + await init(); |
| 30 | + |
| 31 | + for (const repository of repositories) { |
| 32 | + await cloneRepository(repository); |
| 33 | + const symbols = await extractSymbols(repository); |
| 34 | + const repositoryDocuments = await transformSymbolsToDocuments(symbols, repository); |
| 35 | + } |
| 36 | + |
| 37 | + await write("index.json", JSON.stringify(documents, null, 2)); |
| 38 | + |
| 39 | + // await updateIndex(documents); |
| 40 | + } catch (e) { |
| 41 | + console.error("Indexing failed"); |
| 42 | + console.error(e); |
| 43 | + process.exit(1); |
| 44 | + } |
| 45 | +})(); |
| 46 | + |
| 47 | +async function init() { |
| 48 | + const tmpDirPath = "./tmp"; |
| 49 | + const tmpDir = file(tmpDirPath); |
| 50 | + if (!(await tmpDir.exists())) { |
| 51 | + mkdir(tmpDirPath); |
| 52 | + } |
| 53 | + $.cwd("/tmp"); |
| 54 | +} |
| 55 | + |
| 56 | +async function cloneRepository(repository: Repository) { |
| 57 | + await $`git clone ${repository.url} ${repository.name}`; |
| 58 | +} |
5 | 59 |
|
6 |
| -const Config = { |
7 |
| - repository: "https://github.com/supertokens/supertokens-node", |
8 |
| - files: [], |
| 60 | +const ExtractorsMap: Record<Repository["language"], SymbolExtractor> = { |
| 61 | + typescript: TypeScriptSymbolExtractor, |
9 | 62 | };
|
10 | 63 |
|
11 |
| -const symbols = extractor.extract("/Users/bogdan/src/supertokens/docs/scripts/sdk-indexer/samples"); |
| 64 | +async function extractSymbols(repository: Repository): Symbol[] {} |
12 | 65 |
|
13 |
| -console.log(symbols); |
14 |
| -writeFileSync("./result.json", JSON.stringify(symbols, null, 2)); |
| 66 | +async function transformSymbolsToDocuments(symbols: Symbol[], repository: Repository) {} |
| 67 | +async function updateIndex(documents: IndexDocument[]) {} |
0 commit comments