Skip to content

Commit

Permalink
feat: new inquirer
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jan 5, 2024
1 parent 4570e7d commit 9bc2da5
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 61 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@salesforce/apex-node": "^3.0.1",
"@salesforce/core": "^6.4.2",
"@salesforce/kit": "^3.0.15",
"@salesforce/sf-plugins-core": "^5.0.13",
"@salesforce/sf-plugins-core": "5.0.14-dev.2",
"@salesforce/source-deploy-retrieve": "^10.2.5",
"@salesforce/source-tracking": "^5.1.3",
"@salesforce/ts-types": "^2.0.9",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/project/convert/mdapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Interfaces } from '@oclif/core';
import { ConvertMdapiJson } from '../../../utils/types.js';
import { MetadataConvertResultFormatter } from '../../../formatters/metadataConvertResultFormatter.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'convert.mdapi');

export interface EnsureFsFlagOptions {
Expand Down Expand Up @@ -92,7 +92,7 @@ export class Mdapi extends SfCommand<ConvertMdapiJson> {

protected async convert(): Promise<void> {
const [outputDir] = await Promise.all([
resolveOutputDir(this.flags['output-dir'] ?? this.project.getDefaultPackage().path),
resolveOutputDir(this.flags['output-dir'] ?? this.project!.getDefaultPackage().path),
resolveMetadataPaths(this.flags['metadata-dir'] ?? []),
]);

Expand Down
4 changes: 2 additions & 2 deletions src/commands/project/convert/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { getPackageDirs, getSourceApiVersion } from '../../../utils/project.js';
import { SourceConvertResultFormatter } from '../../../formatters/sourceConvertResultFormatter.js';
import { ConvertResultJson } from '../../../utils/types.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'convert.source');

export class Source extends SfCommand<ConvertResultJson> {
Expand Down Expand Up @@ -112,7 +112,7 @@ export class Source extends SfCommand<ConvertResultJson> {

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

this.componentSet = await ComponentSetBuilder.build({
Expand Down
4 changes: 2 additions & 2 deletions src/commands/project/delete/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class Source extends SfCommand<DeleteSourceJson> {

protected async preChecks(): Promise<void> {
if (this.flags['track-source']) {
this.tracking = await SourceTracking.create({ org: this.org, project: this.project });
this.tracking = await SourceTracking.create({ org: this.org, project: this.project! });
}

if (!validateTests(this.flags['test-level'], this.flags.tests)) {
Expand Down Expand Up @@ -471,7 +471,7 @@ export class Source extends SfCommand<DeleteSourceJson> {
? messages.getMessage('areYouSureCheckOnly')
: messages.getMessage('areYouSure')
);
return this.confirm(message.join('\n'));
return this.confirm({ message: message.join('\n') });
}
return true;
}
Expand Down
8 changes: 3 additions & 5 deletions src/commands/project/delete/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/



import { Messages } from '@salesforce/core';
import chalk from 'chalk';
import { SourceTracking } from '@salesforce/source-tracking';
Expand All @@ -18,7 +16,7 @@ import {
SfCommand,
} from '@salesforce/sf-plugins-core';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'delete.tracking');

export type DeleteTrackingResult = {
Expand Down Expand Up @@ -49,9 +47,9 @@ export class DeleteTracking extends SfCommand<DeleteTrackingResult> {
const { flags } = await this.parse(DeleteTracking);

let clearedFiles: string[] = [];
if (flags['no-prompt'] || (await this.confirm(chalk.dim(messages.getMessage('promptMessage'))))) {
if (flags['no-prompt'] || (await this.confirm({ message: chalk.dim(messages.getMessage('promptMessage')) }))) {
const sourceTracking = await SourceTracking.create({
project: this.project,
project: this.project!,
org: flags['target-org'],
});
clearedFiles = await Promise.all([sourceTracking.clearLocalTracking(), sourceTracking.clearRemoteTracking()]);
Expand Down
6 changes: 2 additions & 4 deletions src/commands/project/deploy/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/



import { Messages } from '@salesforce/core';
import { Duration } from '@salesforce/kit';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
Expand All @@ -17,7 +15,7 @@ import { AsyncDeployCancelResultFormatter } from '../../../formatters/asyncDeplo
import { DeployCancelResultFormatter } from '../../../formatters/deployCancelResultFormatter.js';
import { DeployResultJson } from '../../../utils/types.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy.metadata.cancel');

export default class DeployMetadataCancel extends SfCommand<DeployResultJson> {
Expand Down Expand Up @@ -96,7 +94,7 @@ export default class DeployMetadataCancel extends SfCommand<DeployResultJson> {
}
}

protected catch(error: SfCommand.Error): Promise<SfCommand.Error> {
protected catch(error: SfCommand.Error): Promise<never> {
if (error.name.includes('INVALID_ID_FIELD')) {
const err = messages.createError('error.CannotCancelDeploy');
return super.catch({
Expand Down
9 changes: 4 additions & 5 deletions src/commands/project/deploy/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/


import { Messages } from '@salesforce/core';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { SourceTracking } from '@salesforce/source-tracking';
import { ForceIgnore } from '@salesforce/source-deploy-retrieve';
import { buildComponentSet } from '../../../utils/deploy.js';
import { PreviewResult, printTables, compileResults, getConflictFiles } from '../../../utils/previewOutput.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy.metadata.preview');

const exclusiveFlags = ['manifest', 'source-dir', 'metadata'];
Expand Down Expand Up @@ -64,15 +63,15 @@ export default class DeployMetadataPreview extends SfCommand<PreviewResult> {
public async run(): Promise<PreviewResult> {
const { flags } = await this.parse(DeployMetadataPreview);
const deploySpecified = [flags.manifest, flags.metadata, flags['source-dir']].some((f) => f !== undefined);
const forceIgnore = ForceIgnore.findAndCreate(this.project.getDefaultPackage().path);
const forceIgnore = ForceIgnore.findAndCreate(this.project!.getDefaultPackage().path);

// we'll need STL both to check conflicts and to get the list of local changes if no flags are provided
const stl =
flags['ignore-conflicts'] && deploySpecified
? undefined
: await SourceTracking.create({
org: flags['target-org'],
project: this.project,
project: this.project!,
});

const [componentSet, filesWithConflicts] = await Promise.all([
Expand All @@ -82,7 +81,7 @@ export default class DeployMetadataPreview extends SfCommand<PreviewResult> {

const output = compileResults({
componentSet,
projectPath: this.project.getPath(),
projectPath: this.project!.getPath(),
filesWithConflicts,
forceIgnore,
baseOperation: 'deploy',
Expand Down
6 changes: 2 additions & 4 deletions src/commands/project/deploy/quick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/



import chalk from 'chalk';
import { Messages, Org } from '@salesforce/core';
import { SfCommand, toHelpSection, Flags } from '@salesforce/sf-plugins-core';
Expand All @@ -19,7 +17,7 @@ import { AsyncDeployResultFormatter } from '../../../formatters/asyncDeployResul
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter.js';
import { API, DeployResultJson } from '../../../utils/types.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy.metadata.quick');

export default class DeployMetadataQuick extends SfCommand<DeployResultJson> {
Expand Down Expand Up @@ -134,7 +132,7 @@ export default class DeployMetadataQuick extends SfCommand<DeployResultJson> {
return formatter.getJson();
}

protected catch(error: SfCommand.Error): Promise<SfCommand.Error> {
protected catch(error: SfCommand.Error): Promise<never> {
if (error.name.includes('INVALID_ID_FIELD')) {
const err = messages.createError('error.CannotQuickDeploy');
return super.catch({
Expand Down
5 changes: 2 additions & 3 deletions src/commands/project/deploy/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/


import chalk from 'chalk';
import { EnvironmentVariable, Lifecycle, Messages, OrgConfigProperties, SfError } from '@salesforce/core';
import { DeployVersionData } from '@salesforce/source-deploy-retrieve';
Expand All @@ -24,7 +23,7 @@ import { coverageFormattersFlag, fileOrDirFlag, testLevelFlag, testsFlag } from
import { writeConflictTable } from '../../../utils/conflicts.js';
import { getOptionalProject } from '../../../utils/project.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'deploy.metadata');

const exclusiveFlags = ['manifest', 'source-dir', 'metadata', 'metadata-dir'];
Expand Down Expand Up @@ -262,7 +261,7 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
return formatter.getJson();
}

protected catch(error: Error | SfError): Promise<SfCommand.Error> {
protected catch(error: Error | SfError): Promise<never> {
if (error instanceof SourceConflictError && error.data) {
if (!this.jsonEnabled()) {
writeConflictTable(error.data);
Expand Down
6 changes: 3 additions & 3 deletions src/commands/project/list/ignored.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Messages, SfError } from '@salesforce/core';
import { ForceIgnore } from '@salesforce/source-deploy-retrieve';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'list.ignored');

export type SourceIgnoredResults = {
Expand Down Expand Up @@ -43,10 +43,10 @@ export class Ignored extends SfCommand<SourceIgnoredResults> {
public async run(): Promise<SourceIgnoredResults> {
const flags = (await this.parse(Ignored)).flags;
try {
this.forceIgnore = ForceIgnore.findAndCreate(this.project.getPath());
this.forceIgnore = ForceIgnore.findAndCreate(this.project!.getPath());
const sourcepaths = flags['source-dir']
? [flags['source-dir']]
: this.project.getUniquePackageDirectories().map((pDir) => pDir.path);
: this.project!.getUniquePackageDirectories().map((pDir) => pDir.path);

const ignoredFiles = (await Promise.all(sourcepaths.map((sp) => this.statIgnored(sp.trim())))).flat();

Expand Down
11 changes: 6 additions & 5 deletions src/commands/project/reset/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/



import { Messages } from '@salesforce/core';
import { SourceTracking } from '@salesforce/source-tracking';
import {
Expand All @@ -18,7 +16,7 @@ import {
StandardColors,
} from '@salesforce/sf-plugins-core';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'delete.tracking');

export type ResetTrackingResult = {
Expand Down Expand Up @@ -55,9 +53,12 @@ export class ResetTracking extends SfCommand<ResetTrackingResult> {
public async run(): Promise<ResetTrackingResult> {
const { flags } = await this.parse(ResetTracking);

if (flags['no-prompt'] || (await this.confirm(StandardColors.info(messages.getMessage('promptMessage'))))) {
if (
flags['no-prompt'] ||
(await this.confirm({ message: StandardColors.info(messages.getMessage('promptMessage')) }))
) {
const sourceTracking = await SourceTracking.create({
project: this.project,
project: this.project!,
org: flags['target-org'],
});

Expand Down
9 changes: 4 additions & 5 deletions src/commands/project/retrieve/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/


import { Messages } from '@salesforce/core';
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { SourceTracking } from '@salesforce/source-tracking';
import { ForceIgnore } from '@salesforce/source-deploy-retrieve';
import { PreviewResult, printTables, compileResults, getConflictFiles } from '../../../utils/previewOutput.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'retrieve.metadata.preview');

export default class RetrieveMetadataPreview extends SfCommand<PreviewResult> {
Expand Down Expand Up @@ -47,11 +46,11 @@ export default class RetrieveMetadataPreview extends SfCommand<PreviewResult> {

const stl = await SourceTracking.create({
org: flags['target-org'],
project: this.project,
project: this.project!,
ignoreConflicts: flags['ignore-conflicts'],
});

const forceIgnore = ForceIgnore.findAndCreate(this.project.getDefaultPackage().path);
const forceIgnore = ForceIgnore.findAndCreate(this.project!.getDefaultPackage().path);

const [componentSet, filesWithConflicts, remoteDeletes] = await Promise.all([
stl.remoteNonDeletesAsComponentSet(),
Expand All @@ -61,7 +60,7 @@ export default class RetrieveMetadataPreview extends SfCommand<PreviewResult> {

const output = compileResults({
componentSet,
projectPath: this.project.getPath(),
projectPath: this.project!.getPath(),
filesWithConflicts,
forceIgnore,
baseOperation: 'retrieve',
Expand Down
4 changes: 2 additions & 2 deletions src/commands/project/retrieve/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { RetrieveResultJson } from '../../../utils/types.js';
import { writeConflictTable } from '../../../utils/conflicts.js';
import { promisesQueue } from '../../../utils/promiseQueue.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'retrieve.start');
const mdTransferMessages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'metadata.transfer');

Expand Down Expand Up @@ -266,7 +266,7 @@ export default class RetrieveMetadata extends SfCommand<RetrieveResultJson> {
return formatter.getJson();
}

protected catch(error: Error | SfError): Promise<SfCommand.Error> {
protected catch(error: Error | SfError): Promise<never> {
if (!this.jsonEnabled() && error instanceof SourceConflictError && error.data) {
writeConflictTable(error.data);
// set the message and add plugin-specific actions
Expand Down
Loading

0 comments on commit 9bc2da5

Please sign in to comment.