Last active
November 4, 2020 14:14
-
-
Save AlecTaylor/f3f221b4fb86b4375650 to your computer and use it in GitHub Desktop.
Extension of http://stackoverflow.com/a/33685480 to support excludeDirs array argument
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
import * as fs from 'fs'; | |
import * as path from 'path'; | |
// Trivial to extend with `includeDirs`, just follow same pattern | |
function fileList(dir, excludeDirs?) { | |
return fs.readdirSync(dir).reduce(function (list, file) { | |
const name = path.join(dir, file); | |
if (fs.statSync(name).isDirectory()) { | |
if (excludeDirs && excludeDirs.length) { | |
excludeDirs = excludeDirs.map(d => path.normalize(d)); | |
const idx = name.indexOf(path.sep); | |
const directory = name.slice(0, idx === -1 ? name.length : idx); | |
if (excludeDirs.indexOf(directory) !== -1) | |
return list; | |
} | |
return list.concat(fileList(name, excludeDirs)); | |
} | |
return list.concat([name]); | |
}, []); | |
} | |
console.log(fileList('.', ['node_modules', 'typings', 'bower_components'])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, i have problem with this man:
I don't understand why, i'm using it in webpack with babel, webpack.config.babel.js, using this:
.babelrc
Thank's