Skip to content

Commit 376543e

Browse files
authored
Sh/cmd output (#71)
* feat: changes deploy output to more closely match too Temporarily renames the deploy and retrieve commands for testing command output side by side with toolbelt. Introduces output formatters for commands to implement. * refactor: revert temporary renaming for testing * refactor: add an abstract DeployCommand * refactor: standardizing all source commands and output * feat: test updates for code rearrangement * refactor: move createComponentSet to ComponentSetBuilder.build moves the createComponentSet method on SourceCommand to its own class with a static build method since not all source commands need to build a component set. * refactor: move getPackageDir() to SourceCommand * fix: update testkit dep update testkit dep and remove apiversion override
1 parent cbbda7c commit 376543e

31 files changed

+2101
-1032
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ All notable changes to this project will be documented in this file. See [standa
1111

1212
### [0.0.10](https://github.com/salesforcecli/plugin-source/compare/v0.0.9...v0.0.10) (2021-04-23)
1313

14-
1514
### Bug Fixes
1615

17-
* new hooks, updated tests ([#69](https://github.com/salesforcecli/plugin-source/issues/69)) ([81e1058](https://github.com/salesforcecli/plugin-source/commit/81e10581456ceccb4b3e07f3d1310bb18bef25ff))
16+
- new hooks, updated tests ([#69](https://github.com/salesforcecli/plugin-source/issues/69)) ([81e1058](https://github.com/salesforcecli/plugin-source/commit/81e10581456ceccb4b3e07f3d1310bb18bef25ff))
1817

1918
### [0.0.9](https://github.com/salesforcecli/plugin-source/compare/v0.0.8...v0.0.9) (2021-04-13)
2019

command-snapshot.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"packagenames",
6060
"sourcepath",
6161
"targetusername",
62+
"verbose",
6263
"wait"
6364
]
6465
}

messages/deploy.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"$ sfdx force:source:deploy -x path/to/package.xml",
1212
"$ sfdx force:source:deploy -m ApexClass -l RunLocalTests",
1313
"$ sfdx force:source:deploy -m ApexClass -l RunAllTestsInOrg -c",
14-
"$ sfdx force:source:deploy -q 0Af9A00000FTM6pSAH`"
14+
"$ sfdx force:source:deploy -q 0Af9A00000FTM6pSAH"
1515
],
1616
"flags": {
1717
"sourcePath": "comma-separated list of source file paths to deploy",
@@ -24,8 +24,9 @@
2424
"runTests": "tests to run if --testlevel RunSpecifiedTests",
2525
"ignoreErrors": "ignore any errors and do not roll back deployment",
2626
"ignoreWarnings": "whether a warning will allow a deployment to complete successfully",
27-
"validateDeployRequestId": "request ID of the validated deployment to run a Quick Deploy",
27+
"validateDeployRequestId": "deploy request ID of the validated deployment to run a Quick Deploy",
2828
"soapDeploy": "deploy metadata with SOAP API instead of REST API"
2929
},
30-
"checkOnlySuccess": "\nSuccessfully validated the deployment"
30+
"checkOnlySuccess": "Successfully validated the deployment. %s components deployed and %s tests run.\nUse the --verbose parameter to see detailed output.",
31+
"MissingDeployId": "No deploy ID was provided or found in deploy history"
3132
}

messages/retrieve.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
],
1515
"flags": {
1616
"sourcePath": "comma-separated list of source file paths to retrieve",
17-
"manifestParamDescription": "file path for manifest (package.xml) of components to retrieve",
18-
"metadataParamDescription": "comma-separated list of metadata component names",
1917
"wait": "wait time for command to finish in minutes",
2018
"manifest": "file path for manifest (package.xml) of components to retrieve",
2119
"metadata": "comma-separated list of metadata component names",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"devDependencies": {
1717
"@oclif/dev-cli": "^1",
1818
"@oclif/plugin-command-snapshot": "^2.0.0",
19-
"@salesforce/cli-plugins-testkit": "^0.0.15",
19+
"@salesforce/cli-plugins-testkit": "^0.0.27",
2020
"@salesforce/dev-config": "^2.1.0",
2121
"@salesforce/dev-scripts": "^0.9.1",
2222
"@salesforce/plugin-apex": "^0.1.18",

src/commands/force/source/convert.ts

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,17 @@
66
*/
77

88
import * as os from 'os';
9-
import { resolve } from 'path';
109
import { flags, FlagsConfig } from '@salesforce/command';
1110
import { Messages } from '@salesforce/core';
12-
import { MetadataConverter } from '@salesforce/source-deploy-retrieve';
13-
import { asArray, asString } from '@salesforce/ts-types';
11+
import { MetadataConverter, ConvertResult } from '@salesforce/source-deploy-retrieve';
12+
import { getString } from '@salesforce/ts-types';
1413
import { SourceCommand } from '../../../sourceCommand';
14+
import { ConvertResultFormatter, ConvertCommandResult } from '../../../formatters/convertResultFormatter';
15+
import { ComponentSetBuilder } from '../../../componentSetBuilder';
1516

1617
Messages.importMessagesDirectory(__dirname);
1718
const messages = Messages.loadMessages('@salesforce/plugin-source', 'convert');
1819

19-
type ConvertResult = {
20-
location: string;
21-
};
22-
2320
export class Convert extends SourceCommand {
2421
public static readonly description = messages.getMessage('description');
2522
public static readonly examples = messages.getMessage('examples').split(os.EOL);
@@ -55,42 +52,67 @@ export class Convert extends SourceCommand {
5552
}),
5653
};
5754

58-
public async run(): Promise<ConvertResult> {
55+
protected convertResult: ConvertResult;
56+
57+
public async run(): Promise<ConvertCommandResult> {
58+
await this.convert();
59+
this.resolveSuccess();
60+
return this.formatResult();
61+
}
62+
63+
protected async convert(): Promise<void> {
5964
const paths: string[] = [];
6065

61-
if (this.flags.sourcepath) {
62-
paths.push(...this.flags.sourcepath);
66+
const { sourcepath, metadata, manifest, rootdir } = this.flags;
67+
68+
if (sourcepath) {
69+
paths.push(...sourcepath);
6370
}
6471

6572
// rootdir behaves exclusively to sourcepath, metadata, and manifest... to maintain backwards compatibility
6673
// we will check here, instead of adding the exclusive option to the flag definition so we don't break scripts
67-
if (this.flags.rootdir && !this.flags.sourcepath && !this.flags.metadata && !this.flags.manifest) {
74+
if (rootdir && !sourcepath && !metadata && !manifest) {
6875
// only rootdir option passed
69-
paths.push(this.flags.rootdir);
76+
paths.push(rootdir);
7077
}
7178

7279
// no options passed, convert the default package (usually force-app)
73-
if (!this.flags.sourcepath && !this.flags.metadata && !this.flags.manifest && !this.flags.rootdir) {
80+
if (!sourcepath && !metadata && !manifest && !rootdir) {
7481
paths.push(this.project.getDefaultPackage().path);
7582
}
7683

77-
const cs = await this.createComponentSet({
84+
const cs = await ComponentSetBuilder.build({
7885
sourcepath: paths,
79-
manifest: asString(this.flags.manifest),
80-
metadata: asArray<string>(this.flags.metadata),
86+
manifest: manifest && {
87+
manifestPath: this.getFlag<string>('manifest'),
88+
directoryPaths: this.getPackageDirs(),
89+
},
90+
metadata: metadata && {
91+
metadataEntries: this.getFlag<string[]>('metadata'),
92+
directoryPaths: this.getPackageDirs(),
93+
},
8194
});
8295

8396
const converter = new MetadataConverter();
84-
const res = await converter.convert(cs.getSourceComponents().toArray(), 'metadata', {
97+
this.convertResult = await converter.convert(cs.getSourceComponents().toArray(), 'metadata', {
8598
type: 'directory',
86-
outputDirectory: asString(this.flags.outputdir),
87-
packageName: asString(this.flags.packagename),
99+
outputDirectory: this.getFlag<string>('outputdir'),
100+
packageName: this.getFlag<string>('packagename'),
88101
});
102+
}
89103

90-
this.ux.log(messages.getMessage('success', [res.packagePath]));
104+
protected resolveSuccess(): void {
105+
if (!getString(this.convertResult, 'packagePath')) {
106+
this.setExitCode(1);
107+
}
108+
}
91109

92-
return {
93-
location: resolve(res.packagePath),
94-
};
110+
protected formatResult(): ConvertCommandResult {
111+
const formatter = new ConvertResultFormatter(this.logger, this.ux, this.convertResult);
112+
113+
if (!this.isJsonOutput()) {
114+
formatter.display();
115+
}
116+
return formatter.getJson();
95117
}
96118
}

0 commit comments

Comments
 (0)