-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·99 lines (80 loc) · 3.19 KB
/
index.js
File metadata and controls
executable file
·99 lines (80 loc) · 3.19 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
97
98
99
#!/usr/bin/env node
const chalk = require("chalk");
const { input } = require("@inquirer/prompts");
const { GLOBAL_NAME, SHORT_NAME, VERSION, BUILD } = require("./src/variables/constants");
const _intCmds = require("./src/functions/interpret");
const _detectArgs = require("./src/functions/detectArgs");
const exit = require("./src/functions/exit");
const Verbose = require("./src/classes/Verbose");
const PathUtil = require("./src/classes/PathUtil");
(async () => {
// Check if terminal supports color
Verbose.custom("Checking terminal color support...");
require("./src/functions/init/colorSupport")();
// Detect if Node.js version is supported
Verbose.custom("Checking Node.js version...");
require("./src/functions/init/detectNodeVer")();
// Initialize timebomb
Verbose.custom("Detecting no timebomb argument...");
if (!_detectArgs("timebomb")) require("./src/functions/init/timebomb")();
// Initialize checks
Verbose.custom("Detecting no checks argument...");
if (!_detectArgs("checks")) require("./src/functions/init/startupChecks")();
// Initialize startup arguments help
Verbose.custom("Detecting startup arguments help argument...");
if (_detectArgs("help")) {
require("./src/functions/init/startupArgs")();
Verbose.exitProcess();
process.exit(0);
}
// Initialize version
Verbose.custom("Detecting version argument...");
if (_detectArgs("version")) {
Verbose.custom("Showing version information...");
console.log(`${GLOBAL_NAME}, v${VERSION} (Build ${BUILD})\n`);
Verbose.exitProcess();
process.exit(0);
}
// Initialize pre-boot interpreter
Verbose.custom("Starting pre-boot interpreter...");
await require("./src/functions/init/preBootInt")();
// Initialize executable arguments
Verbose.custom("Initializing arguments...");
require("./src/functions/init/initArgs");
// Initialize elevation check
Verbose.custom("Completing elevation check...");
await require("./src/functions/init/checkElevation")();
// Initialize update checker
Verbose.custom("Initializing update checker...");
await require("./src/functions/init/updateChecker")();
// TODO Change the prompt to use built-in readline module,
// to allow for Ctrl+C handling and command history cycling
// on all OSes. When doing so, there are a few bugs:
// - All commands must be converted into async
// - All stdin such as in mkfile will need to be dealt with
// as it acts like the CLI
// CLI of BubbleOS
Verbose.custom("Starting command interpreter...");
while (true) {
try {
const command = await input({
message: `${chalk.blueBright(PathUtil.caseSensitive(process.cwd()))} ${chalk.red("$")}`,
theme: {
prefix: chalk.bold.green(SHORT_NAME.toLowerCase()),
style: {
answer: (text) => chalk.reset(text),
},
},
});
Verbose.custom("Interpreting command...");
await _intCmds(command?.trim());
} catch ({ name }) {
if (name === "ExitPromptError") {
// If the user presses Ctrl+C, exit BubbleOS gracefully
// Note this does not catch if a command is executing
Verbose.custom("Detected Ctrl+C, exiting...");
exit();
}
}
}
})();