dir-analysis-tool 1.0.1 → 1.0.2

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