-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
107 lines (102 loc) · 3.1 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
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
import { text } from "figlet";
import { cwd } from "process";
import { ArgumentParser, ArgumentParserResults } from "./src/arguments";
import { ContentPercent } from "./src/content";
import { CommandLineException } from "./src/exception";
import { displayHistory, TermexHistory } from "./src/history";
import { SetupTermex } from "./src/setup";
import { reportIssue } from "./src/issue";
import { RichPresenceSetup } from "./src/discord/rpc";
import { writeFile } from "fs";
import { yellowBright } from "chalk";
import { RichPresenceSettings } from "./src/discord/settings";
import { openLast } from "./src/last";
import { initializeTermex } from "./src/init";
import { DirectoryFiles } from "./src/files";
import open = require("open");
import { GithubGist } from "./src/gists/gists";
export const VERSION = "1.0.7";
const createTitle = (titleString: string = "Termex"): void => {
text(
"Termex",
{
font: "Ghost",
horizontalLayout: "default",
verticalLayout: "default",
width: 80,
whitespaceBreak: true,
},
(error: Error, result?: string) => {
if (error) {
return null;
}
console.log(result);
}
);
};
const performCommand = (result: ArgumentParserResults): Function => {
const command = result.command;
if (!command) {
return (): void => {
initializeTermex(cwd(), result.parameters);
};
}
if (command == "help") {
return (): void => {
open("https://github.com/pranavbaburaj/termex/tree/main/docs");
};
} else if (command == "history") {
return displayHistory;
} else if (
["%", "percent", "percentage", "polyglot"].includes(command.trim())
) {
return () => {
new ContentPercent(result.parameters);
};
} else if (["issue", "report"].includes(command)) {
return reportIssue;
} else if (command == "rpc") {
return () => {
const rpc = new RichPresenceSetup(result.parameters);
};
} else if (command == "no-rpc") {
return () => {
writeFile(
RichPresenceSettings.settingsFile,
"",
(error: NodeJS.ErrnoException | null): any => {
if (!error) {
console.log(yellowBright(`Disabled RPC`));
return null;
}
new CommandLineException({
message: "Failed to disable rpc",
});
}
);
};
} else if (command == "last") {
return openLast;
} else if (command == "clear-history") {
return () => {
TermexHistory.writeFile(JSON.stringify([]));
console.log(yellowBright("Cleared your termex history"));
};
} else if (command == "files") {
return () => {
const files = new DirectoryFiles(process.cwd(), result.parameters);
};
} else if (command == "gists") {
return () => {
const gist = new GithubGist(result.parameters);
};
}
return (): void => {
initializeTermex(command, result.parameters);
};
};
const setup = SetupTermex.createSetup();
const argumentParser: ArgumentParserResults =
new ArgumentParser().parseArguments();
const execute: Function = performCommand(argumentParser);
const executeResults: any = execute();