UNPKG

crapifyme

Version:

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

101 lines 3.69 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.findFiles = findFiles; exports.readFile = readFile; exports.writeFile = writeFile; exports.getFileExtension = getFileExtension; exports.showBanner = showBanner; exports.showComplete = showComplete; exports.resolvePath = resolvePath; exports.createFilePatterns = createFilePatterns; exports.detectVersionControl = detectVersionControl; const fs_1 = __importDefault(require("fs")); const promises_1 = __importDefault(require("fs/promises")); const glob_1 = require("glob"); const path_1 = __importDefault(require("path")); const ignore_patterns_1 = require("./ignore-patterns"); async function findFiles(patterns, exclude = []) { const allFiles = []; const ignorePatterns = (0, ignore_patterns_1.getIgnorePatterns)(exclude); for (const pattern of patterns) { const files = await (0, glob_1.glob)(pattern, { ignore: ignorePatterns }); allFiles.push(...files); } return [...new Set(allFiles)]; } async function readFile(filePath) { return promises_1.default.readFile(filePath, 'utf-8'); } async function writeFile(filePath, content) { await promises_1.default.writeFile(filePath, content, 'utf-8'); } function getFileExtension(filePath) { return path_1.default.extname(filePath).slice(1); } function showBanner() { console.log('█▀▀ █▀█ ▄▀█ █▀█ █ █▀▀ █▄█'); console.log('█▄▄ █▀▄ █▀█ █▀▀ █ █▀░ ░█░'); console.log(''); } function showComplete() { console.log(''); console.log('█▀▀ █▀█ █▀▄▀█ █▀█ █░░ █▀▀ ▀█▀ █▀▀'); console.log('█▄▄ █▄█ █░▀░█ █▀▀ █▄▄ ██▄ ░█░ ██▄'); console.log(''); } function resolvePath(inputPath) { if (path_1.default.isAbsolute(inputPath)) { return inputPath; } return path_1.default.resolve(process.cwd(), inputPath); } function createFilePatterns(paths, extensions) { return paths.map(p => { const resolved = resolvePath(p); if (p.includes('*')) return resolved; try { const stat = fs_1.default.statSync(resolved); if (stat.isFile()) return resolved; if (stat.isDirectory()) { return `${resolved}/**/*.{${extensions.join(',')}}`; } } catch { } return `${resolved}/**/*.{${extensions.join(',')}}`; }); } function detectVersionControl(startPath = process.cwd()) { const vcsMarkers = [ { name: 'git', marker: '.git' }, { name: 'svn', marker: '.svn' }, { name: 'hg', marker: '.hg' }, { name: 'bzr', marker: '.bzr' } ]; let currentPath = path_1.default.resolve(startPath); const rootPath = path_1.default.parse(currentPath).root; while (currentPath !== rootPath) { for (const vcs of vcsMarkers) { const vcsPath = path_1.default.join(currentPath, vcs.marker); try { if (fs_1.default.existsSync(vcsPath)) { return { detected: true, type: vcs.name, path: currentPath }; } } catch { } } currentPath = path_1.default.dirname(currentPath); } return { detected: false }; } //# sourceMappingURL=file-utils.js.map