Skip to content

Commit

Permalink
feat: devScripts update (#1203)
Browse files Browse the repository at this point in the history
* chore: updates from devScripts

* fix: remove oclif interface

* refactor: use cli-progress directly

* chore: remove unused constructor prop, break inheritance chain

---------

Co-authored-by: mshanemc <[email protected]>
  • Loading branch information
svc-cli-bot and mshanemc authored Jun 6, 2024
1 parent a2b6272 commit 9e5ef50
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 155 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^3.26.6",
"@oclif/core": "^4",
"@salesforce/apex-node": "^6.0.0",
"@salesforce/core": "^7.3.9",
"@salesforce/kit": "^3.1.2",
"@salesforce/sf-plugins-core": "^9.1.1",
"@salesforce/sf-plugins-core": "^10.0.0",
"@salesforce/source-deploy-retrieve": "^11.6.2",
"@salesforce/source-tracking": "^6.3.3",
"@salesforce/ts-types": "^2.0.9",
"chalk": "^5.3.0",
"cli-progress": "^3.12.0",
"got": "^13.0.0",
"proxy-agent": "^6.3.1"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^5.1.7",
"@oclif/plugin-help": "^6.1.0",
"@salesforce/cli-plugins-testkit": "^5.3.5",
"@salesforce/dev-scripts": "^9.1.3",
"@salesforce/dev-scripts": "^10.1.0",
"@salesforce/plugin-command-reference": "^3.0.86",
"@salesforce/source-testkit": "^2.2.23",
"@salesforce/ts-sinon": "1.4.19",
"@types/archiver": "^5.3.2",
"@types/cli-progress": "^3.11.5",
"archiver": "^5.3.2",
"chai-each": "^0.0.1",
"cross-env": "^7.0.3",
Expand Down
5 changes: 2 additions & 3 deletions src/commands/force/mdapi/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from '../../../deployCommand.js';
import { DeployCommandAsyncResult } from '../../../formatters/source/deployAsyncResultFormatter.js';
import { MdDeployResult, MdDeployResultFormatter } from '../../../formatters/mdapi/mdDeployResultFormatter.js';
import { ProgressFormatter } from '../../../formatters/progressFormatter.js';
import { DeployProgressBarFormatter } from '../../../formatters/deployProgressBarFormatter.js';
import { DeployProgressStatusFormatter } from '../../../formatters/deployProgressStatusFormatter.js';
import { MdDeployAsyncResultFormatter } from '../../../formatters/mdapi/mdDeployAsyncResultFormatter.js';
Expand Down Expand Up @@ -205,8 +204,8 @@ export class Deploy extends DeployCommand {

if (!this.isAsync) {
if (!this.jsonEnabled()) {
const progressFormatter: ProgressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
? new DeployProgressBarFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }))
const progressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
? new DeployProgressBarFormatter()
: new DeployProgressStatusFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }));
progressFormatter.progress(deploy);
}
Expand Down
5 changes: 2 additions & 3 deletions src/commands/force/mdapi/deploy/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import { Interfaces } from '@oclif/core';
import { MdDeployResult, MdDeployResultFormatter } from '../../../../formatters/mdapi/mdDeployResultFormatter.js';
import { DeployCommand, getCoverageFormattersOptions, reportsFormatters } from '../../../../deployCommand.js';
import { ProgressFormatter } from '../../../../formatters/progressFormatter.js';
import { DeployProgressBarFormatter } from '../../../../formatters/deployProgressBarFormatter.js';
import { DeployProgressStatusFormatter } from '../../../../formatters/deployProgressStatusFormatter.js';

