UNPKG

dir-analysis-tool

Version:

A comprehensive cross-platform CLI tool for advanced directory analysis with file classification, duplicate detection, large file identification, interactive mode, HTML reports, and multiple export formats. Perfect for disk cleanup, storage audits, and pr

94 lines 3.5 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigManager = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); const CONFIG_FILE_NAMES = ['.dir-analyzer.json', 'dir-analyzer.config.json']; class ConfigManager { config = {}; async loadConfig(searchPath = process.cwd()) { const configPath = await this.findConfigFile(searchPath); if (configPath) { try { const configContent = await fs.promises.readFile(configPath, 'utf-8'); this.config = JSON.parse(configContent); console.log(`Loaded configuration from: ${configPath}`); } catch (error) { console.warn(`Warning: Failed to load config file '${configPath}': ${error}`); } } return this.config; } async findConfigFile(searchPath) { let currentPath = searchPath; while (currentPath !== path.dirname(currentPath)) { for (const configName of CONFIG_FILE_NAMES) { const configPath = path.join(currentPath, configName); try { await fs.promises.access(configPath, fs.constants.F_OK); return configPath; } catch { // File doesn't exist, continue searching } } currentPath = path.dirname(currentPath); } return null; } getConfig() { return this.config; } mergeWithCliOptions(cliOptions) { return { ...this.config, ...Object.fromEntries(Object.entries(cliOptions).filter(([_, value]) => value !== undefined)) }; } static getDefaultConfig() { return { excludePatterns: [], largeSizeThreshold: 100 * 1024 * 1024, enableDuplicateDetection: false, enableProgressBar: true, outputFormat: 'table', maxDepth: -1 }; } } exports.ConfigManager = ConfigManager; //# sourceMappingURL=config.js.map