Added folder exclusion feature and .gitattributes

This commit is contained in:
david 2023-04-11 12:12:34 +10:00
parent 7ff71ffbd9
commit 2f1807812d
3 changed files with 48 additions and 6 deletions

26
.gitattributes vendored Normal file
View file

@ -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

View file

@ -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",

View file

@ -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<string>();
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,