/// import { Stats } from 'fs'; import * as fsx from 'fs-extra'; export declare type Tree = Tree.Read; export declare namespace Tree { type Read = Read.Node; namespace Read { type Node = FileContent | Object | FileSystemRepresentation.Symlink | Other; type FileContent = string; interface Object { [name: string]: Node; } } type Write = Write.Node; namespace Write { type Node = FileContent | Function | FileSystemRepresentation | Object; type FileContent = Read.FileContent | Buffer; type Function = (name: string, param: CreateSecondParam) => Promise | void; interface Object { [name: string]: Node; } } } export interface CreateSecondParam { readonly create: CreateSecondParam.CreateFunc; } export declare namespace CreateSecondParam { type CreateFunc = (tree: Tree.Write, container: string) => Promise; } export interface NestedReadOptions { readonly stat?: NestedReadOptions.StatFunc; readonly filter?: NestedReadOptions.Filter; readonly onerror?: NestedReadOptions.ErrorHandler; readonly onunknown?: NestedReadOptions.Unknown; } export declare namespace NestedReadOptions { type StatFunc = utils.StatFunc; type Filter = (param: Filter.Param) => boolean; type ErrorHandler = (error: Error) => Y; type Unknown = (param: Unknown.Param) => Y; namespace Unknown { interface Param { readonly name: string; readonly stats: Stats; } } namespace Filter { interface Param { readonly container: Param.Container; readonly item: Param.Item; } namespace Param { interface Container { readonly name: string; readonly stats: Stats; } interface Item { readonly name: string; } } } } export declare namespace Traverse { interface Options { readonly deep?: Options.DeepFunc; readonly level?: Options.Level; readonly stat?: Options.StatFunc; } namespace Options { type DeepFunc = (x: DeepFunc.Param) => DeepFunc.Result; namespace DeepFunc { interface Param { readonly container: string; readonly item: string; readonly path: string; readonly stats: fsx.Stats; readonly level: Level; } type Result = boolean; } type Level = number; type StatFunc = utils.StatFunc; } type Result = Promise; namespace Result { type Item = Options.DeepFunc.Param; type Value = ReadonlyArray; } } /** * This class allows to extends `fsTreeUtils.create`'s functionality. * * This class is an abstract class that is meant to be extended upon, * don't instantiated this class directly! */ export declare abstract class FileSystemRepresentation { /** * Turn `FileSystemRepresentation` object into a real filesystem entity. * @param target Name of filesystem entity that needs to be created or written upon. * @param param An object contains `create` function * @returns Undefined or promise of undefined. */ abstract write(target: string, param: CreateSecondParam): Promise | void; } export declare namespace FileSystemRepresentation { /** * Represents a file. */ class File extends FileSystemRepresentation { private readonly content; /** * @param content A string of Buffer which is content of represented file. */ constructor(content: File.Content); write(filename: string): Promise; } namespace File { type Content = Tree.Write.FileContent; } /** * Represent a directory. */ class Directory extends FileSystemRepresentation { private readonly content; /** * @param content An object whose every property represent a child item of represented directory. */ constructor(content?: Directory.Content | null); write(dirname: string, { create }: CreateSecondParam): Promise; } namespace Directory { type Content = Tree.Write.Object; } /** * Represents a symbolic link */ class Symlink extends FileSystemRepresentation { private readonly linkTarget; private readonly type?; /** * @param linkTarget Where symlink points to. * * 🗈 Relative to the represented symlink. * @param options Optional. * * Property `type`: Optional. Either 'file', 'dir' or 'junction'. Only matters in Windows. * @see https://nodejs.org/api/fs.html#fs_fs_symlink_target_path_type_callback */ constructor(linkTarget: string, options?: Symlink.Options); write(linkName: string): Promise; } namespace Symlink { interface Options { readonly type?: Options.Type; } namespace Options { type Type = 'dir' | 'file' | 'junction'; } } /** * Use this to copy files and/or clone directories. */ class Clone extends FileSystemRepresentation { private readonly source; private readonly options?; /** * @param source Path to source. * @param options Options to pass to [`fsExtra.copy`](https://git.io/vh3WC). */ constructor(source: string, options?: Clone.Options); write(destination: string): Promise; } namespace Clone { type Options = fsx.CopyOptions; } } export declare namespace utils { type StatFunc = (name: string) => Promise | Stats; }