Skip to content

Commit

Permalink
chore: building
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Nov 1, 2023
1 parent f78793d commit 002af63
Show file tree
Hide file tree
Showing 41 changed files with 282 additions and 220 deletions.
12 changes: 6 additions & 6 deletions src/commands/force/mdapi/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import { Duration, env } from '@salesforce/kit';
import { Lifecycle, Messages, Org } from '@salesforce/core';
import { DeployVersionData, MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
import { AsyncResult, DeployVersionData, MetadataApiDeploy } from '@salesforce/source-deploy-retrieve';
import {
arrayWithDeprecation,
Flags,
Expand Down Expand Up @@ -137,8 +137,8 @@ export class Deploy extends DeployCommand {
junit: Flags.boolean({ summary: messages.getMessage('flags.junit.summary') }),
};

private flags: Interfaces.InferredFlags<typeof Deploy.flags>;
private org: Org;
private flags!: Interfaces.InferredFlags<typeof Deploy.flags>;
private org!: Org;

public async run(): Promise<DeployResult> {
this.flags = (await this.parse(Deploy)).flags;
Expand Down Expand Up @@ -167,7 +167,7 @@ export class Deploy extends DeployCommand {
const deploymentOptions = this.flags.zipfile
? { zipPath: this.flags.zipfile }
: { mdapiPath: this.flags.deploydir };
const username = this.org.getUsername();
const username = this.org.getUsername() as string;

// still here? we need to deploy a zip file then
const deploy = new MetadataApiDeploy({
Expand Down Expand Up @@ -200,7 +200,7 @@ export class Deploy extends DeployCommand {
this.log(deployMessages.getMessage('apiVersionMsgBasic', [username, apiData.apiVersion, apiData.webService]));
});
await deploy.start();
this.asyncDeployResult = { id: deploy.id };
this.asyncDeployResult = deploy.id ? { id: deploy.id } : undefined;
this.updateDeployId(deploy.id);

if (!this.isAsync) {
Expand Down Expand Up @@ -237,7 +237,7 @@ export class Deploy extends DeployCommand {
? new MdDeployAsyncResultFormatter(
new Ux({ jsonEnabled: this.jsonEnabled() }),
formatterOptions,
this.asyncDeployResult
this.asyncDeployResult as AsyncResult
)
: new MdDeployResultFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }), formatterOptions, this.deployResult);

Expand Down
4 changes: 2 additions & 2 deletions src/commands/force/mdapi/deploy/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export class Cancel extends DeployCommand {
summary: messages.getMessage('flags.jobid.summary'),
}),
};
private flags: Interfaces.InferredFlags<typeof Cancel.flags>;
private conn: Connection;
private flags!: Interfaces.InferredFlags<typeof Cancel.flags>;
private conn!: Connection;

public async run(): Promise<DeployCancelCommandResult> {
this.flags = (await this.parse(Cancel)).flags;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/force/mdapi/deploy/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export class Report extends DeployCommand {
junit: Flags.boolean({ summary: messages.getMessage('flags.junit.summary') }),
};

private flags: Interfaces.InferredFlags<typeof Report.flags>;
private org: Org;
private flags!: Interfaces.InferredFlags<typeof Report.flags>;
private org!: Org;

public async run(): Promise<MdDeployResult> {
this.flags = (await this.parse(Report)).flags;
Expand Down
47 changes: 26 additions & 21 deletions src/commands/force/mdapi/retrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ export class Retrieve extends SourceCommand {
}),
};

protected retrieveResult: RetrieveResult;
private sourceDir: string;
private retrieveTargetDir: string;
private zipFileName: string;
private unzip: boolean;
private wait: Duration;
private isAsync: boolean;
private mdapiRetrieve: MetadataApiRetrieve;
private flags: Interfaces.InferredFlags<typeof Retrieve.flags>;
private org: Org;
protected retrieveResult: RetrieveResult | undefined;
private sourceDir: string | undefined;
private retrieveTargetDir: string | undefined;
private zipFileName: string | undefined;
private unzip: boolean | undefined;
private wait: Duration | undefined;
private isAsync: boolean | undefined;
private mdapiRetrieve: MetadataApiRetrieve | undefined;
private flags!: Interfaces.InferredFlags<typeof Retrieve.flags>;
private org!: Org | undefined;
public async run(): Promise<RetrieveCommandCombinedResult> {
this.flags = (await this.parse(Retrieve)).flags;
this.org = this.flags['target-org'];
Expand All @@ -138,7 +138,7 @@ export class Retrieve extends SourceCommand {
throw new SfError(messages.getMessage('InvalidPackageNames', [packagenames.toString()]), 'InvalidPackageNames');
}

this.spinner.start(spinnerMessages.getMessage('retrieve.main', [this.org.getUsername()]));
this.spinner.start(spinnerMessages.getMessage('retrieve.main', [this.org?.getUsername()]));
this.spinner.status = spinnerMessages.getMessage('retrieve.componentSetBuild');

this.componentSet = await ComponentSetBuilder.build({
Expand All @@ -148,14 +148,16 @@ export class Retrieve extends SourceCommand {
apiversion: this.flags.apiversion,
packagenames,
sourcepath: this.sourceDir ? [this.sourceDir] : undefined,
manifest: manifest && {
manifestPath: manifest,
directoryPaths: [],
},
manifest: manifest
? {
manifestPath: manifest,
directoryPaths: [],
}
: undefined,
});

await Lifecycle.getInstance().emit('preretrieve', { packageXmlPath: manifest });
const username = this.org.getUsername();
const username = this.org?.getUsername() ?? '';
// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('apiVersionRetrieve', async (apiData: RetrieveVersionData) => {
this.log(
Expand All @@ -180,7 +182,7 @@ export class Retrieve extends SourceCommand {
});

Stash.set('MDAPI_RETRIEVE', {
jobid: this.mdapiRetrieve.id,
jobid: this.mdapiRetrieve.id ?? '',
retrievetargetdir: this.retrieveTargetDir,
zipfilename: this.zipFileName,
unzip: this.unzip,
Expand Down Expand Up @@ -210,14 +212,14 @@ export class Retrieve extends SourceCommand {
[RequestStatus.Canceling, 69],
]);
if (!this.isAsync) {
this.setExitCode(StatusCodeMap.get(this.retrieveResult.response.status) ?? 1);
this.setExitCode(StatusCodeMap.get(this.retrieveResult?.response.status as RequestStatus) ?? 1);
}
}

protected formatResult(): RetrieveCommandResult | RetrieveCommandAsyncResult {
// async result
if (this.isAsync) {
let cmdFlags = `--jobid ${this.mdapiRetrieve.id} --retrievetargetdir ${this.retrieveTargetDir}`;
let cmdFlags = `--jobid ${this.mdapiRetrieve?.id} --retrievetargetdir ${this.retrieveTargetDir}`;
const targetusernameFlag = this.flags['target-org'];
if (targetusernameFlag) {
cmdFlags += ` --targetusername ${targetusernameFlag.getUsername()}`;
Expand All @@ -226,21 +228,23 @@ export class Retrieve extends SourceCommand {
this.log(messages.getMessage('checkStatus', [cmdFlags]));
return {
done: false,
id: this.mdapiRetrieve.id,
id: this.mdapiRetrieve?.id ?? '',
state: 'Queued',
status: 'Queued',
timedOut: true,
};
} else {
const formatterOptions = {
waitTime: this.wait.quantity,
waitTime: this.wait?.quantity ?? '',
verbose: this.flags.verbose ?? false,
retrieveTargetDir: this.retrieveTargetDir,
zipFileName: this.zipFileName,
unzip: this.unzip,
};
const formatter = new RetrieveResultFormatter(
new Ux({ jsonEnabled: this.jsonEnabled() }),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
formatterOptions,
this.retrieveResult
);
Expand All @@ -258,6 +262,7 @@ export class Retrieve extends SourceCommand {
} catch (error) {
this.debug('No SFDX project found for default package directory');
}
return '';
}

private resolveRootDir(rootDir?: string): string {
Expand Down
26 changes: 13 additions & 13 deletions src/commands/force/mdapi/retrieve/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ export class Report extends SourceCommand {
}),
};

protected retrieveResult: RetrieveResult;
protected retrieveStatus: MetadataApiRetrieveStatus;
private retrieveTargetDir: string;
private zipFileName: string;
private unzip: boolean;
private wait: Duration;
private isAsync: boolean;
private mdapiRetrieve: MetadataApiRetrieve;
private flags: Interfaces.InferredFlags<typeof Report.flags>;
private org: Org;
protected retrieveResult!: RetrieveResult;
protected retrieveStatus!: MetadataApiRetrieveStatus;
private retrieveTargetDir!: string;
private zipFileName!: string;
private unzip: boolean | undefined;
private wait!: Duration;
private isAsync!: boolean;
private mdapiRetrieve!: MetadataApiRetrieve;
private flags!: Interfaces.InferredFlags<typeof Report.flags>;
private org!: Org;

public async run(): Promise<ReportCommandResult> {
this.flags = (await this.parse(Report)).flags;
Expand All @@ -104,7 +104,7 @@ export class Report extends SourceCommand {
retrieveId = mdRetrieveStash.jobid;
this.retrieveTargetDir = this.resolveOutputDir(mdRetrieveStash?.retrievetargetdir);
this.zipFileName = resolveZipFileName(mdRetrieveStash?.zipfilename);
this.unzip = mdRetrieveStash?.unzip;
this.unzip = mdRetrieveStash.unzip;
} else {
this.retrieveTargetDir = this.resolveOutputDir(this.flags.retrievetargetdir);
this.zipFileName = resolveZipFileName(this.flags.zipfilename);
Expand All @@ -120,7 +120,7 @@ export class Report extends SourceCommand {

this.mdapiRetrieve = new MetadataApiRetrieve({
id: retrieveId,
usernameOrConnection: this.org.getUsername(),
usernameOrConnection: this.org.getUsername() as string,
output: this.retrieveTargetDir,
format: 'metadata',
zipFileName: this.zipFileName,
Expand Down Expand Up @@ -181,7 +181,7 @@ export class Report extends SourceCommand {
return formatter.getJson();
}

private resolveOutputDir(dirPath: string): string {
private resolveOutputDir(dirPath?: string): string {
return this.ensureFlagPath({
flagName: 'retrievetargetdir',
path: dirPath,
Expand Down
33 changes: 20 additions & 13 deletions src/commands/force/source/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { dirname } from 'node:path';
import { Lifecycle, Messages, Org } from '@salesforce/core';
import { Duration, env } from '@salesforce/kit';
import { SourceTracking } from '@salesforce/source-tracking';
import { ComponentSetBuilder, DeployVersionData } from '@salesforce/source-deploy-retrieve';
import { AsyncResult, ComponentSetBuilder, DeployVersionData } from '@salesforce/source-deploy-retrieve';
import {
arrayWithDeprecation,
Flags,
Expand Down Expand Up @@ -163,9 +163,11 @@ export class Deploy extends DeployCommand {
junit: Flags.boolean({ summary: messages.getMessage('flags.junit.summary') }),
};
protected readonly lifecycleEventNames = ['predeploy', 'postdeploy'];
protected tracking: SourceTracking;
protected tracking!: SourceTracking;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
private flags: Interfaces.InferredFlags<typeof Deploy.flags>;
private org: Org;
private org!: Org;
public async run(): Promise<DeployCommandCombinedResult> {
this.flags = (await this.parse(Deploy)).flags;
this.org = await Org.create({ aliasOrUsername: this.flags['target-org'] });
Expand All @@ -192,6 +194,7 @@ export class Deploy extends DeployCommand {
// 1. synchronous - deploy metadata and wait for the deploy to complete.
// 2. asynchronous - deploy metadata and immediately return.
// 3. recent validation - deploy metadata that's already been validated by the org
// eslint-disable-next-line complexity
protected async deploy(): Promise<void> {
const waitDuration = this.flags.wait;
this.isAsync = waitDuration.quantity === 0;
Expand All @@ -211,12 +214,14 @@ export class Deploy extends DeployCommand {
apiversion: this.flags['api-version'],
sourceapiversion: await this.getSourceApiVersion(),
sourcepath: this.flags.sourcepath,
manifest: this.flags.manifest && {
manifestPath: this.flags.manifest,
directoryPaths: this.getPackageDirs(),
destructiveChangesPre: this.flags.predestructivechanges,
destructiveChangesPost: this.flags.postdestructivechanges,
},
manifest: this.flags.manifest
? {
manifestPath: this.flags.manifest,
directoryPaths: this.getPackageDirs(),
destructiveChangesPre: this.flags.predestructivechanges,
destructiveChangesPost: this.flags.postdestructivechanges,
}
: undefined,
metadata: this.flags.metadata && {
metadataEntries: this.flags.metadata,
directoryPaths: this.getPackageDirs(),
Expand All @@ -242,7 +247,7 @@ export class Deploy extends DeployCommand {
}
// fire predeploy event for sync and async deploys
await Lifecycle.getInstance().emit('predeploy', this.componentSet.toArray());
const username = this.org.getUsername();
const username = this.org.getUsername() ?? '';
// eslint-disable-next-line @typescript-eslint/require-await
Lifecycle.getInstance().on('apiVersionDeploy', async (apiData: DeployVersionData) => {
this.log(
Expand Down Expand Up @@ -273,8 +278,10 @@ export class Deploy extends DeployCommand {
...(this.flags.runtests ? { runTests: this.flags.runtests } : {}),
},
});
this.asyncDeployResult = { id: deploy.id };
this.updateDeployId(deploy.id);
const id = deploy.id ?? '';

this.asyncDeployResult = { id };
this.updateDeployId(id);

if (!this.isAsync) {
// we're not print JSON output
Expand Down Expand Up @@ -318,7 +325,7 @@ export class Deploy extends DeployCommand {
? new DeployAsyncResultFormatter(
new Ux({ jsonEnabled: this.jsonEnabled() }),
formatterOptions,
this.asyncDeployResult
this.asyncDeployResult as AsyncResult
)
: new DeployResultFormatter(new Ux({ jsonEnabled: this.jsonEnabled() }), formatterOptions, this.deployResult);

Expand Down
4 changes: 3 additions & 1 deletion src/commands/force/source/deploy/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export class Cancel extends DeployCommand {
}),
};

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
private flags: Interfaces.InferredFlags<typeof Cancel.flags>;

public async run(): Promise<DeployCancelCommandResult> {
Expand All @@ -79,7 +81,7 @@ export class Cancel extends DeployCommand {
}

protected resolveSuccess(): void {
const status = this.deployResult.response.status;
const status = this.deployResult?.response.status;
if (status !== RequestStatus.Canceled) {
this.setExitCode(1);
}
Expand Down
4 changes: 3 additions & 1 deletion src/commands/force/source/deploy/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class Report extends DeployCommand {
}),
junit: Flags.boolean({ summary: messages.getMessage('flags.junit.summary') }),
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
private flags: Interfaces.InferredFlags<typeof Report.flags>;

public async run(): Promise<DeployReportCommandResult> {
Expand Down Expand Up @@ -102,10 +104,10 @@ export class Report extends DeployCommand {
try {
this.project = await SfProject.resolve();
sourcepath = this.project.getUniquePackageDirectories().map((pDir) => pDir.fullPath);
this.componentSet = await ComponentSetBuilder.build({ sourcepath });
} catch (err) {
// ignore the error. this was just to get improved command output.
}
this.componentSet = await ComponentSetBuilder.build({ sourcepath });
}

const waitDuration = this.flags.wait;
Expand Down
Loading

0 comments on commit 002af63

Please sign in to comment.