forked from graphprotocol/graph-tooling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
38 lines (32 loc) · 839 Bytes
/
cli.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
const path = require('path')
const { exec } = require('child_process')
const which = require('which')
const { build, system } = require('gluegun')
const run = async argv => {
let cli = build()
.brand('graph')
.src(__dirname)
const pluginDirs = (
await Promise.all(
['npm root -g', 'npm root', 'yarn global dir'].map(async cmd => {
try {
return await system.run(cmd, { trim: true })
} catch (_) {
return undefined
}
}),
)
).filter(dir => dir !== undefined)
// Inject potential plugin directories
cli = pluginDirs.reduce(
(cli, dir) => cli.plugin(path.join(dir, '@graphprotocol', 'indexer-cli', 'dist')),
cli,
)
cli = cli
.help()
.version()
.defaultCommand()
.create()
return await cli.run(argv)
}
module.exports = { run }