hardhat-deployed-records
Version:
Hardhat plugin for deploying records
32 lines (31 loc) • 1.64 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("hardhat/config");
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("./helpers");
(0, config_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.deployedRecords;
// 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);
// 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+",
});
});