Skip to content

Commit c282f5c

Browse files
committed
Refactor template
1 parent 61a2ea7 commit c282f5c

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

cli.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const provider = require('simplify-sdk/provider');
1212
const readlineSync = require('readline-sync');
1313
const { options } = require('yargs');
1414
const { authenticate, registerUser, confirmRegistration, getCurrentSession, userSignOut } = require('./cognito')
15-
15+
const PLAN_VERSIONS = { "BASIC": "Community", "STANDARD": "Business", "PREMIUM": "Enterprise" }
1616
var functionMeta = { lashHash256: null }
1717
const opName = `executeCLI`
1818
const CGREEN = '\x1b[32m'
@@ -473,7 +473,7 @@ const printListingDialog = function (options, prompt) {
473473
const stackList = fs.existsSync(stackConfigFile) ? JSON.parse(fs.readFileSync(stackConfigFile)) : {}
474474
let tableData = []
475475
if (Object.keys(stackList).length > 0) {
476-
console.log(`\n * ${prompt ? prompt : `Listing installed components for ${CNOTIF}${envName || process.env.DEPLOYMENT_ENV}${CDONE} environment \n`}`)
476+
console.log(`\n - ${prompt ? prompt : `Listing installed components for ${CNOTIF}${envName || process.env.DEPLOYMENT_ENV}${CDONE} environment \n`}`)
477477
Object.keys(stackList).map((stackName, idx) => {
478478
tableData.push({
479479
Index: idx + 1,
@@ -487,7 +487,7 @@ const printListingDialog = function (options, prompt) {
487487
})
488488
utilities.printTableWithJSON(tableData)
489489
} else {
490-
console.log(`\n * Listing installed components for ${CNOTIF}${envName || process.env.DEPLOYMENT_ENV}${CDONE} environment: (empty) \n`)
490+
console.log(`\n - Listing installed components for ${CNOTIF}${envName || process.env.DEPLOYMENT_ENV}${CDONE} environment: (empty) \n`)
491491
}
492492
return tableData
493493
}
@@ -523,7 +523,7 @@ const showAvailableStacks = (options, promptDescription) => {
523523
let stackType = ""
524524
let indexOfTemplate = 0
525525
let tableStackData = []
526-
console.log(`\n * ${promptDescription}\n`)
526+
console.log(`\n - ${promptDescription}\n`)
527527
getDirectories(path.resolve('.')).map((template) => {
528528
const excludeFolders = [".simplify", ".git", ".github", "dist", "node_modules", "output"].indexOf(template) == -1 ? false : true
529529
if (!excludeFolders && !template.startsWith('.') && !template.startsWith('_')) {
@@ -583,6 +583,25 @@ var optCMD = (argv._.length > 1 ? argv._[1] : undefined)
583583
var cmdArg = argv['stack'] || argv['function'] || optCMD
584584
var cmdType = cmdArg ? fs.existsSync(path.resolve(argv.location, cmdArg, "template.yaml")) ? "CF-Stack" : "Function" : undefined
585585

586+
const showSubscriptionPlan = function(userSession) {
587+
const currentPlan = (userSession.getIdToken().payload[`subscription`] || 'Basic')
588+
const currentVersion = PLAN_VERSIONS[currentPlan.toUpperCase()] || 'Community'
589+
console.log(`\n`, ` * ${CPROMPT}Welcome back${CRESET} : ${userSession.getIdToken().payload[`name`]}`)
590+
console.log(` * ${CPROMPT}Subscription${CRESET} : ${CDONE}${currentPlan}${CRESET} Plan - ${currentVersion} Version`)
591+
if (currentPlan.toUpperCase() == 'BASIC') {
592+
console.log(` * ${CGREEN}Change to standard plan with 10$ monthly for advanced resource${CRESET} : simplify-cli upgrade --standard`)
593+
console.log(` * ${CRESET}Or upgrade to premium plan with 99$ monthly for CodeMe support${CRESET} : simplify-cli upgrade --premium`)
594+
}
595+
if (currentPlan.toUpperCase() == 'STANDARD') {
596+
console.log(` * ${CRESET}Change to basic plan (FREE) with 0$ monthly for basic resource${CRESET} : simplify-cli upgrade --basic`)
597+
console.log(` * ${CGREEN}Or upgrade to premium plan with 99$ monthly for CodeMe support${CRESET} : simplify-cli upgrade --premium`)
598+
}
599+
if (currentPlan.toUpperCase() == 'PREMIUM') {
600+
console.log(` * ${CRESET}Change to basic plan (FREE) with 0$ monthly for basic resource${CRESET} : simplify-cli upgrade --basic`)
601+
console.log(` * ${CRESET}Change to standard plan with 10$ monthly for advanced resource${CRESET} : simplify-cli upgrade --standard`)
602+
}
603+
}
604+
586605
const processCLI = function (cmdRun, session) {
587606
if (cmdRun === "DEPLOY") {
588607
if (cmdArg !== undefined) {
@@ -644,9 +663,7 @@ const processCLI = function (cmdRun, session) {
644663
const username = readlineSync.questionEMail(` - ${CPROMPT}Your identity${CRESET} : `, { limitMessage: " * Your login email is invalid." })
645664
const password = readlineSync.question(` - ${CPROMPT}Your password${CRESET} : `, { hideEchoBack: true })
646665
authenticate(username, password).then(function (userSession) {
647-
console.log(`\n`, ` * ${CPROMPT}Welcome back${CRESET} : ${userSession.getIdToken().payload[`name`]}`)
648-
console.log(` * ${CPROMPT}Subscription${CRESET} : ${userSession.getIdToken().payload[`subscription`] || 'Basic Plan - Community Version'}`)
649-
console.log(` * ${CGREEN}Upgrade to premium plan with 100$ monthly for CodeMe support${CRESET} : simplify-cli upgrade`, `\n`)
666+
showSubscriptionPlan(userSession)
650667
}).catch(error => console.error(error))
651668
} else if (cmdRun === "REGISTER") {
652669
const fullname = readlineSync.question(` - ${CPROMPT}What is your name${CRESET} : `, { limitMessage: " * Your name is invalid." })
@@ -717,6 +734,7 @@ if (!fs.existsSync(path.resolve(argv.config || 'config.json'))) {
717734
if (["LOGIN", "REGISTER"].indexOf(cmdOPS) == -1) {
718735
getCurrentSession().then(session => {
719736
if (session && session.isValid()) {
737+
showSubscriptionPlan(session)
720738
processCLI(cmdOPS, session)
721739
} else {
722740
console.log(`${CPROMPT}Session is invalid${CRESET}. Please re-login.`)

cognito.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const registerUser = function (name, email, password) {
2424
}));
2525
attributeList.push(new AmazonCognitoIdentity.CognitoUserAttribute({
2626
Name: 'subscription',
27-
Value: 'Basic Plan - Community Version',
27+
Value: 'Basic',
2828
}));
2929
return new Promise(function (resolve, reject) {
3030
userPool.signUp(v4(), password, attributeList, null, function (err, result) {

0 commit comments

Comments
 (0)