UNPKG

smart-renamer

Version:

🚀 Intelligent file and code naming suggestions based on project-specific naming conventions. Interactive CLI tool with AST-based code analysis for variables, functions, components, and more.

134 lines • 4.59 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.FileWatcher = void 0; const chokidar = __importStar(require("chokidar")); const events_1 = require("events"); const path_1 = require("path"); class FileWatcher extends events_1.EventEmitter { watcher = null; watchPath; filePatterns; constructor(watchPath = process.cwd(), filePatterns = ['**/*']) { super(); this.watchPath = watchPath; this.filePatterns = filePatterns; } start() { if (this.watcher) { console.warn('File watcher is already running'); return; } this.watcher = chokidar.watch(this.filePatterns, { cwd: this.watchPath, ignored: [ '**/node_modules/**', '**/dist/**', '**/build/**', '**/.git/**', '**/.*', '**/CLAUDE.md' ], ignoreInitial: true, persistent: true }); this.watcher .on('add', (path) => this.handleFileEvent('add', path)) .on('addDir', (path) => this.handleFileEvent('addDir', path)) .on('change', (path) => this.handleFileEvent('change', path)) .on('unlink', (path) => this.handleFileEvent('unlink', path)) .on('unlinkDir', (path) => this.handleFileEvent('unlinkDir', path)) .on('error', (error) => this.emit('error', error)) .on('ready', () => { console.log('File watcher is ready and monitoring for changes...'); this.emit('ready'); }); } stop() { if (this.watcher) { this.watcher.close(); this.watcher = null; console.log('File watcher stopped'); this.emit('stopped'); } } isWatching() { return this.watcher !== null; } handleFileEvent(event, filePath) { const fileInfo = { name: (0, path_1.basename)(filePath), path: filePath, extension: (0, path_1.extname)(filePath), isDirectory: event === 'addDir' || event === 'unlinkDir' }; this.emit('fileEvent', { event, fileInfo, timestamp: new Date() }); switch (event) { case 'add': this.emit('fileAdded', fileInfo); break; case 'addDir': this.emit('directoryAdded', fileInfo); break; case 'change': this.emit('fileChanged', fileInfo); break; case 'unlink': this.emit('fileRemoved', fileInfo); break; case 'unlinkDir': this.emit('directoryRemoved', fileInfo); break; } } setFilePatterns(patterns) { this.filePatterns = patterns; if (this.watcher) { this.stop(); this.start(); } } getWatchedPaths() { if (!this.watcher) return []; return this.watcher.getWatched(); } } exports.FileWatcher = FileWatcher; //# sourceMappingURL=file-watcher.js.map