-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFileInput.ts
43 lines (34 loc) · 1.2 KB
/
FileInput.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { readFile } from '../utils/fs'
import { basename } from 'node:path'
import { getTrackOptions, Input, TrackOptions } from './Input'
export class FileInput implements Input {
public readonly fileName: string
constructor(
private readonly path: string,
private trackOptions: TrackOptions = getTrackOptions()
) {
this.fileName = basename(path)
}
public async read(_n = 1): Promise<string[]> {
const buffer = await readFile(this.path)
return [buffer.toString('utf8')]
}
public set fileExtensions(next: RegExp) {
this.trackOptions = { ...this.trackOptions, fileExtensions: next }
}
public set testFilePattern(next: RegExp) {
this.trackOptions = { ...this.trackOptions, testFilePattern: next }
}
public set configurationFilePattern(next: RegExp) {
this.trackOptions = { ...this.trackOptions, configurationFilePattern: next }
}
public get isTestFile(): boolean {
return this.trackOptions.testFilePattern.test(this.path)
}
public get isConfigurationFile(): boolean {
return this.trackOptions.configurationFilePattern.test(this.path)
}
public get hasExpectedExtension(): boolean {
return this.trackOptions.fileExtensions.test(this.fileName)
}
}