Skip to content

Commit

Permalink
feat(clean): allow overriding pathsToClean in config
Browse files Browse the repository at this point in the history
  • Loading branch information
rigor789 committed Mar 7, 2022
1 parent 3063550 commit b33507d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
11 changes: 10 additions & 1 deletion lib/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,26 @@ export class CleanCommand implements ICommand {
const spinner = this.$terminalSpinnerService.createSpinner();
spinner.start("Cleaning project...\n");

const pathsToClean = [
let pathsToClean = [
constants.HOOKS_DIR_NAME,
constants.PLATFORMS_DIR_NAME,
constants.NODE_MODULES_FOLDER_NAME,
constants.PACKAGE_LOCK_JSON_FILE_NAME,
];

try {
const overridePathsToClean = this.$projectConfigService.getValue(
"cli.pathsToClean"
);
const additionalPaths = this.$projectConfigService.getValue(
"cli.additionalPathsToClean"
);

// allow overriding default paths to clean
if (Array.isArray(overridePathsToClean)) {
pathsToClean = overridePathsToClean;
}

if (Array.isArray(additionalPaths)) {
pathsToClean.push(...additionalPaths);
}
Expand Down
13 changes: 8 additions & 5 deletions lib/services/project-cleanup-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ export class ProjectCleanupService implements IProjectCleanupService {
private $logger: ILogger,
private $projectHelper: IProjectHelper,
private $terminalSpinnerService: ITerminalSpinnerService
) {
this.spinner = this.$terminalSpinnerService.createSpinner();
}
) {}

public async clean(pathsToClean: string[]): Promise<boolean> {
this.spinner = this.$terminalSpinnerService.createSpinner();
let success = true;
for (const pathToClean of pathsToClean) {
const isCleaned = await this.cleanPath(pathToClean).catch((error) => {
Expand All @@ -27,13 +26,17 @@ export class ProjectCleanupService implements IProjectCleanupService {
});
success = success && isCleaned;
}

// required to print an empty line for the spinner to not replace the last status... (probably a bug in the spinners)
console.log();
return success;
}

public async cleanPath(pathToClean: string): Promise<boolean> {
this.spinner.clear();
let success = true;
let fileType: string;

if (!pathToClean || pathToClean.trim().length === 0) {
this.$logger.trace("cleanPath called with no pathToClean.");
return success;
Expand Down Expand Up @@ -70,8 +73,8 @@ export class ProjectCleanupService implements IProjectCleanupService {
return success;
}
this.$logger.trace(`Path '${filePath}' not found, skipping.`);
// this.spinner.text = `Skipping ${displayPath} because it doesn't exist.`;
// this.spinner.info();
this.spinner.info(`Skipping ${displayPath} because it doesn't exist.`);

return success;
}
}
Expand Down

0 comments on commit b33507d

Please sign in to comment.