get-recursive-file-list.ts 977 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. items.forEach((item) => {
  8. if (ignore.includes(item)) {
  9. return;
  10. }
  11. // Check out if it's a directory or a file
  12. const isDir = statSync(`${path}/${item}`).isDirectory();
  13. if (isDir) {
  14. // If it's a directory, recursively call the method
  15. files.push(...getRecursiveFileList(`${path}/${item}`));
  16. } else {
  17. // If it's a file, add it to the array of files
  18. files.push(`${path}/${item}`);
  19. }
  20. });
  21. return files.filter((file) => {
  22. // Remove package.json from the root directory
  23. return path === '.' ? file !== './package.json' : true;
  24. });
  25. }