2016-10-09 21:14:02 +02:00
|
|
|
"use strict";
|
|
|
|
|
2017-07-18 11:36:24 +02:00
|
|
|
const colors = require("colors/safe");
|
|
|
|
const fs = require("fs");
|
|
|
|
const fsextra = require("fs-extra");
|
|
|
|
const path = require("path");
|
|
|
|
const program = require("commander");
|
|
|
|
const Helper = require("../helper");
|
2017-08-21 07:49:32 +02:00
|
|
|
const Utils = require("./utils");
|
2014-09-09 13:12:23 +02:00
|
|
|
|
|
|
|
program
|
2016-12-15 07:29:44 +01:00
|
|
|
.command("start")
|
2017-02-18 04:23:01 +01:00
|
|
|
.option("-H, --host <ip>", "set the IP address or hostname for the web server to listen on")
|
|
|
|
.option("-P, --port <port>", "set the port to listen on")
|
|
|
|
.option("-B, --bind <ip>", "set the local IP to bind to for outgoing connections")
|
|
|
|
.option(" --public", "start in public mode")
|
|
|
|
.option(" --private", "start in private mode")
|
2014-09-09 13:12:23 +02:00
|
|
|
.description("Start the server")
|
2017-08-21 07:49:32 +02:00
|
|
|
.on("--help", Utils.extraHelp)
|
2016-12-15 07:29:44 +01:00
|
|
|
.action(function(options) {
|
2017-07-18 11:36:24 +02:00
|
|
|
initalizeConfig();
|
|
|
|
|
|
|
|
const server = require("../server");
|
|
|
|
|
2016-06-08 11:26:24 +02:00
|
|
|
var mode = Helper.config.public;
|
2016-12-15 07:29:44 +01:00
|
|
|
if (options.public) {
|
2014-10-01 21:05:07 +02:00
|
|
|
mode = true;
|
2016-12-15 07:29:44 +01:00
|
|
|
} else if (options.private) {
|
2014-10-01 21:05:07 +02:00
|
|
|
mode = false;
|
|
|
|
}
|
2016-06-08 11:26:24 +02:00
|
|
|
|
2016-12-15 07:29:44 +01:00
|
|
|
Helper.config.host = options.host || Helper.config.host;
|
|
|
|
Helper.config.port = options.port || Helper.config.port;
|
|
|
|
Helper.config.bind = options.bind || Helper.config.bind;
|
2016-06-08 11:26:24 +02:00
|
|
|
Helper.config.public = mode;
|
|
|
|
|
|
|
|
server();
|
2014-09-09 13:12:23 +02:00
|
|
|
});
|
2017-07-18 11:36:24 +02:00
|
|
|
|
|
|
|
function initalizeConfig() {
|
|
|
|
if (!fs.existsSync(Helper.CONFIG_PATH)) {
|
|
|
|
fsextra.ensureDirSync(Helper.HOME);
|
|
|
|
fs.chmodSync(Helper.HOME, "0700");
|
|
|
|
fsextra.copySync(path.resolve(path.join(
|
|
|
|
__dirname,
|
|
|
|
"..",
|
|
|
|
"..",
|
|
|
|
"defaults",
|
|
|
|
"config.js"
|
|
|
|
)), Helper.CONFIG_PATH);
|
|
|
|
log.info(`Configuration file created at ${colors.green(Helper.CONFIG_PATH)}.`);
|
|
|
|
}
|
|
|
|
|
|
|
|
fsextra.ensureDirSync(Helper.USERS_PATH);
|
|
|
|
}
|