Merge pull request #201 from VShell/config-outside-source

Refactor to move config to Shout home by default
This commit is contained in:
Mattias Erming 2014-10-01 21:04:16 +02:00
commit cb4b6786b2
7 changed files with 31 additions and 13 deletions

View File

@ -187,7 +187,3 @@ module.exports = {
certificate: "" certificate: ""
} }
}; };
if ("SHOUT_CONFIG" in process.env) {
module.exports = require(process.env.SHOUT_CONFIG);
}

View File

@ -1,5 +1,4 @@
var _ = require("lodash"); var _ = require("lodash");
var config = require("../config");
var Chan = require("./models/chan"); var Chan = require("./models/chan");
var crypto = require("crypto"); var crypto = require("crypto");
var log = require("./log"); var log = require("./log");
@ -8,6 +7,8 @@ var Msg = require("./models/msg");
var Network = require("./models/network"); var Network = require("./models/network");
var slate = require("slate-irc"); var slate = require("slate-irc");
var tls = require("tls"); var tls = require("tls");
var Helper = require("./helper");
var config = Helper.getConfig();
module.exports = Client; module.exports = Client;

View File

@ -1,15 +1,27 @@
var fs = require("fs");
var path = require("path");
var program = require("commander"); var program = require("commander");
var mkdirp = require("mkdirp");
var child = require("child_process"); var child = require("child_process");
var Helper = require("../helper");
var CONFIG_PATH = process.cwd() + "/config.js"; var CONFIG_PATH = process.env.SHOUT_CONFIG;
if(!CONFIG_PATH) {
CONFIG_PATH = Helper.resolveHomePath("config.js");
}
if(!fs.exists(CONFIG_PATH)) {
mkdirp.sync(Helper.getHomeDirectory());
var configFile = fs.readFileSync(path.resolve(__dirname, "..", "..", "config.js"));
fs.writeFileSync(CONFIG_PATH, configFile);
}
program program
.command("config") .command("config")
.description("Edit config: '" + CONFIG_PATH + "'") .description("Edit config: '" + CONFIG_PATH + "'")
.action(function() { .action(function() {
child.spawn( child.spawn(
"sudo", "vi",
["vi", CONFIG_PATH], [CONFIG_PATH],
{stdio: "inherit"} {stdio: "inherit"}
); );
}); });

View File

@ -1,7 +1,8 @@
var config = require("../../config");
var ClientManager = new require("../clientManager"); var ClientManager = new require("../clientManager");
var program = require("commander"); var program = require("commander");
var shout = require("../server"); var shout = require("../server");
var Helper = require("../helper");
var config = Helper.getConfig();
program program
.option("-H, --host <ip>", "host") .option("-H, --host <ip>", "host")

View File

@ -1,13 +1,21 @@
var fs = require("fs");
var path = require("path"); var path = require("path");
var Helper = module.exports = { var Helper = module.exports = {
getConfig: function () { getConfig: function () {
return require(path.resolve(__dirname, "..", "config")); var filename = process.env.SHOUT_CONFIG;
if(!filename || !fs.exists(filename)) {
filename = this.resolveHomePath("config.js");
if(!fs.exists(filename)) {
filename = path.resolve(__dirname, "..", "config");
}
}
return require(filename);
}, },
getHomeDirectory: function () { getHomeDirectory: function () {
return ( return (
this.getConfig().home (process.env.SHOUT_CONFIG && fs.exists(process.env.SHOUT_CONFIG) && this.getConfig().home)
|| process.env.SHOUT_HOME || process.env.SHOUT_HOME
|| path.resolve(process.env.HOME, ".shout") || path.resolve(process.env.HOME, ".shout")
); );

View File

@ -1,8 +1,8 @@
var config = require("../config");
var fs = require("fs"); var fs = require("fs");
var mkdirp = require("mkdirp"); var mkdirp = require("mkdirp");
var moment = require("moment"); var moment = require("moment");
var Helper = require("./helper"); var Helper = require("./helper");
var config = Helper.getConfig();
module.exports = { module.exports = {
write: function(user, network, chan, msg) { write: function(user, network, chan, msg) {

View File

@ -2,11 +2,11 @@ var _ = require("lodash");
var bcrypt = require("bcrypt"); var bcrypt = require("bcrypt");
var Client = require("./client"); var Client = require("./client");
var ClientManager = require("./clientManager"); var ClientManager = require("./clientManager");
var config = require("../config");
var express = require("express"); var express = require("express");
var fs = require("fs"); var fs = require("fs");
var io = require("socket.io"); var io = require("socket.io");
var Helper = require("./helper"); var Helper = require("./helper");
var config = Helper.getConfig();
var sockets = null; var sockets = null;
var manager = new ClientManager(); var manager = new ClientManager();