-
Notifications
You must be signed in to change notification settings - Fork 497
/
Copy pathbin.ts
executable file
·77 lines (66 loc) · 2.21 KB
/
bin.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
#!/usr/bin/env node
import { spawn } from "cross-spawn";
import {
generate,
isValidChainIdAndContractAddress,
} from "./commands/generate/generate.js";
import { publishStylus } from "./commands/publish-stylus/publish-stylus.js";
// skip the first two args?
const [, , command = "", ...rest] = process.argv;
let secretKey: string | undefined;
const keyIndex = rest.indexOf("-k");
if (keyIndex !== -1 && rest.length > keyIndex + 1) {
secretKey = rest[keyIndex + 1];
rest.splice(keyIndex, 2);
}
async function main() {
switch (command) {
case "generate": {
const [chainIdPlusContract] = rest;
if (!isValidChainIdAndContractAddress(chainIdPlusContract)) {
console.info("Usage: thirdweb generate <chainId>/<contractAddress>");
process.exit(1);
} else {
await generate(chainIdPlusContract);
}
break;
}
case "publish-stylus": {
await publishStylus(secretKey);
break;
}
case "login": {
// Not implemented yet
console.info(
"Please instead pass a secret key to the command directly, learn more: https://support.thirdweb.com/troubleshooting-errors/7Y1BqKNvtLdBv5fZkRZZB3/issue-linking-device-on-the-authorization-page-via-thirdweb-cli/cn9LRA3ax7XCP6uxwRYdvx",
);
process.exit(1);
break;
}
default: {
// check several commands for missing -k flag
const commands = ["deploy", "publish", "generate", "upload"];
if (commands.includes(command) && !rest.includes("-k")) {
console.info(
"Please include the -k flag with your secret key, learn more: https://support.thirdweb.com/troubleshooting-errors/7Y1BqKNvtLdBv5fZkRZZB3/issue-linking-device-on-the-authorization-page-via-thirdweb-cli/cn9LRA3ax7XCP6uxwRYdvx",
);
process.exit(1);
return;
}
const isWindows = /^win/.test(process.platform);
let runner = "npx";
switch (true) {
case isWindows:
runner = "npx.cmd";
break;
}
const args = command
? ["--yes", "@thirdweb-dev/cli@latest", command, ...rest]
: ["--yes", "@thirdweb-dev/cli@latest", ...rest];
spawn(runner, args, {
stdio: "inherit",
});
}
}
}
main();