2016-12-30 20:12:28 +02:00
|
|
|
import Logger from './logger';
|
2017-01-25 13:38:19 +02:00
|
|
|
import { execSync } from 'child_process';
|
2016-12-30 20:12:28 +02:00
|
|
|
|
2017-01-02 21:39:44 +02:00
|
|
|
export default class {
|
2017-05-24 14:50:17 +03:00
|
|
|
private logger: Logger;
|
2016-12-30 20:12:28 +02:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.logger = new Logger('Deps');
|
|
|
|
}
|
|
|
|
|
2017-05-24 14:50:17 +03:00
|
|
|
public showAll(): void {
|
2017-01-25 13:22:45 +02:00
|
|
|
this.show('MongoDB', 'mongo --version', x => x.match(/^MongoDB shell version:? (.*)\r?\n/));
|
2016-12-30 20:24:07 +02:00
|
|
|
this.show('Redis', 'redis-server --version', x => x.match(/v=([0-9\.]*)/));
|
2017-12-09 15:35:26 +02:00
|
|
|
this.show('ImageMagick', 'magick -version', x => x.match(/^Version: ImageMagick (.+?)\r?\n/));
|
2016-12-30 20:12:28 +02:00
|
|
|
}
|
|
|
|
|
2017-05-24 14:50:17 +03:00
|
|
|
public show(serviceName: string, command: string, transform: (x: string) => RegExpMatchArray): void {
|
2017-01-25 13:38:19 +02:00
|
|
|
try {
|
2017-01-26 05:12:37 +02:00
|
|
|
// ステータス0以外のときにexecSyncはstderrをコンソール上に出力してしまうので
|
|
|
|
// プロセスからのstderrをすべて無視するように stdio オプションをセット
|
2017-01-25 13:38:19 +02:00
|
|
|
const x = execSync(command, { stdio: ['pipe', 'pipe', 'ignore'] });
|
|
|
|
const ver = transform(x.toString());
|
2016-12-30 20:12:28 +02:00
|
|
|
if (ver != null) {
|
2018-07-14 14:58:21 +03:00
|
|
|
this.logger.succ(`${serviceName} ${ver[1]} found`);
|
2016-12-30 20:12:28 +02:00
|
|
|
} else {
|
|
|
|
this.logger.warn(`${serviceName} not found`);
|
|
|
|
this.logger.warn(`Regexp used for version check of ${serviceName} is probably messed up`);
|
|
|
|
}
|
2017-01-25 13:38:19 +02:00
|
|
|
} catch (e) {
|
2016-12-30 20:12:28 +02:00
|
|
|
this.logger.warn(`${serviceName} not found`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|