Skip to content

Commit 9330e65

Browse files
authored
feat: GS Enhancement (#121)
* feat: GS Enhancement * fix
1 parent 0e89277 commit 9330e65

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

src/util/GS.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
import { GlobSync } from "glob";
21
import { filesystem } from "@discloudapp/gluegun";
2+
import { GlobSync } from "glob";
33
import { existsSync, readFileSync } from "node:fs";
44
import { blocked_files } from "./constants";
55

66
export class GS {
7-
found: string[];
8-
ignore: string[];
7+
found: string[] = [];
8+
ignore: string[] = [];
9+
ignoreFiles: string[] = [];
910

10-
constructor(public path = "**") {
11+
constructor(public path = "**", ignoreFileName?: string) {
1112
this.path = path = this.normalizePath(path);
1213

14+
if (ignoreFileName)
15+
this.ignoreFiles = this.findIgnoreFiles(ignoreFileName);
16+
1317
this.ignore = this.getDiscloudIgnore(path);
1418

1519
this.found = new GlobSync(path, {
1620
dot: true,
1721
ignore: this.ignore,
22+
windowsPathsNoEscape: true,
1823
}).found;
1924
}
2025

2126
getDiscloudIgnore(path: string) {
2227
return [
2328
...new Set(Object.values(blocked_files).flat()),
24-
...this.resolveIgnoreFile(".discloudignore"),
29+
...this.resolveIgnoreFile(this.ignoreFiles),
2530
]
2631
.map(a => [a, `${a}/**`, `**/${a}`, `**/${a}/**`, `${path}/${a}`, `${path}/${a}/**`]).flat();
2732
}
@@ -32,6 +37,17 @@ export class GS {
3237
return path;
3338
}
3439

40+
findIgnoreFiles(fileName: string, path = "**") {
41+
const regex = RegExp(`${fileName}$`);
42+
43+
const files = new GlobSync(path, {
44+
dot: true,
45+
windowsPathsNoEscape: true,
46+
});
47+
48+
return files.found.filter(f => regex.test(f));
49+
}
50+
3551
resolveIgnoreFile(ignoreFile: string | string[]) {
3652
if (Array.isArray(ignoreFile)) {
3753
const ignored = <string[]>[];
@@ -42,11 +58,12 @@ export class GS {
4258
return ignored;
4359
}
4460

45-
if (existsSync(ignoreFile))
46-
return readFileSync(ignoreFile, "utf8")
47-
.replace(/#[^\r?\n]+/g, "")
48-
.split(/\r?\n/)
49-
.filter(a => a);
61+
if (ignoreFile)
62+
if (existsSync(ignoreFile))
63+
return readFileSync(ignoreFile, "utf8")
64+
.replace(/#[^\r?\n]+/g, "")
65+
.split(/\r?\n/)
66+
.filter(a => a);
5067

5168
return [];
5269
}

src/util/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function objToString(obj: any, sep = ": "): string {
9797
export function arrayOfPathlikeProcessor(paths: string[], files: string[] = []) {
9898
if (!paths?.length) paths = ["**"];
9999
for (let i = 0; i < paths.length; i++)
100-
files.push(...new GS(normalizePathlike(paths[i])).found);
100+
files.push(...new GS(normalizePathlike(paths[i]), ".discloudignore").found);
101101
return files;
102102
}
103103

0 commit comments

Comments
 (0)