2016-12-30 20:12:28 +02:00
|
|
|
import Logger from './logger';
|
|
|
|
import { exec } from 'shelljs';
|
|
|
|
|
2016-12-30 20:24:07 +02:00
|
|
|
export default class DependencyInfo {
|
2016-12-30 20:12:28 +02:00
|
|
|
logger: Logger;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.logger = new Logger('Deps');
|
|
|
|
}
|
|
|
|
|
2016-12-30 20:24:07 +02:00
|
|
|
showAll(): void {
|
2016-12-30 20:12:28 +02:00
|
|
|
this.logger.info('Checking started');
|
2016-12-30 20:24:07 +02:00
|
|
|
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\.]*)/));
|
2016-12-31 10:05:55 +02:00
|
|
|
this.show('GraphicsMagick', 'gm -version', x => x.match(/^GraphicsMagick ([0-9\.]*) .*/));
|
2016-12-30 20:12:28 +02:00
|
|
|
this.logger.info('Checking finished');
|
|
|
|
}
|
|
|
|
|
2016-12-30 20:24:07 +02:00
|
|
|
show(serviceName: string, command: string, transform: (x: string) => RegExpMatchArray): void {
|
2016-12-30 20:12:28 +02:00
|
|
|
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`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|