-
Notifications
You must be signed in to change notification settings - Fork 4
/
default.js
43 lines (41 loc) · 1.27 KB
/
default.js
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
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
const Launcher = require('./Launcher');
(async function() {
try {
const close = await Launcher.launch({
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH
});
const good = await isGood();
try {
await close();
} catch(e) {
// failing to close is fine, we might have already closed
}
process.exit(good ? 0 : 1);
} catch (e) {
console.error('Error launching Chrome!');
console.error(e.code);
process.exit(1);
}
async function isGood() {
const goodAnswers = new Set(['g', 'good', 'y', 'yes']);
const badAnswers = new Set(['b', 'bad', 'n',' no']);
while (true) {
const answer = await ask();
if (goodAnswers.has(answer))
return true;
if (badAnswers.has(answer))
return false;
console.log(`Unknown response '${answer}'. Please enter g or b.`);
}
}
async function ask() {
const answer = await new Promise(x => {
readline.question('Good or bad? [g/b]: ', x);
});
return answer.toLowerCase();
}
})();