UNPKG

crapifyme

Version:

Ultra-fast developer productivity CLI tools - remove comments, logs, and more

105 lines 3.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommentsProcessor = void 0; const tokenizer_1 = require("../../shared/tokenizer"); class CommentsProcessor { constructor(options = {}) { this.keepPatterns = options.keep || ['todo', 'fixme', 'hack', 'ts-ignore', 'eslint-disable']; this.preserveFramework = options.preserveFramework !== false; this.preserveDevelopment = options.preserveDevelopment !== false; this.preserveTooling = options.preserveTooling !== false; this.preserveDocumentation = options.preserveDocumentation !== false; } processFile(content) { const tokenizer = new tokenizer_1.SimpleTokenizer(); const tokens = tokenizer.tokenize(content); const result = []; let removed = 0; let preserved = 0; for (const token of tokens) { if (token.type === 'comment') { if (this.shouldPreserveComment(token.value)) { result.push(token.value); preserved++; } else { removed++; } } else { result.push(token.value); } } const processedContent = result.join(''); return { content: processedContent, modified: content !== processedContent, removed, preserved }; } shouldPreserveComment(comment) { const lowerComment = comment.toLowerCase(); for (const pattern of this.keepPatterns) { if (lowerComment.includes(pattern.toLowerCase())) { return true; } } if (this.preserveFramework) { const frameworkPatterns = [ '@vue', '@svelte', '@react', '@angular', 'typescript', 'webpack', '@ts-', 'vite' ]; for (const pattern of frameworkPatterns) { if (lowerComment.includes(pattern)) { return true; } } } if (this.preserveDevelopment) { const devPatterns = ['todo', 'fixme', 'hack', 'note', 'xxx', 'bug', 'warn']; for (const pattern of devPatterns) { if (lowerComment.includes(pattern)) { return true; } } } if (this.preserveTooling) { const toolingPatterns = [ 'eslint', 'prettier', 'ts-ignore', 'ts-nocheck', 'coverage', 'istanbul', '@ts-expect-error' ]; for (const pattern of toolingPatterns) { if (lowerComment.includes(pattern)) { return true; } } } if (this.preserveDocumentation) { if (comment.includes('/**') || comment.includes('@param') || comment.includes('@return') || comment.includes('@throws') || comment.includes('@author') || comment.includes('@since') || comment.includes('@example') || comment.includes('@see')) { return true; } } return false; } } exports.CommentsProcessor = CommentsProcessor; //# sourceMappingURL=logic.js.map