'use strict';
// node v10.0.0
const fs = require('fs');
const path = require('path');
const paths = require('../../paths');
/**
* Recursively walk dir to retrieve all files
* @param {string} Directory where our files are located
* @return {[string]}
*/
const recursiveFileWalker = (dir) => {
let results = [];
// When fs.readdir() or fs.readdirSync() is called with the withFileTypes option set to true,
// the resulting array is filled with fs.Dirent objects, rather than strings or Buffers.
// https://nodejs.org/api/fs.html#fs_class_fs_dirent
// Added as of node v10.0.0
fs.readdirSync(dir, { withFileTypes: true }).forEach((file) => {
if (file.isDirectory()) {
results = [
...recursiveFileWalker(path.join(dir, file.name)),
...results,
];
}
else {
results.push(path.join(dir, file.name));
}
});
return results;
};
module.exports = recursiveFileWalker;