Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/amplify enhanced status #7698

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
478c17a
enhanced amplify status
Jul 7, 2021
8cc5388
help and test
Jul 7, 2021
00f0868
show summary view on amplify push
Jul 7, 2021
4bc0ad6
Fixed s3
Jul 8, 2021
13997a3
unit test for showStatusTable
Jul 9, 2021
f47b3f3
fixed ViewResourceTableParams
Jul 9, 2021
1698a14
Converted cloudformation file-path to use Glob
Jul 9, 2021
a860901
cleanup and headers
Jul 9, 2021
fd931bb
1. removed custom yaml handling and used library code.
Jul 11, 2021
848ba08
addressed PR comments
Jul 12, 2021
1db112b
Added types to template, diff
Jul 12, 2021
a256d18
addressed more PR comments
Jul 12, 2021
56ead1b
updated unit test coverage and fixed test errors
Jul 13, 2021
97e4e01
Merge branch 'aws-amplify:master' into feature/amplify-enhanced-status
sachscode Jul 14, 2021
bc718d4
fix multi-env diffs for new resources
Jul 15, 2021
eea4be0
1. category filters for summary.
Jul 16, 2021
5a5d2d6
updated help to indicate summary filters
Jul 16, 2021
656a9da
Merge branch 'aws-amplify:master' into feature/amplify-enhanced-status
sachscode Jul 19, 2021
82badbe
Update Readme.md
sachscode Jul 19, 2021
6af0fca
resolved merge errors
Jul 22, 2021
0c1167c
fixed unit tests and merge errors
Jul 23, 2021
270cc71
Merge branch 'aws-amplify:master' into feature/amplify-enhanced-status
sachscode Jul 23, 2021
e9c371e
Update Readme.md
sachscode Jul 23, 2021
fb62416
Update packages/amplify-cli-core/src/cliViewAPI.ts
sachscode Jul 23, 2021
7202d8d
Update packages/amplify-cli/src/extensions/amplify-helpers/resource-s…
sachscode Jul 23, 2021
318e13d
addressed CR comments
Jul 24, 2021
926f388
Merge branch 'aws-amplify:master' into feature/amplify-enhanced-status
sachscode Jul 24, 2021
92555b6
lgtm:fix:removed unused variable
Jul 24, 2021
6b9df61
Merge branch 'feature/amplify-enhanced-status' of github.com:sachscod…
Jul 24, 2021
d78e7ab
unit-tests for cliViewAPI
Jul 27, 2021
8e1216d
removed styling from help test
Jul 27, 2021
b984488
unit-test for detailed cloudformation-diff for one resource
Aug 2, 2021
2d18841
Merge branch 'master' into feature/amplify-enhanced-status
sachscode Aug 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions packages/amplify-cli-core/src/cliViewAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//Use this file to store all types used between the CLI commands and the view/display functions
// CLI=>(command-handler)==[CLI-View-API]=>(ux-handler/report-handler)=>output-stream
import chalk from 'chalk';
export interface CLIParams {
cliCommand : string;
cliSubcommands: string[]|undefined;
cliOptions : {[key:string] : any};
sachscode marked this conversation as resolved.
Show resolved Hide resolved
}
//Resource Table filter and display params (params used for summary/display view of resource table)
export class ViewResourceTableParams {
public command : string;
sachscode marked this conversation as resolved.
Show resolved Hide resolved
public verbose : boolean; //display table in verbose mode
public help : boolean; //display help for the command
public categoryList : string[]|[] //categories to display
public filteredResourceList : any //resources to *not* display - TBD define union of valid types
getCategoryFromCLIOptions( cliOptions : object ){
sachscode marked this conversation as resolved.
Show resolved Hide resolved
if ( cliOptions ){
return (Object.keys(cliOptions).filter( key => (key != 'verbose') && (key !== 'yes') )).map(category => category.toLowerCase());
} else {
return [];
}
}
styleHeader(str : string) {
return chalk.italic(chalk.bgGray.whiteBright(str));
}
styleCommand( str : string) {
return chalk.greenBright(str);
}
styleOption( str : string) {
return chalk.yellowBright(str);
}
stylePrompt( str : string ){
return chalk.bold(chalk.yellowBright(str));
}
styleNOOP( str : string){
return chalk.italic(chalk.grey(str));
}
public getStyledHelp(){
return `
${this.styleHeader("NAME")}
${this.styleCommand("amplify status")} -- Shows the state of local resources not yet pushed to the cloud (Create/Update/Delete)

${this.styleHeader("SYNOPSIS")}
${this.styleCommand("amplify status")} [${this.styleCommand("-v")} [${this.styleOption("category ...")}] ]

${this.styleHeader("DESCRIPTION")}
The amplify status command displays the difference between the deployed state and the local state of the application.
The following options are available:

${this.styleNOOP("no options")} : (Summary mode) Displays the summary of local state vs deployed state of the application
${this.styleCommand("-v [category ...]")} : (Verbose mode) Displays the cloudformation diff for all resources for the specificed category.
If no category is provided, it shows the diff for all categories.
usage:
${this.stylePrompt("#\>")} ${this.styleCommand("amplify status -v")}
${this.stylePrompt("#\>")} ${this.styleCommand("status -v ")}${this.styleOption( "api storage")}

`
}

public constructor( cliParams : CLIParams ){
this.command = cliParams.cliCommand;
this.verbose = (cliParams.cliOptions?.verbose === true );
this.categoryList = this.getCategoryFromCLIOptions( cliParams.cliOptions );
this.filteredResourceList = []; //TBD - add support to provide resources
this.help = (cliParams.cliSubcommands)?cliParams.cliSubcommands.includes("help"):false;
}
}
4 changes: 4 additions & 0 deletions packages/amplify-cli-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ViewResourceTableParams, CLIParams } from './cliViewAPI';
import { ServiceSelection } from './serviceSelection';

