Created
February 9, 2019 19:02
-
-
Save warmbowski/dde917a43b925a5dec41ef5cde8d29fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const relative = require('path').relative; | |
const resolve = require('path').resolve; | |
const glob = require('glob'); | |
const minimatch = require("minimatch"); | |
require("core-js"); | |
const rootURI = './'; | |
const includes = ['./examples/**/*.{ts,tsx}']; | |
const excludes = ['**/build/**', '**/*.d.ts']; | |
function allFiles() { | |
return includes | |
.flatMap(include => | |
glob.sync(include, { cwd: rootURI, absolute: true }) | |
) | |
.filter( | |
filePath => | |
!excludes.some(exclude => | |
minimatch(relative(rootURI, filePath), exclude) | |
) | |
) | |
}; | |
function includesFile(filePath) { | |
filePath = relative(rootURI, filePath); | |
return ( | |
includes.some(include => minimatch(filePath, include)) && | |
!excludes.some(exclude => minimatch(filePath, exclude)) | |
); | |
}; | |
function includesFileImproved(filePath) { | |
return allFiles().includes(filePath); | |
}; | |
console.log('allFiles:', allFiles()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment