UNPKG

hardhat-deployed

Version:

Hardhat plugin for saving deployed contract address.

34 lines (33 loc) 1.7 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const plugins_1 = require("hardhat/plugins"); const task_names_1 = require("hardhat/builtin-tasks/task-names"); const fs_1 = __importDefault(require("fs")); const constants_1 = require("../constants"); const helpers_1 = require("../misc/helpers"); const deployed_1 = require("./deployed"); deployed_1.deployedTaskScope .task(constants_1.TASK_DEPLOYED_ADD, "Add new network deployed") .setAction(async (taskArgs, hre) => { // run `compile` task before all operations await hre.run(task_names_1.TASK_COMPILE); // read configs from `hardhat.config.ts` const configs = hre.config.deployed; // get network name const network = hre.network.name; // default value is `hardhat` // if the network folder already exists, throw an error if (fs_1.default.existsSync(`${configs.deployedDir}/${network}`)) { throw new plugins_1.HardhatPluginError(constants_1.PLUGIN_NAME, "Already added, you can migrate it by using 'deployed migrate' task"); } const { contracts } = await (0, helpers_1.parseArtifacts)(hre, configs.ignoreContracts, configs.externalContracts); // create <network> folder fs_1.default.mkdirSync(`${configs.deployedDir}/${network}`); // write `<network>/contracts.json` file const data = (0, helpers_1.paths2json)({}, contracts, constants_1.DEFAULT_DEPLOYED_ADDRESS); fs_1.default.writeFileSync(`${configs.deployedDir}/${network}/${constants_1.CONTRACTS_JSON_FILE}`, data, { flag: "a+", }); });