cdk-cli
Version:
'ckd aws' cli helper
297 lines (294 loc) • 7.52 kB
JavaScript
const inquirer = require('inquirer');
module.exports = {
askEnvFile: async () => {
const questions = [
{
type: 'list',
name: 'ans',
message: 'Would you like to create an .env file?',
choices: ['Yes', 'No'],
default: ['No']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askTYPE: async () => {
const questions = [
{
type: 'list',
name: 'ans',
message: 'Would you like to create an .env file?',
choices: ['Server', 'Web', 'Both'],
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askCDK_DEFAULT_ACCOUNT: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter a default Aws Account Id, for example 111111111111',
validate: function( value ) {
if (!isNaN(value)) {
return true;
} else {
return 'Please enter a valid Aws Account Id.';
}
},
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askCDK_DEFAULT_REGION: async () => {
const questions = [
{
type: 'list',
name: 'ans',
message: 'Choose a default region',
choices: ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2', 'sa-east-1'],
default: ['us-east-1']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askPROJECT_NAME: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter the project name',
validate: function( value ) {
if (value.length) {
return true;
} else {
return 'Please enter a valid name.';
}
},
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askSTAGE_NAME: async () => {
const questions = [
{
type: 'list',
name: 'ans',
message: 'Choose a stage',
choices: ['PRODUCTION', 'DEVELOPMENT', 'STAGING', 'DEMO'],
default: ['No']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askHOSTED_ZONE_DOMAIN: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter the hosted zone domain',
validate: (value) => {
return verifyDomain(value);
},
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askHOSTED_ZONE_DOMAIN_CERTIFICATE_ARN: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter the arn of hosted zone domain certificate, leave it empty if you want the cdk to request it',
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askRepoBranch: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter the repo branch name',
validate: function( value ) {
if (value.length) {
return true;
} else {
return 'Please enter a valid name.';
}
},
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askRepoOwner: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter the name of the repo owner',
validate: function( value ) {
if (value.length) {
return true;
} else {
return 'Please enter a valid name.';
}
},
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askRepoOwnerOAUTHTOKEN: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter the owner oauthtoken',
validate: function( value ) {
if (value.length) {
return true;
} else {
return 'Please enter a valid name.';
}
},
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askRepoName: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter the repo name',
validate: function( value ) {
if (value.length) {
return true;
} else {
return 'Please enter a valid name.';
}
},
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askFRONTEND_BUILD_COMMAND: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter build stage command tu run in the buildspec.yml',
validate: function( value ) {
if (value.length) {
return true;
} else {
return 'Please enter a valid name.';
}
},
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askWEBAPP_DOMAIN: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter the web domain.',
validate: (value) => {
return verifyDomain(value);
},
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askSHARED_LOAD_BALANCER: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter the Shared Load Balancer arn, leave it empty if you want the cdk to request it.',
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askINSTANCE_TYPE: async () => {
const questions = [
{
type: 'list',
name: 'ans',
message: 'Choose the instance type.',
choices: ['SHARED_LOAD_BALANCER', 'SINGLE'],
default: ['SINGLE']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askBACKEND_PATH: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter a path use to route traffic in the load balancer',
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
askBACKEND_DOMAIN: async () => {
const questions = [
{
type: 'input',
name: 'ans',
message: 'Enter the server domain',
validate: (value) => {
return verifyDomain(value);
},
default: ['']
}
];
const { ans } = await inquirer.prompt(questions);
return ans;
},
};
const verifyDomain = (value) => {
if (!value.length) return 'Please enter a valid domain.';
const parts = value.split('.')
if (parts.length < 2) return 'Please enter a valid domain.';
for (let part, i = 0; i < parts.length; i++) {
part = parts[i]
if (!/^[a-z\u00a1-\uffff0-9-]+$/i.test(part)) return 'Please enter a valid domain.';
if (/[\uff01-\uff5e]/.test(part)) return 'Please enter a valid domain.';
if (part[0] === '-' || part[part.length - 1] === '-') return 'Please enter a valid domain.';
}
return true
}