This repository was archived by the owner on Mar 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands.js
More file actions
55 lines (45 loc) · 1.4 KB
/
Commands.js
File metadata and controls
55 lines (45 loc) · 1.4 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
const exec = require("child_process").exec;
const readLine = require("readline");
const path = require("path");
const fs = require("fs");
const path_config = path.join(__dirname, "run.config");
const commandsList = {};
fs.readFile(path_config, { encoding: "utf-8" }, (error, data) => {
if (!error) {
const extract = data.split("\n").map((keys) => keys.replace("\r", ""));
if (extract.includes("config:")) {
extract.forEach((items) => {
if (items === "config:") {
commandsList[items.replace(":", "")] = {};
} else {
const trimmed = items.split(":").map((_) => _.trim(" "));
commandsList.config[trimmed[0]] = trimmed[1];
}
});
}
Run(commandsList);
} else {
console.log("run.config not found!");
}
});
function Run(inputCommands) {
try {
const list = Object.keys(inputCommands.config);
const prompt = readLine.createInterface({
input: process.stdin,
output: process.stdout,
});
prompt.question("run: ", (answer) => {
if (list.includes(answer)) {
const command = exec(inputCommands.config[answer]);
command.stdout.on("data", (data) => console.log(data));
command.stderr.on("data", (data) => console.log(data));
} else {
console.log("command not found!");
}
prompt.close();
});
} catch (err) {
console.log("[config:] not found!");
}
}