Repository URL to install this package:
|
Version:
1.10.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 => {
if (input && input.length > 0) {
return true;
}
return 'You must supply a first name';
},
},
{
type: 'input',
name: CONFIG_EMAIL_KEY,
message: 'What is your @doodle-test.com email?',
validate: input => {
const domain = input && input.split('@');
if (domain && domain.length === 2 && ['doodle-test.com'].includes(domain[1])) {
return true;
}
return 'Only @doodle-test.com addresses are supported';
},
},
{
type: 'input',
name: CONFIG_PASSWORD_KEY,
message: 'What default 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: 'password',
},
{
type: 'password',
name: CONFIG_GITHUB_TOKEN_KEY,
message: 'Enter your GitHub Personal Access Token (with "read:packages" and "repo" scopes):',
},
]);
await writeJsonFile(CONFIGURATION_FILE, { ...answers, [CONFIG_DEBUG_MODE_KEY]: false });
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);
}
};