Skip to content

Instantly share code, notes, and snippets.

@Istar-Eldritch
Created August 14, 2015 23:15
Show Gist options
  • Save Istar-Eldritch/8b40105ba2eac5826da5 to your computer and use it in GitHub Desktop.
Save Istar-Eldritch/8b40105ba2eac5826da5 to your computer and use it in GitHub Desktop.
Recursively read all files deep into a file path.
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