From 240b10ed6e0c79cf5d0bd526be1cdd58256da520 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Tue, 3 Jan 2017 05:15:01 +0900 Subject: [PATCH] :sparkles: --- src/index.ts | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/index.ts b/src/index.ts index 75bfa35062..31e5cdbf83 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,13 +27,10 @@ require('babel-polyfill'); global.config = require('./config').default(`${__dirname}/../.config/config.yml`); -/** - * Initialize state - */ -enum State { - success, - warn, - failed +enum InitResult { + Success, + Warn, + Failure } // Set process title @@ -58,25 +55,25 @@ function main(): void { * Init master proccess */ async function master(): Promise { - let state: State; + let initResult: InitResult; try { // initialize app - state = await init(); + initResult = await init(); } catch (e) { console.error(e); process.exit(1); } - switch (state) { - case State.failed: + switch (initResult) { + case InitResult.Failure: Logger.error(chalk.red('Fatal error occurred during initializing :(')); process.exit(); return; - case State.warn: + case InitResult.Warn: Logger.warn(chalk.yellow('Initialized with some problem(s) :|')); break; - case State.success: + case InitResult.Success: Logger.info(chalk.green('Successfully initialized :)')); break; } @@ -127,7 +124,7 @@ function worker(): void { /** * Init app */ -async function init(): Promise { +async function init(): Promise { let warn = false; Logger.info('Welcome to Misskey!'); @@ -142,7 +139,7 @@ async function init(): Promise { let configLogger = new Logger('Config'); if (!fs.existsSync(`${__dirname}/../.config/config.yml`)) { configLogger.error('Configuration not found'); - return State.failed; + return InitResult.Failure; } configLogger.info('Successfully loaded'); @@ -150,13 +147,13 @@ async function init(): Promise { if (process.platform === 'linux' && !isRoot() && config.port < 1024) { Logger.error('You need root privileges to listen on port below 1024 on Linux'); - return State.failed; + return InitResult.Failure; } // Check if a port is being used if (await portUsed.check(config.port)) { Logger.error(`Port ${config.port} is already used`); - return State.failed; + return InitResult.Failure; } // Try to connect to MongoDB @@ -167,10 +164,10 @@ async function init(): Promise { db.close(); } catch (e) { mongoDBLogger.error(`${e}`); - return State.failed; + return InitResult.Failure; } - return warn ? State.warn : State.success; + return warn ? InitResult.Warn : InitResult.Success; } /**