diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..198198d --- /dev/null +++ b/.gitattributes @@ -0,0 +1,26 @@ +# js / ts files +*.js text +*.ts text + +# Config text files +*.jsonc text +*.json text +*.yml text +.eslintrc text +.eslintignore text +.gitignore text +.gitattributes text +.prettierignore text +.prettierrc text + +# Standard text files +*.txt text +*.md text +*.sh text eol=lf +*.bat text eol=crlf +LICENSE text + +# Binary files +*.gif binary +*.jpg binary +*.png binary diff --git a/src/config.ts b/src/config.ts index 46e9b1b..396f8a3 100644 --- a/src/config.ts +++ b/src/config.ts @@ -28,6 +28,11 @@ export const config = convict({ env: "BB_SCRIPTFOLDER", arg: "folder", }, + exclude: { + doc: "A list of folders or files to exclude from the sync.", + format: "Array", + default: [".vscode", ".idea", ".github"], + }, quiet: { doc: "Log less internal events to stdout.", format: "Boolean", diff --git a/src/fileWatch.ts b/src/fileWatch.ts index a505560..1dccca9 100644 --- a/src/fileWatch.ts +++ b/src/fileWatch.ts @@ -5,12 +5,7 @@ import { mkdir } from "fs/promises"; import { resolve } from "path"; import type { Signal } from "signal-js"; import type { File } from "./interfaces"; - -function fileFilter(file: File) { - if (config.get("allowedFiletypes").some((extension) => file.path.endsWith(extension))) return true; - if (file.stats.isDirectory()) return true; - return false; -} +import fs from "node:fs"; function isError(err: unknown): err is NodeJS.ErrnoException { return (err as NodeJS.ErrnoException).code !== undefined; @@ -26,6 +21,22 @@ export async function setupWatch(signaller: Signal) { } } + const excludedPaths = config.get("exclude").map((path) => resolve(path)); + const excludedFiles = new Set(); + for (const excludedPath of excludedPaths) { + for (const excludedFile of fs.readdirSync(excludedPath)) { + excludedFiles.add(excludedFile); + } + } + + const fileFilter = (file: File) => { + // If the file is excluded, skip all other checks and ignore it. + if (excludedFiles.has(file.path)) return false; + if (config.get("allowedFiletypes").some((extension) => file.path.endsWith(extension))) return true; + if (file.stats.isDirectory()) return true; + return false; + }; + const watch = new CheapWatch({ dir: config.get("scriptsFolder"), filter: fileFilter,