-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): cLI updates and new features for Amplify Console (#2742)
* feat(cli): cLI updates and new features for Amplify Console * change amplify console command * dev * add migraiton check in attach workflow * dev * dev * allow pulling different env * update message printout * region map * update aws-sdk version * yarn * handle unsupported region of Amplify service * handle unsupported regions of Amplify service * yarn * dev * address PR review comments * text changes to address PR review comments
- Loading branch information
1 parent
0393535
commit 0fd0dd5
Showing
55 changed files
with
1,485 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
{ | ||
"name": "core", | ||
"type": "core", | ||
"commands": [ | ||
"categories", | ||
"configure", | ||
"console", | ||
"delete", | ||
"env", | ||
"help", | ||
"init", | ||
"migrate", | ||
"publish", | ||
"push", | ||
"run", | ||
"status", | ||
"plugin", | ||
"version" | ||
], | ||
"commandAliases":{ | ||
"h": "help", | ||
"serve": "run", | ||
"ls": "status" | ||
} | ||
} | ||
"name": "core", | ||
"type": "core", | ||
"commands": [ | ||
"categories", | ||
"configure", | ||
"console", | ||
"delete", | ||
"env", | ||
"help", | ||
"init", | ||
"migrate", | ||
"publish", | ||
"push", | ||
"pull", | ||
"run", | ||
"status", | ||
"plugin", | ||
"version" | ||
], | ||
"commandAliases": { | ||
"h": "help", | ||
"serve": "run", | ||
"ls": "status" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,43 @@ | ||
const inquirer = require('inquirer'); | ||
const fs = require('fs-extra'); | ||
const open = require('open'); | ||
|
||
const providerName = 'awscloudformation'; | ||
|
||
module.exports = { | ||
name: 'console', | ||
run: async context => { | ||
const categoryPlugins = context.amplify.getCategoryPlugins(context); | ||
const providerPlugins = context.amplify.getProviderPlugins(context); | ||
let consoleUrl = getDefaultURL(); | ||
|
||
const combinedPlugins = { ...categoryPlugins, ...providerPlugins }; | ||
try { | ||
const localEnvInfoFilePath = context.amplify.pathManager.getLocalEnvFilePath(); | ||
if (fs.existsSync(localEnvInfoFilePath)) { | ||
const teamProviderInfoFilePath = context.amplify.pathManager.getProviderInfoFilePath(); | ||
if (fs.existsSync(teamProviderInfoFilePath)) { | ||
const localEnvInfo = context.amplify.readJsonFile(localEnvInfoFilePath); | ||
const teamProviderInfo = context.amplify.readJsonFile(teamProviderInfoFilePath); | ||
const { envName } = localEnvInfo; | ||
const { AmplifyAppId } = teamProviderInfo[envName][providerName]; | ||
|
||
const answer = await inquirer.prompt({ | ||
type: 'list', | ||
name: 'pluginKey', | ||
message: 'Please select the category or provider', | ||
choices: Object.keys(combinedPlugins), | ||
default: Object.keys(providerPlugins)[0], | ||
}); | ||
if (envName && AmplifyAppId) { | ||
consoleUrl = constructStatusURL(AmplifyAppId, envName); | ||
} | ||
} | ||
} | ||
} catch (e) { | ||
context.print.error(e.message); | ||
} | ||
|
||
const plugin = require(combinedPlugins[answer.pluginKey]); | ||
await plugin.console(context); | ||
context.print.green(consoleUrl); | ||
open(consoleUrl, { wait: false }); | ||
}, | ||
}; | ||
|
||
function constructStatusURL(appId, envName) { | ||
const prodURL = `https://console.aws.amazon.com/amplify/home#/${appId}/YmFja2VuZA/${envName}`; // eslint-disable-line | ||
return prodURL; | ||
} | ||
|
||
function getDefaultURL() { | ||
const prodURL = `https://console.aws.amazon.com/amplify/home#/create`; // eslint-disable-line | ||
return prodURL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const fs = require('fs-extra'); | ||
|
||
const { pullBackend } = require('../lib/pull-backend'); | ||
const { attachBackend } = require('../lib/attach-backend'); | ||
const { constructInputParams } = require('../lib/amplify-service-helper'); | ||
const { run: envCheckout } = require('./env/checkout'); | ||
|
||
module.exports = { | ||
name: 'pull', | ||
run: async context => { | ||
const inputParams = constructInputParams(context); | ||
|
||
const currentAmplifyMetaFilePath = context.amplify.pathManager.getCurrentAmplifyMetaFilePath(process.cwd()); | ||
if (fs.existsSync(currentAmplifyMetaFilePath)) { | ||
const { appId: inputAppId, envName: inputEnvName } = inputParams.amplify; | ||
|
||
const teamProviderInfoFilePath = context.amplify.pathManager.getProviderInfoFilePath(process.cwd()); | ||
const localEnvInfoFilePath = context.amplify.pathManager.getLocalEnvFilePath(process.cwd()); | ||
const teamProviderInfo = context.amplify.readJsonFile(teamProviderInfoFilePath); | ||
const { envName } = context.amplify.readJsonFile(localEnvInfoFilePath); | ||
const { AmplifyAppId } = teamProviderInfo[envName].awscloudformation; | ||
const localEnvNames = Object.keys(teamProviderInfo); | ||
|
||
if (inputAppId && AmplifyAppId && inputAppId !== AmplifyAppId) { | ||
context.print.error('Amplify appId mismatch.'); | ||
context.print.info(`You are currently working in the amplify project with Id ${AmplifyAppId}`); | ||
process.exit(1); | ||
} | ||
|
||
if (inputEnvName) { | ||
if (inputEnvName === envName) { | ||
await pullBackend(context, inputParams); | ||
} else if (localEnvNames.includes(inputEnvName)) { | ||
context.parameters.options = {}; | ||
context.parameters.first = inputEnvName; | ||
await envCheckout(context); | ||
} else { | ||
inputParams.amplify.appId = inputAppId; | ||
await attachBackend(context, inputParams); | ||
} | ||
} else { | ||
await pullBackend(context, inputParams); | ||
} | ||
} else { | ||
await attachBackend(context, inputParams); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.