2022-06-19 00:25:21 +00:00
|
|
|
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";
|
2014-09-09 11:12:23 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const program = new Command("start");
|
2014-09-09 11:12:23 +00:00
|
|
|
program
|
|
|
|
.description("Start the server")
|
2019-11-07 20:19:54 +00:00
|
|
|
.option("--dev", "Development mode with hot module reloading")
|
2017-08-21 05:49:32 +00:00
|
|
|
.on("--help", Utils.extraHelp)
|
2020-03-21 20:55:36 +00:00
|
|
|
.action(function (options) {
|
2017-07-18 09:36:24 +00:00
|
|
|
initalizeConfig();
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
const newLocal = "../server";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
|
|
const server = require(newLocal);
|
|
|
|
server.default(options);
|
2014-09-09 11:12:23 +00:00
|
|
|
});
|
2017-07-18 09:36:24 +00:00
|
|
|
|
|
|
|
function initalizeConfig() {
|
2022-05-01 19:12:39 +00:00
|
|
|
if (!fs.existsSync(Config.getConfigPath())) {
|
|
|
|
fs.mkdirSync(Config.getHomePath(), {recursive: true});
|
|
|
|
fs.chmodSync(Config.getHomePath(), "0700");
|
2020-03-16 11:53:48 +00:00
|
|
|
fs.copyFileSync(
|
2019-07-17 09:33:59 +00:00
|
|
|
path.resolve(path.join(__dirname, "..", "..", "defaults", "config.js")),
|
2022-05-01 19:12:39 +00:00
|
|
|
Config.getConfigPath()
|
2019-07-17 09:33:59 +00:00
|
|
|
);
|
2022-05-01 19:12:39 +00:00
|
|
|
log.info(`Configuration file created at ${colors.green(Config.getConfigPath())}.`);
|
2017-07-18 09:36:24 +00:00
|
|
|
}
|
|
|
|
|
2022-05-01 19:12:39 +00:00
|
|
|
fs.mkdirSync(Config.getUsersPath(), {recursive: true, mode: 0o700});
|
2017-07-18 09:36:24 +00:00
|
|
|
}
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
export default program;
|