/
StrykerInquirer.ts
91 lines (82 loc) · 3.56 KB
/
StrykerInquirer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import * as inquirer from 'inquirer';
import PromptOption from './PromptOption';
import CommandTestRunner from '../test-runner/CommandTestRunner';
import Preset from './presets/Preset';
export interface PromptResult {
additionalNpmDependencies: string[];
additionalConfig: object;
}
export class StrykerInquirer {
public async promptPresets(options: Preset[]): Promise<Preset | undefined> {
const choices: inquirer.ChoiceType[] = options.map(_ => _.name);
choices.push(new inquirer.Separator());
choices.push('None/other');
const answers = await inquirer.prompt<{ preset: string }>({
choices,
message: 'Are you using one of these frameworks? Then select a preset configuration.',
name: 'preset',
type: 'list'
});
return options.find(_ => _.name === answers.preset);
}
public async promptTestRunners(options: PromptOption[]): Promise<PromptOption> {
const choices: inquirer.ChoiceType[] = options.map(_ => _.name);
choices.push(new inquirer.Separator());
choices.push(CommandTestRunner.runnerName);
const answers = await inquirer.prompt<{ testRunner: string }>({
choices,
default: 'Mocha',
message: 'Which test runner do you want to use? If your test runner isn\'t listed here, you can choose "command" (it uses your `npm test` command, but will come with a big performance penalty)',
name: 'testRunner',
type: 'list'
});
return options.filter(_ => _.name === answers.testRunner)[0] || { name: CommandTestRunner.runnerName, pkg: null };
}
public async promptTestFrameworks(options: PromptOption[]): Promise<PromptOption> {
const answers = await inquirer.prompt<{ testFramework: string }>({
choices: options.map(_ => _.name),
message: 'Which test framework do you want to use?',
name: 'testFramework',
type: 'list'
});
return options.filter(_ => _.name === answers.testFramework)[0];
}
public async promptMutator(options: PromptOption[]): Promise<PromptOption> {
const answers = await inquirer.prompt<{ mutator: string }>({
choices: options.map(_ => _.name),
message: 'What kind of code do you want to mutate?',
name: 'mutator',
type: 'list'
});
return options.filter(_ => _.name === answers.mutator)[0];
}
public async promptTranspilers(options: PromptOption[]): Promise<PromptOption[]> {
const answers = await inquirer.prompt<{ transpilers: string[] }>({
choices: options.map(_ => _.name),
message: '[optional] What kind transformations should be applied to your code?',
name: 'transpilers',
type: 'checkbox'
});
return options.filter(option => answers.transpilers.some(transpilerName => option.name === transpilerName));
}
public async promptReporters(options: PromptOption[]): Promise<PromptOption[]> {
const answers = await inquirer.prompt<{ reporters: string[] }>({
choices: options.map(_ => _.name),
default: ['clear-text', 'progress'],
message: 'Which reporter(s) do you want to use?',
name: 'reporters',
type: 'checkbox'
});
return options.filter(option => answers.reporters.some(reporterName => option.name === reporterName));
}
public async promptPackageManager(options: PromptOption[]): Promise<PromptOption> {
const answers = await inquirer.prompt<{ packageManager: string }>({
choices: options.map(_ => _.name),
default: ['npm'],
message: 'Which package manager do you want to use?',
name: 'packageManager',
type: 'list'
});
return options.filter(_ => _.name === answers.packageManager)[0];
}
}