yumechi-no-kuni/src/misc/dependencyInfo.ts

34 lines
1.2 KiB
TypeScript
Raw Normal View History

2016-12-30 12:12:28 -06:00
import Logger from './logger';
import { execSync } from 'child_process';
2016-12-30 12:12:28 -06:00
2017-01-02 13:39:44 -06:00
export default class {
2017-05-24 06:50:17 -05:00
private logger: Logger;
2016-12-30 12:12:28 -06:00
constructor() {
this.logger = new Logger('Deps');
}
2017-05-24 06:50:17 -05:00
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 ([^ ]*)/));
2016-12-30 12:12:28 -06:00
}
2017-05-24 06:50:17 -05:00
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());
2016-12-30 12:12:28 -06:00
if (ver != null) {
2018-07-14 06:58:21 -05:00
this.logger.succ(`${serviceName} ${ver[1]} found`);
2016-12-30 12:12:28 -06:00
} else {
this.logger.warn(`${serviceName} not found`);
this.logger.warn(`Regexp used for version check of ${serviceName} is probably messed up`);
}
} catch (e) {
2016-12-30 12:12:28 -06:00
this.logger.warn(`${serviceName} not found`);
}
}
}