-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.ts
110 lines (100 loc) · 2.58 KB
/
cli.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
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
#!/usr/bin/env node
import { exec } from "node:child_process";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { WagmiKnownChain } from ".";
import { configDirectory, getChain } from "lib";
function explorer(config: WagmiKnownChain) {
exec(`open ${config.etherscanUrl || config.blockExplorer}`);
}
function etherscan(config: WagmiKnownChain) {
console.log(`${config.etherscanApiKey}`);
}
function rpc(config: WagmiKnownChain) {
console.log(config.rpcUrl);
}
function forge(
config: WagmiKnownChain,
args: { verify?: boolean; deploy?: boolean }
) {
if (args.verify) {
const command = [`--chain ${config.id}`];
if (config.etherscanApiKey) {
command.push(`--etherscan-api-key ${config.etherscanApiKey}`);
} else {
command.push(
`--verifier-url ${config.verifierUrl} --verifier blockscout`
);
}
console.log(command.join(" "));
return;
}
if (args.deploy) {
const command = [`--rpc-url ${config.rpcUrl}`];
if (config.verifierUrl) {
command.push(
`--verifier-url ${config.verifierUrl} --verifier blockscout`
);
}
if (config.etherscanApiKey) {
command.push(`--etherscan-api-key ${config.etherscanApiKey}`);
}
console.log(command.join(" "));
return;
}
const command = [`--rpc-url ${config.rpcUrl}`];
console.log(command.join(" "));
}
function updateChainsConfigRepo() {
console.log("Updating repo...");
const command = "git pull origin main";
console.log(`running: ${command}`);
const proc = exec(command, { cwd: configDirectory });
proc.stdout?.pipe(process.stdout);
proc.stderr?.pipe(process.stderr);
}
function getConfig(fn: (config: WagmiKnownChain, args: any) => void) {
return async ({ chain, ...rest }: { chain: string; [key: string]: any }) => {
fn(await getChain(chain), rest);
};
}
yargs(hideBin(process.argv))
.command(
["forge <chain>", "$0 <chain>"],
"print output for forge",
// @ts-ignore
(yargs) => {
yargs
.option("verify", { desc: "Verify contract" })
.option("deploy", { desc: "Deploy contract" });
},
getConfig(forge)
)
.command(
"etherscan <chain>",
"print etherscan api key",
// @ts-ignore
() => {},
getConfig(etherscan)
)
.command(
"rpc <chain>",
"print rpc url",
// @ts-ignore
() => {},
getConfig(rpc)
)
.command(
"explorer <chain>",
"open block explorer",
// @ts-ignore
() => {},
getConfig(explorer)
)
.command(
"update",
"Updates repo with remote main",
() => {},
updateChainsConfigRepo
)
.parse();