From 6ead284f31564a2fd1905a5683a94fbc33dc45f9 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Sat, 31 Dec 2016 03:24:07 +0900 Subject: Rename DependencyChecker to DependencyInfo --- src/utils/dependencyInfo.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/utils/dependencyInfo.ts (limited to 'src/utils/dependencyInfo.ts') diff --git a/src/utils/dependencyInfo.ts b/src/utils/dependencyInfo.ts new file mode 100644 index 0000000000..e0d8f24d74 --- /dev/null +++ b/src/utils/dependencyInfo.ts @@ -0,0 +1,38 @@ +import Logger from './logger'; +import { exec } from 'shelljs'; + +export default class DependencyInfo { + logger: Logger; + + constructor() { + this.logger = new Logger('Deps'); + } + + showAll(): void { + this.logger.info('Checking started'); + this.show('Node.js', 'node -v', x => x.match(/^v(.*)\r?\n$/)); + this.show('npm', 'npm -v', x => x.match(/^(.*)\r?\n$/)); + 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.logger.info('Checking finished'); + } + + show(serviceName: string, command: string, transform: (x: string) => RegExpMatchArray): void { + const code = { + success: 0, + notFound: 127 + }; + const x = exec(command, { silent: true }) as any; + if (x.code === code.success) { + let ver = transform(x.stdout); + 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`); + } + } else if (x.code === code.notFound) { + this.logger.warn(`${serviceName} not found`); + } + } +} -- cgit v1.2.3-freya