From ca0cb6fd42a445455cfc1d27538725e14ae60a12 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Mon, 19 Nov 2018 13:39:10 +0900 Subject: [PATCH] Merge environmentInfo and machineInfo into index.ts (#3319) --- src/index.ts | 32 ++++++++++++++++++++++++++++---- src/misc/environmentInfo.ts | 17 ----------------- src/misc/machineInfo.ts | 17 ----------------- 3 files changed, 28 insertions(+), 38 deletions(-) delete mode 100644 src/misc/environmentInfo.ts delete mode 100644 src/misc/machineInfo.ts diff --git a/src/index.ts b/src/index.ts index 742b140452..c58a214054 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,11 +14,10 @@ import * as portscanner from 'portscanner'; import isRoot = require('is-root'); import Xev from 'xev'; import * as program from 'commander'; +import * as sysUtils from 'systeminformation'; import mongo, { nativeDbConn } from './db/mongodb'; import Logger from './misc/logger'; -import EnvironmentInfo from './misc/environmentInfo'; -import MachineInfo from './misc/machineInfo'; import serverStats from './daemons/server-stats'; import notesStats from './daemons/notes-stats'; import loadConfig from './config/load'; @@ -107,6 +106,31 @@ const runningNodejsVersion = process.version.slice(1).split('.').map(x => parseI const requiredNodejsVersion = [10, 0, 0]; const satisfyNodejsVersion = !lessThan(runningNodejsVersion, requiredNodejsVersion); +async function showMachine() { + const logger = new Logger('Machine'); + logger.info(`Hostname: ${os.hostname()}`); + logger.info(`Platform: ${process.platform}`); + logger.info(`Architecture: ${process.arch}`); + logger.info(`CPU: ${os.cpus().length} core`); + const mem = await sysUtils.mem(); + const totalmem = (mem.total / 1024 / 1024 / 1024).toFixed(1); + const availmem = (mem.available / 1024 / 1024 / 1024).toFixed(1); + logger.info(`MEM: ${totalmem}GB (available: ${availmem}GB)`); +} + +function showEnvironment(): void { + const env = process.env.NODE_ENV; + const logger = new Logger('Env'); + logger.info(typeof env == 'undefined' ? 'NODE_ENV is not set' : `NODE_ENV: ${env}`); + + if (env !== 'production') { + logger.warn('The environment is not in production mode'); + logger.warn('Do not use for production purpose'); + } + + logger.info(`You ${isRoot() ? '' : 'do not '}have root privileges`); +} + /** * Init app */ @@ -121,8 +145,8 @@ async function init(): Promise { process.exit(1); } - await MachineInfo.show(); - EnvironmentInfo.show(); + await showMachine(); + showEnvironment(); const configLogger = new Logger('Config'); let config; diff --git a/src/misc/environmentInfo.ts b/src/misc/environmentInfo.ts deleted file mode 100644 index cee42ef9c0..0000000000 --- a/src/misc/environmentInfo.ts +++ /dev/null @@ -1,17 +0,0 @@ -import Logger from './logger'; -import isRoot = require('is-root'); - -export default class { - public static show(): void { - const env = process.env.NODE_ENV; - const logger = new Logger('Env'); - logger.info(typeof env == 'undefined' ? 'NODE_ENV is not set' : `NODE_ENV: ${env}`); - - if (env !== 'production') { - logger.warn('The environment is not in production mode'); - logger.warn('Do not use for production purpose'); - } - - logger.info(`You ${isRoot() ? '' : 'do not '}have root privileges`); - } -} diff --git a/src/misc/machineInfo.ts b/src/misc/machineInfo.ts deleted file mode 100644 index 7d8a52ff9a..0000000000 --- a/src/misc/machineInfo.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as os from 'os'; -import Logger from './logger'; -import * as sysUtils from 'systeminformation'; - -export default class { - public static async show() { - const logger = new Logger('Machine'); - logger.info(`Hostname: ${os.hostname()}`); - logger.info(`Platform: ${process.platform}`); - logger.info(`Architecture: ${process.arch}`); - logger.info(`CPU: ${os.cpus().length} core`); - const mem = await sysUtils.mem(); - const totalmem = (mem.total / 1024 / 1024 / 1024).toFixed(1); - const availmem = (mem.available / 1024 / 1024 / 1024).toFixed(1); - logger.info(`MEM: ${totalmem}GB (available: ${availmem}GB)`); - } -}