dir-analysis-tool 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dir-analyzer.json +11 -0
- package/README.md +502 -0
- package/bin/index.js +5 -0
- package/example-config.json +13 -0
- package/package.json +48 -0
- package/src/advanced-analysis.ts +185 -0
- package/src/analyzer.ts +278 -0
- package/src/classifier.ts +83 -0
- package/src/cli.ts +431 -0
- package/src/config.ts +66 -0
- package/src/export.ts +80 -0
- package/src/html-report.ts +704 -0
- package/src/index.ts +2 -0
- package/src/interactive.ts +656 -0
- package/src/progress.ts +47 -0
- package/src/tree-view.ts +129 -0
- package/src/types.ts +47 -0
- package/src/utils.ts +54 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { DirectoryAnalyzer, AnalysisOptions } from './analyzer';
|
|
4
|
+
import { ExtendedAnalysisResult } from './export';
|
|
5
|
+
import { ProgressBar } from './progress';
|
|
6
|
+
import { CSVExporter } from './export';
|
|
7
|
+
import { formatSize, EMOJIS } from './utils';
|
|
8
|
+
import { promises as fs } from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
|
|
11
|
+
export class InteractiveMode {
|
|
12
|
+
private analyzer: DirectoryAnalyzer;
|
|
13
|
+
private currentResult: ExtendedAnalysisResult | null = null;
|
|
14
|
+
private currentPath: string = process.cwd();
|
|
15
|
+
|
|
16
|
+
constructor() {
|
|
17
|
+
this.analyzer = new DirectoryAnalyzer();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async start(): Promise<void> {
|
|
21
|
+
console.log(chalk.blue.bold('\nš Welcome to Interactive Directory Analyzer!'));
|
|
22
|
+
console.log(chalk.gray('Explore directories interactively with advanced analysis features.\n'));
|
|
23
|
+
|
|
24
|
+
while (true) {
|
|
25
|
+
const action = await this.showMainMenu();
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
switch (action) {
|
|
29
|
+
case 'analyze':
|
|
30
|
+
await this.analyzeDirectory();
|
|
31
|
+
break;
|
|
32
|
+
case 'change_path':
|
|
33
|
+
await this.changePath();
|
|
34
|
+
break;
|
|
35
|
+
case 'view_results':
|
|
36
|
+
await this.viewResults();
|
|
37
|
+
break;
|
|
38
|
+
case 'export':
|
|
39
|
+
await this.exportResults();
|
|
40
|
+
break;
|
|
41
|
+
case 'advanced':
|
|
42
|
+
await this.advancedOptions();
|
|
43
|
+
break;
|
|
44
|
+
case 'exit':
|
|
45
|
+
console.log(chalk.green('\nš Goodbye!'));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(chalk.red('\nā Error:'), error instanceof Error ? error.message : String(error));
|
|
50
|
+
console.log(chalk.gray('Press any key to continue...'));
|
|
51
|
+
await inquirer.prompt([{ type: 'input', name: 'continue', message: '' }]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private async showMainMenu(): Promise<string> {
|
|
57
|
+
console.log(chalk.cyan(`\nš Current Path: ${this.currentPath}`));
|
|
58
|
+
if (this.currentResult) {
|
|
59
|
+
console.log(chalk.green(`š Last Analysis: ${this.currentResult.files} files, ${formatSize(this.currentResult.totalSizeBytes)}`));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const { action } = await inquirer.prompt([
|
|
63
|
+
{
|
|
64
|
+
type: 'list',
|
|
65
|
+
name: 'action',
|
|
66
|
+
message: 'What would you like to do?',
|
|
67
|
+
choices: [
|
|
68
|
+
{ name: 'š Analyze Current Directory', value: 'analyze' },
|
|
69
|
+
{ name: 'š Change Directory', value: 'change_path' },
|
|
70
|
+
...(this.currentResult ? [{ name: 'š View Results', value: 'view_results' }] : []),
|
|
71
|
+
...(this.currentResult ? [{ name: 'š¾ Export Results', value: 'export' }] : []),
|
|
72
|
+
{ name: 'āļø Advanced Options', value: 'advanced' },
|
|
73
|
+
{ name: 'šŖ Exit', value: 'exit' }
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
return action;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private async analyzeDirectory(): Promise<void> {
|
|
82
|
+
const options = await this.getAnalysisOptions();
|
|
83
|
+
|
|
84
|
+
console.log(chalk.blue('\nš Starting analysis...'));
|
|
85
|
+
const progressCallback = ProgressBar.createCallback(true); this.currentResult = await this.analyzer.analyze({
|
|
86
|
+
path: this.currentPath,
|
|
87
|
+
recursive: options.recursive ?? true,
|
|
88
|
+
excludePatterns: options.excludePatterns ?? [],
|
|
89
|
+
largeSizeThreshold: options.largeSizeThreshold,
|
|
90
|
+
enableDuplicateDetection: options.enableDuplicateDetection ?? false,
|
|
91
|
+
progressCallback,
|
|
92
|
+
maxDepth: options.maxDepth ?? -1,
|
|
93
|
+
minSize: options.minSize,
|
|
94
|
+
maxSize: options.maxSize,
|
|
95
|
+
dateFrom: options.dateFrom,
|
|
96
|
+
dateTo: options.dateTo,
|
|
97
|
+
topN: options.topN,
|
|
98
|
+
showEmptyFiles: options.showEmptyFiles ?? false
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
console.log(chalk.green('ā
Analysis complete!\n'));
|
|
102
|
+
await this.displayBasicResults();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private async getAnalysisOptions(): Promise<Partial<AnalysisOptions>> {
|
|
106
|
+
const { features } = await inquirer.prompt([
|
|
107
|
+
{
|
|
108
|
+
type: 'checkbox',
|
|
109
|
+
name: 'features',
|
|
110
|
+
message: 'Select analysis features:',
|
|
111
|
+
choices: [
|
|
112
|
+
{ name: 'š Recursive scan', value: 'recursive', checked: true },
|
|
113
|
+
{ name: 'š File type classification', value: 'types', checked: true },
|
|
114
|
+
{ name: 'šØ Large file detection', value: 'large_files' },
|
|
115
|
+
{ name: 'š Duplicate detection', value: 'duplicates' },
|
|
116
|
+
{ name: 'š Empty file detection', value: 'empty_files' },
|
|
117
|
+
{ name: 'š³ Tree view generation', value: 'tree_view' },
|
|
118
|
+
{ name: 'š Top largest files', value: 'top_files' }
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
]);
|
|
122
|
+
|
|
123
|
+
const options: Partial<AnalysisOptions> = {
|
|
124
|
+
recursive: features.includes('recursive'),
|
|
125
|
+
excludePatterns: []
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
if (features.includes('large_files')) {
|
|
129
|
+
const { threshold } = await inquirer.prompt([
|
|
130
|
+
{
|
|
131
|
+
type: 'input',
|
|
132
|
+
name: 'threshold',
|
|
133
|
+
message: 'Large file threshold (MB):',
|
|
134
|
+
default: '100',
|
|
135
|
+
validate: (input) => {
|
|
136
|
+
const num = parseFloat(input);
|
|
137
|
+
return num > 0 ? true : 'Please enter a positive number';
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
]);
|
|
141
|
+
options.largeSizeThreshold = parseFloat(threshold) * 1024 * 1024;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (features.includes('duplicates')) {
|
|
145
|
+
options.enableDuplicateDetection = true;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (features.includes('empty_files')) {
|
|
149
|
+
options.showEmptyFiles = true;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (features.includes('top_files')) {
|
|
153
|
+
const { topN } = await inquirer.prompt([
|
|
154
|
+
{
|
|
155
|
+
type: 'input',
|
|
156
|
+
name: 'topN',
|
|
157
|
+
message: 'Number of top largest files to show:',
|
|
158
|
+
default: '10',
|
|
159
|
+
validate: (input) => {
|
|
160
|
+
const num = parseInt(input);
|
|
161
|
+
return num > 0 ? true : 'Please enter a positive number';
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
]);
|
|
165
|
+
options.topN = parseInt(topN);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Advanced filters
|
|
169
|
+
const { useFilters } = await inquirer.prompt([
|
|
170
|
+
{
|
|
171
|
+
type: 'confirm',
|
|
172
|
+
name: 'useFilters',
|
|
173
|
+
message: 'Apply file filters (size, date)?',
|
|
174
|
+
default: false
|
|
175
|
+
}
|
|
176
|
+
]);
|
|
177
|
+
|
|
178
|
+
if (useFilters) {
|
|
179
|
+
const filters = await this.getFileFilters();
|
|
180
|
+
Object.assign(options, filters);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return options;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private async getFileFilters(): Promise<Partial<AnalysisOptions>> {
|
|
187
|
+
const { filterType } = await inquirer.prompt([
|
|
188
|
+
{
|
|
189
|
+
type: 'checkbox',
|
|
190
|
+
name: 'filterType',
|
|
191
|
+
message: 'Select filters:',
|
|
192
|
+
choices: [
|
|
193
|
+
{ name: 'š Size filters', value: 'size' },
|
|
194
|
+
{ name: 'š
Date filters', value: 'date' }
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
]);
|
|
198
|
+
|
|
199
|
+
const filters: Partial<AnalysisOptions> = {};
|
|
200
|
+
|
|
201
|
+
if (filterType.includes('size')) {
|
|
202
|
+
const { minSize, maxSize } = await inquirer.prompt([
|
|
203
|
+
{
|
|
204
|
+
type: 'input',
|
|
205
|
+
name: 'minSize',
|
|
206
|
+
message: 'Minimum file size (bytes, leave empty for no limit):',
|
|
207
|
+
validate: (input) => {
|
|
208
|
+
if (!input) return true;
|
|
209
|
+
const num = parseInt(input);
|
|
210
|
+
return num >= 0 ? true : 'Please enter a non-negative number';
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
type: 'input',
|
|
215
|
+
name: 'maxSize',
|
|
216
|
+
message: 'Maximum file size (bytes, leave empty for no limit):',
|
|
217
|
+
validate: (input) => {
|
|
218
|
+
if (!input) return true;
|
|
219
|
+
const num = parseInt(input);
|
|
220
|
+
return num >= 0 ? true : 'Please enter a non-negative number';
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
]);
|
|
224
|
+
|
|
225
|
+
if (minSize) filters.minSize = parseInt(minSize);
|
|
226
|
+
if (maxSize) filters.maxSize = parseInt(maxSize);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (filterType.includes('date')) {
|
|
230
|
+
const { dateFrom, dateTo } = await inquirer.prompt([
|
|
231
|
+
{
|
|
232
|
+
type: 'input',
|
|
233
|
+
name: 'dateFrom',
|
|
234
|
+
message: 'Files modified after (YYYY-MM-DD, leave empty for no limit):',
|
|
235
|
+
validate: (input) => {
|
|
236
|
+
if (!input) return true;
|
|
237
|
+
const date = new Date(input);
|
|
238
|
+
return !isNaN(date.getTime()) ? true : 'Please enter a valid date (YYYY-MM-DD)';
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
type: 'input',
|
|
243
|
+
name: 'dateTo',
|
|
244
|
+
message: 'Files modified before (YYYY-MM-DD, leave empty for no limit):',
|
|
245
|
+
validate: (input) => {
|
|
246
|
+
if (!input) return true;
|
|
247
|
+
const date = new Date(input);
|
|
248
|
+
return !isNaN(date.getTime()) ? true : 'Please enter a valid date (YYYY-MM-DD)';
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
]);
|
|
252
|
+
|
|
253
|
+
if (dateFrom) filters.dateFrom = new Date(dateFrom);
|
|
254
|
+
if (dateTo) filters.dateTo = new Date(dateTo);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return filters;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private async changePath(): Promise<void> {
|
|
261
|
+
const { newPath } = await inquirer.prompt([
|
|
262
|
+
{
|
|
263
|
+
type: 'input',
|
|
264
|
+
name: 'newPath',
|
|
265
|
+
message: 'Enter new directory path:',
|
|
266
|
+
default: this.currentPath,
|
|
267
|
+
validate: async (input) => {
|
|
268
|
+
try {
|
|
269
|
+
const stats = await fs.stat(input);
|
|
270
|
+
return stats.isDirectory() ? true : 'Path is not a directory';
|
|
271
|
+
} catch {
|
|
272
|
+
return 'Path does not exist';
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
]);
|
|
277
|
+
|
|
278
|
+
this.currentPath = path.resolve(newPath);
|
|
279
|
+
this.currentResult = null; // Clear previous results
|
|
280
|
+
console.log(chalk.green(`š Changed to: ${this.currentPath}`));
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
private async displayBasicResults(): Promise<void> {
|
|
284
|
+
if (!this.currentResult) return;
|
|
285
|
+
|
|
286
|
+
const result = this.currentResult;
|
|
287
|
+
console.log(chalk.blue(`${EMOJIS.folder} Directory: ${result.path}`));
|
|
288
|
+
console.log(chalk.green(`${EMOJIS.package} Total Size: ${formatSize(result.totalSizeBytes)}`));
|
|
289
|
+
console.log(chalk.yellow(`${EMOJIS.folderIcon} Folders: ${result.folders}`));
|
|
290
|
+
console.log(chalk.cyan(`${EMOJIS.fileIcon} Files: ${result.files}`));
|
|
291
|
+
|
|
292
|
+
// File types
|
|
293
|
+
console.log(chalk.magenta(`\n${EMOJIS.types} File Types:`));
|
|
294
|
+
const typeEntries = [
|
|
295
|
+
{ key: 'code', emoji: EMOJIS.code, label: 'Code' },
|
|
296
|
+
{ key: 'images', emoji: EMOJIS.images, label: 'Images' },
|
|
297
|
+
{ key: 'documents', emoji: EMOJIS.documents, label: 'Documents' },
|
|
298
|
+
{ key: 'videos', emoji: EMOJIS.videos, label: 'Videos' },
|
|
299
|
+
{ key: 'audio', emoji: EMOJIS.audio, label: 'Audio' },
|
|
300
|
+
{ key: 'archives', emoji: EMOJIS.archives, label: 'Archives' },
|
|
301
|
+
{ key: 'other', emoji: EMOJIS.other, label: 'Other' }
|
|
302
|
+
];
|
|
303
|
+
|
|
304
|
+
typeEntries.forEach(({ key, emoji, label }) => {
|
|
305
|
+
const count = (result.types as any)[key];
|
|
306
|
+
if (count > 0) {
|
|
307
|
+
console.log(` ${emoji} ${label}: ${count}`);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
private async viewResults(): Promise<void> {
|
|
313
|
+
if (!this.currentResult) {
|
|
314
|
+
console.log(chalk.yellow('No results available. Run an analysis first.'));
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const { viewType } = await inquirer.prompt([
|
|
319
|
+
{
|
|
320
|
+
type: 'list',
|
|
321
|
+
name: 'viewType',
|
|
322
|
+
message: 'How would you like to view the results?',
|
|
323
|
+
choices: [
|
|
324
|
+
{ name: 'š Summary', value: 'summary' },
|
|
325
|
+
{ name: 'š³ Tree View', value: 'tree' },
|
|
326
|
+
{ name: 'šØ Large Files', value: 'large_files' },
|
|
327
|
+
{ name: 'š Duplicates', value: 'duplicates' },
|
|
328
|
+
{ name: 'š Empty Files', value: 'empty_files' },
|
|
329
|
+
{ name: 'š Top Largest Files', value: 'top_files' },
|
|
330
|
+
{ name: 'š Full JSON', value: 'json' }
|
|
331
|
+
]
|
|
332
|
+
}
|
|
333
|
+
]);
|
|
334
|
+
|
|
335
|
+
switch (viewType) {
|
|
336
|
+
case 'summary':
|
|
337
|
+
await this.displayBasicResults();
|
|
338
|
+
break;
|
|
339
|
+
case 'tree':
|
|
340
|
+
this.displayTreeView();
|
|
341
|
+
break;
|
|
342
|
+
case 'large_files':
|
|
343
|
+
this.displayLargeFiles();
|
|
344
|
+
break;
|
|
345
|
+
case 'duplicates':
|
|
346
|
+
this.displayDuplicates();
|
|
347
|
+
break;
|
|
348
|
+
case 'empty_files':
|
|
349
|
+
this.displayEmptyFiles();
|
|
350
|
+
break;
|
|
351
|
+
case 'top_files':
|
|
352
|
+
this.displayTopFiles();
|
|
353
|
+
break;
|
|
354
|
+
case 'json':
|
|
355
|
+
console.log(JSON.stringify(this.currentResult, null, 2));
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
console.log(chalk.gray('\nPress Enter to continue...'));
|
|
360
|
+
await inquirer.prompt([{ type: 'input', name: 'continue', message: '' }]);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
private displayTreeView(): void {
|
|
364
|
+
if (!this.currentResult?.treeView) {
|
|
365
|
+
console.log(chalk.yellow('Tree view not available (dataset too large or not generated)'));
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
console.log(chalk.blue('\nš³ Directory Tree:'));
|
|
369
|
+
console.log(this.currentResult.treeView);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
private displayLargeFiles(): void {
|
|
373
|
+
if (!this.currentResult?.largeFiles || this.currentResult.largeFiles.length === 0) {
|
|
374
|
+
console.log(chalk.yellow('No large files found'));
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
console.log(chalk.red(`\nšØ Large Files (${this.currentResult.largeFiles.length}):`));
|
|
379
|
+
this.currentResult.largeFiles.forEach((file, index) => {
|
|
380
|
+
const relativePath = path.relative(this.currentResult!.path, file.path);
|
|
381
|
+
console.log(` ${index + 1}. ${relativePath} - ${chalk.yellow(file.sizeFormatted)}`);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
private displayDuplicates(): void {
|
|
386
|
+
if (!this.currentResult?.duplicateGroups || this.currentResult.duplicateGroups.length === 0) {
|
|
387
|
+
console.log(chalk.yellow('No duplicate files found'));
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
console.log(chalk.yellow(`\nš Duplicate Files (${this.currentResult.duplicateGroups.length} groups):`));
|
|
392
|
+
if (this.currentResult.duplicateStats) {
|
|
393
|
+
console.log(`š¾ Total wasted space: ${chalk.red(this.currentResult.duplicateStats.totalWastedSpaceFormatted)}`);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
this.currentResult.duplicateGroups.slice(0, 5).forEach((group, index) => {
|
|
397
|
+
console.log(`\n Group ${index + 1}: ${group.sizeFormatted} each Ć ${group.files.length} files`);
|
|
398
|
+
group.files.slice(0, 3).forEach(file => {
|
|
399
|
+
const relativePath = path.relative(this.currentResult!.path, file);
|
|
400
|
+
console.log(` š ${relativePath}`);
|
|
401
|
+
});
|
|
402
|
+
if (group.files.length > 3) {
|
|
403
|
+
console.log(chalk.gray(` ... and ${group.files.length - 3} more`));
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
private displayEmptyFiles(): void {
|
|
409
|
+
if (!this.currentResult?.emptyFiles || this.currentResult.emptyFiles.length === 0) {
|
|
410
|
+
console.log(chalk.yellow('No empty files found'));
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
console.log(chalk.yellow(`\nš Empty Files (${this.currentResult.emptyFiles.length}):`));
|
|
415
|
+
const displayCount = Math.min(10, this.currentResult.emptyFiles.length);
|
|
416
|
+
|
|
417
|
+
this.currentResult.emptyFiles.slice(0, displayCount).forEach(file => {
|
|
418
|
+
const relativePath = path.relative(this.currentResult!.path, file.path);
|
|
419
|
+
const date = file.modifiedDate.toLocaleDateString();
|
|
420
|
+
console.log(` š ${relativePath} ${chalk.gray(`(modified: ${date})`)}`);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
if (this.currentResult.emptyFiles.length > displayCount) {
|
|
424
|
+
console.log(chalk.gray(` ... and ${this.currentResult.emptyFiles.length - displayCount} more`));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
private displayTopFiles(): void {
|
|
429
|
+
if (!this.currentResult?.topLargestFiles || this.currentResult.topLargestFiles.length === 0) {
|
|
430
|
+
console.log(chalk.yellow('No top files data available'));
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
console.log(chalk.red(`\nš Top ${this.currentResult.topLargestFiles.length} Largest Files:`));
|
|
435
|
+
this.currentResult.topLargestFiles.forEach((file, index) => {
|
|
436
|
+
const relativePath = path.relative(this.currentResult!.path, file.path);
|
|
437
|
+
console.log(` ${index + 1}. ${relativePath} - ${chalk.yellow(file.sizeFormatted)}`);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
private async exportResults(): Promise<void> {
|
|
442
|
+
if (!this.currentResult) {
|
|
443
|
+
console.log(chalk.yellow('No results available. Run an analysis first.'));
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
const { exportType } = await inquirer.prompt([
|
|
448
|
+
{
|
|
449
|
+
type: 'list',
|
|
450
|
+
name: 'exportType',
|
|
451
|
+
message: 'Select export format:',
|
|
452
|
+
choices: [
|
|
453
|
+
{ name: 'š CSV - General analysis', value: 'csv' },
|
|
454
|
+
{ name: 'š CSV - Large files only', value: 'csv_large' },
|
|
455
|
+
{ name: 'š CSV - Duplicates only', value: 'csv_duplicates' },
|
|
456
|
+
{ name: 'š JSON - Full results', value: 'json' }
|
|
457
|
+
]
|
|
458
|
+
}
|
|
459
|
+
]);
|
|
460
|
+
|
|
461
|
+
const { filename } = await inquirer.prompt([
|
|
462
|
+
{
|
|
463
|
+
type: 'input',
|
|
464
|
+
name: 'filename',
|
|
465
|
+
message: 'Output filename:',
|
|
466
|
+
default: this.getDefaultFilename(exportType),
|
|
467
|
+
validate: (input) => input.trim() ? true : 'Please enter a filename'
|
|
468
|
+
}
|
|
469
|
+
]);
|
|
470
|
+
|
|
471
|
+
try {
|
|
472
|
+
let content: string;
|
|
473
|
+
switch (exportType) {
|
|
474
|
+
case 'csv':
|
|
475
|
+
content = CSVExporter.exportAnalysis(this.currentResult);
|
|
476
|
+
break;
|
|
477
|
+
case 'csv_large':
|
|
478
|
+
if (!this.currentResult.largeFiles || this.currentResult.largeFiles.length === 0) {
|
|
479
|
+
console.log(chalk.yellow('No large files to export'));
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
content = CSVExporter.exportLargeFiles(this.currentResult.largeFiles);
|
|
483
|
+
break;
|
|
484
|
+
case 'csv_duplicates':
|
|
485
|
+
if (!this.currentResult.duplicateGroups || this.currentResult.duplicateGroups.length === 0) {
|
|
486
|
+
console.log(chalk.yellow('No duplicates to export'));
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
content = CSVExporter.exportDuplicates(this.currentResult.duplicateGroups);
|
|
490
|
+
break;
|
|
491
|
+
case 'json':
|
|
492
|
+
content = JSON.stringify(this.currentResult, null, 2);
|
|
493
|
+
break;
|
|
494
|
+
default:
|
|
495
|
+
throw new Error('Unknown export type');
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
await fs.writeFile(filename, content);
|
|
499
|
+
console.log(chalk.green(`ā
Results exported to: ${filename}`));
|
|
500
|
+
} catch (error) {
|
|
501
|
+
console.error(chalk.red('Export failed:'), error instanceof Error ? error.message : String(error));
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
private getDefaultFilename(exportType: string): string {
|
|
506
|
+
const timestamp = new Date().toISOString().slice(0, 19).replace(/:/g, '-');
|
|
507
|
+
const baseName = `dir-analysis-${timestamp}`;
|
|
508
|
+
|
|
509
|
+
switch (exportType) {
|
|
510
|
+
case 'csv':
|
|
511
|
+
return `${baseName}.csv`;
|
|
512
|
+
case 'csv_large':
|
|
513
|
+
return `${baseName}-large-files.csv`;
|
|
514
|
+
case 'csv_duplicates':
|
|
515
|
+
return `${baseName}-duplicates.csv`;
|
|
516
|
+
case 'json':
|
|
517
|
+
return `${baseName}.json`;
|
|
518
|
+
default:
|
|
519
|
+
return `${baseName}.txt`;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
private async advancedOptions(): Promise<void> {
|
|
524
|
+
const { option } = await inquirer.prompt([
|
|
525
|
+
{
|
|
526
|
+
type: 'list',
|
|
527
|
+
name: 'option',
|
|
528
|
+
message: 'Advanced Options:',
|
|
529
|
+
choices: [
|
|
530
|
+
{ name: 'š Compare Two Directories', value: 'compare' },
|
|
531
|
+
{ name: 'āļø Settings', value: 'settings' },
|
|
532
|
+
{ name: 'ā Help', value: 'help' },
|
|
533
|
+
{ name: 'š Back to Main Menu', value: 'back' }
|
|
534
|
+
]
|
|
535
|
+
}
|
|
536
|
+
]);
|
|
537
|
+
|
|
538
|
+
switch (option) {
|
|
539
|
+
case 'compare':
|
|
540
|
+
await this.comparDirectories();
|
|
541
|
+
break;
|
|
542
|
+
case 'settings':
|
|
543
|
+
await this.showSettings();
|
|
544
|
+
break;
|
|
545
|
+
case 'help':
|
|
546
|
+
this.showHelp();
|
|
547
|
+
break;
|
|
548
|
+
case 'back':
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
private async comparDirectories(): Promise<void> {
|
|
554
|
+
console.log(chalk.blue('\nš Directory Comparison'));
|
|
555
|
+
console.log(chalk.gray('Compare the current directory with another directory\n'));
|
|
556
|
+
|
|
557
|
+
const { otherPath } = await inquirer.prompt([
|
|
558
|
+
{
|
|
559
|
+
type: 'input',
|
|
560
|
+
name: 'otherPath',
|
|
561
|
+
message: 'Enter path to compare with:',
|
|
562
|
+
validate: async (input) => {
|
|
563
|
+
try {
|
|
564
|
+
const stats = await fs.stat(input);
|
|
565
|
+
return stats.isDirectory() ? true : 'Path is not a directory';
|
|
566
|
+
} catch {
|
|
567
|
+
return 'Path does not exist';
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
]);
|
|
572
|
+
|
|
573
|
+
console.log(chalk.blue('\nš Analyzing both directories...'));
|
|
574
|
+
const progressCallback = ProgressBar.createCallback(true);
|
|
575
|
+
|
|
576
|
+
const [result1, result2] = await Promise.all([
|
|
577
|
+
this.analyzer.analyze({
|
|
578
|
+
path: this.currentPath,
|
|
579
|
+
recursive: true,
|
|
580
|
+
excludePatterns: [],
|
|
581
|
+
topN: 10,
|
|
582
|
+
progressCallback
|
|
583
|
+
}),
|
|
584
|
+
this.analyzer.analyze({
|
|
585
|
+
path: otherPath,
|
|
586
|
+
recursive: true,
|
|
587
|
+
excludePatterns: [],
|
|
588
|
+
topN: 10,
|
|
589
|
+
progressCallback
|
|
590
|
+
})
|
|
591
|
+
]);
|
|
592
|
+
|
|
593
|
+
this.displayComparison(result1, result2);
|
|
594
|
+
console.log(chalk.gray('\nPress Enter to continue...'));
|
|
595
|
+
await inquirer.prompt([{ type: 'input', name: 'continue', message: '' }]);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
private displayComparison(result1: ExtendedAnalysisResult, result2: ExtendedAnalysisResult): void {
|
|
599
|
+
console.log(chalk.blue('\nš Directory Comparison Results:'));
|
|
600
|
+
console.log(chalk.cyan(`\nš Directory 1: ${result1.path}`));
|
|
601
|
+
console.log(` š¦ Size: ${formatSize(result1.totalSizeBytes)}`);
|
|
602
|
+
console.log(` š Folders: ${result1.folders}`);
|
|
603
|
+
console.log(` š Files: ${result1.files}`);
|
|
604
|
+
|
|
605
|
+
console.log(chalk.cyan(`\nš Directory 2: ${result2.path}`));
|
|
606
|
+
console.log(` š¦ Size: ${formatSize(result2.totalSizeBytes)}`);
|
|
607
|
+
console.log(` š Folders: ${result2.folders}`);
|
|
608
|
+
console.log(` š Files: ${result2.files}`);
|
|
609
|
+
|
|
610
|
+
console.log(chalk.yellow('\nš Comparison:'));
|
|
611
|
+
const sizeDiff = result1.totalSizeBytes - result2.totalSizeBytes;
|
|
612
|
+
const filesDiff = result1.files - result2.files;
|
|
613
|
+
const foldersDiff = result1.folders - result2.folders;
|
|
614
|
+
|
|
615
|
+
console.log(` š¦ Size difference: ${sizeDiff >= 0 ? '+' : ''}${formatSize(Math.abs(sizeDiff))} (${sizeDiff >= 0 ? 'Dir1 larger' : 'Dir2 larger'})`);
|
|
616
|
+
console.log(` š Files difference: ${filesDiff >= 0 ? '+' : ''}${Math.abs(filesDiff)} (${filesDiff >= 0 ? 'Dir1 more' : 'Dir2 more'})`);
|
|
617
|
+
console.log(` š Folders difference: ${foldersDiff >= 0 ? '+' : ''}${Math.abs(foldersDiff)} (${foldersDiff >= 0 ? 'Dir1 more' : 'Dir2 more'})`);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
private async showSettings(): Promise<void> {
|
|
621
|
+
console.log(chalk.blue('\nāļø Settings'));
|
|
622
|
+
console.log(chalk.gray('Settings are configured per analysis. No persistent settings available in this version.'));
|
|
623
|
+
console.log(chalk.gray('\nPress Enter to continue...'));
|
|
624
|
+
await inquirer.prompt([{ type: 'input', name: 'continue', message: '' }]);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
private showHelp(): void {
|
|
628
|
+
console.log(chalk.blue('\nā Help - Interactive Directory Analyzer'));
|
|
629
|
+
console.log(chalk.gray('ā'.repeat(50)));
|
|
630
|
+
console.log(chalk.yellow('\nš Analysis Features:'));
|
|
631
|
+
console.log(' ⢠Recursive scanning of directories');
|
|
632
|
+
console.log(' ⢠File type classification (code, images, documents, etc.)');
|
|
633
|
+
console.log(' ⢠Large file detection with configurable thresholds');
|
|
634
|
+
console.log(' ⢠Duplicate file detection using MD5 hashing');
|
|
635
|
+
console.log(' ⢠Empty file detection');
|
|
636
|
+
console.log(' ⢠Tree view visualization');
|
|
637
|
+
console.log(' ⢠Top N largest files ranking');
|
|
638
|
+
|
|
639
|
+
console.log(chalk.yellow('\nš Filtering Options:'));
|
|
640
|
+
console.log(' ⢠Size filters (minimum/maximum file size)');
|
|
641
|
+
console.log(' ⢠Date filters (modification date range)');
|
|
642
|
+
console.log(' ⢠Exclude patterns (file/directory patterns)');
|
|
643
|
+
|
|
644
|
+
console.log(chalk.yellow('\nš¾ Export Options:'));
|
|
645
|
+
console.log(' ⢠CSV format (general, large files, duplicates)');
|
|
646
|
+
console.log(' ⢠JSON format (complete results)');
|
|
647
|
+
console.log(' ⢠Custom filename support');
|
|
648
|
+
|
|
649
|
+
console.log(chalk.yellow('\nš Advanced Features:'));
|
|
650
|
+
console.log(' ⢠Directory comparison');
|
|
651
|
+
console.log(' ⢠Interactive result browsing');
|
|
652
|
+
console.log(' ⢠Progress tracking for large analyses');
|
|
653
|
+
|
|
654
|
+
console.log(chalk.gray('\nPress Enter to continue...'));
|
|
655
|
+
}
|
|
656
|
+
}
|