Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@ interface IProjectCleanupService {
* Clean multiple paths
* @param {string[]} pathsToClean
*/
clean(pathsToClean: string[]): Promise<void>;
clean(pathsToClean: string[]): Promise<boolean>;

/**
* Clean a single path
* @param {string} pathToClean
*/
cleanPath(pathToClean: string): Promise<void>;
cleanPath(pathToClean: string): Promise<boolean>;
}

interface IBackup {
Expand Down
30 changes: 22 additions & 8 deletions lib/services/project-cleanup-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,28 @@ export class ProjectCleanupService implements IProjectCleanupService {
this.spinner = this.$terminalSpinnerService.createSpinner();
}

public async clean(pathsToClean: string[]): Promise<void> {
public async clean(pathsToClean: string[]): Promise<boolean> {
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<void> {
public async cleanPath(pathToClean: string): Promise<boolean> {
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);
Expand All @@ -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;
}
}

Expand Down