Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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