UNPKG

observermc

Version:

A Node.js wrapper and API for multiple Minecraft Servers

48 lines (47 loc) 1.72 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var fs_1 = __importDefault(require("fs")); var crypto_1 = __importDefault(require("crypto")); var commander_1 = require("commander"); var ObserverApi_1 = require("./observer/ObserverApi"); var util_1 = require("./util"); var program = new commander_1.Command(); program .version("v1.0.3") .description("ObserverMC CLI.") .option("-c, --config <path>", "Configuration file path") .parse(process.argv); var opts = program.opts(); if (opts.config) { var config = loadConfig(opts.config); var observerApi = new ObserverApi_1.ObserverApi(config); observerApi.listen(); } else { console.error("Please provide the config file path using the --config option"); process.exit(0); } function loadConfig(path) { var config; try { config = JSON.parse(fs_1.default.readFileSync(path, "utf-8")); } catch (_a) { util_1.Logger.error("Could not load the config file, creating example file..."); config = { servers: [], apiKey: crypto_1.default.randomBytes(20).toString("hex"), port: 3000, }; fs_1.default.writeFileSync(path, JSON.stringify(config)); util_1.Logger.log("Generated config file! Edit it and restart the wrapper to apply changes."); // Display API key console.log("\nYour auto-generated API key is: " + config.apiKey); console.log("DO NOT SHARE IT\n"); } return config; }