1
0
Fork 0
mirror of synced 2026-06-05 14:48:19 +00:00
test-reporter/src/input-providers/local-file-provider.ts
2026-03-02 14:28:52 +01:00

28 lines
753 B
TypeScript

import * as fs from 'fs'
import glob from 'fast-glob'
import {FileContent, InputProvider, ReportInput} from './input-provider.js'
import {listFiles} from '../utils/git.js'
export class LocalFileProvider implements InputProvider {
constructor(
readonly name: string,
readonly pattern: string[]
) {}
async load(): Promise<ReportInput> {
const result: FileContent[] = []
for (const pat of this.pattern) {
const paths = await glob(pat, {dot: true})
for (const file of paths) {
const content = await fs.promises.readFile(file, {encoding: 'utf8'})
result.push({file, content})
}
}
return {[this.name]: result}
}
async listTrackedFiles(): Promise<string[]> {
return listFiles()
}
}