UNPKG

@mrgalaxy/tjme

Version:
73 lines (72 loc) 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const minimist_1 = tslib_1.__importDefault(require("minimist")); const rc_1 = tslib_1.__importDefault(require("rc")); const fs_1 = tslib_1.__importDefault(require("fs")); const path_1 = tslib_1.__importDefault(require("path")); const index_1 = tslib_1.__importDefault(require("./index")); const pkgsrc = fs_1.default.readFileSync(path_1.default.resolve(__dirname, "../package.json"), "utf8"); const pkg = JSON.parse(pkgsrc); const argv = (0, minimist_1.default)(process.argv.slice(2), { boolean: ["help", "version"], alias: { h: "help", H: "help", v: "version", V: "version", c: "config", p: "port", }, }); if (argv.help) { console.log(` $ tjme-server [OPTIONS] -c, --config <file> Set options via a JSON config file, relative to PWD. -p, --port <port> The HTTP server port. -h, --help Shows this message. -v, --version Prints the name and version of this software. `); process.exit(0); } if (argv.version) { console.log("%s %s", pkg.name, pkg.version); process.exit(0); } const conf = (0, rc_1.default)("tjme", {}, argv); if (conf.production) { process.env.NODE_ENV = "production"; } else if (!process.env.NODE_ENV) { process.env.NODE_ENV = "development"; } let host, port; if (conf.bind && typeof conf.bind === "string") { [host, port] = conf.bind.split(":"); } if (!host) host = conf.host || "127.0.0.1"; if (!port) port = conf.port || process.env.PORT || "3000"; const app = (0, index_1.default)({ hostname: conf.hostname, template: conf.template, name: conf.name, version: conf.version, }); app .listen(port, host, function () { const addr = this.address(); if (typeof addr === "string") { console.log("tylerjohnson.me server listening at %s", addr); } else if (addr != null) { console.log("tylerjohnson.me server listening at http://%s:%s", addr.address, addr.port); } console.log("Enter Ctrl-C to stop the server."); }) .on("error", function (e) { console.error(e.stack || e); process.exit(1); }); //# sourceMappingURL=cli.js.map