forked from FoundKeyGang/FoundKey
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import Logger from './logger';
|
|
import { execSync } from 'child_process';
|
|
|
|
export default class {
|
|
logger: Logger;
|
|
|
|
constructor() {
|
|
this.logger = new Logger('Deps');
|
|
}
|
|
|
|
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('GraphicsMagick', 'gm -version', x => x.match(/^GraphicsMagick ([0-9\.]*) .*/));
|
|
}
|
|
|
|
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`);
|
|
}
|
|
}
|
|
}
|