Added folder exclusion feature and .gitattributes
This commit is contained in:
parent
7ff71ffbd9
commit
2f1807812d
3 changed files with 48 additions and 6 deletions
26
.gitattributes
vendored
Normal file
26
.gitattributes
vendored
Normal 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
|
|
@ -28,6 +28,11 @@ export const config = convict({
|
||||||
env: "BB_SCRIPTFOLDER",
|
env: "BB_SCRIPTFOLDER",
|
||||||
arg: "folder",
|
arg: "folder",
|
||||||
},
|
},
|
||||||
|
exclude: {
|
||||||
|
doc: "A list of folders or files to exclude from the sync.",
|
||||||
|
format: "Array",
|
||||||
|
default: [".vscode", ".idea", ".github"],
|
||||||
|
},
|
||||||
quiet: {
|
quiet: {
|
||||||
doc: "Log less internal events to stdout.",
|
doc: "Log less internal events to stdout.",
|
||||||
format: "Boolean",
|
format: "Boolean",
|
||||||
|
|
|
@ -5,12 +5,7 @@ import { mkdir } from "fs/promises";
|
||||||
import { resolve } from "path";
|
import { resolve } from "path";
|
||||||
import type { Signal } from "signal-js";
|
import type { Signal } from "signal-js";
|
||||||
import type { File } from "./interfaces";
|
import type { File } from "./interfaces";
|
||||||
|
import fs from "node:fs";
|
||||||
function fileFilter(file: File) {
|
|
||||||
if (config.get("allowedFiletypes").some((extension) => file.path.endsWith(extension))) return true;
|
|
||||||
if (file.stats.isDirectory()) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isError(err: unknown): err is NodeJS.ErrnoException {
|
function isError(err: unknown): err is NodeJS.ErrnoException {
|
||||||
return (err as NodeJS.ErrnoException).code !== undefined;
|
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({
|
const watch = new CheapWatch({
|
||||||
dir: config.get("scriptsFolder"),
|
dir: config.get("scriptsFolder"),
|
||||||
filter: fileFilter,
|
filter: fileFilter,
|
||||||
|
|
Loading…
Add table
Reference in a new issue