Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
44 changes: 33 additions & 11 deletions src/cli/cli.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ export class CliController {
private initUi(): void {
this.uiHeader = new HeaderUi(this.config);
this.uiService.add(this.uiHeader);
this.uiResults = new ResultsUi(this.resultsService, this.consoleService);
this.uiResults = new ResultsUi(
this.resultsService,
this.consoleService,
this.config,
);
this.uiService.add(this.uiResults);
this.uiStats = new StatsUi(this.config, this.resultsService, this.logger);
this.uiService.add(this.uiStats);
Expand Down Expand Up @@ -535,6 +539,10 @@ export class CliController {
this.config.jsonSimple = true;
}

if (options.isTrue('disable-size')) {
this.config.disableSize = true;
}

if (this.config.jsonStream && this.config.jsonSimple) {
this.logger.error(ERROR_MSG.CANT_USE_BOTH_JSON_OPTIONS);
this.exitWithError();
Expand Down Expand Up @@ -756,21 +764,31 @@ export class CliController {
this.uiStatus.start();
this.searchStart = Date.now();

this.scanSubscription = this.scanService
const scan$ = this.scanService
.scan(this.config)
.pipe(
tap((nodeFolder) => this.processNodeFolderForUi(nodeFolder)),
mergeMap(
(nodeFolder) => this.scanService.calculateFolderStats(nodeFolder),
10, // Limit to 10 concurrent stat calculations at a time
),
tap((folder) => this.processFolderStatsForUi(folder)),
)
.subscribe({
.pipe(tap((nodeFolder) => this.processNodeFolderForUi(nodeFolder)));

if (this.config.disableSize) {
this.scanSubscription = scan$.subscribe({
next: () => this.printFoldersSection(),
error: (error) => this.newError(error),
complete: () => this.completeSearch(),
});
} else {
this.scanSubscription = scan$
.pipe(
mergeMap(
(nodeFolder) => this.scanService.calculateFolderStats(nodeFolder),
10, // Limit to 10 concurrent stat calculations at a time
),
tap((folder) => this.processFolderStatsForUi(folder)),
)
.subscribe({
next: () => this.printFoldersSection(),
error: (error) => this.newError(error),
complete: () => this.completeSearch(),
});
}
}

private setupJsonModeSignalHandlers(): void {
Expand All @@ -792,6 +810,10 @@ export class CliController {
this.uiResults.clear();
}

if (this.config.disableSize && this.config.deleteAll) {
this.deleteFolder(nodeFolder);
}

this.uiResults.render();
}

Expand Down
1 change: 1 addition & 0 deletions src/cli/interfaces/config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export interface IConfig {
yes: boolean;
jsonStream: boolean;
jsonSimple: boolean;
disableSize: boolean;
}
13 changes: 11 additions & 2 deletions src/cli/ui/components/results.ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class ResultsUi extends HeavyUi implements InteractiveUi {
private searchText = '';
private filteredResults: CliScanFoundFolder[] = [];

private readonly config: IConfig = DEFAULT_CONFIG;
private config: IConfig = DEFAULT_CONFIG;
private readonly KEYS = {
up: () => this.cursorUp(),
down: () => this.cursorDown(),
Expand Down Expand Up @@ -78,8 +78,12 @@ export class ResultsUi extends HeavyUi implements InteractiveUi {
constructor(
private readonly resultsService: ResultsService,
private readonly consoleService: ConsoleService,
config?: IConfig,
) {
super();
if (config) {
this.config = config;
}
}

private openFolder(): void {
Expand Down Expand Up @@ -512,7 +516,12 @@ export class ResultsUi extends HeavyUi implements InteractiveUi {
// Only show "..." if size is exactly 0 AND modificationTime is -1 (not yet calculated)
// If size is 0 but modificationTime is set, then it's a truly empty folder
const isCalculating = folder.size === 0 && folder.modificationTime === -1;
const folderSizeText = isCalculating ? pc.gray(' .....') : folderSize;
let folderSizeText: string;
if (this.config.disableSize) {
folderSizeText = pc.gray(' ...');
} else {
folderSizeText = isCalculating ? pc.gray(' .....') : folderSize;
}

return {
path: folderText,
Expand Down
6 changes: 6 additions & 0 deletions src/constants/cli.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export const OPTIONS: ICliOptions[] = [
description: 'Output results in a JSON format.',
name: 'jsonSimple',
},
{
arg: ['--disable-size'],
description:
'Skip size and age calculation. Useful for faster scanning and deletion when space info is not needed.',
name: 'disable-size',
},
{
arg: ['-v', '--version'],
description: 'Show version.',
Expand Down
1 change: 1 addition & 0 deletions src/constants/main.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const DEFAULT_CONFIG: IConfig = {
yes: false,
jsonStream: false,
jsonSimple: false,
disableSize: false,
};

export const MARGINS = {
Expand Down
1 change: 1 addition & 0 deletions tests/cli/services/scan.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('ScanService', () => {
yes: false,
jsonStream: false,
jsonSimple: false,
disableSize: false,
};

const mockScanFoundFolder: ScanFoundFolder = {
Expand Down