From b0ae3e9cbf099174ad66aaf3bca3f9f99a8b46af Mon Sep 17 00:00:00 2001 From: Jason Cassidy Date: Wed, 27 Oct 2021 11:24:58 +0100 Subject: [PATCH 1/6] fix(clean) report failures to remove --- lib/commands/clean.ts | 8 +++++-- lib/definitions/project.d.ts | 4 ++-- lib/services/project-cleanup-service.ts | 30 ++++++++++++++++++------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/commands/clean.ts b/lib/commands/clean.ts index 2f7ae0910a..a506683008 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); + let result = await this.$projectCleanupService.clean(pathsToClean); - spinner.succeed("Project successfully cleaned."); + if (result) { + 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..5d45b31f41 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 result = 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; }); + result = result && isCleaned; } + return result; } - public async cleanPath(pathToClean: string): Promise { + public async cleanPath(pathToClean: string): Promise { this.spinner.clear(); - + let result = true; + var fileType: string; if (!pathToClean || pathToClean.trim().length === 0) { this.$logger.trace("cleanPath called with no pathToClean."); - return; + return result; } 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"; + } + + result = !this.$fs.exists(filePath); + if (result) { + this.spinner.succeed(`Cleaned ${fileType} ${displayPath}`); + } else { + const message = `Failed to Clean ${fileType}`.red; + this.spinner.fail(`${message} ${displayPath}`); } - return; + return result; } this.$logger.trace(`Path '${filePath}' not found, skipping.`); // this.spinner.text = `Skipping ${displayPath} because it doesn't exist.`; // this.spinner.info(); + return result; } } From 097b7c935db8500bad15a14a396e0e2259e77916 Mon Sep 17 00:00:00 2001 From: Jason Cassidy <47318351+jcassidyav@users.noreply.github.com> Date: Wed, 27 Oct 2021 12:27:33 +0100 Subject: [PATCH 2/6] Rename variable Co-authored-by: Igor Randjelovic --- lib/commands/clean.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/clean.ts b/lib/commands/clean.ts index a506683008..a6941e1128 100644 --- a/lib/commands/clean.ts +++ b/lib/commands/clean.ts @@ -37,7 +37,7 @@ export class CleanCommand implements ICommand { // ignore } - let result = await this.$projectCleanupService.clean(pathsToClean); + const success = await this.$projectCleanupService.clean(pathsToClean); if (result) { spinner.succeed("Project successfully cleaned."); From 4017a32674f338a542634d28225e9e6b5be6bfef Mon Sep 17 00:00:00 2001 From: Jason Cassidy <47318351+jcassidyav@users.noreply.github.com> Date: Wed, 27 Oct 2021 12:27:54 +0100 Subject: [PATCH 3/6] rename variable Co-authored-by: Igor Randjelovic --- lib/commands/clean.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands/clean.ts b/lib/commands/clean.ts index a6941e1128..9aa03539ee 100644 --- a/lib/commands/clean.ts +++ b/lib/commands/clean.ts @@ -39,7 +39,7 @@ export class CleanCommand implements ICommand { const success = await this.$projectCleanupService.clean(pathsToClean); - if (result) { + if (success) { spinner.succeed("Project successfully cleaned."); } else { spinner.fail(`${"Project unsuccessfully cleaned.".red}`); From 6125226cafe356ac9d0b88c9bb353cac18b35014 Mon Sep 17 00:00:00 2001 From: Jason Cassidy <47318351+jcassidyav@users.noreply.github.com> Date: Wed, 27 Oct 2021 12:30:52 +0100 Subject: [PATCH 4/6] use let Co-authored-by: Igor Randjelovic --- lib/services/project-cleanup-service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/project-cleanup-service.ts b/lib/services/project-cleanup-service.ts index 5d45b31f41..b1b0de8974 100644 --- a/lib/services/project-cleanup-service.ts +++ b/lib/services/project-cleanup-service.ts @@ -33,7 +33,7 @@ export class ProjectCleanupService implements IProjectCleanupService { public async cleanPath(pathToClean: string): Promise { this.spinner.clear(); let result = true; - var fileType: string; + let fileType: string; if (!pathToClean || pathToClean.trim().length === 0) { this.$logger.trace("cleanPath called with no pathToClean."); return result; From b215245b386c3ed7875c37bbe95291ae5a8e8061 Mon Sep 17 00:00:00 2001 From: Jason Cassidy Date: Wed, 27 Oct 2021 12:35:48 +0100 Subject: [PATCH 5/6] Rename varialbe to success for clarity. --- lib/services/project-cleanup-service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/services/project-cleanup-service.ts b/lib/services/project-cleanup-service.ts index b1b0de8974..1d722aaff7 100644 --- a/lib/services/project-cleanup-service.ts +++ b/lib/services/project-cleanup-service.ts @@ -16,7 +16,7 @@ export class ProjectCleanupService implements IProjectCleanupService { } public async clean(pathsToClean: string[]): Promise { - let result = true; + let success = true; for (const pathToClean of pathsToClean) { const isCleaned = await this.cleanPath(pathToClean).catch((error) => { this.$logger.trace( @@ -25,9 +25,9 @@ export class ProjectCleanupService implements IProjectCleanupService { ); return false; }); - result = result && isCleaned; + success = success && isCleaned; } - return result; + return success; } public async cleanPath(pathToClean: string): Promise { From 1534842c30ba712489f1fb589f3496eb7fd61d6e Mon Sep 17 00:00:00 2001 From: Jason Cassidy Date: Wed, 27 Oct 2021 12:48:01 +0100 Subject: [PATCH 6/6] Rename varialbe to success for clarity. --- lib/services/project-cleanup-service.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/services/project-cleanup-service.ts b/lib/services/project-cleanup-service.ts index 1d722aaff7..da592435ec 100644 --- a/lib/services/project-cleanup-service.ts +++ b/lib/services/project-cleanup-service.ts @@ -32,11 +32,11 @@ export class ProjectCleanupService implements IProjectCleanupService { public async cleanPath(pathToClean: string): Promise { this.spinner.clear(); - let result = true; + let success = true; let fileType: string; if (!pathToClean || pathToClean.trim().length === 0) { this.$logger.trace("cleanPath called with no pathToClean."); - return result; + return success; } const filePath = path.resolve(this.$projectHelper.projectDir, pathToClean); @@ -60,19 +60,19 @@ export class ProjectCleanupService implements IProjectCleanupService { fileType = "file"; } - result = !this.$fs.exists(filePath); - if (result) { + 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 result; + return success; } this.$logger.trace(`Path '${filePath}' not found, skipping.`); // this.spinner.text = `Skipping ${displayPath} because it doesn't exist.`; // this.spinner.info(); - return result; + return success; } }