Commit 2efd7f3a authored by Mark Tyneway's avatar Mark Tyneway

hardhat-deploy-config: better api for other networks

Add ability to get other network's deploy configs, good
to pair with companion networks feature from hh deploy.
parent 56782b9d
......@@ -7,7 +7,7 @@ import {
HardhatRuntimeEnvironment,
HardhatUserConfig,
} from 'hardhat/types'
import { lazyObject } from 'hardhat/plugins'
import { lazyObject, lazyFunction } from 'hardhat/plugins'
import { ethers } from 'ethers'
// From: https://github.com/wighawag/hardhat-deploy/blob/master/src/index.ts#L63-L76
......@@ -26,8 +26,10 @@ const normalizePath = (
return userPath
}
export const loadDeployConfig = (hre: HardhatRuntimeEnvironment): any => {
const getDeployConfig = (dir: string, network: string): any => {
const getDeployConfig = (
dir: string,
network: string
): { [key: string]: any } => {
let config: any
try {
const base = `${dir}/${network}`
......@@ -42,20 +44,17 @@ export const loadDeployConfig = (hre: HardhatRuntimeEnvironment): any => {
}
} catch (err) {
throw new Error(
`error while loading deploy config for network: ${hre.network.name}, ${err}`
`error while loading deploy config for network: ${network}, ${err}`
)
}
return config
}
}
export const loadDeployConfig = (hre: HardhatRuntimeEnvironment): any => {
const paths = hre.config.paths.deployConfig
const conf = getDeployConfig(paths, hre.network.name)
const spec = parseDeployConfig(hre, conf)
spec.getDeployConfig = (network: string) => {
return getDeployConfig(paths, network)
}
return new Proxy(spec, {
get: (target, prop) => {
if (target.hasOwnProperty(prop)) {
......@@ -124,4 +123,8 @@ extendConfig(
extendEnvironment((hre) => {
hre.deployConfig = lazyObject(() => loadDeployConfig(hre))
hre.getDeployConfig = lazyFunction(() => {
const paths = hre.config.paths.deployConfig
return (network: string) => getDeployConfig(paths, network)
})
})
......@@ -25,7 +25,7 @@ declare module 'hardhat/types/runtime' {
interface HardhatRuntimeEnvironment {
deployConfig: {
[key: string]: any
getDeployConfig(arg0: string): { [key: string]: any }
}
getDeployConfig(network: string): { [key: string]: any }
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment