UNPKG

smart-renamer

Version:

🚀 Intelligent file naming suggestions based on project-specific naming conventions. Interactive CLI tool that asks yes/no for each file renaming.

99 lines • 3.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigManager = void 0; const fs_1 = require("fs"); const path_1 = require("path"); class ConfigManager { configPath; defaultConfig = { convention: 'camelCase', files: ['*.ts', '*.js'], folders: 'kebab-case', exceptions: ['index', 'main', 'app'] }; constructor(projectRoot = process.cwd()) { this.configPath = (0, path_1.join)(projectRoot, 'naming.config'); } loadConfig() { if (!(0, fs_1.existsSync)(this.configPath)) { return this.defaultConfig; } try { const content = (0, fs_1.readFileSync)(this.configPath, 'utf-8'); return this.parseConfig(content); } catch (error) { console.warn('Failed to load naming.config, using defaults:', error); return this.defaultConfig; } } saveConfig(config) { try { const content = this.stringifyConfig(config); (0, fs_1.writeFileSync)(this.configPath, content, 'utf-8'); } catch (error) { throw new Error(`Failed to save naming.config: ${error}`); } } parseConfig(content) { const config = {}; const lines = content.split('\n'); let currentSection = ''; for (const line of lines) { const trimmed = line.trim(); if (trimmed.startsWith('[') && trimmed.endsWith(']')) { currentSection = trimmed.slice(1, -1); continue; } if (trimmed.includes('=') && currentSection === 'naming') { const [key, value] = trimmed.split('=').map(s => s.trim()); switch (key) { case 'convention': if (value && this.isValidConvention(value)) { config.convention = value; } break; case 'files': if (value) { config.files = value.split(',').map(s => s.trim()); } break; case 'folders': if (value && this.isValidConvention(value)) { config.folders = value; } break; case 'exceptions': if (value) { config.exceptions = value.split(',').map(s => s.trim()); } break; } } } return { ...this.defaultConfig, ...config }; } stringifyConfig(config) { return `[naming] convention=${config.convention} files=${config.files.join(',')} folders=${config.folders || 'kebab-case'} exceptions=${config.exceptions?.join(',') || ''} `; } isValidConvention(value) { const validConventions = [ 'camelCase', 'snake_case', 'kebab-case', 'PascalCase', 'UPPER_SNAKE_CASE' ]; return validConventions.includes(value); } configExists() { return (0, fs_1.existsSync)(this.configPath); } createDefaultConfig() { this.saveConfig(this.defaultConfig); } } exports.ConfigManager = ConfigManager; //# sourceMappingURL=config-manager.js.map