export type FileVisitor = ( file: File, ) => boolean | void | Promise export interface File { readonly path: string readonly content: Promise readonly stats: Promise } export namespace File { export interface Stats { mode: number } } export interface Directory { readonly path: string dir(name: string): Promise file(name: string): Promise visit(visitor: FileVisitor): Promise } export interface Tree { // Read get(path: string): Promise getDir(path: string): Promise // Change file overwrite(path: string, content: Buffer | string, stat?: File.Stats): void // Structural changes create(path: string, content: Buffer | string, stat?: File.Stats): void delete(path: string): void move(from: string, to: string): void } export namespace Tree { export type Action = | OverwriteAction | CreateAction | DeleteAction | MoveAction export interface OverwriteAction { type: 'overwrite' path: string content?: Buffer stat?: File.Stats } export interface CreateAction { type: 'create' path: string content: Buffer stat?: File.Stats } export interface DeleteAction { type: 'delete' path: string } export interface MoveAction { type: 'move' from: string to: string } } export interface Host { readFile(path: string): Buffer | Promise readDir(path: string): Host.readDir.Resp | Promise readStat(path: string): Host.Stats | Promise writeFile( path: string, content?: Buffer, options?: Host.writeFile.Options, ): void | Promise moveFile(from: string, to: string): void | Promise deleteFile(path: string): void | Promise mkdirp(path: string): void | Promise } export namespace Host { export interface Stats extends File.Stats { isFile(): boolean isDirectory(): boolean } export namespace readDir { export interface Resp { files: string[] dirs: string[] } } export namespace writeFile { export interface Options { mode: number } } }