UNPKG

buidler-typechain

Version:
45 lines 2.05 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const task_names_1 = require("@nomiclabs/buidler/builtin-tasks/task-names"); const config_1 = require("@nomiclabs/buidler/config"); const plugins_1 = require("@nomiclabs/buidler/plugins"); const fs_extra_1 = __importDefault(require("fs-extra")); const ts_generator_1 = require("ts-generator"); const TypeChain_1 = require("typechain/dist/TypeChain"); const config_2 = require("./config"); config_1.task("typechain", "Generate Typechain typings for compiled contracts").setAction(async ({}, { config, run }) => { const typechain = config_2.getDefaultTypechainConfig(config); const typechainTargets = [ "ethers-v4", "ethers-v5", "truffle", "web3-v1", "truffle-v5", ]; if (!typechainTargets.includes(typechain.target)) { throw new plugins_1.BuidlerPluginError("Typechain", "Invalid Typechain target, please provide via buidler.config.js (typechain.target)"); } await run(task_names_1.TASK_COMPILE); console.log(`Creating Typechain artifacts in directory ${typechain.outDir} for target ${typechain.target}`); const cwd = process.cwd(); await ts_generator_1.tsGenerator({ cwd }, new TypeChain_1.TypeChain({ cwd, rawConfig: { files: `${config.paths.artifacts}/*.json`, outDir: typechain.outDir, target: typechain.target, }, })); console.log(`Successfully generated Typechain artifacts!`); }); config_1.task(task_names_1.TASK_CLEAN, "Clears the cache and deletes all artifacts", async (_, { config }) => { await fs_extra_1.default.remove(config.paths.cache); await fs_extra_1.default.remove(config.paths.artifacts); if (config.typechain && config.typechain.outDir) { await fs_extra_1.default.remove(config.typechain.outDir); } }); //# sourceMappingURL=index.js.map