Created
August 14, 2015 23:15
-
-
Save Istar-Eldritch/8b40105ba2eac5826da5 to your computer and use it in GitHub Desktop.
Recursively read all files deep into a file path.
This file contains hidden or 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 R from 'ramda'; | |
import fs from 'fs'; | |
import path from 'path'; | |
function deepRead(dir) { | |
function isFile(f) { | |
return fs.statSync(f).isFile(); | |
} | |
function concatToPath(f) { | |
return path.join(dir,f); | |
} | |
// Read all files in a folder. | |
let reader = R.pipe( | |
fs.readdirSync, | |
R.map(concatToPath), | |
R.map(R.ifElse(isFile, require, deepRead)), | |
R.flatten | |
); | |
let files = reader(dir); | |
return files; | |
} | |
export default deepRead; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment