generate-deploy-config.ts 805 Bytes
Newer Older
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
import fs from 'fs'
import path from 'path'

import { task } from 'hardhat/config'
import { HardhatRuntimeEnvironment } from 'hardhat/types'

task(
  'generate-deploy-config',
  'generates a json config file for the current network'
).setAction(async ({}, hre: HardhatRuntimeEnvironment) => {
  try {
    const base = path.join(hre.config.paths.deployConfig, hre.network.name)
    if (fs.existsSync(`${base}.ts`)) {
      // eslint-disable-next-line @typescript-eslint/no-var-requires
      const config = require(`${base}.ts`).default
      fs.writeFileSync(`${base}.json`, JSON.stringify(config, null, 2), 'utf8')
    } else {
      throw new Error('not found')
    }
  } catch (err) {
    throw new Error(
      `error while loading deploy config for network: ${hre.network.name}, ${err}`
    )
  }
})