1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-11-28 14:58:29 +09:00
This commit is contained in:
Aya Morisawa 2016-12-30 03:20:25 +09:00
parent a81d908a4d
commit ada382f53f

View File

@ -2,21 +2,27 @@ import Logger from './logger';
import { exec } from 'shelljs';
export default function(): void {
checkDependency('Node.js', 'node -v', x => x.match(/^v(.*)\r?\n$/)[1]);
checkDependency('npm', 'npm -v', x => x.match(/^(.*)\r?\n$/)[1]);
checkDependency('MongoDB', 'mongo --version', x => x.match(/^MongoDB shell version: (.*)\r?\n$/)[1]);
checkDependency('Redis', 'redis-server --version', x => x.match(/v=([0-9\.]*)/)[1]);
checkDependency('Node.js', 'node -v', x => x.match(/^v(.*)\r?\n$/));
checkDependency('npm', 'npm -v', x => x.match(/^(.*)\r?\n$/));
checkDependency('MongoDB', 'mongo --version', x => x.match(/^MongoDDB shell version: (.*)\r?\n$/));
checkDependency('Redis', 'redis-server --version', x => x.match(/v=([0-9\.]*)/));
}
function checkDependency(serviceName: string, command: string, transform: (x: string) => string): void {
function checkDependency(serviceName: string, command: string, transform: (x: string) => RegExpMatchArray): void {
const code = {
success: 0,
notFound: 127
};
const x = exec(command, { silent: true }) as any;
let depsLogger = new Logger('Deps');
const x = exec(command, { silent: true }) as any;
if (x.code === code.success) {
depsLogger.info(`${serviceName} ${transform(x.stdout)} found`);
let ver = transform(x.stdout);
if (ver != null) {
depsLogger.info(`${serviceName} ${ver[1]} found`);
} else {
depsLogger.warn(`${serviceName} not found`);
depsLogger.warn(`Regexp used for version check of ${serviceName} is probably messed up`);
}
} else if (x.code === code.notFound) {
depsLogger.warn(`${serviceName} not found`);
}