UNPKG

2.97 kBJavaScriptView Raw
1"use strict";
2
3const colors = require("colors/safe");
4const fs = require("fs");
5const fsextra = require("fs-extra");
6const path = require("path");
7const program = require("commander");
8const Helper = require("../helper");
9const Utils = require("./utils");
10
11program
12 .command("start")
13 .option("-H, --host <ip>", `${colors.bold.red("[DEPRECATED]")} to set the IP address or hostname for the web server to listen on, use ${colors.bold("-c host=<ip>")} instead`)
14 .option("-P, --port <port>", `${colors.bold.red("[DEPRECATED]")} to set the port to listen on, use ${colors.bold("-c port=<port>")} instead`)
15 .option("-B, --bind <ip>", `${colors.bold.red("[DEPRECATED]")} to set the local IP to bind to for outgoing connections, use ${colors.bold("-c bind=<ip>")} instead`)
16 .option(" --public", `${colors.bold.red("[DEPRECATED]")} to start in public mode, use ${colors.bold("-c public=true")} instead`)
17 .option(" --private", `${colors.bold.red("[DEPRECATED]")} to start in private mode, use ${colors.bold("-c public=false")} instead`)
18 .description("Start the server")
19 .on("--help", Utils.extraHelp)
20 .action(function(options) {
21 initalizeConfig();
22
23 const server = require("../server");
24
25 if (options.host) {
26 log.warn(`${colors.bold("-H, --host <ip>")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3. Use ${colors.bold("-c host=<ip>")} instead.`);
27 }
28 if (options.port) {
29 log.warn(`${colors.bold("-P, --port <port>")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3. Use ${colors.bold("-c port=<port>")} instead.`);
30 }
31 if (options.bind) {
32 log.warn(`${colors.bold("-B, --bind <ip>")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3. Use ${colors.bold("-c bind=<ip>")} instead.`);
33 }
34 if (options.public) {
35 log.warn(`${colors.bold("--public")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3. Use ${colors.bold("-c public=true")} instead.`);
36 }
37 if (options.private) {
38 log.warn(`${colors.bold("--private")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3. Use ${colors.bold("-c public=false")} instead.`);
39 }
40
41 var mode = Helper.config.public;
42 if (options.public) {
43 mode = true;
44 } else if (options.private) {
45 mode = false;
46 }
47
48 Helper.config.host = options.host || Helper.config.host;
49 Helper.config.port = options.port || Helper.config.port;
50 Helper.config.bind = options.bind || Helper.config.bind;
51 Helper.config.public = mode;
52
53 server();
54 });
55
56function initalizeConfig() {
57 if (!fs.existsSync(Helper.getConfigPath())) {
58 fsextra.ensureDirSync(Helper.getHomePath());
59 fs.chmodSync(Helper.getHomePath(), "0700");
60 fsextra.copySync(path.resolve(path.join(
61 __dirname,
62 "..",
63 "..",
64 "defaults",
65 "config.js"
66 )), Helper.getConfigPath());
67 log.info(`Configuration file created at ${colors.green(Helper.getConfigPath())}.`);
68 }
69
70 fsextra.ensureDirSync(Helper.getUsersPath());
71}