UNPKG

tyr-cli

Version:

A command line interface for hammer-io.

219 lines (174 loc) 12.6 kB
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.repromptForProjectName = exports.promptForHerokuCredentials = exports.promptForGithubCredentials = exports.promptForEmailAndPasswordApiKey = exports.promptForUsernamePassword = exports.promptForToolingConfigurations = exports.promptForProjectConfigurations = undefined; /** * Prompts the user for their project configurations * @returns {Object} an object representing the user's project configurations */let promptForProjectConfigurations = exports.promptForProjectConfigurations = (() => {var _ref = _asyncToGenerator( function* () { console.log(_chalk2.default.blue('Enter your Project Configurations: ')); const projectConfigurationQuestions = [{ name: 'projectName', type: 'input', message: 'Project Name:', validate: function (value) {return projectConfigurationValidator.validateProjectName(value);} }, { name: 'description', type: 'input', message: 'Project Description:' }, { name: 'isPrivateProject', type: 'confirm', message: 'Private Project?', default: false }, { name: 'version', type: 'input', default: '0.0.0', message: 'Version:', validate: projectConfigurationValidator.validateVersionNumber }, { name: 'author', type: 'input', message: 'Author:' }, { name: 'license', type: 'input', message: 'License:', validate: projectConfigurationValidator.validateLicense }]; const projectConfigurations = yield _inquirer2.default.prompt(projectConfigurationQuestions); return projectConfigurations; });return function promptForProjectConfigurations() {return _ref.apply(this, arguments);};})(); /** * Cleans the tooling data by removing any key/value pairs that have a value of <None> * @param toolingConfig the config object to clean * @returns {Object} the cleaned config object */ /** * Prompts the user for their tooling configurations * @returns {Object} an object representing their choices in tooling */let promptForToolingConfigurations = exports.promptForToolingConfigurations = (() => {var _ref2 = _asyncToGenerator( function* () { console.log(_chalk2.default.blue('Choose your Tooling: ')); const toolingQuestions = [{ name: 'sourceControl', type: 'list', choices: _choices2.default.sourceControlChoices, message: 'Source Control:' }, { name: 'ci', type: 'list', choices: _choices2.default.ciChoices, message: 'Continuous Integration:', when: function (answers) {return ( // the ci choices question should only be asked if the user selected a source control method typeof answers.ci !== 'undefined' || answers.sourceControl !== _choices2.default.none || !answers.sourceControl);} }, { name: 'containerization', type: 'list', choices: _choices2.default.containerizationChoices, message: 'Containerization Tool:', when: function (answers) {return ( // the container choices questions should only be asked if the user selected a ci tool typeof answers.ci !== 'undefined' && (answers.ci !== _choices2.default.none || !answers.ci));} }, { name: 'deployment', type: 'list', choices: _choices2.default.deploymentChoices, message: 'Hosting Service:', when: function (answers) {return ( // the deployment choices question should only be asked if the user selected a container typeof answers.containerization !== 'undefined' && (answers.containerization !== _choices2.default.none || !answers.containerization));} }, { name: 'web', type: 'list', choices: _choices2.default.webChoices, message: 'Web Application Framework:' }, { name: 'test', type: 'list', choices: _choices2.default.testChoices, message: 'Testing Framework:' }, { name: 'orm', type: 'list', choices: _choices2.default.ormChoices, message: 'Object-relational Mapping Tool:' }]; const tooling = yield _inquirer2.default.prompt(toolingQuestions); return cleanToolingData(tooling); });return function promptForToolingConfigurations() {return _ref2.apply(this, arguments);};})(); /** * Prompt for username and password combination * @returns {Object} object containing an username and password key/value pair */let promptForUsernamePassword = exports.promptForUsernamePassword = (() => {var _ref3 = _asyncToGenerator( function* () { const usernamePasswordQuestions = [{ name: 'username', type: 'input', message: 'Username:', validate: credentialValidator.validateUsername }, { name: 'password', type: 'password', message: 'Password:', validate: credentialValidator.validatePassword }]; const credentials = yield _inquirer2.default.prompt(usernamePasswordQuestions); return credentials; });return function promptForUsernamePassword() {return _ref3.apply(this, arguments);};})(); /** * Prompts the user for an email and password combination * @returns {Object} object containing an email and password key/value pair */let promptForEmailAndPasswordApiKey = exports.promptForEmailAndPasswordApiKey = (() => {var _ref4 = _asyncToGenerator( function* () { const usernamePasswordQuestions = [{ name: 'email', type: 'input', message: 'Email:', validate: credentialValidator.validateEmail }, { name: 'password', type: 'password', message: 'Password:', validate: credentialValidator.validatePassword }, { name: 'apiKey', type: 'password', message: 'API Key:', validate: credentialValidator.validateApiKey }]; const credentials = yield _inquirer2.default.prompt(usernamePasswordQuestions); return credentials; });return function promptForEmailAndPasswordApiKey() {return _ref4.apply(this, arguments);};})(); /** * Prompts the user for their username and password on github * @returns {Promise<*>} */let promptForGithubCredentials = exports.promptForGithubCredentials = (() => {var _ref5 = _asyncToGenerator( function* () { console.log(_chalk2.default.blue('Enter your GitHub username and Password:')); const githubCredentials = yield promptForUsernamePassword(); return githubCredentials; });return function promptForGithubCredentials() {return _ref5.apply(this, arguments);};})(); /** * Prompts the user for their email and password on Heroku * @returns {Promise<void>} */let promptForHerokuCredentials = exports.promptForHerokuCredentials = (() => {var _ref6 = _asyncToGenerator( function* () { console.log(_chalk2.default.blue('Enter your Heroku email and password:')); const herokuCredentials = yield promptForEmailAndPasswordApiKey(); return herokuCredentials; });return function promptForHerokuCredentials() {return _ref6.apply(this, arguments);};})();let repromptForProjectName = exports.repromptForProjectName = (() => {var _ref7 = _asyncToGenerator( function* (repositories) { console.log(_chalk2.default.blue('ReEnter a Valid Project Name: ')); const question = [{ name: 'projectName', type: 'input', message: 'Project Name:', validate: function (value) { const isValid = githubService.isValidGithubRepositoryName(value, repositories) && projectConfigurationValidator.validateProjectConfigurations(value); if (!isValid) { return 'GitHub repository with this name already exists.'; } return true; } }]; const answer = yield _inquirer2.default.prompt(question); return answer.projectName; });return function repromptForProjectName(_x) {return _ref7.apply(this, arguments);};})();exports.cleanToolingData = cleanToolingData;var _inquirer = require('inquirer');var _inquirer2 = _interopRequireDefault(_inquirer);var _chalk = require('chalk');var _chalk2 = _interopRequireDefault(_chalk);var _projectConfigurationValidator = require('../utils/project-configuration-validator');var projectConfigurationValidator = _interopRequireWildcard(_projectConfigurationValidator);var _choices = require('../constants/choices');var _choices2 = _interopRequireDefault(_choices);var _githubService = require('../services/github-service');var githubService = _interopRequireWildcard(_githubService);var _credentialValidator = require('../utils/credential-validator');var credentialValidator = _interopRequireWildcard(_credentialValidator);function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;} else {var newObj = {};if (obj != null) {for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];}}newObj.default = obj;return newObj;}}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _asyncToGenerator(fn) {return function () {var gen = fn.apply(this, arguments);return new Promise(function (resolve, reject) {function step(key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {return Promise.resolve(value).then(function (value) {step("next", value);}, function (err) {step("throw", err);});}}return step("next");});};}function cleanToolingData(toolingConfig) {Object.keys(toolingConfig).forEach(key => {if (toolingConfig[key]) {if (toolingConfig[key] === _choices2.default.none) {// eslint-disable-next-line no-param-reassign delete toolingConfig[key];}}});return toolingConfig;}