-
Notifications
You must be signed in to change notification settings - Fork 676
Expand file tree
/
Copy pathbin.ts
More file actions
executable file
·96 lines (81 loc) · 2.5 KB
/
Copy pathbin.ts
File metadata and controls
executable file
·96 lines (81 loc) · 2.5 KB
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
#!/usr/bin/env node
import { spawn } from "cross-spawn";
import {
generate,
isValidChainIdAndContractAddress,
} from "./commands/generate/generate.js";
import { deployStylus, publishStylus } from "./commands/stylus/builder.js";
import { createStylusProject } from "./commands/stylus/create.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];
}
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 "deploy-stylus": {
await deployStylus(secretKey);
break;
}
case "create-stylus": {
await createStylusProject();
break;
}
case "create": {
console.info(
"The 'thirdweb create' command is deprecated. Please use the thirdweb dashboard instead: https://thirdweb.com/dashboard",
);
process.exit(1);
break;
}
case "login": {
// Not implemented yet
console.info(
"Please instead pass a secret key to the command directly, learn more: https://portal.thirdweb.com/knowledge-base/onchain-common-errors/thirdweb-cli/device-link-error",
);
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://portal.thirdweb.com/knowledge-base/onchain-common-errors/thirdweb-cli/device-link-error",
);
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();