2016-10-09 15:14:02 -04:00
|
|
|
"use strict";
|
|
|
|
|
2016-04-28 21:36:09 +03:00
|
|
|
global.log = require("../log.js");
|
2016-04-16 14:32:38 +03:00
|
|
|
|
2017-12-09 15:06:41 -05:00
|
|
|
const _ = require("lodash");
|
2017-11-12 20:28:13 +02:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
2017-07-18 12:36:24 +03:00
|
|
|
const program = require("commander");
|
2018-03-02 20:28:54 +02:00
|
|
|
const colors = require("chalk");
|
2017-07-18 12:36:24 +03:00
|
|
|
const Helper = require("../helper");
|
2017-08-21 01:49:32 -04:00
|
|
|
const Utils = require("./utils");
|
2014-08-18 18:18:40 -07:00
|
|
|
|
2017-02-17 22:23:01 -05:00
|
|
|
program.version(Helper.getVersion(), "-v, --version")
|
2017-12-09 15:06:41 -05:00
|
|
|
.option(
|
|
|
|
"-c, --config <key=value>",
|
|
|
|
"override entries of the configuration file, must be specified for each entry that needs to be overriden",
|
|
|
|
Utils.parseConfigOptions
|
|
|
|
)
|
2017-12-10 16:57:26 -05:00
|
|
|
.on("--help", Utils.extraHelp);
|
|
|
|
|
|
|
|
// Parse options from `argv` returning `argv` void of these options.
|
|
|
|
const argvWithoutOptions = program.parseOptions(process.argv);
|
2016-05-09 19:19:16 +03:00
|
|
|
|
2017-11-12 20:28:13 +02: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"
|
|
|
|
))) {
|
2018-03-18 15:42:29 -04:00
|
|
|
log.error(`The client application was not built. Run ${colors.bold("NODE_ENV=production yarn build")} to resolve this.`);
|
2017-11-12 20:28:13 +02:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2017-11-22 16:51:22 -05:00
|
|
|
Helper.setHome(process.env.THELOUNGE_HOME || Utils.defaultHome());
|
2014-10-03 16:33:44 -07:00
|
|
|
|
2018-03-02 18:59:37 +02:00
|
|
|
Utils.checkOldHome();
|
|
|
|
|
2017-12-09 15:06:41 -05:00
|
|
|
// Merge config key-values passed as CLI options into the main config
|
|
|
|
_.merge(Helper.config, program.config);
|
|
|
|
|
2016-04-19 23:58:49 +03:00
|
|
|
require("./start");
|
2018-02-20 09:28:04 +02:00
|
|
|
|
2017-12-06 21:28:21 -05:00
|
|
|
if (!Helper.config.public && !Helper.config.ldap.enable) {
|
|
|
|
require("./users");
|
|
|
|
}
|
2018-02-20 09:28:04 +02:00
|
|
|
|
2017-09-18 18:57:24 +03:00
|
|
|
require("./install");
|
2018-01-04 21:09:59 -05:00
|
|
|
require("./uninstall");
|
2016-04-19 23:58:49 +03:00
|
|
|
|
2017-12-10 16:57:26 -05:00
|
|
|
// `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-18 18:18:40 -07:00
|
|
|
if (!program.args.length) {
|
2017-02-17 22:23:01 -05:00
|
|
|
program.help();
|
2014-08-18 18:18:40 -07:00
|
|
|
}
|