thelounge/server/command-line/start.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

import log from "../log";
import colors from "chalk";
import fs from "fs";
import path from "path";
import {Command} from "commander";
import Config from "../config";
import Utils from "./utils";
const program = new Command("start");
program
.description("Start the server")
.option("--dev", "Development mode with hot module reloading")
.on("--help", Utils.extraHelp)
.action(function (options) {
initalizeConfig();
const newLocal = "../server";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const server = require(newLocal);
server.default(options);
});
function initalizeConfig() {
if (!fs.existsSync(Config.getConfigPath())) {
fs.mkdirSync(Config.getHomePath(), {recursive: true});
fs.chmodSync(Config.getHomePath(), "0700");
fs.copyFileSync(
2019-07-17 09:33:59 +00:00
path.resolve(path.join(__dirname, "..", "..", "defaults", "config.js")),
Config.getConfigPath()
2019-07-17 09:33:59 +00:00
);
log.info(`Configuration file created at ${colors.green(Config.getConfigPath())}.`);
}
fs.mkdirSync(Config.getUsersPath(), {recursive: true, mode: 0o700});
}
export default program;