Skip to content

Commit 1d2b36f

Browse files
authored
Updates to pretty sandbox display (#2599)
* Move the spinner between timestamp and spinner text * Updates to pretty sandbox display
1 parent 82f3195 commit 1d2b36f

File tree

9 files changed

+50
-45
lines changed

9 files changed

+50
-45
lines changed

.changeset/ten-ravens-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/cli-core': patch
3+
---
4+
5+
Move the spinner between timestamp and spinner text

.changeset/vast-dragons-yawn.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@aws-amplify/cli-core': patch
3+
'@aws-amplify/sandbox': patch
4+
---
5+
6+
Updates to pretty sandbox display

packages/cli-core/src/format/format.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ void describe('format.error', async () => {
127127
const expectedOutput =
128128
red(bold('[Error]')) +
129129
' something went wrong' +
130-
format.indent(
131-
os.EOL + 'Caused by: ' + red(bold('[Error]')) + ' nested error',
132-
);
130+
os.EOL +
131+
format.indent('∟ Caused by: ' + red(bold('[Error]')) + ' nested error');
133132
const actualOutput = format.error(input);
134133
assert.strictEqual(actualOutput, expectedOutput);
135134
});

packages/cli-core/src/format/format.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ export class Format {
4242
}`;
4343

4444
if (typeof error?.cause === 'object' && !!error.cause) {
45-
message =
46-
message +
47-
this.indent(os.EOL + `Caused by: ${this.error(error.cause)}`);
45+
message = `${message}${os.EOL}${format.indent(`∟ Caused by: ${this.error(error.cause)}`)}`;
4846
}
4947

5048
if (AmplifyError.isAmplifyError(error) && error.resolution) {

packages/cli-core/src/loggers/amplify_event_logger_for_sandbox.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void describe('amplify sandbox event logging', () => {
170170
)} | CloudFormation:Stack | ${format.color(
171171
format.bold('∟ data stack'),
172172
'Green',
173-
)}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}`,
173+
)}${EOL}`,
174174
],
175175
);
176176

@@ -404,7 +404,7 @@ void describe('amplify sandbox event logging', () => {
404404
)} | S3BucketNotifications | ${format.color(
405405
format.bold('∟ Notifications'),
406406
'Green',
407-
)}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}`,
407+
)}${EOL}`,
408408
);
409409
break;
410410
case 29:
@@ -470,7 +470,7 @@ void describe('amplify sandbox event logging', () => {
470470
)} | AmplifyDynamoDBTable | ${format.color(
471471
format.bold(' ∟ Default'),
472472
'Green',
473-
)}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}`,
473+
)}${EOL}`,
474474
);
475475
break;
476476
case 41:
@@ -488,7 +488,7 @@ void describe('amplify sandbox event logging', () => {
488488
)} | CloudFormation:Stack | ${format.color(
489489
format.bold('data'),
490490
'Green',
491-
)}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}`,
491+
)}${EOL}`,
492492
);
493493
break;
494494
default:
@@ -614,7 +614,7 @@ void describe('amplify sandbox event logging', () => {
614614
)} | IAM:Policy | ${format.color(
615615
format.bold('∟ DefaultPolicy'),
616616
'Green',
617-
)}${EOL}${cll()}${EOL}${cll()}${EOL}`,
617+
)}${EOL}`,
618618
);
619619
break;
620620
case 19:
@@ -646,7 +646,7 @@ void describe('amplify sandbox event logging', () => {
646646
'∟ BucketNotificationsHandler050a0587b7544547bf325f094a3db834',
647647
),
648648
'Green',
649-
)}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}`,
649+
)}${EOL}`,
650650
);
651651
break;
652652
case 23:
@@ -670,7 +670,7 @@ void describe('amplify sandbox event logging', () => {
670670
)} | CloudFormation:Stack | ${format.color(
671671
format.bold('storage'),
672672
'Green',
673-
)}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}`,
673+
)}${EOL}`,
674674
);
675675
break;
676676
default:
@@ -748,7 +748,7 @@ void describe('amplify sandbox event logging', () => {
748748
)} | CloudFormation:Stack | ${format.color(
749749
format.bold('∟ data stack'),
750750
'Green',
751-
)}${EOL}${cll()}${EOL}`,
751+
)}${EOL}`,
752752
);
753753
break;
754754
case 7:
@@ -816,7 +816,7 @@ void describe('amplify sandbox event logging', () => {
816816
)} | IAM:Role | ${format.color(
817817
format.bold('sayhellolambdaServiceRole4BCAA6E2'),
818818
'Yellow',
819-
)}${EOL}${cll()}${EOL}`,
819+
)}${EOL}`,
820820
);
821821
break;
822822

@@ -835,7 +835,7 @@ void describe('amplify sandbox event logging', () => {
835835
)} | CloudFormation:Stack | ${format.color(
836836
format.bold('function1351588B'),
837837
'Yellow',
838-
)}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}`,
838+
)}${EOL}`,
839839
);
840840
break;
841841
default:
@@ -974,7 +974,7 @@ void describe('amplify sandbox event logging', () => {
974974
'∟ BucketNotificationsHandler050a0587b7544547bf325f094a3db834',
975975
),
976976
'Yellow',
977-
)}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}`,
977+
)}${EOL}`,
978978
);
979979
break;
980980
case 9:
@@ -1028,7 +1028,7 @@ void describe('amplify sandbox event logging', () => {
10281028
)} | SNS:Topic | ${format.color(
10291029
format.bold('∟ CustomTopics'),
10301030
'Yellow',
1031-
)}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}`,
1031+
)}${EOL}`,
10321032
);
10331033
break;
10341034
case 19:
@@ -1046,7 +1046,7 @@ void describe('amplify sandbox event logging', () => {
10461046
)} | CloudFormation:Stack | ${format.color(
10471047
format.bold('data'),
10481048
'Yellow',
1049-
)}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}`,
1049+
)}${EOL}`,
10501050
);
10511051
break;
10521052
case 25:
@@ -1070,7 +1070,7 @@ void describe('amplify sandbox event logging', () => {
10701070
)} | CloudFormation:Stack | ${format.color(
10711071
format.bold('auth'),
10721072
'Yellow',
1073-
)}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}${cll()}${EOL}`,
1073+
)}${EOL}`,
10741074
);
10751075
break;
10761076
default:
@@ -1207,7 +1207,7 @@ void describe('amplify sandbox event logging', () => {
12071207
)}${EOL}${cll()}${format.color(
12081208
'Resource handler returned message: "Cognito received the following error from Amazon SES when attempting to send email: Email address is not verified. The following identities failed the check in region US-WEST-2: arn:aws:ses:us-west-2:123456789012:identity/[email protected] (Service: CognitoIdentityProvider, Status Code: 400, Request ID: 3bf35a6e-9667-4baf-8eab-19676643ac8d)" (RequestToken: 8c4cec48-3f40-7c73-a8b6-3afc0314b029, HandlerErrorCode: InvalidRequest)',
12091209
'Red',
1210-
)}${EOL}${cll()}${EOL}${cll()}${EOL}`,
1210+
)}${EOL}`,
12111211
);
12121212
break;
12131213
default:

packages/cli-core/src/loggers/cfn-deployment-progress/rewritable_block.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { EOL } from 'os';
77
*/
88
export class RewritableBlock {
99
private lastHeight = 0;
10-
private trailingEmptyLines = 0;
1110

1211
/**
1312
* Constructor for RewritableBlock
@@ -23,7 +22,7 @@ export class RewritableBlock {
2322

2423
/**
2524
* Display the given lines in this rewritable block. It expands to make room for more lines
26-
* and keep the size of the block constant until finished.
25+
* and compress when not needed. It also takes care of not overflowing the block.
2726
*/
2827
async displayLines(lines: string[]) {
2928
lines = this.terminalWrap(this.getBlockWidth(), this.expandNewlines(lines));
@@ -37,13 +36,6 @@ export class RewritableBlock {
3736
progressUpdate.push(this.cll() + line + EOL);
3837
}
3938

40-
this.trailingEmptyLines = Math.max(0, this.lastHeight - lines.length);
41-
42-
// Clear remainder of unwritten lines
43-
for (let i = 0; i < this.trailingEmptyLines; i++) {
44-
progressUpdate.push(this.cll() + EOL);
45-
}
46-
4739
await this.ioHost.notify({
4840
message: progressUpdate.join(''),
4941
code: 'AMPLIFY_CFN_PROGRESS_UPDATE',

packages/cli-core/src/printer/printer.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export class Printer {
100100
}
101101
this.currentSpinner = {
102102
instance: ora({
103-
text: this.prefixedMessage(message),
103+
text: message,
104+
prefixText: this.getLogPrefix(),
104105
color: 'white',
105106
stream: this.stdout,
106107
spinner: 'dots',
@@ -164,7 +165,8 @@ export class Printer {
164165
return;
165166
}
166167
if (options.prefixText) {
167-
this.currentSpinner.instance.prefixText = options.prefixText;
168+
this.currentSpinner.instance.prefixText =
169+
options.prefixText + this.getLogPrefix();
168170
} else if (options.message) {
169171
this.currentSpinner.instance.text = options.message;
170172
}
@@ -185,18 +187,14 @@ export class Printer {
185187
};
186188

187189
private printWhileSpinnerRunning = (message: string) => {
188-
if (this.isSpinnerRunning()) {
189-
if (this.currentSpinner.instance?.prefixText) {
190-
const spinnerPrefixMessage = this.currentSpinner.instance?.prefixText;
191-
this.currentSpinner.instance.prefixText =
192-
message + EOL + spinnerPrefixMessage;
193-
} else {
194-
const spinnerMessage = this.currentSpinner.instance?.text;
195-
this.currentSpinner.instance?.clear();
196-
this.stdout.write(message);
197-
this.currentSpinner.instance?.start(spinnerMessage);
198-
}
190+
if (!this.isSpinnerRunning()) {
191+
return;
199192
}
193+
const spinnerMessage = this.currentSpinner.instance?.text;
194+
this.currentSpinner.instance?.clear();
195+
this.stdout.write(message);
196+
this.printNewLine();
197+
this.currentSpinner.instance?.start(spinnerMessage);
200198
};
201199

202200
private stringify = (msg: unknown): string => {

packages/sandbox/src/file_watching_sandbox.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const printer = {
9090
log: mock.fn(),
9191
print: mock.fn(),
9292
clearConsole: mock.fn(),
93+
printNewLine: mock.fn(),
9394
};
9495

9596
const sandboxExecutor = new AmplifySandboxExecutor(

packages/sandbox/src/file_watching_sandbox.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export class FileWatchingSandbox extends EventEmitter implements Sandbox {
157157
this.outputFilesExcludedFromWatch =
158158
this.outputFilesExcludedFromWatch.concat(...ignoredPaths);
159159

160+
this.printer.clearConsole();
160161
await this.printSandboxNameInfo(options.identifier);
161162

162163
// Since 'cdk deploy' is a relatively slow operation for a 'watch' process,
@@ -189,6 +190,7 @@ export class FileWatchingSandbox extends EventEmitter implements Sandbox {
189190
// and thinks the above 'while' condition is always 'false' without the cast
190191
latch = 'deploying';
191192
this.printer.clearConsole();
193+
await this.printSandboxNameInfo(options.identifier);
192194
this.printer.log(
193195
"[Sandbox] Detected file changes while previous deployment was in progress. Invoking 'sandbox' again",
194196
);
@@ -210,9 +212,12 @@ export class FileWatchingSandbox extends EventEmitter implements Sandbox {
210212
async (_, events) => {
211213
// Log and track file changes.
212214
await Promise.all(
213-
events.map(({ type: eventName, path: filePath }) => {
215+
events.map(async ({ type: eventName, path: filePath }) => {
214216
this.filesChangesTracker.trackFileChange(filePath);
215-
latch === 'open' && this.printer.clearConsole();
217+
if (latch === 'open') {
218+
this.printer.clearConsole();
219+
await this.printSandboxNameInfo();
220+
}
216221
this.printer.log(
217222
`[Sandbox] Triggered due to a file ${eventName} event: ${path.relative(
218223
process.cwd(),
@@ -443,6 +448,7 @@ export class FileWatchingSandbox extends EventEmitter implements Sandbox {
443448
)}${format.bold('--identifier')}`,
444449
);
445450
}
451+
this.printer.printNewLine();
446452
};
447453

448454
/**

0 commit comments

Comments
 (0)