Skip to content

Commit 3902257

Browse files
jcassidyavrigor789
andauthored
fix(clean): report failures to remove item (#5601)
* fix(clean) report failures to remove * Rename variable Co-authored-by: Igor Randjelovic <[email protected]> * rename variable Co-authored-by: Igor Randjelovic <[email protected]> * use let Co-authored-by: Igor Randjelovic <[email protected]> * Rename varialbe to success for clarity. * Rename varialbe to success for clarity. Co-authored-by: Igor Randjelovic <[email protected]>
1 parent fd3b3a8 commit 3902257

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

lib/commands/clean.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ export class CleanCommand implements ICommand {
3737
// ignore
3838
}
3939

40-
await this.$projectCleanupService.clean(pathsToClean);
40+
const success = await this.$projectCleanupService.clean(pathsToClean);
4141

42-
spinner.succeed("Project successfully cleaned.");
42+
if (success) {
43+
spinner.succeed("Project successfully cleaned.");
44+
} else {
45+
spinner.fail(`${"Project unsuccessfully cleaned.".red}`);
46+
}
4347
}
4448
}
4549

lib/definitions/project.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,13 @@ interface IProjectCleanupService {
308308
* Clean multiple paths
309309
* @param {string[]} pathsToClean
310310
*/
311-
clean(pathsToClean: string[]): Promise<void>;
311+
clean(pathsToClean: string[]): Promise<boolean>;
312312

313313
/**
314314
* Clean a single path
315315
* @param {string} pathToClean
316316
*/
317-
cleanPath(pathToClean: string): Promise<void>;
317+
cleanPath(pathToClean: string): Promise<boolean>;
318318
}
319319

320320
interface IBackup {

lib/services/project-cleanup-service.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,28 @@ export class ProjectCleanupService implements IProjectCleanupService {
1515
this.spinner = this.$terminalSpinnerService.createSpinner();
1616
}
1717

18-
public async clean(pathsToClean: string[]): Promise<void> {
18+
public async clean(pathsToClean: string[]): Promise<boolean> {
19+
let success = true;
1920
for (const pathToClean of pathsToClean) {
20-
await this.cleanPath(pathToClean).catch((error) => {
21+
const isCleaned = await this.cleanPath(pathToClean).catch((error) => {
2122
this.$logger.trace(
2223
`Encountered error while cleaning. Error is: ${error.message}.`,
2324
error
2425
);
26+
return false;
2527
});
28+
success = success && isCleaned;
2629
}
30+
return success;
2731
}
2832

29-
public async cleanPath(pathToClean: string): Promise<void> {
33+
public async cleanPath(pathToClean: string): Promise<boolean> {
3034
this.spinner.clear();
31-
35+
let success = true;
36+
let fileType: string;
3237
if (!pathToClean || pathToClean.trim().length === 0) {
3338
this.$logger.trace("cleanPath called with no pathToClean.");
34-
return;
39+
return success;
3540
}
3641

3742
const filePath = path.resolve(this.$projectHelper.projectDir, pathToClean);
@@ -48,17 +53,26 @@ export class ProjectCleanupService implements IProjectCleanupService {
4853
if (stat.isDirectory()) {
4954
this.$logger.trace(`Path '${filePath}' is a directory, deleting.`);
5055
this.$fs.deleteDirectorySafe(filePath);
51-
this.spinner.succeed(`Cleaned directory ${displayPath}`);
56+
fileType = "directory";
5257
} else {
5358
this.$logger.trace(`Path '${filePath}' is a file, deleting.`);
5459
this.$fs.deleteFile(filePath);
55-
this.spinner.succeed(`Cleaned file ${displayPath}`);
60+
fileType = "file";
61+
}
62+
63+
success = !this.$fs.exists(filePath);
64+
if (success) {
65+
this.spinner.succeed(`Cleaned ${fileType} ${displayPath}`);
66+
} else {
67+
const message = `Failed to Clean ${fileType}`.red;
68+
this.spinner.fail(`${message} ${displayPath}`);
5669
}
57-
return;
70+
return success;
5871
}
5972
this.$logger.trace(`Path '${filePath}' not found, skipping.`);
6073
// this.spinner.text = `Skipping ${displayPath} because it doesn't exist.`;
6174
// this.spinner.info();
75+
return success;
6276
}
6377
}
6478

0 commit comments

Comments
 (0)