UNPKG

diginext-utils

Version:
33 lines (32 loc) 1.11 kB
import fs from "fs"; import path from "path"; export default function getAllFiles(dirPath, skipDotStart) { // const list = []; const files = fs.readdirSync(dirPath); files.forEach(function (file) { if (!/^(node_modules|_next|\.next|\.git)/.test(file)) { if (skipDotStart) { if (!/^\..*/.test(file)) { const newPath = path.join(dirPath, "/", file).replace(/\\/g, "/"); if (fs.statSync(newPath).isDirectory()) { list.push(...getAllFiles(newPath)); } else { list.push(newPath); } } } else { const newPath = path.join(dirPath, "/", file).replace(/\\/g, "/"); if (fs.statSync(newPath).isDirectory()) { list.push(...getAllFiles(newPath)); } else { list.push(newPath); } } } }); return list; }