-
Notifications
You must be signed in to change notification settings - Fork 7
/
scripts.js
117 lines (106 loc) · 3.6 KB
/
scripts.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env node
'use strict';
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const {spawn} = require('child_process');
const program = require('commander');
function execute(command) {
return new Promise((resolve, reject) => {
const onExit = (error) => {
if (error) {
return reject(error);
}
resolve();
};
spawn(command.split(' ')[0], command.split(' ').slice(1), {
stdio: 'inherit',
shell: true,
}).on('exit', onExit);
});
}
program.version('0.0.1');
program
.command('run <network> <file> [extra...]')
.description('run file against a network')
.action(async (network, file, extra) => {
await execute(
`cross-env HARDHAT_NETWORK=${network} ts-node --files ${file} ${
extra ? extra.join(' ') : ''
}`
);
});
program
.command('deploy <network> [extra...]')
.description('deploy to network')
.action(async (network, extra) => {
await execute(
`hardhat --network ${network} deploy --reset ${extra ? extra.join(' ') : ''}`
);
});
program
.command('export <network> <file>')
.description('export contracts for network')
.action(async (network, file) => {
await execute(`hardhat --network ${network} export --export ${file}`);
});
program
.command('fork:run <network> <file> [extra...]')
.option('--blockNumber <blockNumber>')
.option('--deploy')
.description('run file against a fork')
.action(async (network, file, extra, options) => {
await execute(
`cross-env ${
options.deploy ? 'HARDHAT_DEPLOY_FIXTURE=true' : ''
} HARDHAT_DEPLOY_ACCOUNTS_NETWORK=${network} HARDHAT_FORK=${network} ${
options.blockNumber ? `HARDHAT_FORK_NUMBER=${options.blockNumber}` : ''
} ts-node --files ${file} ${extra ? extra.join(' ') : ''}`
);
});
program
.command('fork:deploy <network> [extra...]')
.option('--blockNumber <blockNumber>')
.description('deploy on a fork')
.action(async (network, extra, options) => {
// console.log({network, extra, options});
await execute(
`cross-env HARDHAT_DEPLOY_ACCOUNTS_NETWORK=${network} HARDHAT_FORK=${network} ${
options.blockNumber ? `HARDHAT_FORK_NUMBER=${options.blockNumber}` : ''
} hardhat deploy ${extra ? extra.join(' ') : ''}`
);
});
program
.command('fork:test <network> [extra...]')
.option('--blockNumber <blockNumber>')
.description('test on a fork')
.action(async (network, extra, options) => {
// console.log({network, extra, options});
await execute(
`cross-env HARDHAT_DEPLOY_ACCOUNTS_NETWORK=${network} HARDHAT_FORK=${network} ${
options.blockNumber ? `HARDHAT_FORK_NUMBER=${options.blockNumber}` : ''
} HARDHAT_DEPLOY_FIXTURE=true HARDHAT_COMPILE=true mocha --bail --recursive test ${
extra ? extra.join(' ') : ''
}`
);
});
program
.command('fork:dev <network> [extra...]')
.option('--blockNumber <blockNumber>')
.description('deploy on a fork and keep running')
.action(async (network, extra, options) => {
await execute(
`cross-env HARDHAT_DEPLOY_ACCOUNTS_NETWORK=${network} HARDHAT_FORK=${network} ${
options.blockNumber ? `HARDHAT_FORK_NUMBER=${options.blockNumber}` : ''
} hardhat node --watch --export contractsInfo.json ${
extra ? extra.join(' ') : ''
}`
);
});
// program
// .command('exec <command> [options...]')
// .description('exec program in PATH')
// .action(async (command, options) => {
// const actualCommand = command + ' ' + options ? options.join(' ') : '';
// await execute(actualCommand);
// });
program.parse(process.argv);