2016-12-30 12:12:28 -06:00
|
|
|
import Logger from './logger';
|
2017-01-25 05:38:19 -06:00
|
|
|
import { execSync } from 'child_process';
|
2016-12-30 12:12:28 -06:00
|
|
|
|
2017-01-02 13:39:44 -06:00
|
|
|
export default class {
|
2016-12-30 12:12:28 -06:00
|
|
|
logger: Logger;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.logger = new Logger('Deps');
|
|
|
|
}
|
|
|
|
|
2016-12-30 12:24:07 -06:00
|
|
|
showAll(): void {
|
2017-01-25 05:22:45 -06:00
|
|
|
this.show('MongoDB', 'mongo --version', x => x.match(/^MongoDB shell version:? (.*)\r?\n/));
|
2016-12-30 12:24:07 -06:00
|
|
|
this.show('Redis', 'redis-server --version', x => x.match(/v=([0-9\.]*)/));
|
2016-12-31 02:05:55 -06:00
|
|
|
this.show('GraphicsMagick', 'gm -version', x => x.match(/^GraphicsMagick ([0-9\.]*) .*/));
|
2016-12-30 12:12:28 -06:00
|
|
|
}
|
|
|
|
|
2016-12-30 12:24:07 -06:00
|
|
|
show(serviceName: string, command: string, transform: (x: string) => RegExpMatchArray): void {
|
2017-01-25 05:38:19 -06:00
|
|
|
try {
|
2017-01-25 21:12:37 -06:00
|
|
|
// ステータス0以外のときにexecSyncはstderrをコンソール上に出力してしまうので
|
|
|
|
// プロセスからのstderrをすべて無視するように stdio オプションをセット
|
2017-01-25 05:38:19 -06:00
|
|
|
const x = execSync(command, { stdio: ['pipe', 'pipe', 'ignore'] });
|
|
|
|
const ver = transform(x.toString());
|
2016-12-30 12:12:28 -06:00
|
|
|
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`);
|
|
|
|
}
|
2017-01-25 05:38:19 -06:00
|
|
|
} catch (e) {
|
2016-12-30 12:12:28 -06:00
|
|
|
this.logger.warn(`${serviceName} not found`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|