UNPKG

2.5 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3Object.defineProperty(exports, "__esModule", { value: true });
4const fs = require("fs");
5const path = require("path");
6const minimist = require("minimist");
7const data_helper_1 = require("./helpers/data.helper");
8const help_helper_1 = require("./helpers/help.helper");
9const pckg = JSON.parse(fs.readFileSync(path.dirname(__dirname) + "/package.json").toString());
10const CommandFiles = fs.readdirSync(__dirname + "/commands/");
11const args = minimist(process.argv.slice(2));
12const RequestedCommand = args._[0];
13const Commands = [];
14CommandFiles.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});
36data_helper_1.DataHelper.Commands = Commands;
37if (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}
42Commands.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});