-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathconfig.ts
42 lines (36 loc) · 1.43 KB
/
config.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
40
41
42
import { GraphPluginError } from './sdk/utils/error'
import { logDebug } from './logger'
import { normalizePath } from './sdk/utils/path'
import type { GraphDeployment, GraphRuntimeEnvironmentOptions } from './types'
import type { HardhatRuntimeEnvironment } from 'hardhat/types'
export function getAddressBookPath(
deployment: GraphDeployment,
hre: HardhatRuntimeEnvironment,
opts: GraphRuntimeEnvironmentOptions,
): string {
const optsPath = getPath(opts.deployments?.[deployment])
const networkPath = getPath(hre.network.config.deployments?.[deployment])
const globalPath = getPath(hre.config.graph?.deployments?.[deployment])
logDebug(`Getting address book path...`)
logDebug(`Graph base dir: ${hre.config.paths.graph}`)
logDebug(`1) opts: ${optsPath}`)
logDebug(`2) network: ${networkPath}`)
logDebug(`3) global: ${globalPath}`)
const addressBookPath = optsPath ?? networkPath ?? globalPath
if (addressBookPath === undefined) {
throw new GraphPluginError('Must set a an addressBook path!')
}
const normalizedAddressBookPath = normalizePath(addressBookPath, hre.config.paths.graph)
logDebug(`Address book path: ${normalizedAddressBookPath}`)
return normalizedAddressBookPath
}
function getPath(value: string | {
addressBook: string
} | undefined): string | undefined {
if (typeof value === 'string') {
return value
} else if (value && typeof value == 'object') {
return value.addressBook
}
return
}