Skip to content

Commit b1d8b82

Browse files
fix: remove packagename, change some types
1 parent 70876e3 commit b1d8b82

File tree

5 files changed

+101
-124
lines changed

5 files changed

+101
-124
lines changed

messages/deploy.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
2-
"description": "retrieve source from an org",
2+
"description": "deploy source to an org",
33
"examples": [
4-
"sfdx force:source:retrieve -p path/to/source",
5-
"sfdx force:source:retrieve -p \"path/to/apex/classes/MyClass.cls,path/to/source/objects\"",
6-
"sfdx force:source:retrieve -p \"path/to/objects/MyCustomObject/fields/MyField.field-meta.xml, path/to/apex/classes\"",
7-
"sfdx force:source:retrieve -m ApexClass",
8-
"sfdx force:source:retrieve -m ApexClass:MyApexClass",
9-
"sfdx force:source:retrieve -m \"CustomObject,ApexClass\"",
10-
"sfdx force:source:retrieve -x path/to/package.xml",
11-
"sfdx force:source:retrieve -n \"Package1, PackageName With Spaces, Package3\"",
12-
"sfdx force:source:retrieve -n MyPackageName -p path/to/apex/classes",
13-
"sfdx force:source:retrieve -n MyPackageName -x path/to/package.xml"
4+
"$ sfdx force:source:deploy -p path/to/source",
5+
"$ sfdx force:source:deploy -p \"path/to/apex/classes/MyClass.cls,path/to/source/objects\"",
6+
"$ sfdx force:source:deploy -p \"path/to/objects/MyCustomObject/fields/MyField.field-meta.xml, path/to/apex/classes\"",
7+
"$ sfdx force:source:deploy -m ApexClass",
8+
"$ sfdx force:source:deploy -m ApexClass:MyApexClass",
9+
"$ sfdx force:source:deploy -m \"CustomObject,ApexClass\"",
10+
"$ sfdx force:source:deploy -m \"ApexClass, Profile:My Profile, Profile: AnotherProfile\"",
11+
"$ sfdx force:source:deploy -x path/to/package.xml",
12+
"$ sfdx force:source:deploy -m ApexClass -l RunLocalTests",
13+
"$ sfdx force:source:deploy -m ApexClass -l RunAllTestsInOrg -c",
14+
"$ sfdx force:source:deploy -q 0Af9A00000FTM6pSAH`"
1415
],
1516
"flags": {
1617
"sourcePath": "comma-separated list of source file paths to retrieve",

src/commands/force/source/deploy.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ export class deploy extends SourceCommand {
9797
const hookEmitter = Lifecycle.getInstance();
9898

9999
const cs = await this.createComponentSet({
100-
// safe to cast from the flags as an array of strings
101-
packagenames: this.flags.packagenames as string[],
102100
sourcepath: this.flags.sourcepath as string[],
103101
manifest: asString(this.flags.manifest),
104102
metadata: this.flags.metadata as string[],
@@ -166,7 +164,7 @@ export class deploy extends SourceCommand {
166164
// get relative path for table output
167165
files.forEach((file) => {
168166
if (file.component.content) {
169-
return (file.component.content = path.relative(process.cwd(), file.component.content));
167+
file.component.content = path.relative(process.cwd(), file.component.content);
170168
}
171169
});
172170
this.ux.log('');

src/commands/force/source/retrieve.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import * as os from 'os';
88
import * as path from 'path';
99
import { flags, FlagsConfig } from '@salesforce/command';
10-
import { Lifecycle, Messages, SfdxError } from '@salesforce/core';
10+
import { Lifecycle, Messages, SfdxError, SfdxProjectJson } from '@salesforce/core';
1111
import { SourceRetrieveResult } from '@salesforce/source-deploy-retrieve';
1212
import { Duration } from '@salesforce/kit';
1313
import { asString } from '@salesforce/ts-types';
@@ -53,7 +53,9 @@ export class retrieve extends SourceCommand {
5353

5454
public async run(): Promise<SourceRetrieveResult> {
5555
const hookEmitter = Lifecycle.getInstance();
56-
const packages = await this.retrievePackageDirs();
56+
57+
const proj = await SfdxProjectJson.create({});
58+
const packages = await proj.getPackageDirectories();
5759
const defaultPackage = packages.find((pkg) => pkg.default);
5860

5961
const cs = await this.createComponentSet({
@@ -72,6 +74,8 @@ export class retrieve extends SourceCommand {
7274
merge: true,
7375
// TODO: fix this once wait has been updated in library
7476
wait: 1000000,
77+
// TODO: implement retrieve via package name
78+
// package: options.packagenames
7579
});
7680

7781
await hookEmitter.emit('postretrieve', results);

src/sourceCommand.ts

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,104 +7,78 @@
77
import * as path from 'path';
88
import { SfdxCommand } from '@salesforce/command';
99
import { ComponentSet } from '@salesforce/source-deploy-retrieve';
10-
import { fs, PackageDir, SfdxError, SfdxProjectJson } from '@salesforce/core';
10+
import { fs, SfdxError } from '@salesforce/core';
1111
import { ComponentLike } from '@salesforce/source-deploy-retrieve/lib/src/common';
1212

1313
export type FlagOptions = {
1414
packagenames?: string[];
15-
sourcepath?: string[];
16-
manifest?: string;
17-
metadata?: string[];
15+
sourcepath: string[];
16+
manifest: string;
17+
metadata: string[];
1818
};
1919

2020
export const MINIMUM_SRC_WAIT_MINUTES = 1;
2121
export const DEFAULT_SRC_WAIT_MINUTES = 33;
2222

2323
export abstract class SourceCommand extends SfdxCommand {
24-
public async retrievePackageDirs(): Promise<PackageDir[]> {
25-
const proj = await SfdxProjectJson.create({});
26-
return proj.getPackageDirectories();
27-
}
28-
2924
/**
3025
* will create one ComponentSet to be deployed/retrieved
3126
* will combine from all options passed in
3227
*
3328
* @param options: FlagOptions where to create ComponentSets from
3429
*/
35-
public async createComponentSet(options: FlagOptions): Promise<ComponentSet> {
36-
const setAggregator: ComponentSet[] = [];
37-
const pkgs = await this.retrievePackageDirs();
30+
protected async createComponentSet(options: FlagOptions): Promise<ComponentSet> {
31+
const setAggregator: ComponentLike[] = [];
32+
3833
// go through options to create a list of ComponentSets
3934
// we'll then combine all of those to deploy/retrieve
4035
if (options.sourcepath) {
4136
options.sourcepath.forEach((filepath) => {
4237
if (fs.fileExistsSync(filepath)) {
4338
this.logger.debug(`Creating ComponentSet from sourcepath ${path.resolve(filepath)}`);
44-
setAggregator.push(ComponentSet.fromSource(path.resolve(filepath)));
39+
setAggregator.push(...ComponentSet.fromSource(path.resolve(filepath)));
4540
} else {
4641
throw SfdxError.create('@salesforce/plugin-source', 'sourceCommand', 'SourcePathInvalid', [filepath]);
4742
}
4843
});
4944
}
5045

5146
if (options.packagenames) {
52-
// filter from all the packages to the ones requested
53-
// will be package name, could include spaces
54-
pkgs
55-
.filter((pkg) => {
56-
return options.packagenames.includes(pkg.path);
57-
})
58-
// for the requested ones get the ComponentSet from their path
59-
.forEach((pkg) => {
60-
this.logger.debug(`Creating ComponentSet from source with ${path.resolve(pkg.path)}`);
61-
setAggregator.push(ComponentSet.fromSource(path.resolve(pkg.path)));
62-
});
47+
// retrieve only
48+
// TODO: @W-8908888@
6349
}
6450

6551
if (options.manifest) {
6652
this.logger.debug(`Creating ComponentSet from manifest ${path.resolve(options.manifest)}`);
6753

6854
setAggregator.push(
69-
await ComponentSet.fromManifestFile(options.manifest, {
55+
...(await ComponentSet.fromManifestFile(options.manifest, {
7056
// to create a link to the actual source component we need to have it resolve through all packages
7157
// to find the matching source metadata
7258
// this allows us to deploy after
73-
resolve: pkgs.map((pkg) => path.resolve(pkg.path)),
74-
})
59+
resolve: process.cwd(),
60+
}))
7561
);
7662
}
7763

7864
if (options.metadata) {
7965
options.metadata.forEach((entry) => {
8066
const splitEntry = entry.split(':');
81-
const metadata: ComponentLike = { fullName: undefined, type: undefined };
82-
if (splitEntry.length === 1) {
83-
// -m ApexClass
84-
metadata.type = splitEntry[0];
85-
metadata.fullName = '*';
86-
} else {
87-
// -m ApexClass:MyApexClass
88-
metadata.type = splitEntry[0];
89-
metadata.fullName = splitEntry[1];
90-
}
67+
const metadata: ComponentLike = {
68+
type: splitEntry[0],
69+
// either -m ApexClass or -m ApexClass:MyApexClass
70+
fullName: splitEntry.length === 1 ? '*' : splitEntry[1],
71+
};
9172
this.logger.debug(`Creating ComponentSet from metadata member ${metadata.type}:${metadata.fullName}`);
9273

9374
const cs = new ComponentSet([metadata]);
9475
// we need to search the entire project for the matching metadata component
9576
// no better way than to have it search than process.cwd()
9677
cs.resolveSourceComponents(process.cwd(), { filter: cs });
97-
setAggregator.push(cs);
78+
setAggregator.push(...cs);
9879
});
9980
}
10081

101-
// join the ComponentSets in the aggregator into one
102-
// combining ComponentLike objects from across packages to do a single deploy/retrieve call
103-
const merged: ComponentLike[] = [];
104-
setAggregator.forEach((set) => {
105-
merged.push(...set);
106-
});
107-
108-
return new ComponentSet(merged);
82+
return new ComponentSet(setAggregator);
10983
}
11084
}

0 commit comments

Comments
 (0)