Repository URL to install this package:
|
Version:
0.0.1 ▾
|
const inquirer = require('inquirer');
const writeJsonFile = require('write-json-file');
const chalk = require('chalk');
const {
CONFIGURATION_FILE,
CONFIG_EMAIL_KEY,
CONFIG_FIRST_NAME_KEY,
CONFIG_PASSWORD_KEY,
CONFIG_GITHUB_TOKEN_KEY,
CONFIG_DEBUG_MODE_KEY,
} = require('./constants');
module.exports = async () => {
try {
const answers = await inquirer.prompt([
{
type: 'input',
name: CONFIG_FIRST_NAME_KEY,
message: 'What is your first name?',
validate: input => input.length > 0,
},
{
type: 'input',
name: CONFIG_EMAIL_KEY,
message: 'What is your Doodle or gmail email address?',
validate(input) {
const domain = input && input.split('@');
if (domain && domain.length === 2 && ['doodle.com', 'gmail.com'].includes(domain[1])) {
return true;
}
return 'Only doodle.com or gmail.com addresses are supported';
},
},
{
type: 'password',
name: CONFIG_PASSWORD_KEY,
message: 'What password should we use when creating test accounts? (This will be saved in plaintext)',
validate: input => {
if (input && input.length >= 8) {
return true;
}
return 'A password should be at least 8 characters';
},
default: 'foobarbaz',
},
{
type: 'password',
name: CONFIG_GITHUB_TOKEN_KEY,
message: 'What is your GitHub Personal Access Token? (It just needs the "repo" scope)',
},
{
type: 'confirm',
name: CONFIG_DEBUG_MODE_KEY,
message: 'Should we enable debug mode?',
default: false,
},
]);
await writeJsonFile(CONFIGURATION_FILE, answers);
console.log(chalk.cyan('\nConfiguration has been saved to'), chalk.gray(CONFIGURATION_FILE));
console.log(
`To edit your settings you can run this utility again with ${chalk.yellow(
'doodle init'
)}, or modify/delete the config file`
);
} catch (err) {
console.log(chalk.red('Something went wrong. You might want to try again'));
console.log(err);
}
};