-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Installer asks to install stryker if not instaled. Added some nice colors for readability.
- Loading branch information
Olaf Haalstra
authored and
Olaf Haalstra
committed
Jan 28, 2017
1 parent
2aebd00
commit a467a88
Showing
2 changed files
with
29 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,41 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as chalk from 'chalk'; | ||
import * as inquirer from 'inquirer'; | ||
|
||
const NODE_MODULES_DIRNAME = 'node_modules'; | ||
const STRYKER_DIRNAME = 'stryker'; | ||
const BIN_DIRNAME = 'bin'; | ||
const STRYKER_FILENAME = 'stryker'; | ||
|
||
function fileExists(filePath: string) { | ||
try { | ||
return fs.statSync(filePath).isFile(); | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
|
||
function strykerNotFound() { | ||
console.error(chalk.red.bold('Cannot find Stryker!\nPlease install Stryker using "npm install stryker".')); | ||
process.exit(1); | ||
try { | ||
return fs.statSync(filePath).isFile(); | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
|
||
const baseDir = process.cwd(); | ||
|
||
const strykerPathFromNode = path.resolve(baseDir, NODE_MODULES_DIRNAME, STRYKER_DIRNAME, BIN_DIRNAME, STRYKER_FILENAME); | ||
const strykerPathFromBuild = path.resolve(baseDir, BIN_DIRNAME, STRYKER_FILENAME); | ||
|
||
try { | ||
if (fileExists(strykerPathFromNode)) { | ||
require(strykerPathFromNode); | ||
} else if (fileExists(strykerPathFromBuild)) { | ||
require(strykerPathFromBuild); | ||
if (fileExists(strykerPathFromNode)) { | ||
require(strykerPathFromNode); | ||
} else if (fileExists(strykerPathFromBuild)) { | ||
require(strykerPathFromBuild); | ||
} else { | ||
console.log(chalk.yellow('Stryker is currently not installed.')); | ||
inquirer.prompt([{ type: 'confirm', name: 'install', message: 'Do you want to automatically install Stryker?', default: 'true' }]).then((answers) => { | ||
if (answers['install']) { | ||
// Install stryker; | ||
require('child_process').execSync('npm i --save-dev stryker stryker-api'); | ||
console.log(chalk.green('Stryker installation done.')); | ||
console.log('Get started by using ' + chalk.blue('`stryker init`') + '.'); | ||
} else { | ||
strykerNotFound(); | ||
console.log('I understand. You can install Stryker manually using `npm install stryker`.'); | ||
} | ||
} catch (error) { | ||
strykerNotFound(); | ||
} | ||
}) | ||
} | ||
|