react-compress-dist
Version:
Easy way to compress your JS bundle when you compile build folder
31 lines (27 loc) • 828 B
text/typescript
const fs = require('fs');
const path = require('path');
interface FilesTypes {
dirPath: string,
arrayOfFiles: any,
filetypes:any,
file: any
}
const _getFiles = ({dirPath, arrayOfFiles, filetypes}:FilesTypes) => {
const files = fs.readdirSync(dirPath);
files.forEach(({file}:FilesTypes) => {
if (fs.statSync(dirPath + '/' + file).isDirectory()) {
arrayOfFiles = _getFiles(dirPath + '/' + file, arrayOfFiles, filetypes);
} else {
const filePath = path.join(dirPath, '/', file);
if (filetypes.includes(path.extname(filePath))) {
arrayOfFiles.push(filePath);
}
}
});
return arrayOfFiles;
};
const getFiles = ({dirPath, filetypes}:FilesTypes) => {
return _getFiles(dirPath, [], filetypes);
};
module.exports = getFiles;
export {}