From 7e4091c7795d2bd72a0b6a4c3740bebdf3f002d9 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Sat, 31 Dec 2016 03:19:59 +0900 Subject: [PATCH] Extract MachineInfo --- src/index.ts | 10 ++-------- src/utils/machineInfo.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 src/utils/machineInfo.ts diff --git a/src/index.ts b/src/index.ts index 47354eab0d..c4cba4d46e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,7 @@ const portUsed = require('tcp-port-used'); const isRoot = require('is-root'); import ProgressBar from './utils/cli/progressbar'; import initdb from './db/mongodb'; +import MachineInfo from './utils/machineInfo'; import DependencyChecker from './utils/dependencyChecker'; // Init babel @@ -158,14 +159,7 @@ async function init(): Promise { envLogger.warn('Do not use for production purpose'); } - // Get machine info - const totalmem = (os.totalmem() / 1024 / 1024 / 1024).toFixed(1); - const freemem = (os.freemem() / 1024 / 1024 / 1024).toFixed(1); - let machineLogger = new Logger('Machine'); - machineLogger.info(os.hostname()); - machineLogger.info(`CPU: ${os.cpus().length}core`); - machineLogger.info(`MEM: ${totalmem}GB (available: ${freemem}GB)`); - + MachineInfo.show(); new DependencyChecker().checkAll(); let configLogger = new Logger('Config'); diff --git a/src/utils/machineInfo.ts b/src/utils/machineInfo.ts new file mode 100644 index 0000000000..600460e4da --- /dev/null +++ b/src/utils/machineInfo.ts @@ -0,0 +1,13 @@ +import * as os from 'os'; +import Logger from './logger'; + +export default class MachineInfo { + static show() { + const totalmem = (os.totalmem() / 1024 / 1024 / 1024).toFixed(1); + const freemem = (os.freemem() / 1024 / 1024 / 1024).toFixed(1); + let logger = new Logger('Machine'); + logger.info(os.hostname()); + logger.info(`CPU: ${os.cpus().length}core`); + logger.info(`MEM: ${totalmem}GB (available: ${freemem}GB)`); + } +}