diff options
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/cli/indicator.ts | 35 | ||||
| -rw-r--r-- | src/utils/cli/progressbar.ts | 85 | ||||
| -rw-r--r-- | src/utils/dependencyInfo.ts | 33 | ||||
| -rw-r--r-- | src/utils/environmentInfo.ts | 14 | ||||
| -rw-r--r-- | src/utils/logger.ts | 53 | ||||
| -rw-r--r-- | src/utils/machineInfo.ts | 16 |
6 files changed, 0 insertions, 236 deletions
diff --git a/src/utils/cli/indicator.ts b/src/utils/cli/indicator.ts deleted file mode 100644 index 3e23f9b274..0000000000 --- a/src/utils/cli/indicator.ts +++ /dev/null @@ -1,35 +0,0 @@ -import * as readline from 'readline'; - -/** - * Indicator - */ -export default class { - private clock: NodeJS.Timer; - - constructor(text: string) { - let i = 0; // Dots counter - - draw(); - this.clock = setInterval(draw, 300); - - function draw(): void { - cll(); - i = (i + 1) % 4; - const dots = new Array(i + 1).join('.'); - process.stdout.write(text + dots); // Write text - } - } - - public end(): void { - clearInterval(this.clock); - cll(); - } -} - -/** - * Clear current line - */ -function cll(): void { - readline.clearLine(process.stdout, 0); // Clear current text - readline.cursorTo(process.stdout, 0, null); // Move cursor to the head of line -} diff --git a/src/utils/cli/progressbar.ts b/src/utils/cli/progressbar.ts deleted file mode 100644 index 72496fdedc..0000000000 --- a/src/utils/cli/progressbar.ts +++ /dev/null @@ -1,85 +0,0 @@ -import { EventEmitter } from 'events'; -import * as readline from 'readline'; -import chalk from 'chalk'; - -/** - * Progress bar - */ -export default class extends EventEmitter { - public max: number; - public value: number; - public text: string; - private indicator: number; - - constructor(max: number, text: string = null) { - super(); - this.max = max; - this.value = 0; - this.text = text; - this.indicator = 0; - this.draw(); - - const iclock = setInterval(() => { - this.indicator = (this.indicator + 1) % 4; - this.draw(); - }, 200); - - this.on('complete', () => { - clearInterval(iclock); - }); - } - - public increment(): void { - this.value++; - this.draw(); - - // Check if it is fulfilled - if (this.value === this.max) { - this.indicator = null; - - cll(); - process.stdout.write(`${this.render()} -> ${chalk.bold('Complete')}\n`); - - this.emit('complete'); - } - } - - public draw(): void { - const str = this.render(); - cll(); - process.stdout.write(str); - } - - private render(): string { - const width = 30; - const t = this.text ? `${this.text} ` : ''; - - const v = Math.floor((this.value / this.max) * width); - const vs = new Array(v + 1).join('*'); - - const p = width - v; - const ps = new Array(p + 1).join(' '); - - const percentage = Math.floor((this.value / this.max) * 100); - const percentages = chalk.gray(`(${percentage} %)`); - - let i: string; - switch (this.indicator) { - case 0: i = '-'; break; - case 1: i = '\\'; break; - case 2: i = '|'; break; - case 3: i = '/'; break; - case null: i = '+'; break; - } - - return `${i} ${t}[${vs}${ps}] ${this.value} / ${this.max} ${percentages}`; - } -} - -/** - * Clear current line - */ -function cll(): void { - readline.clearLine(process.stdout, 0); // Clear current text - readline.cursorTo(process.stdout, 0, null); // Move cursor to the head of line -} diff --git a/src/utils/dependencyInfo.ts b/src/utils/dependencyInfo.ts deleted file mode 100644 index 89af0d20fb..0000000000 --- a/src/utils/dependencyInfo.ts +++ /dev/null @@ -1,33 +0,0 @@ -import Logger from './logger'; -import { execSync } from 'child_process'; - -export default class { - private logger: Logger; - - constructor() { - this.logger = new Logger('Deps'); - } - - 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('ImageMagick', 'magick -version', x => x.match(/^Version: ImageMagick (.+?)\r?\n/)); - } - - public show(serviceName: string, command: string, transform: (x: string) => RegExpMatchArray): void { - try { - // ステータス0以外のときにexecSyncはstderrをコンソール上に出力してしまうので - // プロセスからのstderrをすべて無視するように stdio オプションをセット - const x = execSync(command, { stdio: ['pipe', 'pipe', 'ignore'] }); - const ver = transform(x.toString()); - if (ver != null) { - this.logger.info(`${serviceName} ${ver[1]} found`); - } else { - this.logger.warn(`${serviceName} not found`); - this.logger.warn(`Regexp used for version check of ${serviceName} is probably messed up`); - } - } catch (e) { - this.logger.warn(`${serviceName} not found`); - } - } -} diff --git a/src/utils/environmentInfo.ts b/src/utils/environmentInfo.ts deleted file mode 100644 index e6084cde0e..0000000000 --- a/src/utils/environmentInfo.ts +++ /dev/null @@ -1,14 +0,0 @@ -import Logger from './logger'; - -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'); - } - } -} diff --git a/src/utils/logger.ts b/src/utils/logger.ts deleted file mode 100644 index fae1042c39..0000000000 --- a/src/utils/logger.ts +++ /dev/null @@ -1,53 +0,0 @@ -import chalk, { Chalk } from 'chalk'; - -export type LogLevel = 'Error' | 'Warn' | 'Info'; - -function toLevelColor(level: LogLevel): Chalk { - switch (level) { - case 'Error': return chalk.red; - case 'Warn': return chalk.yellow; - case 'Info': return chalk.blue; - } -} - -export default class Logger { - private domain: string; - - constructor(domain: string) { - this.domain = domain; - } - - 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}`); - } - - public error(message: string): void { - this.log('Error', message); - } - - public warn(message: string): void { - this.log('Warn', message); - } - - public info(message: string): void { - this.log('Info', message); - } -} diff --git a/src/utils/machineInfo.ts b/src/utils/machineInfo.ts deleted file mode 100644 index 0c189cc7ca..0000000000 --- a/src/utils/machineInfo.ts +++ /dev/null @@ -1,16 +0,0 @@ -import * as os from 'os'; -import Logger from './logger'; - -export default class { - public static show(): void { - const totalmem = (os.totalmem() / 1024 / 1024 / 1024).toFixed(1); - const freemem = (os.freemem() / 1024 / 1024 / 1024).toFixed(1); - const logger = new Logger('Machine'); - logger.info(`Hostname: ${os.hostname()}`); - logger.info(`Platform: ${process.platform}`); - logger.info(`Architecture: ${process.arch}`); - logger.info(`Node.js: ${process.version}`); - logger.info(`CPU: ${os.cpus().length}core`); - logger.info(`MEM: ${totalmem}GB (available: ${freemem}GB)`); - } -} |