Refactoring

This commit is contained in:
syuilo
2017-05-24 20:50:17 +09:00
parent 5a3cd80973
commit caeba1197c
16 changed files with 84 additions and 206 deletions

View File

@ -2,19 +2,19 @@ import Logger from './logger';
import { execSync } from 'child_process';
export default class {
logger: Logger;
private logger: Logger;
constructor() {
this.logger = new Logger('Deps');
}
showAll(): void {
public showAll(): void {
this.show('MongoDB', 'mongo --version', x => x.match(/^MongoDB shell version:? (.*)\r?\n/));
this.show('Redis', 'redis-server --version', x => x.match(/v=([0-9\.]*)/));
this.show('GraphicsMagick', 'gm -version', x => x.match(/^GraphicsMagick ([0-9\.]*) .*/));
}
show(serviceName: string, command: string, transform: (x: string) => RegExpMatchArray): void {
public show(serviceName: string, command: string, transform: (x: string) => RegExpMatchArray): void {
try {
// ステータス0以外のときにexecSyncはstderrをコンソール上に出力してしまうので
// プロセスからのstderrをすべて無視するように stdio オプションをセット

View File

@ -1,10 +1,11 @@
import Logger from './logger';
export default class {
static show(): void {
public static show(): void {
const env = process.env.NODE_ENV;
let logger = new Logger('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');

View File

@ -11,43 +11,43 @@ function toLevelColor(level: LogLevel): chalk.ChalkStyle {
}
export default class Logger {
domain: string;
static log(level: LogLevel, message: string): void {
let color = toLevelColor(level);
let time = (new Date()).toLocaleTimeString('ja-JP');
console.log(`[${time} ${color.bold(level.toUpperCase())}]: ${message}`);
}
static error(message: string): void {
Logger.log('Error', message);
}
static warn(message: string): void {
Logger.log('Warn', message);
}
static info(message: string): void {
Logger.log('Info', message);
}
private domain: string;
constructor(domain: string) {
this.domain = domain;
}
log(level: LogLevel, message: string): void {
public static log(level: LogLevel, message: string): void {
const color = toLevelColor(level);
const time = (new Date()).toLocaleTimeString('ja-JP');
console.log(`[${time} ${color.bold(level.toUpperCase())}]: ${message}`);
}
public static error(message: string): void {
Logger.log('Error', message);
}
public static warn(message: string): void {
Logger.log('Warn', message);
}
public static info(message: string): void {
Logger.log('Info', message);
}
public log(level: LogLevel, message: string): void {
Logger.log(level, `[${this.domain}] ${message}`);
}
error(message: string): void {
public error(message: string): void {
this.log('Error', message);
}
warn(message: string): void {
public warn(message: string): void {
this.log('Warn', message);
}
info(message: string): void {
public info(message: string): void {
this.log('Info', message);
}
}

View File

@ -2,10 +2,10 @@ import * as os from 'os';
import Logger from './logger';
export default class {
static show(): void {
public static show(): void {
const totalmem = (os.totalmem() / 1024 / 1024 / 1024).toFixed(1);
const freemem = (os.freemem() / 1024 / 1024 / 1024).toFixed(1);
let logger = new Logger('Machine');
const logger = new Logger('Machine');
logger.info(`Hostname: ${os.hostname()}`);
logger.info(`Platform: ${process.platform}`);
logger.info(`Architecture: ${process.arch}`);