Skip to content

Commit

Permalink
chore: backout server error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Sep 17, 2021
1 parent de9bd53 commit a20f8b6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/commands/force/source/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as os from 'os';
import * as path from 'path';
import { confirm } from 'cli-ux/lib/prompt';
import { flags, FlagsConfig } from '@salesforce/command';
import { fs, Messages } from '@salesforce/core';
Expand Down Expand Up @@ -192,10 +193,40 @@ export class Delete extends DeployCommand {
}
}

// TODO: maybe move to fs in sfdx-core?
private readDirectoryRecursively(directory: string): string[] {
const files: string[] = [];

const filesInDirectory = fs.readdirSync(directory);
for (const file of filesInDirectory) {
const absolute = path.join(directory, file);
if (fs.statSync(absolute).isDirectory()) {
files.push(...this.readDirectoryRecursively(absolute));
} else {
files.push(absolute);
}
}
return files;
}

private async handlePrompt(): Promise<boolean> {
if (!this.getFlag('noprompt')) {
const paths = this.sourceComponents.map((component) => component.content + '\n' + component.xml).join('\n');
const promptMessage = messages.getMessage('prompt', [paths]);
const paths: string[] = [];
this.sourceComponents.map((component) => {
if (component.content) {
if (fs.lstatSync(component.content).isDirectory()) {
// display all paths in the folder to be deleted
paths.push(...this.readDirectoryRecursively(component.content));
} else {
paths.push(component.content);
}
}
// this will prevent displaying the xml file twice in the confirmation
if (component.xml && !paths.includes(component.xml)) {
paths.push(component.xml);
}
});
const promptMessage = messages.getMessage('prompt', [paths.join('\n')]);

return confirm(promptMessage);
}
Expand Down
21 changes: 21 additions & 0 deletions src/formatters/deleteResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,25 @@ export class DeleteResultFormatter extends DeployResultFormatter {
this.ux.styledHeader(chalk.blue('Deleted Source'));
this.ux.log('No results found');
}

protected displaySuccesses(): void {
if (this.isSuccess() && this.fileResponses?.length) {
const successes = this.fileResponses.filter((f) => f.state !== 'Failed');
if (!successes.length) {
return;
}
this.sortFileResponses(successes);
this.asRelativePaths(successes);

this.ux.log('');
this.ux.styledHeader(chalk.blue('Deleted Source'));
this.ux.table(successes, {
columns: [
{ key: 'fullName', label: 'FULL NAME' },
{ key: 'type', label: 'TYPE' },
{ key: 'filePath', label: 'PROJECT PATH' },
],
});
}
}
}

0 comments on commit a20f8b6

Please sign in to comment.