@towercg2/cli
Version:
The command-line components for TowerCG2's server.
32 lines (31 loc) • 1.17 kB
JavaScript
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = __importStar(require("path"));
const server_1 = require("@towercg2/server");
async function withConfig(configPath, fn) {
try {
const tsNode = require("ts-node");
tsNode.register({});
const obj = require(path.resolve(configPath));
if (!(obj instanceof server_1.Config)) {
throw new Error(`'${configPath}' is not a TowerCG2 server config object.`);
}
const config = obj;
config.logger.info("Config loaded.");
return fn(config);
}
catch (error) {
console.error("An error occurred during initial config bootstrap.");
console.error(error);
process.exit(1);
throw error; // tsc doesn't realize that the function terminates with process.exit
}
}
exports.withConfig = withConfig;
;