-
Notifications
You must be signed in to change notification settings - Fork 11
/
_scripts.js
36 lines (32 loc) · 1 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
const {spawn} = require('child_process');
require('dotenv').config();
const commandlineArgs = process.argv.slice(2);
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);
});
}
async function performAction(rawArgs){
const action = rawArgs[0];
const args = rawArgs.slice(1);
if (action === 'deploy') {
await execute(
`forge create NFT --rpc-url=${process.env['RPC_URL']} --private-key=${process.env['PRIVATE_KEY']} --constructor-args ${args.join(' ')} --force`
);
}
if (action === 'send') {
await execute(
`cast send --rpc-url=${process.env['RPC_URL']} --private-key=${process.env['PRIVATE_KEY']} ${args[0]} "${args[1]}" ${args.slice(2).join(' ')}`
);
}
}
performAction(commandlineArgs);