get-recursive-file-list.ts 983 B

12345678910111213141516171819202122232425262728
  1. // Point method at path and return a list of all the files in the directory recursively
  2. import { readdirSync, statSync } from 'node:fs';
  3. export function getRecursiveFileList(path: string): string[] {
  4. const ignore = ['.git', '.github', '.idea', '.next', '.vercel', '.vscode', 'coverage', 'dist', 'node_modules'];
  5. const files: string[] = [];
  6. const items = readdirSync(path);
  7. for (const item of items) {
  8. if (!ignore.includes(item)) {
  9. // Check out if it's a directory or a file
  10. const isDir = statSync(`${path}/${item}`).isDirectory();
  11. if (isDir) {
  12. // If it's a directory, recursively call the method
  13. files.push(...getRecursiveFileList(`${path}/${item}`));
  14. } else {
  15. // If it's a file, add it to the array of files
  16. files.push(`${path}/${item}`);
  17. }
  18. }
  19. }
  20. return files.filter((file) => {
  21. // Remove package.json from the root directory
  22. return path === '.' ? file !== './package.json' : true;
  23. });
  24. }