Added '--home <path>' option
This commit is contained in:
parent
83f4c5dd69
commit
2ed7d6364c
|
@ -34,15 +34,6 @@ module.exports = {
|
||||||
//
|
//
|
||||||
theme: "themes/example.css",
|
theme: "themes/example.css",
|
||||||
|
|
||||||
//
|
|
||||||
// Override home directory.
|
|
||||||
// Leaving this field empty will default to '~/.shout/'.
|
|
||||||
//
|
|
||||||
// @type string
|
|
||||||
// @default ""
|
|
||||||
//
|
|
||||||
home: "",
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Autoload users
|
// Autoload users
|
||||||
//
|
//
|
||||||
|
|
|
@ -8,7 +8,6 @@ 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 Helper = require("./helper");
|
||||||
var config = Helper.getConfig();
|
|
||||||
|
|
||||||
module.exports = Client;
|
module.exports = Client;
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ ClientManager.prototype.loadUsers = function() {
|
||||||
ClientManager.prototype.loadUser = function(name) {
|
ClientManager.prototype.loadUser = function(name) {
|
||||||
try {
|
try {
|
||||||
var json = fs.readFileSync(
|
var json = fs.readFileSync(
|
||||||
Helper.resolveHomePath("users", name, "user.json"),
|
Helper.HOME + "/users/" + name + "/user.json",
|
||||||
"utf-8"
|
"utf-8"
|
||||||
);
|
);
|
||||||
json = JSON.parse(json);
|
json = JSON.parse(json);
|
||||||
|
@ -56,10 +56,8 @@ ClientManager.prototype.loadUser = function(name) {
|
||||||
|
|
||||||
ClientManager.prototype.getUsers = function() {
|
ClientManager.prototype.getUsers = function() {
|
||||||
var users = [];
|
var users = [];
|
||||||
var path = Helper.resolveHomePath("users");
|
var path = Helper.HOME + "/users";
|
||||||
|
|
||||||
mkdirp.sync(path);
|
mkdirp.sync(path);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
users = fs.readdirSync(path);
|
users = fs.readdirSync(path);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
@ -103,7 +101,7 @@ ClientManager.prototype.removeUser = function(name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var path = Helper.resolveHomePath("users", name);
|
var path = Helper.HOME + "/users/" + name;
|
||||||
fs.unlinkSync(path + "/user.json");
|
fs.unlinkSync(path + "/user.json");
|
||||||
fs.rmdirSync(path);
|
fs.rmdirSync(path);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ program
|
||||||
.command("add <name> [<password>]")
|
.command("add <name> [<password>]")
|
||||||
.description("Add a new user")
|
.description("Add a new user")
|
||||||
.action(function(name, password) {
|
.action(function(name, password) {
|
||||||
var path = Helper.resolveHomePath("users");
|
var path = Helper.HOME + "/users";
|
||||||
try {
|
try {
|
||||||
mkdirp.sync(path);
|
mkdirp.sync(path);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -59,6 +59,6 @@ function add(manager, name, password) {
|
||||||
hash
|
hash
|
||||||
);
|
);
|
||||||
console.log("User '" + name + "' created:");
|
console.log("User '" + name + "' created:");
|
||||||
console.log(Helper.resolveHomePath("users", name, "user.json"));
|
console.log(Helper.HOME + "/users/" + name + "/user.json");
|
||||||
console.log("");
|
console.log("");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,23 +5,13 @@ var mkdirp = require("mkdirp");
|
||||||
var child = require("child_process");
|
var child = require("child_process");
|
||||||
var Helper = require("../helper");
|
var Helper = require("../helper");
|
||||||
|
|
||||||
var CONFIG_PATH = process.env.SHOUT_CONFIG;
|
|
||||||
if (!CONFIG_PATH) {
|
|
||||||
CONFIG_PATH = Helper.resolveHomePath("config.js");
|
|
||||||
}
|
|
||||||
if (!fs.existsSync(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: '" + Helper.HOME + "/config.js'")
|
||||||
.action(function() {
|
.action(function() {
|
||||||
child.spawn(
|
child.spawn(
|
||||||
"vi",
|
"vi",
|
||||||
[CONFIG_PATH],
|
[Helper.HOME + "/config.js"],
|
||||||
{stdio: "inherit"}
|
{stdio: "inherit"}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,7 +5,7 @@ var Helper = require("../helper");
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("edit <name>")
|
.command("edit <name>")
|
||||||
.description("Edit user: '" + Helper.resolveHomePath("users", "<name>", "user.json") + "'")
|
.description("Edit user: '" + Helper.HOME + "/users/<name>/user.json'")
|
||||||
.action(function(name) {
|
.action(function(name) {
|
||||||
var users = new ClientManager().getUsers();
|
var users = new ClientManager().getUsers();
|
||||||
if (users.indexOf(name) === -1) {
|
if (users.indexOf(name) === -1) {
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
var program = require("commander");
|
var program = require("commander");
|
||||||
var pkg = require("../../package.json");
|
var pkg = require("../../package.json");
|
||||||
|
var fs = require("fs");
|
||||||
|
var mkdirp = require("mkdirp");
|
||||||
|
var Helper = require("../helper");
|
||||||
|
|
||||||
program.version(pkg.version, "-v, --version");
|
program.version(pkg.version, "-v, --version");
|
||||||
|
program.option("");
|
||||||
|
program.option(" --home <path>", "home path");
|
||||||
|
|
||||||
require("./start");
|
require("./start");
|
||||||
require("./config");
|
require("./config");
|
||||||
|
@ -13,6 +18,16 @@ require("./edit");
|
||||||
|
|
||||||
program.parse(process.argv);
|
program.parse(process.argv);
|
||||||
|
|
||||||
|
if (program.home) {
|
||||||
|
Helper.HOME = program.home;
|
||||||
|
} else {
|
||||||
|
var config = Helper.HOME + "/config.js";
|
||||||
|
if (!fs.existsSync(config)) {
|
||||||
|
mkdirp.sync(Helper.HOME);
|
||||||
|
fs.writeFileSync(config, fs.readFileSync(__dirname + "/../../config.js"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!program.args.length) {
|
if (!program.args.length) {
|
||||||
program.parse(process.argv.concat("start"));
|
program.parse(process.argv.concat("start"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ var program = require("commander");
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("list")
|
.command("list")
|
||||||
.description("List all existing users")
|
.description("List all users")
|
||||||
.action(function() {
|
.action(function() {
|
||||||
var users = new ClientManager().getUsers();
|
var users = new ClientManager().getUsers();
|
||||||
if (!users.length) {
|
if (!users.length) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ program
|
||||||
.description("Remove an existing user")
|
.description("Remove an existing user")
|
||||||
.action(function(name) {
|
.action(function(name) {
|
||||||
try {
|
try {
|
||||||
var path = Helper.resolveHomePath("users");
|
var path = Helper.HOME + "/users";
|
||||||
var test = path + "/.test";
|
var test = path + "/.test";
|
||||||
fs.mkdirSync(test);
|
fs.mkdirSync(test);
|
||||||
fs.rmdirSync(test);
|
fs.rmdirSync(test);
|
||||||
|
|
|
@ -15,7 +15,7 @@ program
|
||||||
console.log("");
|
console.log("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var file = Helper.resolveHomePath("users/" + name + "/user.json");
|
var file = Helper.HOME + "/users/" + name + "/user.json";
|
||||||
var user = require(file);
|
var user = require(file);
|
||||||
require("read")({
|
require("read")({
|
||||||
prompt: "Password: ",
|
prompt: "Password: ",
|
||||||
|
|
|
@ -2,7 +2,6 @@ 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 Helper = require("../helper");
|
||||||
var config = Helper.getConfig();
|
|
||||||
|
|
||||||
program
|
program
|
||||||
.option("-H, --host <ip>", "host")
|
.option("-H, --host <ip>", "host")
|
||||||
|
@ -13,6 +12,7 @@ program
|
||||||
.description("Start the server")
|
.description("Start the server")
|
||||||
.action(function() {
|
.action(function() {
|
||||||
var users = new ClientManager().getUsers();
|
var users = new ClientManager().getUsers();
|
||||||
|
var config = Helper.getConfig();
|
||||||
var mode = config.public;
|
var mode = config.public;
|
||||||
if (program.public) {
|
if (program.public) {
|
||||||
mode = true;
|
mode = true;
|
||||||
|
|
|
@ -1,30 +1,8 @@
|
||||||
var fs = require("fs");
|
module.exports = {
|
||||||
var path = require("path");
|
HOME: process.env.HOME + "/.shout",
|
||||||
|
getConfig: getConfig
|
||||||
var Helper = module.exports = {
|
|
||||||
getConfig: function () {
|
|
||||||
var filename = process.env.SHOUT_CONFIG;
|
|
||||||
if(!filename || !fs.existsSync(filename)) {
|
|
||||||
filename = this.resolveHomePath("config.js");
|
|
||||||
if(!fs.existsSync(filename)) {
|
|
||||||
filename = path.resolve(__dirname, "..", "config");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return require(filename);
|
|
||||||
},
|
|
||||||
|
|
||||||
getHomeDirectory: function () {
|
|
||||||
return (
|
|
||||||
(process.env.SHOUT_CONFIG && fs.existsSync(process.env.SHOUT_CONFIG) && this.getConfig().home)
|
|
||||||
|| process.env.SHOUT_HOME
|
|
||||||
|| path.resolve(process.env.HOME, ".shout")
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
resolveHomePath: function () {
|
|
||||||
var fragments = [ Helper.HOME ].concat([].slice.apply(arguments));
|
|
||||||
return path.resolve.apply(path, fragments);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Helper.HOME = Helper.getHomeDirectory()
|
function getConfig() {
|
||||||
|
return require(this.HOME + "/config.js");
|
||||||
|
};
|
||||||
|
|
|
@ -2,17 +2,17 @@ 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) {
|
||||||
var path = Helper.resolveHomePath("users", user, "logs", network);
|
var path = Helper.HOME + "/users/" + user + "/logs/" + network;
|
||||||
try {
|
try {
|
||||||
mkdirp.sync(path);
|
mkdirp.sync(path);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var config = Helper.getConfig();
|
||||||
var format = (config.logs || {}).format || "YYYY-MM-DD HH:mm:ss";
|
var format = (config.logs || {}).format || "YYYY-MM-DD HH:mm:ss";
|
||||||
var tz = (config.logs || {}).timezone || "UTC+00:00";
|
var tz = (config.logs || {}).timezone || "UTC+00:00";
|
||||||
|
|
||||||
|
|
|
@ -6,20 +6,20 @@ 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 config = {};
|
||||||
|
|
||||||
var sockets = null;
|
var sockets = null;
|
||||||
var manager = new ClientManager();
|
var manager = new ClientManager();
|
||||||
|
|
||||||
module.exports = function(port, host, isPublic) {
|
module.exports = function(port, host, isPublic) {
|
||||||
|
config = Helper.getConfig();
|
||||||
config.port = port;
|
config.port = port;
|
||||||
config.host = host;
|
config.host = host;
|
||||||
config.public = isPublic;
|
config.public = isPublic;
|
||||||
|
|
||||||
var app = express()
|
var app = express()
|
||||||
.use(index)
|
.use(index)
|
||||||
.use(express.static("client"))
|
.use(express.static("client"));
|
||||||
.use(express.static(Helper.resolveHomePath("cache")));
|
|
||||||
|
|
||||||
var server = null;
|
var server = null;
|
||||||
var https = config.https || {};
|
var https = config.https || {};
|
||||||
|
|
Loading…
Reference in New Issue