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 { ...@@ -7,7 +7,7 @@ import {
HardhatRuntimeEnvironment, HardhatRuntimeEnvironment,
HardhatUserConfig, HardhatUserConfig,
} from 'hardhat/types' } from 'hardhat/types'
import { lazyObject } from 'hardhat/plugins' import { lazyObject, lazyFunction } from 'hardhat/plugins'
import { ethers } from 'ethers' import { ethers } from 'ethers'
// From: https://github.com/wighawag/hardhat-deploy/blob/master/src/index.ts#L63-L76 // From: https://github.com/wighawag/hardhat-deploy/blob/master/src/index.ts#L63-L76
...@@ -26,8 +26,10 @@ const normalizePath = ( ...@@ -26,8 +26,10 @@ const normalizePath = (
return userPath return userPath
} }
export const loadDeployConfig = (hre: HardhatRuntimeEnvironment): any => { const getDeployConfig = (
const getDeployConfig = (dir: string, network: string): any => { dir: string,
network: string
): { [key: string]: any } => {
let config: any let config: any
try { try {
const base = `${dir}/${network}` const base = `${dir}/${network}`
...@@ -42,20 +44,17 @@ export const loadDeployConfig = (hre: HardhatRuntimeEnvironment): any => { ...@@ -42,20 +44,17 @@ export const loadDeployConfig = (hre: HardhatRuntimeEnvironment): any => {
} }
} catch (err) { } catch (err) {
throw new Error( 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 return config
} }
export const loadDeployConfig = (hre: HardhatRuntimeEnvironment): any => {
const paths = hre.config.paths.deployConfig const paths = hre.config.paths.deployConfig
const conf = getDeployConfig(paths, hre.network.name) const conf = getDeployConfig(paths, hre.network.name)
const spec = parseDeployConfig(hre, conf) const spec = parseDeployConfig(hre, conf)
spec.getDeployConfig = (network: string) => {
return getDeployConfig(paths, network)
}
return new Proxy(spec, { return new Proxy(spec, {
get: (target, prop) => { get: (target, prop) => {
if (target.hasOwnProperty(prop)) { if (target.hasOwnProperty(prop)) {
...@@ -124,4 +123,8 @@ extendConfig( ...@@ -124,4 +123,8 @@ extendConfig(
extendEnvironment((hre) => { extendEnvironment((hre) => {
hre.deployConfig = lazyObject(() => loadDeployConfig(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' { ...@@ -25,7 +25,7 @@ declare module 'hardhat/types/runtime' {
interface HardhatRuntimeEnvironment { interface HardhatRuntimeEnvironment {
deployConfig: { deployConfig: {
[key: string]: any [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