export * from './cfnUtilities';
Expand All @@ -21,6 +22,7 @@ export * from './utils';
export * from './banner-message';
export * from './cliGetCategories';
export * from './cliRemoveResourcePrompt';
export * from "./cliViewAPI";

// Temporary types until we can finish full type definition across the whole CLI

Expand Down Expand Up @@ -164,6 +166,7 @@ export interface AmplifyProjectConfig {

export type $TSCopyJob = any;


// Temporary interface until Context refactor
interface AmplifyToolkit {
confirmPrompt: (prompt: string, defaultValue?: boolean) => Promise<boolean>;
Expand Down Expand Up @@ -216,6 +219,7 @@ interface AmplifyToolkit {
showHelp: (header: string, commands: { name: string; description: string }[]) => $TSAny;
showHelpfulProviderLinks: () => $TSAny;
showResourceTable: () => $TSAny;
showStatusTable:( resourceTableParams : ViewResourceTableParams )=> $TSAny; //Enhanced Status with CFN-Diff
serviceSelectionPrompt: (
context: $TSContext,
category: string,
Expand Down
65 changes: 65 additions & 0 deletions packages/amplify-cli/src/__tests__/commands/status.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { UnknownArgumentError } from 'amplify-cli-core';


describe('amplify status: ', () => {
const mockExit = jest.fn();
jest.mock('amplify-cli-core', () => ({
exitOnNextTick: mockExit,
UnknownArgumentError: UnknownArgumentError,
}));
const { run } = require('../../commands/status');
const runStatusCmd = run;

it('status run method should exist', () => {
expect(runStatusCmd).toBeDefined();
});

it('status run method should call context.amplify.showStatusTable', async () => {
const mockContextNoCLArgs = {
amplify: {
showStatusTable: jest.fn(),
},
parameters: {
array: [],
},
};
runStatusCmd(mockContextNoCLArgs)
expect(mockContextNoCLArgs.amplify.showStatusTable).toBeCalled();
});

it('status -v run method should call context.amplify.showStatusTable', async () => {
const mockContextWithVerboseOptionAndCLArgs = {
amplify: {
showStatusTable: jest.fn(),
},
input :{
command: "status",
options: {
verbose : true
}
}
};
runStatusCmd(mockContextWithVerboseOptionAndCLArgs)
expect(mockContextWithVerboseOptionAndCLArgs.amplify.showStatusTable).toBeCalled();
});

it('status -v <category>* run method should call context.amplify.showStatusTable', async () => {
const mockContextWithVerboseOptionWithCategoriesAndCLArgs = {
amplify: {
showStatusTable: jest.fn(),
},
input :{
command: "status",
options: {
verbose : true,
api : true,
storage : true
}
}
};
runStatusCmd(mockContextWithVerboseOptionWithCategoriesAndCLArgs)
expect(mockContextWithVerboseOptionWithCategoriesAndCLArgs.amplify.showStatusTable).toBeCalled();
});


})
20 changes: 16 additions & 4 deletions packages/amplify-cli/src/commands/status.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import { constructCloudWatchEventComponent } from "amplify-category-function/src/provider-utils/awscloudformation/utils/cloudformationHelpers";
sachscode marked this conversation as resolved.
Show resolved Hide resolved
import { ViewResourceTableParams, CLIParams } from "amplify-cli-core/lib/cliViewAPI";


export const run = async context => {
await context.amplify.showResourceTable();
await context.amplify.showHelpfulProviderLinks(context);
await showAmplifyConsoleHostingStatus(context);
const cliParams:CLIParams = { cliCommand : context?.input?.command,
cliSubcommands: context?.input?.subCommands,
cliOptions : context?.input?.options }
const view = new ViewResourceTableParams( cliParams );
if ( context?.input?.subCommands?.includes("help")){
console.log( view.getStyledHelp())
} else {
await context.amplify.showStatusTable( view );
sachscode marked this conversation as resolved.
Show resolved Hide resolved
await context.amplify.showHelpfulProviderLinks(context);
await showAmplifyConsoleHostingStatus(context);
}
};

async function showAmplifyConsoleHostingStatus(context) {
async function showAmplifyConsoleHostingStatus( context) {
const pluginInfo = context.amplify.getCategoryPluginInfo(context, 'hosting', 'amplifyhosting');
if (pluginInfo && pluginInfo.packageLocation) {
const { status } = require(pluginInfo.packageLocation);
Expand Down
8 changes: 8 additions & 0 deletions packages/amplify-cli/src/domain/amplify-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class AmplifyToolkit {
private _showHelp: any;
private _showHelpfulProviderLinks: any;
private _showResourceTable: any;
private _showStatusTable: any;
private _serviceSelectionPrompt: any;
private _updateProjectConfig: any;
private _updateamplifyMetaAfterResourceUpdate: any;
Expand Down Expand Up @@ -258,6 +259,13 @@ export class AmplifyToolkit {
this._showResourceTable || require(path.join(this._amplifyHelpersDirPath, 'resource-status')).showResourceTable;
return this._showResourceTable;
}

get showStatusTable(): any {
this._showStatusTable =
this._showStatusTable || require(path.join(this._amplifyHelpersDirPath, 'resource-status')).showStatusTable;
akshbhu marked this conversation as resolved.
Show resolved Hide resolved
return this._showStatusTable;
}

get serviceSelectionPrompt(): any {
this._serviceSelectionPrompt =
this._serviceSelectionPrompt || require(path.join(this._amplifyHelpersDirPath, 'service-select-prompt')).serviceSelectionPrompt;
Expand Down
Loading