Only create config folder in 'start' command

Fixes #520.
Fixes #1288.
This commit is contained in:
Pavel Djundik 2017-07-18 12:36:24 +03:00 committed by Jérémie Astori
parent 6ba2b8a3d1
commit 252dca3d3f
No known key found for this signature in database
GPG Key ID: B9A4F245CD67BDE8
8 changed files with 94 additions and 48 deletions

View File

@ -1,9 +1,9 @@
"use strict"; "use strict";
var ClientManager = new require("../clientManager"); const colors = require("colors/safe");
var colors = require("colors/safe"); const program = require("commander");
var program = require("commander"); const fs = require("fs");
var Helper = require("../helper"); const Helper = require("../helper");
const Utils = require("./utils"); const Utils = require("./utils");
program program
@ -11,6 +11,13 @@ program
.description("Add a new user") .description("Add a new user")
.on("--help", Utils.extraHelp) .on("--help", Utils.extraHelp)
.action(function(name) { .action(function(name) {
if (!fs.existsSync(Helper.USERS_PATH)) {
log.error(`${Helper.USERS_PATH} does not exist.`);
return;
}
const ClientManager = require("../clientManager");
if (Helper.config.public) { if (Helper.config.public) {
log.warn(`Users have no effect in ${colors.bold("public")} mode.`); log.warn(`Users have no effect in ${colors.bold("public")} mode.`);
} }

View File

@ -1,9 +1,10 @@
"use strict"; "use strict";
var program = require("commander"); const program = require("commander");
var child = require("child_process"); const child = require("child_process");
var colors = require("colors/safe"); const colors = require("colors/safe");
var Helper = require("../helper"); const fs = require("fs");
const Helper = require("../helper");
const Utils = require("./utils"); const Utils = require("./utils");
program program
@ -11,6 +12,11 @@ program
.description(`Edit configuration file located at ${colors.green(Helper.CONFIG_PATH)}.`) .description(`Edit configuration file located at ${colors.green(Helper.CONFIG_PATH)}.`)
.on("--help", Utils.extraHelp) .on("--help", Utils.extraHelp)
.action(function() { .action(function() {
if (!fs.existsSync(Helper.CONFIG_PATH)) {
log.error(`${Helper.CONFIG_PATH} does not exist.`);
return;
}
var child_spawn = child.spawn( var child_spawn = child.spawn(
process.env.EDITOR || "vi", process.env.EDITOR || "vi",
[Helper.CONFIG_PATH], [Helper.CONFIG_PATH],

View File

@ -1,10 +1,10 @@
"use strict"; "use strict";
var ClientManager = new require("../clientManager"); const program = require("commander");
var program = require("commander"); const child = require("child_process");
var child = require("child_process"); const colors = require("colors/safe");
var colors = require("colors/safe"); const fs = require("fs");
var Helper = require("../helper"); const Helper = require("../helper");
const Utils = require("./utils"); const Utils = require("./utils");
program program
@ -12,6 +12,13 @@ program
.description(`Edit user file located at ${colors.green(Helper.getUserConfigPath("<name>"))}.`) .description(`Edit user file located at ${colors.green(Helper.getUserConfigPath("<name>"))}.`)
.on("--help", Utils.extraHelp) .on("--help", Utils.extraHelp)
.action(function(name) { .action(function(name) {
if (!fs.existsSync(Helper.USERS_PATH)) {
log.error(`${Helper.USERS_PATH} does not exist.`);
return;
}
const ClientManager = require("../clientManager");
var users = new ClientManager().getUsers(); var users = new ClientManager().getUsers();
if (users === undefined) { // There was an error, already logged if (users === undefined) { // There was an error, already logged

View File

@ -2,12 +2,9 @@
global.log = require("../log.js"); global.log = require("../log.js");
var program = require("commander"); const program = require("commander");
var colors = require("colors/safe"); const colors = require("colors/safe");
var fs = require("fs"); const Helper = require("../helper");
var fsextra = require("fs-extra");
var path = require("path");
var Helper = require("../helper");
const Utils = require("./utils"); const Utils = require("./utils");
program.version(Helper.getVersion(), "-v, --version") program.version(Helper.getVersion(), "-v, --version")
@ -28,21 +25,6 @@ if (!home) {
Helper.setHome(home); Helper.setHome(home);
if (!fs.existsSync(Helper.CONFIG_PATH)) {
fsextra.ensureDirSync(Helper.HOME);
fs.chmodSync(Helper.HOME, "0700");
fsextra.copySync(path.resolve(path.join(
__dirname,
"..",
"..",
"defaults",
"config.js"
)), Helper.CONFIG_PATH);
log.info(`Configuration file created at ${colors.green(Helper.CONFIG_PATH)}.`);
}
fsextra.ensureDirSync(Helper.USERS_PATH);
require("./start"); require("./start");
require("./config"); require("./config");
require("./list"); require("./list");

View File

@ -1,8 +1,8 @@
"use strict"; "use strict";
var ClientManager = new require("../clientManager"); const colors = require("colors/safe");
var program = require("commander"); const program = require("commander");
var colors = require("colors/safe"); const fs = require("fs");
const Helper = require("../helper"); const Helper = require("../helper");
const Utils = require("./utils"); const Utils = require("./utils");
@ -11,6 +11,13 @@ program
.description("List all users") .description("List all users")
.on("--help", Utils.extraHelp) .on("--help", Utils.extraHelp)
.action(function() { .action(function() {
if (!fs.existsSync(Helper.USERS_PATH)) {
log.error(`${Helper.USERS_PATH} does not exist.`);
return;
}
const ClientManager = require("../clientManager");
if (Helper.config.public) { if (Helper.config.public) {
log.warn(`Users have no effect in ${colors.bold("public")} mode.`); log.warn(`Users have no effect in ${colors.bold("public")} mode.`);
} }

View File

@ -1,8 +1,9 @@
"use strict"; "use strict";
var ClientManager = new require("../clientManager"); const colors = require("colors/safe");
var program = require("commander"); const program = require("commander");
var colors = require("colors/safe"); const fs = require("fs");
const Helper = require("../helper");
const Utils = require("./utils"); const Utils = require("./utils");
program program
@ -10,6 +11,12 @@ program
.description("Remove an existing user") .description("Remove an existing user")
.on("--help", Utils.extraHelp) .on("--help", Utils.extraHelp)
.action(function(name) { .action(function(name) {
if (!fs.existsSync(Helper.USERS_PATH)) {
log.error(`${Helper.USERS_PATH} does not exist.`);
return;
}
const ClientManager = require("../clientManager");
const manager = new ClientManager(); const manager = new ClientManager();
try { try {

View File

@ -1,10 +1,9 @@
"use strict"; "use strict";
var ClientManager = new require("../clientManager"); const colors = require("colors/safe");
var fs = require("fs"); const program = require("commander");
var program = require("commander"); const fs = require("fs");
var colors = require("colors/safe"); const Helper = require("../helper");
var Helper = require("../helper");
const Utils = require("./utils"); const Utils = require("./utils");
program program
@ -12,6 +11,13 @@ program
.description("Reset user password") .description("Reset user password")
.on("--help", Utils.extraHelp) .on("--help", Utils.extraHelp)
.action(function(name) { .action(function(name) {
if (!fs.existsSync(Helper.USERS_PATH)) {
log.error(`${Helper.USERS_PATH} does not exist.`);
return;
}
const ClientManager = require("../clientManager");
var users = new ClientManager().getUsers(); var users = new ClientManager().getUsers();
if (users === undefined) { // There was an error, already logged if (users === undefined) { // There was an error, already logged

View File

@ -1,8 +1,11 @@
"use strict"; "use strict";
var program = require("commander"); const colors = require("colors/safe");
var server = require("../server"); const fs = require("fs");
var Helper = require("../helper"); const fsextra = require("fs-extra");
const path = require("path");
const program = require("commander");
const Helper = require("../helper");
const Utils = require("./utils"); const Utils = require("./utils");
program program
@ -15,6 +18,10 @@ program
.description("Start the server") .description("Start the server")
.on("--help", Utils.extraHelp) .on("--help", Utils.extraHelp)
.action(function(options) { .action(function(options) {
initalizeConfig();
const server = require("../server");
var mode = Helper.config.public; var mode = Helper.config.public;
if (options.public) { if (options.public) {
mode = true; mode = true;
@ -29,3 +36,20 @@ program
server(); server();
}); });
function initalizeConfig() {
if (!fs.existsSync(Helper.CONFIG_PATH)) {
fsextra.ensureDirSync(Helper.HOME);
fs.chmodSync(Helper.HOME, "0700");
fsextra.copySync(path.resolve(path.join(
__dirname,
"..",
"..",
"defaults",
"config.js"
)), Helper.CONFIG_PATH);
log.info(`Configuration file created at ${colors.green(Helper.CONFIG_PATH)}.`);
}
fsextra.ensureDirSync(Helper.USERS_PATH);
}