forked from DefiLlama/DefiLlama-Adapters
-
Notifications
You must be signed in to change notification settings - Fork 1
/
runInteractive.js
67 lines (56 loc) · 1.5 KB
/
runInteractive.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const inquirer = require('inquirer')
const childProcess = require('child_process')
inquirer.registerPrompt('fuzzypath', require('inquirer-fuzzy-path'))
const adapterPrompt = {
type: 'fuzzypath',
name: 'adapterPath',
excludePath: nodePath => nodePath.startsWith('helper'),
excludeFilter: nodePath => nodePath == '.',
itemType: 'any',
rootPath: 'projects',
message: 'Select an adapter to run:',
suggestOnly: false,
depthLimit: 0,
}
const enableDebugPrompt = {
type: 'confirm',
name: 'debugMode',
message: 'Enable Debug Mode:',
default: false
}
async function run() {
let adapterPath
const { debugMode, ...response } = await inquirer.prompt([
// enableDebugPrompt,
adapterPrompt,
])
adapterPath = response.adapterPath
while (true) {
adapterPrompt.default = adapterPath
await runAdapter(adapterPath, true)
const answer = await inquirer.prompt([adapterPrompt])
adapterPath = answer.adapterPath
}
}
async function runAdapter(adapterPath, debugMode) {
const startTime = Date.now()
return new Promise((resolve, reject) => {
const env = {
LLAMA_SDK_MAX_PARALLEL: 100,
LLAMA_DEBUG_MODE: !!debugMode
}
const startTime = Date.now()
const child = childProcess.fork('test.js', [adapterPath], {
...process.env,
env,
})
child.on('error', reject)
child.on('close', function (code) {
console.log(`
Run time: ${(Date.now() - startTime) / 1000} (seconds)
`)
resolve()
})
})
}
run()