excludes.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import fs from "fs/promises"
  2. import { join } from "path"
  3. import { fileExistsAtPath } from "../../utils/fs"
  4. import { GIT_DISABLED_SUFFIX } from "./constants"
  5. const getBuildArtifactPatterns = () => [
  6. ".gradle/",
  7. ".idea/",
  8. ".parcel-cache/",
  9. ".pytest_cache/",
  10. ".next/",
  11. ".nuxt/",
  12. ".sass-cache/",
  13. ".vs/",
  14. ".vscode/",
  15. "Pods/",
  16. "__pycache__/",
  17. "bin/",
  18. "build/",
  19. "bundle/",
  20. "coverage/",
  21. "deps/",
  22. "dist/",
  23. "env/",
  24. "node_modules/",
  25. "obj/",
  26. "out/",
  27. "pkg/",
  28. "pycache/",
  29. "target/dependency/",
  30. "temp/",
  31. "vendor/",
  32. "venv/",
  33. ]
  34. const getMediaFilePatterns = () => [
  35. "*.jpg",
  36. "*.jpeg",
  37. "*.png",
  38. "*.gif",
  39. "*.bmp",
  40. "*.ico",
  41. "*.webp",
  42. "*.tiff",
  43. "*.tif",
  44. "*.raw",
  45. "*.heic",
  46. "*.avif",
  47. "*.eps",
  48. "*.psd",
  49. "*.3gp",
  50. "*.aac",
  51. "*.aiff",
  52. "*.asf",
  53. "*.avi",
  54. "*.divx",
  55. "*.flac",
  56. "*.m4a",
  57. "*.m4v",
  58. "*.mkv",
  59. "*.mov",
  60. "*.mp3",
  61. "*.mp4",
  62. "*.mpeg",
  63. "*.mpg",
  64. "*.ogg",
  65. "*.opus",
  66. "*.rm",
  67. "*.rmvb",
  68. "*.vob",
  69. "*.wav",
  70. "*.webm",
  71. "*.wma",
  72. "*.wmv",
  73. ]
  74. const getCacheFilePatterns = () => [
  75. "*.DS_Store",
  76. "*.bak",
  77. "*.cache",
  78. "*.crdownload",
  79. "*.dmp",
  80. "*.dump",
  81. "*.eslintcache",
  82. "*.lock",
  83. "*.log",
  84. "*.old",
  85. "*.part",
  86. "*.partial",
  87. "*.pyc",
  88. "*.pyo",
  89. "*.stackdump",
  90. "*.swo",
  91. "*.swp",
  92. "*.temp",
  93. "*.tmp",
  94. "*.Thumbs.db",
  95. ]
  96. const getConfigFilePatterns = () => ["*.env*", "*.local", "*.development", "*.production"]
  97. const getLargeDataFilePatterns = () => [
  98. "*.zip",
  99. "*.tar",
  100. "*.gz",
  101. "*.rar",
  102. "*.7z",
  103. "*.iso",
  104. "*.bin",
  105. "*.exe",
  106. "*.dll",
  107. "*.so",
  108. "*.dylib",
  109. "*.dat",
  110. "*.dmg",
  111. "*.msi",
  112. ]
  113. const getDatabaseFilePatterns = () => [
  114. "*.arrow",
  115. "*.accdb",
  116. "*.aof",
  117. "*.avro",
  118. "*.bak",
  119. "*.bson",
  120. "*.csv",
  121. "*.db",
  122. "*.dbf",
  123. "*.dmp",
  124. "*.frm",
  125. "*.ibd",
  126. "*.mdb",
  127. "*.myd",
  128. "*.myi",
  129. "*.orc",
  130. "*.parquet",
  131. "*.pdb",
  132. "*.rdb",
  133. "*.sql",
  134. "*.sqlite",
  135. ]
  136. const getGeospatialPatterns = () => [
  137. "*.shp",
  138. "*.shx",
  139. "*.dbf",
  140. "*.prj",
  141. "*.sbn",
  142. "*.sbx",
  143. "*.shp.xml",
  144. "*.cpg",
  145. "*.gdb",
  146. "*.mdb",
  147. "*.gpkg",
  148. "*.kml",
  149. "*.kmz",
  150. "*.gml",
  151. "*.geojson",
  152. "*.dem",
  153. "*.asc",
  154. "*.img",
  155. "*.ecw",
  156. "*.las",
  157. "*.laz",
  158. "*.mxd",
  159. "*.qgs",
  160. "*.grd",
  161. "*.csv",
  162. "*.dwg",
  163. "*.dxf",
  164. ]
  165. const getLogFilePatterns = () => [
  166. "*.error",
  167. "*.log",
  168. "*.logs",
  169. "*.npm-debug.log*",
  170. "*.out",
  171. "*.stdout",
  172. "yarn-debug.log*",
  173. "yarn-error.log*",
  174. ]
  175. const getLfsPatterns = async (workspacePath: string) => {
  176. try {
  177. const attributesPath = join(workspacePath, ".gitattributes")
  178. if (await fileExistsAtPath(attributesPath)) {
  179. return (await fs.readFile(attributesPath, "utf8"))
  180. .split("\n")
  181. .filter((line) => line.includes("filter=lfs"))
  182. .map((line) => line.split(" ")[0].trim())
  183. }
  184. } catch (error) {}
  185. return []
  186. }
  187. export const getExcludePatterns = async (workspacePath: string) => [
  188. ".git/",
  189. `.git${GIT_DISABLED_SUFFIX}/`,
  190. ...getBuildArtifactPatterns(),
  191. ...getMediaFilePatterns(),
  192. ...getCacheFilePatterns(),
  193. ...getConfigFilePatterns(),
  194. ...getLargeDataFilePatterns(),
  195. ...getDatabaseFilePatterns(),
  196. ...getGeospatialPatterns(),
  197. ...getLogFilePatterns(),
  198. ...(await getLfsPatterns(workspacePath)),
  199. ]