forked from Itsavirus-com/infi-smartcontract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardhat-tasks.ts
46 lines (36 loc) · 1.1 KB
/
hardhat-tasks.ts
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import path from 'path';
import { copy, pathExists, remove } from 'fs-extra';
import {
TASK_CLEAN,
TASK_COMPILE_SOLIDITY_COMPILE_JOBS,
} from 'hardhat/builtin-tasks/task-names';
import { subtask, task } from 'hardhat/config';
const COPY_TYPECHAIN_OUTDIR_TO_PATH = '../contracts/typechain/generated';
subtask(
TASK_COMPILE_SOLIDITY_COMPILE_JOBS,
'Copy typechain outDir to contracts package'
).setAction(async (taskArgs, { config, run }, runSuper) => {
const compileSolOutput = await runSuper(taskArgs);
const typechainIndexFilePath = path.resolve(
config.typechain.outDir,
'index.ts'
);
if (!(await pathExists(typechainIndexFilePath))) {
await run('typechain');
}
await copy(config.typechain.outDir, COPY_TYPECHAIN_OUTDIR_TO_PATH);
return compileSolOutput;
});
task(
TASK_CLEAN,
'Clears the cache and deletes all artifacts',
async ({ global }: { global: boolean }, { config: _ }, runSuper) => {
if (global) {
return;
}
if (await pathExists(COPY_TYPECHAIN_OUTDIR_TO_PATH)) {
await remove(COPY_TYPECHAIN_OUTDIR_TO_PATH);
}
await runSuper();
}
);