-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinit.js
41 lines (32 loc) · 1.35 KB
/
init.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
const inquirer = require('inquirer');
const PromptGenerator = require('../../utils/PromptGenerator');
const getLengthValidator = invalidMessage => (value) => {
if (value.length) {
return true;
}
return invalidMessage;
};
const usernamePromptGenerator = new PromptGenerator();
usernamePromptGenerator.addProperty('name', 'username');
usernamePromptGenerator.addProperty('type', 'input');
usernamePromptGenerator.addProperty('message', 'Enter your AutolabJS username:');
usernamePromptGenerator.addProperty('validate', getLengthValidator('Please enter your username'));
const passwordPromptGenerator = new PromptGenerator();
passwordPromptGenerator.addProperty('name', 'password');
passwordPromptGenerator.addProperty('type', 'password');
passwordPromptGenerator.addProperty('message', 'Enter your AutolabJS password:');
passwordPromptGenerator.addProperty('validate', getLengthValidator('Please enter your password'));
const credentials = [
usernamePromptGenerator.getPrompt(),
passwordPromptGenerator.getPrompt(),
];
const areCredentialsValid = (username, password) => typeof username === 'string' && typeof password === 'string';
const getInput = async (args, options) => {
if (areCredentialsValid(options.u, options.p)) {
return { username: options.u, password: options.p };
}
return inquirer.prompt(credentials);
};
module.exports = {
getInput,
};