Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/lib-node-utilities / bin / initConfiguration.js
Size: Mime:
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);
	}
};