Expand Down Expand Up @@ -112,8 +111,8 @@ export class Report extends DeployCommand {

const deploy = this.createDeploy(this.org.getConnection(), deployId);
if (!this.jsonEnabled()) {
const progressFormatter: ProgressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
? new DeployProgressBarFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }))
const progressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
? new DeployProgressBarFormatter()
: new DeployProgressStatusFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }));
progressFormatter.progress(deploy);
}
Expand Down
5 changes: 2 additions & 3 deletions src/commands/force/source/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
DeployAsyncResultFormatter,
DeployCommandAsyncResult,
} from '../../../formatters/source/deployAsyncResultFormatter.js';
import { ProgressFormatter } from '../../../formatters/progressFormatter.js';
import { DeployProgressBarFormatter } from '../../../formatters/deployProgressBarFormatter.js';
import { DeployProgressStatusFormatter } from '../../../formatters/deployProgressStatusFormatter.js';
import { filterConflictsByComponentSet, trackingSetup, updateTracking } from '../../../trackingFunctions.js';
Expand Down Expand Up @@ -283,8 +282,8 @@ export class Deploy extends DeployCommand {
if (!this.isAsync) {
// we're not print JSON output
if (!this.jsonEnabled()) {
const progressFormatter: ProgressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
? new DeployProgressBarFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }))
const progressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
? new DeployProgressBarFormatter()
: new DeployProgressStatusFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }), {
verbose: this.flags.verbose,
});
Expand Down
5 changes: 2 additions & 3 deletions src/commands/force/source/deploy/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
DeployReportCommandResult,
DeployReportResultFormatter,
} from '../../../../formatters/deployReportResultFormatter.js';
import { ProgressFormatter } from '../../../../formatters/progressFormatter.js';
import { DeployProgressBarFormatter } from '../../../../formatters/deployProgressBarFormatter.js';
import { DeployProgressStatusFormatter } from '../../../../formatters/deployProgressStatusFormatter.js';
import { ResultFormatterOptions } from '../../../../formatters/resultFormatter.js';
Expand Down Expand Up @@ -112,8 +111,8 @@ export class Report extends DeployCommand {
const waitDuration = this.flags.wait;
const deploy = this.createDeploy(this.flags['target-org'].getConnection(), deployId);
if (!this.jsonEnabled()) {
const progressFormatter: ProgressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
? new DeployProgressBarFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }))
const progressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
? new DeployProgressBarFormatter()
: new DeployProgressStatusFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }));
progressFormatter.progress(deploy);
}
Expand Down
5 changes: 2 additions & 3 deletions src/commands/force/source/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import { Interfaces } from '@oclif/core';
import { DeployCommand } from '../../../deployCommand.js';
import { PushResponse, PushResultFormatter } from '../../../formatters/source/pushResultFormatter.js';
import { ProgressFormatter } from '../../../formatters/progressFormatter.js';
import { DeployProgressBarFormatter } from '../../../formatters/deployProgressBarFormatter.js';
import { DeployProgressStatusFormatter } from '../../../formatters/deployProgressStatusFormatter.js';
import { trackingSetup, updateTracking } from '../../../trackingFunctions.js';
Expand Down Expand Up @@ -149,8 +148,8 @@ export default class Push extends DeployCommand {

// we're not print JSON output
if (!this.jsonEnabled()) {
const progressFormatter: ProgressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
? new DeployProgressBarFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }))
const progressFormatter = env.getBoolean('SF_USE_PROGRESS_BAR', true)
? new DeployProgressBarFormatter()
: new DeployProgressStatusFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }));
progressFormatter.progress(deploy);
}
Expand Down
4 changes: 1 addition & 3 deletions src/commands/force/source/retrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
requiredOrgFlagWithDeprecations,
Ux,
} from '@salesforce/sf-plugins-core';
import { AlphabetLowercase } from '@oclif/core/lib/interfaces';
import { SourceCommand } from '../../../sourceCommand.js';
import {
PackageRetrieval,
Expand Down Expand Up @@ -57,8 +56,7 @@ export class Retrieve extends SourceCommand {
message: messages.getMessage('deprecation', [replacement]),
};
public static readonly flags = {
// I have no idea why 'a' isn't matching the type AlphabetLowercase automatically
'api-version': { ...orgApiVersionFlagWithDeprecations, char: 'a' as AlphabetLowercase },
'api-version': { ...orgApiVersionFlagWithDeprecations, char: 'a' as const },
loglevel,
'target-org': requiredOrgFlagWithDeprecations,
retrievetargetdir: Flags.directory({
Expand Down
48 changes: 22 additions & 26 deletions src/formatters/deployProgressBarFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,38 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
import { once } from '@salesforce/kit';
import { ux as coreUx } from '@oclif/core';
import { Ux } from '@salesforce/sf-plugins-core';
import { ProgressFormatter } from './progressFormatter.js';
import { MetadataApiDeploy, MetadataApiDeployStatus } from '@salesforce/source-deploy-retrieve';
import { SingleBar } from 'cli-progress';

export class DeployProgressBarFormatter extends ProgressFormatter {
protected progressBar = coreUx.progress({
export class DeployProgressBarFormatter {
protected progressBar = new SingleBar({
format: 'DEPLOY PROGRESS | {bar} | {value}/{total} Components',
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
linewrap: true,
noTTYOutput: Boolean(process.env.TERM === 'dumb' || !process.stdin.isTTY),
});
public constructor(ux: Ux) {
super(ux);
}

public constructor() {}

// displays the progress of the Deployment
public progress(deploy: MetadataApiDeploy): void {
const startProgressBar = once((componentTotal: number) => {
this.progressBar.start(componentTotal, 0);
});

deploy.onUpdate((data) => {
// the numCompTot. isn't computed right away, wait to start until we know how many we have
const total = data.numberComponentsTotal + data.numberTestsTotal;
if (data.numberComponentsTotal) {
startProgressBar(total);
this.progressBar.update(data.numberComponentsDeployed + data.numberTestsCompleted);
this.progressBar.start(0, 0);
deploy.onUpdate(
({
numberComponentsTotal,
numberTestsTotal,
numberComponentsDeployed,
numberTestsCompleted,
}: MetadataApiDeployStatus) => {
// the numberComponentsTotal isn't computed right away, wait to start until we know how many we have
const total = numberComponentsTotal + numberTestsTotal;
if (this.progressBar.getTotal() !== total) {
this.progressBar.setTotal(total);
}
this.progressBar.update(numberComponentsDeployed + numberTestsCompleted);
}

// the numTestsTot. isn't computed until validated as tests by the server, update the PB once we know
if (data.numberTestsTotal && data.numberComponentsTotal) {
this.progressBar.setTotal(total);
}
});
);

// any thing else should stop the progress bar
deploy.onFinish((data) => {
Expand Down
10 changes: 5 additions & 5 deletions src/sourceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ import fs from 'node:fs';
import { Messages, SfError } from '@salesforce/core';
import { ComponentSet } from '@salesforce/source-deploy-retrieve';
import { getString, Optional } from '@salesforce/ts-types';
import { ux } from '@oclif/core';
import { SingleBar } from 'cli-progress';
import { SfCommand } from '@salesforce/sf-plugins-core';
import { EnsureFsFlagOptions, FsError, ProgressBar } from './types.js';
import { EnsureFsFlagOptions, FsError } from './types.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-source', 'flags.validation');

export abstract class SourceCommand extends SfCommand<unknown> {
public static readonly DEFAULT_WAIT_MINUTES = 33;

protected progressBar?: ProgressBar;
protected progressBar?: SingleBar;
protected componentSet?: ComponentSet;

protected initProgressBar(): void {
this.debug('initializing progress bar');
this.progressBar = ux.progress({
this.progressBar = new SingleBar({
format: 'SOURCE PROGRESS | {bar} | {value}/{total} Components',
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
linewrap: true,
}) as ProgressBar;
});
}

/**
Expand Down
11 changes: 1 addition & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@

export type FsError = {
code: string;
} & Error
} & Error;

export type EnsureFsFlagOptions = {
flagName: string;
path?: string;
type: 'dir' | 'file' | 'any';
throwOnENOENT?: boolean;
}

export type ProgressBar = {
total?: number;
value?: number;
start: (total: number, startValue: number, payload?: object) => void;
update: (num: number, payload?: object) => void;
setTotal: (num: number) => void;
stop: () => void;
};
Loading

0 comments on commit 9e5ef50

Please sign in to comment.