Skip to content

Commit

Permalink
fix: remove packagename, change some types
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Feb 18, 2021
1 parent 70876e3 commit b1d8b82
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 124 deletions.
23 changes: 12 additions & 11 deletions messages/deploy.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"description": "retrieve source from an org",
"description": "deploy source to an org",
"examples": [
"sfdx force:source:retrieve -p path/to/source",
"sfdx force:source:retrieve -p \"path/to/apex/classes/MyClass.cls,path/to/source/objects\"",
"sfdx force:source:retrieve -p \"path/to/objects/MyCustomObject/fields/MyField.field-meta.xml, path/to/apex/classes\"",
"sfdx force:source:retrieve -m ApexClass",
"sfdx force:source:retrieve -m ApexClass:MyApexClass",
"sfdx force:source:retrieve -m \"CustomObject,ApexClass\"",
"sfdx force:source:retrieve -x path/to/package.xml",
"sfdx force:source:retrieve -n \"Package1, PackageName With Spaces, Package3\"",
"sfdx force:source:retrieve -n MyPackageName -p path/to/apex/classes",
"sfdx force:source:retrieve -n MyPackageName -x path/to/package.xml"
"$ sfdx force:source:deploy -p path/to/source",
"$ sfdx force:source:deploy -p \"path/to/apex/classes/MyClass.cls,path/to/source/objects\"",
"$ sfdx force:source:deploy -p \"path/to/objects/MyCustomObject/fields/MyField.field-meta.xml, path/to/apex/classes\"",
"$ sfdx force:source:deploy -m ApexClass",
"$ sfdx force:source:deploy -m ApexClass:MyApexClass",
"$ sfdx force:source:deploy -m \"CustomObject,ApexClass\"",
"$ sfdx force:source:deploy -m \"ApexClass, Profile:My Profile, Profile: AnotherProfile\"",
"$ sfdx force:source:deploy -x path/to/package.xml",
"$ sfdx force:source:deploy -m ApexClass -l RunLocalTests",
"$ sfdx force:source:deploy -m ApexClass -l RunAllTestsInOrg -c",
"$ sfdx force:source:deploy -q 0Af9A00000FTM6pSAH`"
],
"flags": {
"sourcePath": "comma-separated list of source file paths to retrieve",
Expand Down
4 changes: 1 addition & 3 deletions src/commands/force/source/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ export class deploy extends SourceCommand {
const hookEmitter = Lifecycle.getInstance();

const cs = await this.createComponentSet({
// safe to cast from the flags as an array of strings
packagenames: this.flags.packagenames as string[],
sourcepath: this.flags.sourcepath as string[],
manifest: asString(this.flags.manifest),
metadata: this.flags.metadata as string[],
Expand Down Expand Up @@ -166,7 +164,7 @@ export class deploy extends SourceCommand {
// get relative path for table output
files.forEach((file) => {
if (file.component.content) {
return (file.component.content = path.relative(process.cwd(), file.component.content));
file.component.content = path.relative(process.cwd(), file.component.content);
}
});
this.ux.log('');
Expand Down
8 changes: 6 additions & 2 deletions src/commands/force/source/retrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import * as os from 'os';
import * as path from 'path';
import { flags, FlagsConfig } from '@salesforce/command';
import { Lifecycle, Messages, SfdxError } from '@salesforce/core';
import { Lifecycle, Messages, SfdxError, SfdxProjectJson } from '@salesforce/core';
import { SourceRetrieveResult } from '@salesforce/source-deploy-retrieve';
import { Duration } from '@salesforce/kit';
import { asString } from '@salesforce/ts-types';
Expand Down Expand Up @@ -53,7 +53,9 @@ export class retrieve extends SourceCommand {

public async run(): Promise<SourceRetrieveResult> {
const hookEmitter = Lifecycle.getInstance();
const packages = await this.retrievePackageDirs();

const proj = await SfdxProjectJson.create({});
const packages = await proj.getPackageDirectories();
const defaultPackage = packages.find((pkg) => pkg.default);

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

await hookEmitter.emit('postretrieve', results);
Expand Down
66 changes: 20 additions & 46 deletions src/sourceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,104 +7,78 @@
import * as path from 'path';
import { SfdxCommand } from '@salesforce/command';
import { ComponentSet } from '@salesforce/source-deploy-retrieve';
import { fs, PackageDir, SfdxError, SfdxProjectJson } from '@salesforce/core';
import { fs, SfdxError } from '@salesforce/core';
import { ComponentLike } from '@salesforce/source-deploy-retrieve/lib/src/common';

export type FlagOptions = {
packagenames?: string[];
sourcepath?: string[];
manifest?: string;
metadata?: string[];
sourcepath: string[];
manifest: string;
metadata: string[];
};

export const MINIMUM_SRC_WAIT_MINUTES = 1;
export const DEFAULT_SRC_WAIT_MINUTES = 33;

export abstract class SourceCommand extends SfdxCommand {
public async retrievePackageDirs(): Promise<PackageDir[]> {
const proj = await SfdxProjectJson.create({});
return proj.getPackageDirectories();
}

/**
* will create one ComponentSet to be deployed/retrieved
* will combine from all options passed in
*
* @param options: FlagOptions where to create ComponentSets from
*/
public async createComponentSet(options: FlagOptions): Promise<ComponentSet> {
const setAggregator: ComponentSet[] = [];
const pkgs = await this.retrievePackageDirs();
protected async createComponentSet(options: FlagOptions): Promise<ComponentSet> {
const setAggregator: ComponentLike[] = [];

// go through options to create a list of ComponentSets
// we'll then combine all of those to deploy/retrieve
if (options.sourcepath) {
options.sourcepath.forEach((filepath) => {
if (fs.fileExistsSync(filepath)) {
this.logger.debug(`Creating ComponentSet from sourcepath ${path.resolve(filepath)}`);
setAggregator.push(ComponentSet.fromSource(path.resolve(filepath)));
setAggregator.push(...ComponentSet.fromSource(path.resolve(filepath)));
} else {
throw SfdxError.create('@salesforce/plugin-source', 'sourceCommand', 'SourcePathInvalid', [filepath]);
}
});
}

if (options.packagenames) {
// filter from all the packages to the ones requested
// will be package name, could include spaces
pkgs
.filter((pkg) => {
return options.packagenames.includes(pkg.path);
})
// for the requested ones get the ComponentSet from their path
.forEach((pkg) => {
this.logger.debug(`Creating ComponentSet from source with ${path.resolve(pkg.path)}`);
setAggregator.push(ComponentSet.fromSource(path.resolve(pkg.path)));
});
// retrieve only
// TODO: @W-8908888@
}

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

setAggregator.push(
await ComponentSet.fromManifestFile(options.manifest, {
...(await ComponentSet.fromManifestFile(options.manifest, {
// to create a link to the actual source component we need to have it resolve through all packages
// to find the matching source metadata
// this allows us to deploy after
resolve: pkgs.map((pkg) => path.resolve(pkg.path)),
})
resolve: process.cwd(),
}))
);
}

if (options.metadata) {
options.metadata.forEach((entry) => {
const splitEntry = entry.split(':');
const metadata: ComponentLike = { fullName: undefined, type: undefined };
if (splitEntry.length === 1) {
// -m ApexClass
metadata.type = splitEntry[0];
metadata.fullName = '*';
} else {
// -m ApexClass:MyApexClass
metadata.type = splitEntry[0];
metadata.fullName = splitEntry[1];
}
const metadata: ComponentLike = {
type: splitEntry[0],
// either -m ApexClass or -m ApexClass:MyApexClass
fullName: splitEntry.length === 1 ? '*' : splitEntry[1],
};
this.logger.debug(`Creating ComponentSet from metadata member ${metadata.type}:${metadata.fullName}`);

const cs = new ComponentSet([metadata]);
// we need to search the entire project for the matching metadata component
// no better way than to have it search than process.cwd()
cs.resolveSourceComponents(process.cwd(), { filter: cs });
setAggregator.push(cs);
setAggregator.push(...cs);
});
}

// join the ComponentSets in the aggregator into one
// combining ComponentLike objects from across packages to do a single deploy/retrieve call
const merged: ComponentLike[] = [];
setAggregator.forEach((set) => {
merged.push(...set);
});

return new ComponentSet(merged);
return new ComponentSet(setAggregator);
}
}
Loading

0 comments on commit b1d8b82

Please sign in to comment.