-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
75 lines (70 loc) · 1.96 KB
/
index.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
import { stdin } from "node:process";
import { initializeArgs } from "./args.js";
import { abort, setDryrun } from "./exitMessages.js";
import { index } from "./newCommands/index.js";
import { addKnownHost } from "./newCommands/register.js";
import { CTRL_C, moveToBottom, NORMAL_COLOR, RED } from "./prompt.js";
import {
checkVersionIfOutdated,
outputGit,
package_json,
} from "./printUtils.js";
process.argv.splice(0, 1); // Remove node
process.argv.splice(0, 1); // Remove index
if (process.argv.length > 0 && process.argv[0].endsWith("version")) {
console.log(package_json.version);
process.exit(0);
}
if (process.argv[0] === "dryrun") {
setDryrun();
process.argv.splice(0, 1);
}
initializeArgs(
process.argv.flatMap((x) =>
x.startsWith("-")
? x
.substring(1)
.split("")
.map((x) => `-${x}`)
: [x]
)
);
if (stdin.isTTY) {
// without this, we would only get streams once enter is pressed
stdin.setRawMode(true);
// resume stdin in the parent process (node app won't quit all by itself
// unless an error or process.exit() happens)
stdin.resume();
// i don't want binary, do you?
// stdin.setEncoding("utf8");
// You can always exit with crtl-c
stdin.on("data", (key) => {
const k = key.toString();
if (k === CTRL_C) {
abort();
}
});
}
// TODO Change join to invite
// TODO roles
(async () => {
checkVersionIfOutdated();
const token: never = await index();
})().catch((e) => {
moveToBottom();
const eStr = "" + e;
if (eStr.includes("Permission denied (publickey)")) {
addKnownHost();
outputGit(
`A permission error occurred. Please try these solutions:
1. Make sure you have registered the device with the correct email using 'mm start'
2. Run 'mm help'
3. Run this command again.
4. If the problem persists reach out on http://discord.merrymake.eu` +
NORMAL_COLOR
);
} else {
console.error(`\x1b[31mERROR ${eStr.trimEnd()}\x1b[0m`);
}
abort();
});