-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
39 lines (33 loc) · 1.42 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env node
import { evaluateSearchQuery, type FunctionDetail } from './src/evaluator'
import { getMethodsAndFunctions } from './src/explorer/explorer'
import { parse } from './src/lexer'
import { prettify } from './src/prettyfier'
const tsConfigFilePath = process.argv[2]
const userSearchQuery = process.argv[3]
export async function tsoogle (tsConfigFilePath: string, userSearchQuery: string, useIndex = true): Promise<FunctionDetail[]> {
const searchQuery = parse(userSearchQuery)
const projectFunctions = await getMethodsAndFunctions(searchQuery.kind, tsConfigFilePath, useIndex)
return evaluateSearchQuery(projectFunctions, searchQuery)
}
export async function tsoogleCmd (tsConfigFilePath: string, userSearchQuery: string, useIndex = true): Promise<string> {
const searchQuery = parse(userSearchQuery)
let output = ''
const projectFunctions = await getMethodsAndFunctions(searchQuery.kind, tsConfigFilePath, useIndex)
evaluateSearchQuery(projectFunctions, searchQuery).forEach(func => {
output += `${prettify(func)}\n`
})
return output
}
async function main (): Promise<void> {
if (tsConfigFilePath !== undefined && userSearchQuery !== undefined) {
try {
const response = await tsoogleCmd(tsConfigFilePath, userSearchQuery)
console.log(response)
} catch (error) {
console.error('Error:', error)
}
}
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
main()