UNPKG

3.1 kBJavaScriptView Raw
1"use strict";
2
3global.log = require("../log.js");
4
5const _ = require("lodash");
6const fs = require("fs");
7const path = require("path");
8const program = require("commander");
9const colors = require("colors/safe");
10const Helper = require("../helper");
11const Utils = require("./utils");
12
13if (require("semver").lt(process.version, "6.0.0")) {
14 log.warn(`Support of Node.js v4 is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3.`);
15 log.warn("Please upgrade to Node.js v6 or more recent.");
16}
17
18program.version(Helper.getVersion(), "-v, --version")
19 .option("--home <path>", `${colors.bold.red("[DEPRECATED]")} Use the ${colors.green("THELOUNGE_HOME")} environment variable instead.`)
20 .option(
21 "-c, --config <key=value>",
22 "override entries of the configuration file, must be specified for each entry that needs to be overriden",
23 Utils.parseConfigOptions
24 )
25 .on("--help", Utils.extraHelp);
26
27// Parse options from `argv` returning `argv` void of these options.
28const argvWithoutOptions = program.parseOptions(process.argv);
29
30if (program.home) {
31 log.warn(`${colors.bold("--home")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3. Use the ${colors.bold("THELOUNGE_HOME")} environment variable instead.`);
32}
33
34// Check if the app was built before calling setHome as it wants to load manifest.json from the public folder
35if (!fs.existsSync(path.join(
36 __dirname,
37 "..",
38 "..",
39 "public",
40 "manifest.json"
41))) {
42 log.error(`The client application was not built. Run ${colors.bold("NODE_ENV=production npm run build")} to resolve this.`);
43 process.exit(1);
44}
45
46if (process.env.LOUNGE_HOME) {
47 log.warn(`${colors.green("LOUNGE_HOME")} is ${colors.bold.red("deprecated")} and will be removed in The Lounge v3.`);
48 log.warn(`Use ${colors.green("THELOUNGE_HOME")} instead.`);
49}
50
51let home = process.env.THELOUNGE_HOME || program.home || process.env.LOUNGE_HOME;
52
53if (!home) {
54 home = Utils.defaultHome();
55}
56
57Helper.setHome(home);
58
59// Merge config key-values passed as CLI options into the main config
60_.merge(Helper.config, program.config);
61
62require("./start");
63require("./config");
64if (!Helper.config.public && !Helper.config.ldap.enable) {
65 require("./users");
66}
67require("./install");
68require("./uninstall");
69
70// TODO: Remove this when releasing The Lounge v3
71if (process.argv[1].endsWith(`${require("path").sep}lounge`)) {
72 log.warn(`The ${colors.red("lounge")} CLI is ${colors.bold.red("deprecated")} and will be removed in v3.`);
73 log.warn(`Use ${colors.green("thelounge")} instead.`);
74 process.argv[1] = "thelounge";
75}
76
77// `parse` expects to be passed `process.argv`, but we need to remove to give it
78// a version of `argv` that does not contain options already parsed by
79// `parseOptions` above.
80// This is done by giving it the updated `argv` that `parseOptions` returned,
81// except it returns an object with `args`/`unknown`, so we need to concat them.
82// See https://github.com/tj/commander.js/blob/fefda77f463292/index.js#L686-L763
83program.parse(argvWithoutOptions.args.concat(argvWithoutOptions.unknown));
84
85if (!program.args.length) {
86 program.help();
87}