-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitignore.ts
28 lines (25 loc) · 862 Bytes
/
gitignore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { readFileSync } from "fs";
import { join } from "path";
import { directoryExists } from "./index";
export const ignore = (file: string, path: string, ignores: Array<string>) => {
const ignored: Array<string> = ignores.filter(
(ignoreFile: string): boolean => {
return file.endsWith(ignoreFile.slice(0, -1));
}
);
return ignored.length == 0;
};
const parseGitignore = (content: string): Array<string> => {
return content.split("\n").filter((element: string) => {
return element.length != 0 && element.charAt(0) != "#";
});
};
export const gitignore = (path: string): Array<string> => {
const file: string = join(path, ".gitignore");
const exists: boolean = directoryExists(file, false);
if (!exists) {
return [];
}
const files: Array<string> = parseGitignore(readFileSync(file).toString());
return files;
};