Skip to content

Commit

Permalink
Merge pull request #61 from laggingreflex/doctor-cygwin
Browse files Browse the repository at this point in the history
Cygwin check for Windows in doctor command
  • Loading branch information
Joel Griffith committed Nov 7, 2016
2 parents 2a0c5a4 + f135e07 commit 51a767e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/doctor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os from 'os';
import { spawnSync } from 'child_process';
import _ from 'lodash';
import chalk from 'chalk';
import fs from 'fs-extra';
Expand Down Expand Up @@ -233,6 +235,38 @@ export function projectHasRightShape(project) {
});
}

export function hasCygwinOnWindows(project) {
return new Promise((resolve, reject) => {
let erroredCommands = []
function test({command, args = [], expectError}) {
const output = spawnSync(command, args, {encoding: 'utf8'});
if (output.output) {
const [, stdout, stderr] = output.output;
if (stdout && stdout.match(command)) return;
if (expectError && stderr.match(expectError)) return;
}
erroredCommands.push(command)
}
[{
command: 'cygpath', args: ['--version'],
}, {
command: 'ssh', args: ['-V'], expectError: 'OpenSSH' // ssh -V outputs to stderr
}, {
command: 'rsync', args: ['--version']
}].forEach(test);
if (!erroredCommands.length) {
console.info(chalk.green(`Your Windows has Cygwin and all the required modules!`));
return resolve(true);
}
erroredCommands = '`' + erroredCommands.join('`, `') + '`';
const errMsg = 'Couldn\'t run: ' + erroredCommands + '. '
+ 'Please make sure you have Cygwin/MinGW/Babun installed, '
+ 'with ' + erroredCommands + ' module(s)';
console.info(chalk.red(errMsg));
reject(false);
});
}

export function checkAll(config) {
console.info(chalk.yellow('* Checking if config is present...'));

Expand All @@ -246,6 +280,14 @@ export function checkAll(config) {

return Promise.all(_.map(config.projects, projectHasRightShape));
})
.then(() => {
if (os.platform() === 'win32') {
console.info(chalk.yellow('\n* Checking Cygwin on Windows...'));
return hasCygwinOnWindows();
} else {
return Promise.resolve(true);
}
})
.then(() => {
console.info(chalk.yellow('\n* Checking host for each project'));

Expand Down

0 comments on commit 51a767e

Please sign in to comment.