Skip to content

Commit

Permalink
feat: GA new tracking commands (#457)
Browse files Browse the repository at this point in the history
* fix: cli-ux table can't handle an undefined row

* feat: ga new tracking commands

* docs: tracking subtopic

* feat: aliases for moved commands

* chore: bump STL

Co-authored-by: Willie Ruemmele <[email protected]>
  • Loading branch information
mshanemc and WillieRuemmele authored Mar 23, 2022
1 parent a707396 commit eb54c09
Show file tree
Hide file tree
Showing 18 changed files with 158 additions and 181 deletions.
60 changes: 30 additions & 30 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,36 +97,6 @@
"flags": ["apiversion", "folder", "json", "loglevel", "metadatatype", "resultfile", "targetusername"],
"alias": []
},
{
"command": "force:source:beta:pull",
"plugin": "@salesforce/plugin-source",
"flags": ["apiversion", "forceoverwrite", "json", "loglevel", "targetusername", "wait"],
"alias": []
},
{
"command": "force:source:beta:push",
"plugin": "@salesforce/plugin-source",
"flags": ["apiversion", "forceoverwrite", "ignorewarnings", "json", "loglevel", "quiet", "targetusername", "wait"],
"alias": []
},
{
"command": "force:source:beta:status",
"plugin": "@salesforce/plugin-source",
"flags": ["apiversion", "concise", "json", "local", "loglevel", "remote", "targetusername"],
"alias": []
},
{
"command": "force:source:beta:tracking:clear",
"plugin": "@salesforce/plugin-source",
"flags": ["apiversion", "json", "loglevel", "noprompt", "targetusername"],
"alias": []
},
{
"command": "force:source:beta:tracking:reset",
"plugin": "@salesforce/plugin-source",
"flags": ["apiversion", "json", "loglevel", "noprompt", "revision", "targetusername"],
"alias": []
},
{
"command": "force:source:convert",
"plugin": "@salesforce/plugin-source",
Expand Down Expand Up @@ -222,6 +192,18 @@
"flags": ["apiversion", "json", "loglevel", "sourcefile", "targetusername", "urlonly"],
"alias": []
},
{
"command": "force:source:pull",
"plugin": "@salesforce/plugin-source",
"flags": ["apiversion", "forceoverwrite", "json", "loglevel", "targetusername", "wait"],
"alias": ["force:source:beta:pull"]
},
{
"command": "force:source:push",
"plugin": "@salesforce/plugin-source",
"flags": ["apiversion", "forceoverwrite", "ignorewarnings", "json", "loglevel", "quiet", "targetusername", "wait"],
"alias": ["force:source:beta:push"]
},
{
"command": "force:source:retrieve",
"plugin": "@salesforce/plugin-source",
Expand All @@ -240,5 +222,23 @@
"wait"
],
"alias": []
},
{
"command": "force:source:status",
"plugin": "@salesforce/plugin-source",
"flags": ["apiversion", "concise", "json", "local", "loglevel", "remote", "targetusername"],
"alias": ["force:source:beta:status"]
},
{
"command": "force:source:tracking:clear",
"plugin": "@salesforce/plugin-source",
"flags": ["apiversion", "json", "loglevel", "noprompt", "targetusername"],
"alias": ["force:source:beta:tracking:clear"]
},
{
"command": "force:source:tracking:reset",
"plugin": "@salesforce/plugin-source",
"flags": ["apiversion", "json", "loglevel", "noprompt", "revision", "targetusername"],
"alias": ["force:source:beta:tracking:reset"]
}
]
13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"main": "lib/index.js",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/config": "^1.18.2",
"@oclif/config": "^1.18.3",
"@oclif/plugin-help": "^3.3.1",
"@salesforce/command": "^4.2.2",
"@salesforce/core": "^2.35.0",
"@salesforce/source-deploy-retrieve": "^5.12.2",
"@salesforce/source-tracking": "^1.1.3",
"@salesforce/source-tracking": "^1.2.0",
"chalk": "^4.1.2",
"cli-ux": "^5.6.3",
"got": "^11.8.3",
Expand Down Expand Up @@ -114,13 +114,8 @@
"manifest": {
"description": "create a manifest to use in a deploy/retrieve"
},
"beta": {
"description": "new versions of source tracking commands",
"subtopics": {
"tracking": {
"description": "new versions of source tracking commands"
}
}
"tracking": {
"description": "reset and clear source tracking"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ import {
RetrieveResult,
SourceComponent,
} from '@salesforce/source-deploy-retrieve';
import { ChangeResult, replaceRenamedCommands, SourceTracking } from '@salesforce/source-tracking';
import { SourceCommand } from '../../../../sourceCommand';
import { PullResponse, PullResultFormatter } from '../../../../formatters/source/pullFormatter';
import { trackingSetup, updateTracking } from '../../../../trackingFunctions';
import { ChangeResult, SourceTracking } from '@salesforce/source-tracking';
import { SourceCommand } from '../../../sourceCommand';
import { PullResponse, PullResultFormatter } from '../../../formatters/source/pullFormatter';
import { trackingSetup, updateTracking } from '../../../trackingFunctions';

Messages.importMessagesDirectory(__dirname);
const messages: Messages = Messages.loadMessages('@salesforce/plugin-source', 'pull');

export default class Pull extends SourceCommand {
public static aliases = ['force:source:beta:pull'];
public static description = messages.getMessage('description');
public static help = messages.getMessage('help');
protected static readonly flagsConfig: FlagsConfig = {
Expand Down Expand Up @@ -65,7 +66,7 @@ export default class Pull extends SourceCommand {
protected async preChecks(): Promise<void> {
this.ux.startSpinner('Loading source tracking information');
this.tracking = await trackingSetup({
commandName: replaceRenamedCommands('force:source:pull'),
commandName: 'force:source:pull',
ignoreConflicts: this.getFlag<boolean>('forceoverwrite', false),
org: this.org,
project: this.project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ import { flags, FlagsConfig } from '@salesforce/command';
import { Duration, env } from '@salesforce/kit';
import { Messages } from '@salesforce/core';
import { DeployResult, RequestStatus } from '@salesforce/source-deploy-retrieve';
import { replaceRenamedCommands, SourceTracking } from '@salesforce/source-tracking';
import { SourceTracking } from '@salesforce/source-tracking';
import { getBoolean } from '@salesforce/ts-types';
import { DeployCommand, getVersionMessage } from '../../../../deployCommand';
import { PushResponse, PushResultFormatter } from '../../../../formatters/source/pushResultFormatter';
import { ProgressFormatter } from '../../../../formatters/progressFormatter';
import { DeployProgressBarFormatter } from '../../../../formatters/deployProgressBarFormatter';
import { DeployProgressStatusFormatter } from '../../../../formatters/deployProgressStatusFormatter';
import { trackingSetup, updateTracking } from '../../../../trackingFunctions';
import { DeployCommand, getVersionMessage } from '../../../deployCommand';
import { PushResponse, PushResultFormatter } from '../../../formatters/source/pushResultFormatter';
import { ProgressFormatter } from '../../../formatters/progressFormatter';
import { DeployProgressBarFormatter } from '../../../formatters/deployProgressBarFormatter';
import { DeployProgressStatusFormatter } from '../../../formatters/deployProgressStatusFormatter';
import { trackingSetup, updateTracking } from '../../../trackingFunctions';

Messages.importMessagesDirectory(__dirname);
const messages: Messages = Messages.loadMessages('@salesforce/plugin-source', 'push');

export default class Push extends DeployCommand {
public static aliases = ['force:source:beta:push'];
public static description = messages.getMessage('description');
public static help = messages.getMessage('help');
protected static readonly flagsConfig: FlagsConfig = {
Expand Down Expand Up @@ -64,7 +65,7 @@ export default class Push extends DeployCommand {

protected async prechecks(): Promise<void> {
this.tracking = await trackingSetup({
commandName: replaceRenamedCommands('force:source:push'),
commandName: 'force:source:push',
ignoreConflicts: this.getFlag<boolean>('forceoverwrite', false),
org: this.org,
project: this.project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import * as os from 'os';
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import { ChangeResult, replaceRenamedCommands, StatusOutputRow, throwIfInvalid } from '@salesforce/source-tracking';
import { StatusFormatter, StatusResult } from '../../../../formatters/source/statusFormatter';
import { trackingSetup } from '../../../../trackingFunctions';
import { ChangeResult, StatusOutputRow } from '@salesforce/source-tracking';
import { StatusFormatter, StatusResult } from '../../../formatters/source/statusFormatter';
import { trackingSetup } from '../../../trackingFunctions';

Messages.importMessagesDirectory(__dirname);
const messages: Messages = Messages.loadMessages('@salesforce/plugin-source', 'status');

export default class Status extends SfdxCommand {
public static aliases = ['force:source:beta:status'];
public static description = messages.getMessage('description');
public static readonly examples = messages.getMessage('examples').split(os.EOL);
protected static flagsConfig: FlagsConfig = {
Expand All @@ -41,11 +42,13 @@ export default class Status extends SfdxCommand {
protected localAdds: ChangeResult[] = [];

public async run(): Promise<StatusResult[]> {
throwIfInvalid({
const tracking = await trackingSetup({
commandName: 'force:source:status',
ignoreConflicts: true,
org: this.org,
projectPath: this.project.getPath(),
toValidate: 'plugin-source',
command: replaceRenamedCommands('force:source:status'),
project: this.project,
ux: this.ux,
apiVersion: this.flags.apiversion as string,
});

const wantsLocal = (this.flags.local as boolean) || (!this.flags.remote && !this.flags.local);
Expand All @@ -57,14 +60,7 @@ export default class Status extends SfdxCommand {
.map((dir) => dir.path)
.join(',')}`
);
const tracking = await trackingSetup({
commandName: replaceRenamedCommands('force:source:status'),
ignoreConflicts: true,
org: this.org,
project: this.project,
ux: this.ux,
apiVersion: this.flags.apiversion as string,
});

const stlStatusResult = await tracking.getStatus({ local: wantsLocal, remote: wantsRemote });
this.results = stlStatusResult.map((result) => resultConverter(result));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import * as chalk from 'chalk';
import { replaceRenamedCommands, SourceTracking, throwIfInvalid } from '@salesforce/source-tracking';
import { SourceTracking, throwIfInvalid } from '@salesforce/source-tracking';

Messages.importMessagesDirectory(__dirname);
const messages: Messages = Messages.loadMessages('@salesforce/plugin-source', 'tracking');
Expand All @@ -18,8 +18,8 @@ export type SourceTrackingClearResult = {
};

export class Clear extends SfdxCommand {
public static readonly description = replaceRenamedCommands(messages.getMessage('clearDescription'));

public static aliases = ['force:source:beta:tracking:clear'];
public static readonly description = messages.getMessage('clearDescription');
public static readonly requiresProject = true;
public static readonly requiresUsername = true;

Expand All @@ -36,13 +36,10 @@ export class Clear extends SfdxCommand {
org: this.org,
projectPath: this.project.getPath(),
toValidate: 'plugin-source',
command: replaceRenamedCommands('force:source:tracking:clear'),
command: 'force:source:tracking:clear',
});
let clearedFiles: string[] = [];
if (
this.flags.noprompt ||
(await this.ux.confirm(chalk.dim(replaceRenamedCommands(messages.getMessage('promptMessage')))))
) {
if (this.flags.noprompt || (await this.ux.confirm(chalk.dim(messages.getMessage('promptMessage'))))) {
const sourceTracking = await SourceTracking.create({
project: this.project,
org: this.org,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import * as chalk from 'chalk';
import { replaceRenamedCommands, SourceTracking, throwIfInvalid } from '@salesforce/source-tracking';
import { SourceTracking, throwIfInvalid } from '@salesforce/source-tracking';

Messages.importMessagesDirectory(__dirname);
const messages: Messages = Messages.loadMessages('@salesforce/plugin-source', 'tracking');
Expand All @@ -19,8 +19,8 @@ export type SourceTrackingResetResult = {
};

export class Reset extends SfdxCommand {
public static readonly description = replaceRenamedCommands(messages.getMessage('resetDescription'));

public static aliases = ['force:source:beta:tracking:reset'];
public static readonly description = messages.getMessage('resetDescription');
public static readonly requiresProject = true;
public static readonly requiresUsername = true;

Expand All @@ -41,13 +41,10 @@ export class Reset extends SfdxCommand {
org: this.org,
projectPath: this.project.getPath(),
toValidate: 'plugin-source',
command: replaceRenamedCommands('force:source:tracking:clear'),
command: 'force:source:tracking:clear',
});

if (
this.flags.noprompt ||
(await this.ux.confirm(chalk.dim(replaceRenamedCommands(messages.getMessage('promptMessage')))))
) {
if (this.flags.noprompt || (await this.ux.confirm(chalk.dim(messages.getMessage('promptMessage'))))) {
const sourceTracking = await SourceTracking.create({
project: this.project,
org: this.org,
Expand Down
32 changes: 18 additions & 14 deletions src/trackingFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { UX } from '@salesforce/command';
import {
ChangeResult,
getTrackingFileVersion,
replaceRenamedCommands,
SourceTracking,
SourceTrackingOptions,
throwIfInvalid,
Expand Down Expand Up @@ -77,13 +76,13 @@ export const filterConflictsByComponentSet = async ({
export const trackingSetup = async (options: TrackingSetupRequest): Promise<SourceTracking> => {
const { ux, org, ignoreConflicts, commandName, ...createOptions } = options;
const projectPath = options.project.getPath();
// 2 commands use throwIfInvalid
// 3 commands use throwIfInvalid
if (commandName.endsWith('push') || commandName.endsWith('pull') || commandName.endsWith('status')) {
throwIfInvalid({
org,
projectPath,
toValidate: 'plugin-source',
command: replaceRenamedCommands(commandName),
command: commandName,
});
} else {
// confirm tracking file version is plugin-source for all --tracksource flags (deploy, retrieve, delete)
Expand All @@ -92,7 +91,7 @@ export const trackingSetup = async (options: TrackingSetupRequest): Promise<Sour
'You cannot use the "tracksource" flag with the old version of the tracking files',
'sourceTrackingFileVersionMismatch',
[
'Clear the old version of the tracking files with "sfdx force:source:tracking:clear"',
'Clear the old version of the tracking files with "sfdx force:source:legacy:tracking:clear"',
'Create a new org to use the new tracking files',
]
);
Expand Down Expand Up @@ -151,9 +150,9 @@ const writeConflictTable = (conflicts: ConflictResponse[], ux: UX): void => {
ux.table(conflicts, {
columns: [
{ label: 'STATE', key: 'state' },
{ label: 'FULL NAME', key: 'name' },
{ label: 'FULL NAME', key: 'fullName' },
{ label: 'TYPE', key: 'type' },
{ label: 'PROJECT PATH', key: 'filenames' },
{ label: 'PROJECT PATH', key: 'filePath' },
],
});
};
Expand All @@ -169,14 +168,19 @@ const processConflicts = (conflicts: ChangeResult[], ux: UX, message: string): v
if (conflicts.length === 0) {
return;
}
const reformattedConflicts: ConflictResponse[] = conflicts.flatMap((conflict) =>
conflict.filenames.map((f) => ({
state: 'Conflict',
fullName: conflict.name,
type: conflict.type,
filePath: path.resolve(f),
}))
);
// map do dedupe by name-type-filename
const conflictMap = new Map<string, ConflictResponse>();
conflicts.forEach((c) => {
c.filenames?.forEach((f) => {
conflictMap.set(`${c.name}#${c.type}#${f}`, {
state: 'Conflict',
fullName: c.name,
type: c.type,
filePath: path.resolve(f),
});
});
});
const reformattedConflicts = Array.from(conflictMap.values());
writeConflictTable(reformattedConflicts, ux);
const err = new SfdxError(message, 'sourceConflictDetected');
err.setData(reformattedConflicts);
Expand Down
Loading

0 comments on commit eb54c09

Please sign in to comment.