Skip to content

Instantly share code, notes, and snippets.

@maciejcieslar
Last active November 9, 2018 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maciejcieslar/1c1f79d5778af4c2ee17927de769cea3 to your computer and use it in GitHub Desktop.
Save maciejcieslar/1c1f79d5778af4c2ee17927de769cea3 to your computer and use it in GitHub Desktop.
const isInDirectory = (directories: string[]) => (filePath: string) =>
directories.some(filePath.startsWith.bind(filePath))
const isExpectedExtension = (extensions: string[]) => (extension: string) =>
extensions.some(is(extension))
// ...
const shouldPathBeIgnored = isInDirectory(ignoredDirectories)
const shouldPathBeWatched = isInDirectory(watchedDirectories)
const shouldExtensionBeWatched = isExpectedExtension(extensions)
// ...
fromEvent(chokidar.watch(process.cwd()), 'all').pipe(
// ...
filter(
({ filePath, extension }) =>
(shouldWatchEveryDirectory || shouldPathBeWatched(filePath)) &&
(shouldWatchEveryExtension || shouldExtensionBeWatched(extension)) &&
not(shouldPathBeIgnored(filePath)),
),
// ...
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment