1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | const fs = require("fs");
|
5 | const path = require("path");
|
6 | const minimist = require("minimist");
|
7 | const data_helper_1 = require("./helpers/data.helper");
|
8 | const help_helper_1 = require("./helpers/help.helper");
|
9 | const pckg = JSON.parse(fs.readFileSync(path.dirname(__dirname) + "/package.json").toString());
|
10 | const CommandFiles = fs.readdirSync(__dirname + "/commands/");
|
11 | const args = minimist(process.argv.slice(2));
|
12 | const RequestedCommand = args._[0];
|
13 | const Commands = [];
|
14 | CommandFiles.forEach(CommandFile => {
|
15 | if (CommandFile.split(".").includes("ts") ||
|
16 | CommandFile.split(".").includes("js")) {
|
17 | const CurrentCommand = require(`./commands/${CommandFile}`).default;
|
18 | if (!CurrentCommand.Signature().includes("<") ||
|
19 | !CurrentCommand.Signature().includes(">")) {
|
20 | throw new Error(`Cannot find the start, and or the end of the parameters in the Signature method of the command called "${CurrentCommand.Signature()}".`);
|
21 | }
|
22 | Commands.push({
|
23 | name: CurrentCommand.Signature()
|
24 | .split("<")[0]
|
25 | .trim(),
|
26 | arguments: CurrentCommand.Signature()
|
27 | .split("<")[1]
|
28 | .split(">")[0]
|
29 | .trim()
|
30 | .split(","),
|
31 | description: CurrentCommand.Description(),
|
32 | handle: CurrentCommand.HandleCommand
|
33 | });
|
34 | }
|
35 | });
|
36 | data_helper_1.DataHelper.Commands = Commands;
|
37 | if (Commands.filter(Command => typeof RequestedCommand === "undefined"
|
38 | ? true
|
39 | : Command.name.toLowerCase() === RequestedCommand.toLowerCase()).length === 0) {
|
40 | console.error(`Cannot find a command called ${RequestedCommand.toLowerCase()}!`);
|
41 | }
|
42 | Commands.forEach(Command => {
|
43 | if (typeof RequestedCommand !== "undefined" &&
|
44 | RequestedCommand.toLowerCase() === Command.name.toLowerCase()) {
|
45 | const CommandArguments = args._.slice(1);
|
46 | const MissingArguments = Command.arguments.filter(Argument => Argument.endsWith("?")
|
47 | ? false
|
48 | : Argument === ""
|
49 | ? false
|
50 | : !CommandArguments.includes(Argument));
|
51 | if (MissingArguments.length > 0) {
|
52 | console.error(`Missing parameter ${MissingArguments[0]}!`);
|
53 | }
|
54 | Command.handle(args);
|
55 | }
|
56 | else {
|
57 | help_helper_1.HelpHelper.OutputHelp();
|
58 | }
|
59 | });
|