Skip to content

Commit

Permalink
Merge pull request #1123 from salesforcecli/mdonnalley/ink
Browse files Browse the repository at this point in the history
feat: use @oclif/multi-stage-output
  • Loading branch information
WillieRuemmele authored Aug 21, 2024
2 parents 2098219 + 8786aa3 commit c4f1cff
Show file tree
Hide file tree
Showing 11 changed files with 558 additions and 170 deletions.
12 changes: 0 additions & 12 deletions messages/retrieve.start.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,6 @@ Extract all files from the retrieved zip file.

File name to use for the retrieved zip file.

# spinner.start

Preparing retrieve request

# spinner.sending

Sending request to org

# spinner.polling

Waiting for the org to respond

# error.Conflicts

There are changes in your local files that conflict with the org changes you're trying to retrieve.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^4.0.17",
"@oclif/multi-stage-output": "^0.3.0",
"@salesforce/apex-node": "^8.1.3",
"@salesforce/core": "^8.4.0",
"@salesforce/kit": "^3.2.1",
Expand Down
12 changes: 9 additions & 3 deletions src/commands/project/delete/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
requiredOrgFlagWithDeprecations,
SfCommand,
} from '@salesforce/sf-plugins-core';
import { DeployStages } from '../../../utils/deployStages.js';
import { writeConflictTable } from '../../../utils/conflicts.js';
import { isNonDecomposedCustomLabel, isNonDecomposedCustomLabelsOrCustomLabel } from '../../../utils/metadataTypes.js';
import { getFileResponseSuccessProps, tableHeader } from '../../../utils/output.js';
Expand All @@ -41,7 +42,6 @@ import { getPackageDirs, getSourceApiVersion } from '../../../utils/project.js';
import { resolveApi, validateTests } from '../../../utils/deploy.js';
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter.js';
import { DeleteResultFormatter } from '../../../formatters/deleteResultFormatter.js';
import { DeployProgress } from '../../../utils/progressBar.js';
import { DeployCache } from '../../../utils/deployCache.js';
import { testLevelFlag, testsFlag } from '../../../utils/flags.js';
const testFlags = 'Test';
Expand Down Expand Up @@ -244,8 +244,14 @@ export class Source extends SfCommand<DeleteSourceJson> {

// fire predeploy event for the delete
await Lifecycle.getInstance().emit('predeploy', this.components);

const stages = new DeployStages({
title: 'Deleting Metadata',
jsonEnabled: this.jsonEnabled(),
});

const isRest = (await resolveApi()) === API['REST'];
this.log(`*** Deleting with ${isRest ? 'REST' : 'SOAP'} API ***`);
stages.update({ message: `Deleting with ${isRest ? 'REST' : 'SOAP'} API` });

const deploy = await this.componentSet.deploy({
usernameOrConnection: this.org.getUsername() as string,
Expand All @@ -257,7 +263,7 @@ export class Source extends SfCommand<DeleteSourceJson> {
},
});

new DeployProgress(deploy, this.jsonEnabled()).start();
stages.start({ deploy, username: this.org.getUsername() });
this.deployResult = await deploy.pollStatus({ timeout: this.flags.wait });
if (!deploy.id) {
throw new SfError('The deploy id is not available.');
Expand Down
9 changes: 6 additions & 3 deletions src/commands/project/deploy/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import { Messages, Org, SfProject } from '@salesforce/core';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { ComponentSet, DeployResult, MetadataApiDeploy, RequestStatus } from '@salesforce/source-deploy-retrieve';
import { DeployStages } from '../../../utils/deployStages.js';
import { buildComponentSet } from '../../../utils/deploy.js';
import { DeployProgress } from '../../../utils/progressBar.js';
import { DeployCache } from '../../../utils/deployCache.js';
import { DeployReportResultFormatter } from '../../../formatters/deployReportResultFormatter.js';
import { API, DeployResultJson } from '../../../utils/types.js';
Expand Down Expand Up @@ -70,7 +70,7 @@ export default class DeployMetadataReport extends SfCommand<DeployResultJson> {
const jobId = cache.resolveLatest(flags['use-most-recent'], flags['job-id'], false);

const deployOpts = cache.maybeGet(jobId);
const wait = flags['wait'];
const { wait } = flags;
const org = deployOpts?.['target-org']
? await Org.create({ aliasOrUsername: deployOpts['target-org'] })
: flags['target-org'];
Expand Down Expand Up @@ -124,7 +124,10 @@ export default class DeployMetadataReport extends SfCommand<DeployResultJson> {
if (wait) {
// poll for deploy results
try {
new DeployProgress(mdapiDeploy, this.jsonEnabled()).start();
new DeployStages({
title: 'Deploying Metadata',
jsonEnabled: this.jsonEnabled(),
}).start({ deploy: mdapiDeploy, username: org.getUsername() });
result = await mdapiDeploy.pollStatus(500, wait.seconds);
} catch (error) {
if (error instanceof Error && error.message.includes('The client has timed out')) {
Expand Down
10 changes: 6 additions & 4 deletions src/commands/project/deploy/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import ansis from 'ansis';
import { EnvironmentVariable, Messages, Org, SfError } from '@salesforce/core';
import { SfCommand, toHelpSection, Flags } from '@salesforce/sf-plugins-core';
import { DeployResult, MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
import { Duration } from '@salesforce/kit';
import { DeployStages } from '../../../utils/deployStages.js';
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter.js';
import { DeployProgress } from '../../../utils/progressBar.js';
import { API, DeployResultJson } from '../../../utils/types.js';
import { buildComponentSet, determineExitCode, executeDeploy, isNotResumable } from '../../../utils/deploy.js';
import { DeployCache } from '../../../utils/deployCache.js';
Expand Down Expand Up @@ -124,8 +123,11 @@ export default class DeployMetadataResume extends SfCommand<DeployResultJson> {
jobId
);

this.log(`Deploy ID: ${ansis.bold(jobId)}`);
new DeployProgress(deploy, this.jsonEnabled()).start();
new DeployStages({
title: 'Resuming Deploy',
jsonEnabled: this.jsonEnabled(),
}).start({ deploy, username: deployOpts['target-org'] });

result = await deploy.pollStatus(500, wait.seconds);

if (!deploy.id) {
Expand Down
63 changes: 42 additions & 21 deletions src/commands/project/deploy/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import ansis from 'ansis';
import { MultiStageOutput } from '@oclif/multi-stage-output';
import { EnvironmentVariable, Lifecycle, Messages, OrgConfigProperties, SfError } from '@salesforce/core';
import { DeployVersionData } from '@salesforce/source-deploy-retrieve';
import { DeployVersionData, MetadataApiDeployStatus } from '@salesforce/source-deploy-retrieve';
import { Duration } from '@salesforce/kit';
import { SfCommand, toHelpSection, Flags } from '@salesforce/sf-plugins-core';
import { SourceConflictError } from '@salesforce/source-tracking';
import { SourceConflictError, SourceMemberPollingEvent } from '@salesforce/source-tracking';
import { DeployStages } from '../../../utils/deployStages.js';
import { AsyncDeployResultFormatter } from '../../../formatters/asyncDeployResultFormatter.js';
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter.js';
import { DeployProgress } from '../../../utils/progressBar.js';
import { DeployResultJson, TestLevel } from '../../../utils/types.js';
import { executeDeploy, resolveApi, validateTests, determineExitCode } from '../../../utils/deploy.js';
import { DeployCache } from '../../../utils/deployCache.js';
Expand Down Expand Up @@ -176,6 +176,16 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {

public static errorCodes = toHelpSection('ERROR CODES', DEPLOY_STATUS_CODES_DESCRIPTIONS);

protected ms!: MultiStageOutput<{
mdapiDeploy: MetadataApiDeployStatus;
sourceMemberPolling: SourceMemberPollingEvent;
status: string;
apiData: DeployVersionData;
targetOrg: string;
}>;

protected stages!: DeployStages;

public async run(): Promise<DeployResultJson> {
const { flags } = await this.parse(DeployMetadata);
const project = await getOptionalProject();
Expand All @@ -197,23 +207,30 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {

const api = await resolveApi(this.configAggregator);
const username = flags['target-org'].getUsername();
const action = flags['dry-run'] ? 'Deploying (dry-run)' : 'Deploying';
const title = flags['dry-run'] ? 'Deploying Metadata (dry-run)' : 'Deploying Metadata';

// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('apiVersionDeploy', async (apiData: DeployVersionData) => {
this.log(
messages.getMessage('apiVersionMsgDetailed', [
action,
// technically manifestVersion can be undefined, but only on raw mdapi deployments.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
flags['metadata-dir'] ? '<version specified in manifest>' : `v${apiData.manifestVersion}`,
username,
apiData.apiVersion,
apiData.webService,
])
);
this.stages = new DeployStages({
title,
jsonEnabled: this.jsonEnabled(),
});

const lifecycle = Lifecycle.getInstance();
lifecycle.on('apiVersionDeploy', async (apiData: DeployVersionData) =>
Promise.resolve(
this.stages.update({
message: messages.getMessage('apiVersionMsgDetailed', [
flags['dry-run'] ? 'Deploying (dry-run)' : 'Deploying',
// technically manifestVersion can be undefined, but only on raw mdapi deployments.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
flags['metadata-dir'] ? '<version specified in manifest>' : `v${apiData.manifestVersion}`,
username,
apiData.apiVersion,
apiData.webService,
]),
})
)
);

const { deploy } = await executeDeploy(
{
...flags,
Expand All @@ -224,16 +241,20 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
);

if (!deploy) {
this.stages.stop();
this.log('No changes to deploy');
return { status: 'Nothing to deploy', files: [] };
}

if (!deploy.id) {
throw new SfError('The deploy id is not available.');
}
this.log(`Deploy ID: ${ansis.bold(deploy.id)}`);

this.stages.start({ username, deploy });

if (flags.async) {
this.stages.done({ status: 'Queued', username });
this.stages.stop();
if (flags['coverage-formatters']) {
this.warn(messages.getMessage('asyncCoverageJunitWarning'));
}
Expand All @@ -242,8 +263,6 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
return asyncFormatter.getJson();
}

new DeployProgress(deploy, this.jsonEnabled()).start();

const result = await deploy.pollStatus({ timeout: flags.wait });
process.exitCode = determineExitCode(result);
const formatter = new DeployResultFormatter(result, flags);
Expand All @@ -261,6 +280,8 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
protected catch(error: Error | SfError): Promise<never> {
if (error instanceof SourceConflictError && error.data) {
if (!this.jsonEnabled()) {
this.stages.update({ status: 'Failed' });
this.stages.stop(error);
writeConflictTable(error.data);
// set the message and add plugin-specific actions
return super.catch({
Expand Down
9 changes: 6 additions & 3 deletions src/commands/project/deploy/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { EnvironmentVariable, Lifecycle, Messages, OrgConfigProperties, SfError
import { CodeCoverageWarnings, DeployVersionData, RequestStatus } from '@salesforce/source-deploy-retrieve';
import { Duration, ensureArray } from '@salesforce/kit';
import { SfCommand, toHelpSection, Flags } from '@salesforce/sf-plugins-core';
import { DeployStages } from '../../../utils/deployStages.js';
import { AsyncDeployResultFormatter } from '../../../formatters/asyncDeployResultFormatter.js';
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter.js';
import { DeployProgress } from '../../../utils/progressBar.js';
import { DeployResultJson, TestLevel } from '../../../utils/types.js';
import { executeDeploy, resolveApi, determineExitCode, validateTests } from '../../../utils/deploy.js';
import { DEPLOY_STATUS_CODES_DESCRIPTIONS } from '../../../utils/errorCodes.js';
Expand Down Expand Up @@ -195,15 +195,18 @@ export default class DeployMetadataValidate extends SfCommand<DeployResultJson>
if (!deploy.id) {
throw new SfError('The deploy id is not available.');
}
this.log(`Deploy ID: ${ansis.bold(deploy.id)}`);

if (flags.async) {
this.log(`Deploy ID: ${ansis.bold(deploy.id)}`);
const asyncFormatter = new AsyncDeployResultFormatter(deploy.id);
if (!this.jsonEnabled()) asyncFormatter.display();
return asyncFormatter.getJson();
}

new DeployProgress(deploy, this.jsonEnabled()).start();
new DeployStages({
title: 'Validating Deployment',
jsonEnabled: this.jsonEnabled(),
}).start({ deploy, username });

const result = await deploy.pollStatus(500, flags.wait?.seconds);
process.exitCode = determineExitCode(result);
Expand Down
Loading

0 comments on commit c4f1cff

Please sign in to comment.