thelounge/src/command-line/index.js

64 lines
1.9 KiB
JavaScript
Raw Normal View History

"use strict";
global.log = require("../log.js");
2016-04-16 13:32:38 +02:00
const _ = require("lodash");
2017-11-12 19:28:13 +01:00
const fs = require("fs");
const path = require("path");
const program = require("commander");
const colors = require("colors/safe");
const Helper = require("../helper");
const Utils = require("./utils");
2014-08-19 03:18:40 +02:00
program.version(Helper.getVersion(), "-v, --version")
.option(
"-c, --config <key=value>",
"override entries of the configuration file, must be specified for each entry that needs to be overriden",
Utils.parseConfigOptions
)
.on("--help", Utils.extraHelp);
// Parse options from `argv` returning `argv` void of these options.
const argvWithoutOptions = program.parseOptions(process.argv);
2016-05-09 18:19:16 +02:00
2017-11-12 19:28:13 +01:00
// Check if the app was built before calling setHome as it wants to load manifest.json from the public folder
if (!fs.existsSync(path.join(
__dirname,
"..",
"..",
"public",
"manifest.json"
))) {
log.error(`The client application was not built. Run ${colors.bold("NODE_ENV=production npm run build")} to resolve this.`);
process.exit(1);
}
Helper.setHome(process.env.THELOUNGE_HOME || Utils.defaultHome());
2014-10-04 01:33:44 +02:00
2018-03-02 17:59:37 +01:00
Utils.checkOldHome();
// Merge config key-values passed as CLI options into the main config
_.merge(Helper.config, program.config);
require("./start");
require("./config");
if (!Helper.config.public && !Helper.config.ldap.enable) {
require("./users");
}
2017-09-18 17:57:24 +02:00
require("./install");
require("./uninstall");
// `parse` expects to be passed `process.argv`, but we need to remove to give it
// a version of `argv` that does not contain options already parsed by
// `parseOptions` above.
// This is done by giving it the updated `argv` that `parseOptions` returned,
// except it returns an object with `args`/`unknown`, so we need to concat them.
// See https://github.com/tj/commander.js/blob/fefda77f463292/index.js#L686-L763
program.parse(argvWithoutOptions.args.concat(argvWithoutOptions.unknown));
2014-10-14 22:53:26 +02:00
2014-08-19 03:18:40 +02:00
if (!program.args.length) {
program.help();
2014-08-19 03:18:40 +02:00
}