Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
feat(setup): add domain questions in setup
Browse files Browse the repository at this point in the history
issue #16
  • Loading branch information
ianpogi5 committed Oct 26, 2019
1 parent d673746 commit 433fc83
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 36 deletions.
9 changes: 9 additions & 0 deletions packages/kdc-cms-setup/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
const crypto = require("crypto");
const clear = require("clear");
const chalk = require("chalk");
const figlet = require("figlet");
const questionsAWS = require("./lib/questions-aws");
const createFile = require("./lib/create-file");

clear();

console.log(
chalk.yellow(figlet.textSync("KDC CMS", { horizontalLayout: "full" }))
);

const args = process.argv.slice(2);
const [stage] = args;

Expand Down
129 changes: 94 additions & 35 deletions packages/kdc-cms-setup/lib/questions-aws.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,114 @@
const inquirer = require("inquirer");
const validator = require("validator");
const {
regions: awsRegions,
regionNames: awsRegionNames
} = require("./aws-regions");
const awsProfiles = require("./aws-profiles");
const indexOf = require("lodash.indexof");

let region = null;
let profile = null;

const askAWSQuestions = async () => {
let ans = await inquirer.prompt({
type: "list",
name: "region",
message: "Select AWS Region:",
choices: awsRegionNames,
default: "Asia Pacific (Singapore)",
filter: val => {
const k = indexOf(awsRegionNames, val);
return awsRegions[k];
},
when: () => !region
});

if (ans.region) region = ans.region;

ans = await inquirer.prompt({
type: "list",
name: "profile",
message: "Select AWS Profile:",
choices: awsProfiles,
default: "default",
when: () => !profile
});

if (ans.profile) profile = ans.profile;
};

const start = async ctx => {
const { stage } = ctx;
if (stage === "local") {
return ctx;
}

while (!region || !profile) {
await askAWSQuestions();
}
const ans = await inquirer.prompt([
{
type: "list",
name: "region",
message: "Select AWS Region:",
choices: awsRegionNames,
default: "Asia Pacific (Singapore)",
filter: val => {
const k = indexOf(awsRegionNames, val);
return awsRegions[k];
}
},
{
type: "list",
name: "profile",
message: "Select AWS Profile:",
choices: awsProfiles,
default: "default"
},
{
type: "input",
message: "Enter your domain name:",
name: "domain",
validate: function(value) {
if (validator.isFQDN(value)) {
return true;
} else {
return "Please enter a valid domain name";
}
}
},
{
type: "input",
message: "Enter your API endpoint:",
name: "apiUrl",
default: function(answers) {
if (stage === "prod" || stage === "production") {
return `api.${answers.domain}`;
} else {
return `api-${stage}.${answers.domain}`;
}
},
validate: function(value, answers) {
if (validator.isFQDN(value)) {
return true;
} else {
return `Please enter a valid endpoint. Example: api-${stage}.${answers.domain}`;
}
},
when: function(answers) {
// Only run if user set a name
return !!answers.domain;
}
},
{
type: "confirm",
message: "Do you want to use CloudFront for your API endpoint?",
name: "apiUrlCF",
default: false
},
{
type: "input",
message: "Enter your CMS endpoint:",
name: "adminUrl",
default: function(answers) {
if (stage === "prod" || stage === "production") {
return `admin.${answers.domain}`;
} else {
return `admin-${stage}.${answers.domain}`;
}
},
validate: function(value, answers) {
if (validator.isFQDN(value)) {
return true;
} else {
return `Please enter a valid endpoint. Example: admin-${stage}.${answers.domain}`;
}
},
when: function(answers) {
// Only run if user set a name
return !!answers.domain;
}
},
{
type: "confirm",
message: "Do you want to use CloudFront for your CMS endpoint?",
name: "adminUrlCF",
default: false
}
]);

console.log(ans);

return {
...ctx,
aws: { region, profile }
aws: { ...ans }
};
};

Expand Down
6 changes: 5 additions & 1 deletion packages/kdc-cms-setup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
"license": "MIT",
"private": true,
"dependencies": {
"chalk": "^2.4.2",
"clear": "^0.1.0",
"esm": "^3.2.25",
"figlet": "^1.2.4",
"inquirer": "^7.0.0",
"js-yaml": "^3.13.1",
"kdc-cms-dynamodb": "0.1.0",
"kdc-cms-utils": "0.1.0",
"lodash.indexof": "^4.0.5"
"lodash.indexof": "^4.0.5",
"validator": "^11.1.0"
}
}

0 comments on commit 433fc83

Please sign in to comment.