Created
October 17, 2024 21:00
-
-
Save aleclarson/b8000869315d95bd3fafee016ae20b2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { RealFileSystemHost } from '@ts-morph/common' | |
import { JumpgenFS } from 'jumpgen' | |
export class JumpgenFileSystemHost extends RealFileSystemHost { | |
constructor(private fs: JumpgenFS) { | |
super() | |
} | |
readFile(filePath: string, encoding?: string): Promise<string> { | |
notImplemented('readFile') | |
} | |
readFileSync(filePath: string, encoding: string = 'utf8'): string { | |
return this.fs.read(filePath, encoding as BufferEncoding) | |
} | |
readDirSync(dirPath: string): RuntimeDirEntry[] { | |
return this.fs.list(dirPath, { withFileTypes: true }).map(file => ({ | |
name: file.name, | |
get isFile() { | |
return file.isFile() | |
}, | |
get isDirectory() { | |
return file.isDirectory() | |
}, | |
get isSymlink() { | |
return file.isSymlink() | |
}, | |
})) | |
} | |
directoryExists(dirPath: string): Promise<boolean> { | |
notImplemented('directoryExists') | |
} | |
directoryExistsSync(dirPath: string): boolean { | |
return this.fs.directoryExists(dirPath) | |
} | |
glob(patterns: ReadonlyArray<string>): Promise<string[]> { | |
notImplemented('glob') | |
} | |
globSync(patterns: ReadonlyArray<string>): string[] { | |
return this.fs.scan(patterns) | |
} | |
fileExists(filePath: string): Promise<boolean> { | |
notImplemented('fileExists') | |
} | |
fileExistsSync(filePath: string): boolean { | |
return this.fs.fileExists(filePath) | |
} | |
} | |
function notImplemented(methodName: string): never { | |
throw new Error(`Method '${methodName}' is not implemented.`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment