Skip to content

Commit

Permalink
feat: ui for tracking (#819)
Browse files Browse the repository at this point in the history
* chore: handle new error with generic missing data

* feat: ui for tracking

* feat: hide testInfo until tests run

* refactor: more concise ui

* feat: hide test errors when there are none

* fix: bump STL

---------

Co-authored-by: Cristian Dominguez <[email protected]>
  • Loading branch information
mshanemc and cristiand391 authored Nov 28, 2023
1 parent 9f53e78 commit a340a5a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@salesforce/kit": "^3.0.15",
"@salesforce/sf-plugins-core": "^5.0.3",
"@salesforce/source-deploy-retrieve": "^10.0.2",
"@salesforce/source-tracking": "^5.0.1",
"@salesforce/source-tracking": "^5.1.0",
"chalk": "^5.3.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/project/deploy/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
}

protected catch(error: Error | SfError): Promise<SfCommand.Error> {
if (error instanceof SourceConflictError) {
if (error instanceof SourceConflictError && error.data) {
if (!this.jsonEnabled()) {
writeConflictTable(error.data);
// set the message and add plugin-specific actions
Expand Down
2 changes: 1 addition & 1 deletion src/commands/project/retrieve/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export default class RetrieveMetadata extends SfCommand<RetrieveResultJson> {
}

protected catch(error: Error | SfError): Promise<SfCommand.Error> {
if (!this.jsonEnabled() && error instanceof SourceConflictError) {
if (!this.jsonEnabled() && error instanceof SourceConflictError && error.data) {
writeConflictTable(error.data);
// set the message and add plugin-specific actions
return super.catch({
Expand Down
36 changes: 27 additions & 9 deletions src/utils/progressBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
*/
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { envVars as env, EnvironmentVariable, Messages } from '@salesforce/core';
import { envVars as env, EnvironmentVariable, Lifecycle, Messages } from '@salesforce/core';
import { MetadataApiDeploy, MetadataApiDeployStatus } from '@salesforce/source-deploy-retrieve';
import { Progress } from '@salesforce/sf-plugins-core';
import { SourceMemberPollingEvent } from '@salesforce/source-tracking';

Messages.importMessagesDirectory(dirname(fileURLToPath(import.meta.url)));
const mdTransferMessages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'metadata.transfer');
Expand All @@ -20,21 +21,27 @@ const showBar = Boolean(
export class DeployProgress extends Progress {
private static OPTIONS = {
title: 'Status',
format: `%s: {status} ${showBar ? '| {bar} ' : ''}| {value}/{total} Components (Errors:{errorCount}) {testInfo}`,
format: `%s: {status} ${showBar ? '| {bar} ' : ''}| {value}/{total} Components{errorInfo}{testInfo}{trackingInfo}`,
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
linewrap: true,
// people really like to get text output in CI systems
// they won't get the "bar" but will get the remaining template bits this way
noTTYOutput: true,
};
private lifecycle = Lifecycle.getInstance();

public constructor(private deploy: MetadataApiDeploy, jsonEnabled = false) {
super(!jsonEnabled);
}

public start(): void {
super.start(0, { status: 'Waiting' }, DeployProgress.OPTIONS);
super.start(0, { status: 'Waiting', trackingInfo: '', testInfo: '' }, DeployProgress.OPTIONS);

// for sourceMember polling events
this.lifecycle.on<SourceMemberPollingEvent>('sourceMemberPollingEvent', (event: SourceMemberPollingEvent) =>
Promise.resolve(this.updateTrackingProgress(event))
);

this.deploy.onUpdate((data) => this.updateProgress(data));

Expand All @@ -52,21 +59,32 @@ export class DeployProgress extends Progress {
});
}

private updateTrackingProgress(data: SourceMemberPollingEvent): void {
const { remaining, original } = data;
this.update(0, {
status: 'Polling SourceMembers',
trackingInfo: ` | Tracking: ${original - remaining}/${original}`,
});
}

private updateProgress(data: MetadataApiDeployStatus): void {
// the numCompTot. isn't computed right away, wait to start until we know how many we have
const errorCount = data.numberComponentErrors ?? 0;
const testInfo = `| ${data.numberTestsCompleted ?? 0}/${data.numberTestsTotal ?? 0} Tests (Errors:${
data.numberTestErrors
})`;
const testInfo = data.numberTestsTotal
? ` | ${data.numberTestsCompleted ?? 0}/${data.numberTestsTotal ?? 0} Tests${
data.numberTestErrors ? `(Errors:${data.numberTestErrors})` : ''
}`
: '';
const errorInfo = data.numberComponentErrors > 0 ? ` | Errors: ${data.numberComponentErrors}` : '';

if (data.numberComponentsTotal) {
this.setTotal(data.numberComponentsTotal);
this.update(data.numberComponentsDeployed, {
errorCount,
errorInfo: data.numberComponentErrors > 0 ? ` | Errors: ${data.numberComponentErrors}` : '',
status: mdTransferMessages.getMessage(data.status),
testInfo,
});
} else {
this.update(0, { errorCount, testInfo, status: mdTransferMessages.getMessage(data.status) ?? 'Waiting' });
this.update(0, { errorInfo, testInfo, status: mdTransferMessages.getMessage(data.status) ?? 'Waiting' });
}
}
}
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1200,15 +1200,15 @@
shelljs "^0.8.4"
sinon "^10.0.0"

"@salesforce/source-tracking@^5.0.0", "@salesforce/source-tracking@^5.0.1":
version "5.0.1"
resolved "https://registry.yarnpkg.com/@salesforce/source-tracking/-/source-tracking-5.0.1.tgz#3b54b2ed8eee9c7bc8506ca9b1c0e88f961b435a"
integrity sha512-9ckOvid03/J5Lvq83aW7GIlLm9HtJ9NMLwalppDMvSd4T/lyWe8y4bxh4LKbqTC7fhzHMxet8yYTpzub0t+DPA==
"@salesforce/source-tracking@^5.0.0", "@salesforce/source-tracking@^5.1.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@salesforce/source-tracking/-/source-tracking-5.1.0.tgz#c0d6336f0002a8c4abeae4ff3392de4adc169fd3"
integrity sha512-FTuDwLjERm1OR/xTy4a5oHThGOQvI0Rqs4ZqClQFUdgUKREcbxvO3UivSekgXA3az6nuSeNRmaTZGTC5gPjtKA==
dependencies:
"@oclif/core" "^3.10.8"
"@salesforce/core" "^6.1.3"
"@salesforce/core" "^6.2.0"
"@salesforce/kit" "^3.0.15"
"@salesforce/source-deploy-retrieve" "^10.0.0"
"@salesforce/source-deploy-retrieve" "^10.0.2"
"@salesforce/ts-types" "^2.0.9"
fast-xml-parser "^4.2.5"
graceful-fs "^4.2.11"
Expand Down

0 comments on commit a340a5a

Please sign in to comment.