| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- import fs from "fs/promises"
- import { join } from "path"
- import { fileExistsAtPath } from "../../utils/fs"
- import { GIT_DISABLED_SUFFIX } from "./constants"
- const getBuildArtifactPatterns = () => [
- ".gradle/",
- ".idea/",
- ".parcel-cache/",
- ".pytest_cache/",
- ".next/",
- ".nuxt/",
- ".sass-cache/",
- ".vs/",
- ".vscode/",
- "Pods/",
- "__pycache__/",
- "bin/",
- "build/",
- "bundle/",
- "coverage/",
- "deps/",
- "dist/",
- "env/",
- "node_modules/",
- "obj/",
- "out/",
- "pkg/",
- "pycache/",
- "target/dependency/",
- "temp/",
- "vendor/",
- "venv/",
- ]
- const getMediaFilePatterns = () => [
- "*.jpg",
- "*.jpeg",
- "*.png",
- "*.gif",
- "*.bmp",
- "*.ico",
- "*.webp",
- "*.tiff",
- "*.tif",
- "*.raw",
- "*.heic",
- "*.avif",
- "*.eps",
- "*.psd",
- "*.3gp",
- "*.aac",
- "*.aiff",
- "*.asf",
- "*.avi",
- "*.divx",
- "*.flac",
- "*.m4a",
- "*.m4v",
- "*.mkv",
- "*.mov",
- "*.mp3",
- "*.mp4",
- "*.mpeg",
- "*.mpg",
- "*.ogg",
- "*.opus",
- "*.rm",
- "*.rmvb",
- "*.vob",
- "*.wav",
- "*.webm",
- "*.wma",
- "*.wmv",
- ]
- const getCacheFilePatterns = () => [
- "*.DS_Store",
- "*.bak",
- "*.cache",
- "*.crdownload",
- "*.dmp",
- "*.dump",
- "*.eslintcache",
- "*.lock",
- "*.log",
- "*.old",
- "*.part",
- "*.partial",
- "*.pyc",
- "*.pyo",
- "*.stackdump",
- "*.swo",
- "*.swp",
- "*.temp",
- "*.tmp",
- "*.Thumbs.db",
- ]
- const getConfigFilePatterns = () => ["*.env*", "*.local", "*.development", "*.production"]
- const getLargeDataFilePatterns = () => [
- "*.zip",
- "*.tar",
- "*.gz",
- "*.rar",
- "*.7z",
- "*.iso",
- "*.bin",
- "*.exe",
- "*.dll",
- "*.so",
- "*.dylib",
- "*.dat",
- "*.dmg",
- "*.msi",
- ]
- const getDatabaseFilePatterns = () => [
- "*.arrow",
- "*.accdb",
- "*.aof",
- "*.avro",
- "*.bak",
- "*.bson",
- "*.csv",
- "*.db",
- "*.dbf",
- "*.dmp",
- "*.frm",
- "*.ibd",
- "*.mdb",
- "*.myd",
- "*.myi",
- "*.orc",
- "*.parquet",
- "*.pdb",
- "*.rdb",
- "*.sql",
- "*.sqlite",
- ]
- const getGeospatialPatterns = () => [
- "*.shp",
- "*.shx",
- "*.dbf",
- "*.prj",
- "*.sbn",
- "*.sbx",
- "*.shp.xml",
- "*.cpg",
- "*.gdb",
- "*.mdb",
- "*.gpkg",
- "*.kml",
- "*.kmz",
- "*.gml",
- "*.geojson",
- "*.dem",
- "*.asc",
- "*.img",
- "*.ecw",
- "*.las",
- "*.laz",
- "*.mxd",
- "*.qgs",
- "*.grd",
- "*.csv",
- "*.dwg",
- "*.dxf",
- ]
- const getLogFilePatterns = () => [
- "*.error",
- "*.log",
- "*.logs",
- "*.npm-debug.log*",
- "*.out",
- "*.stdout",
- "yarn-debug.log*",
- "yarn-error.log*",
- ]
- const getLfsPatterns = async (workspacePath: string) => {
- try {
- const attributesPath = join(workspacePath, ".gitattributes")
- if (await fileExistsAtPath(attributesPath)) {
- return (await fs.readFile(attributesPath, "utf8"))
- .split("\n")
- .filter((line) => line.includes("filter=lfs"))
- .map((line) => line.split(" ")[0].trim())
- }
- } catch (error) {}
- return []
- }
- export const getExcludePatterns = async (workspacePath: string) => [
- ".git/",
- `.git${GIT_DISABLED_SUFFIX}/`,
- ...getBuildArtifactPatterns(),
- ...getMediaFilePatterns(),
- ...getCacheFilePatterns(),
- ...getConfigFilePatterns(),
- ...getLargeDataFilePatterns(),
- ...getDatabaseFilePatterns(),
- ...getGeospatialPatterns(),
- ...getLogFilePatterns(),
- ...(await getLfsPatterns(workspacePath)),
- ]
|