diff --git a/lib/commands/clean.ts b/lib/commands/clean.ts index 2f7ae0910a..9aa03539ee 100644 --- a/lib/commands/clean.ts +++ b/lib/commands/clean.ts @@ -37,9 +37,13 @@ export class CleanCommand implements ICommand { // ignore } - await this.$projectCleanupService.clean(pathsToClean); + const success = await this.$projectCleanupService.clean(pathsToClean); - spinner.succeed("Project successfully cleaned."); + if (success) { + spinner.succeed("Project successfully cleaned."); + } else { + spinner.fail(`${"Project unsuccessfully cleaned.".red}`); + } } } diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index a7467b90eb..e771d3dddb 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -302,13 +302,13 @@ interface IProjectCleanupService { * Clean multiple paths * @param {string[]} pathsToClean */ - clean(pathsToClean: string[]): Promise; + clean(pathsToClean: string[]): Promise; /** * Clean a single path * @param {string} pathToClean */ - cleanPath(pathToClean: string): Promise; + cleanPath(pathToClean: string): Promise; } interface IBackup { diff --git a/lib/services/project-cleanup-service.ts b/lib/services/project-cleanup-service.ts index ba62535471..da592435ec 100644 --- a/lib/services/project-cleanup-service.ts +++ b/lib/services/project-cleanup-service.ts @@ -15,23 +15,28 @@ export class ProjectCleanupService implements IProjectCleanupService { this.spinner = this.$terminalSpinnerService.createSpinner(); } - public async clean(pathsToClean: string[]): Promise { + public async clean(pathsToClean: string[]): Promise { + let success = true; for (const pathToClean of pathsToClean) { - await this.cleanPath(pathToClean).catch((error) => { + const isCleaned = await this.cleanPath(pathToClean).catch((error) => { this.$logger.trace( `Encountered error while cleaning. Error is: ${error.message}.`, error ); + return false; }); + success = success && isCleaned; } + return success; } - public async cleanPath(pathToClean: string): Promise { + public async cleanPath(pathToClean: string): Promise { this.spinner.clear(); - + let success = true; + let fileType: string; if (!pathToClean || pathToClean.trim().length === 0) { this.$logger.trace("cleanPath called with no pathToClean."); - return; + return success; } const filePath = path.resolve(this.$projectHelper.projectDir, pathToClean); @@ -48,17 +53,26 @@ export class ProjectCleanupService implements IProjectCleanupService { if (stat.isDirectory()) { this.$logger.trace(`Path '${filePath}' is a directory, deleting.`); this.$fs.deleteDirectorySafe(filePath); - this.spinner.succeed(`Cleaned directory ${displayPath}`); + fileType = "directory"; } else { this.$logger.trace(`Path '${filePath}' is a file, deleting.`); this.$fs.deleteFile(filePath); - this.spinner.succeed(`Cleaned file ${displayPath}`); + fileType = "file"; + } + + success = !this.$fs.exists(filePath); + if (success) { + this.spinner.succeed(`Cleaned ${fileType} ${displayPath}`); + } else { + const message = `Failed to Clean ${fileType}`.red; + this.spinner.fail(`${message} ${displayPath}`); } - return; + return success; } this.$logger.trace(`Path '${filePath}' not found, skipping.`); // this.spinner.text = `Skipping ${displayPath} because it doesn't exist.`; // this.spinner.info(); + return success; } }