forked from davidbierbauer/simplesite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.js
43 lines (34 loc) · 1.39 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var fs = require("fs");
var system = require("system");
var log = require("ringo/logging").getLogger(module.id);
// Load the default configuration
var config = require("gestalt").load(module.resolve("./config/config.json"));
// Parse command line arguments
var {Parser} = require("ringo/args");
var parser = new Parser();
parser.addOption("c", "config", "config", "Path to a custom configuration directory");
var opts = parser.parse(system.args.slice(1));
// look for environment variable
var envConfig = system.env["SIMPLESITE_CONFIG"];
// Load the config file
var configHome = fs.resolve(envConfig || opts.config || module.directory);
log.info("Config home: " + configHome);
if (envConfig || opts.config) {
var customConfigFile = fs.join(configHome, "config.json");
if (fs.exists(customConfigFile)) {
log.info("Loading config:", customConfigFile);
config.merge(customConfigFile);
} else {
log.error("Config file does not exist!", customConfigFile);
}
}
var logConfig = fs.join(configHome, "log4j.properties");
if (!fs.exists(logConfig)) {
logConfig = module.resolve("./config/log4j.properties");
}
log.info("Logging config: " + fs.absolute(logConfig));
config.set("configHome", configHome);
config.set("logging", getResource(fs.absolute(logConfig)));
// Set the logging config
require("ringo/logging").setConfig(config.get("logging"), true);
module.exports = config;