diff --git a/src/index.ts b/src/index.ts index 42553f0..d894ce2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import path, { posix } from 'node:path'; import { type Options as FdirOptions, fdir } from 'fdir'; import picomatch from 'picomatch'; -import { escapePath, getPartialMatcher, isDynamicPattern, log, splitPattern } from './utils.ts'; +import { coloredLog, escapePath, getPartialMatcher, isDynamicPattern, log, splitPattern } from './utils.ts'; const PARENT_DIRECTORY = /^(\/?\.\.)+/; const ESCAPING_BACKSLASHES = /\\(?=[()[\]{}!*+?@|])/g; @@ -207,7 +207,7 @@ function crawl(options: GlobOptions, cwd: string, sync: boolean) { const matches = matcher(path); if (matches) { - log(`matched ${path}`); + coloredLog(`matched ${path}`, 'matched'); } return matches; @@ -220,9 +220,9 @@ function crawl(options: GlobOptions, cwd: string, sync: boolean) { const skipped = (relativePath !== '.' && !partialMatcher(relativePath)) || ignore(relativePath); if (skipped) { - log(`skipped ${p}`); + coloredLog(`skipped ${p}`, 'skipped'); } else { - log(`crawling ${p}`); + coloredLog(`crawling ${p}`, 'crawling'); } return skipped; diff --git a/src/utils.ts b/src/utils.ts index cdf6ecd..17a0a75 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -150,4 +150,17 @@ export function isDynamicPattern(pattern: string, options?: { caseSensitiveMatch export function log(...tasks: unknown[]): void { console.log(`[tinyglobby ${new Date().toLocaleTimeString('es')}]`, ...tasks); } +export function coloredLog(msg: string, type: 'matched' | 'skipped' | 'crawling'): void { + const colors = { + matched: '\x1b[32m', + skipped: '\x1b[90m', + crawling: '\x1b[34m' + }; + const color = colors[type as keyof typeof colors]; + if (color) { + console.log(`${color}%s\x1b[0m`, `[tinyglobby ${new Date().toLocaleTimeString('es')}]${msg}`); + return; + } + console.log(`[tinyglobby ${new Date().toLocaleTimeString('es')}]`, msg); +} // #endregion