Interface FileModule

{@link http://gruntjs.com/api/grunt.file}

Index

Properties

Methods

Properties

public defaultEncoding: string

Set this property to change the default encoding used by all grunt.file methods. Defaults to 'utf8'.

If you do have to change this value, it's recommended that you change it as early as possible inside your Gruntfile.

public findup: any

public glob: any

public minimatch: any

Methods

public arePathsEquivalent(path: string, append?: Array<string>): boolean

Do all the specified paths refer to the same path?

Parameters

  • path: string
  • append?: Array<string> optional

Returns

boolean

public copy(srcpath: string, destpath: string)

Copy a source file to a destination path, creating intermediate directories if necessary.

Parameters

  • srcpath: string
  • destpath: string

public copy(srcpath: string, destpath: string, options: IFileWriteStringOption)

Parameters

public copy(srcpath: string, destpath: string, options: IFileWriteBufferOption)

Parameters

public delete(filepath: string, options?: { force?: boolean; }): boolean

Delete the specified filepath. Will delete files and folders recursively.

Parameters

  • filepath: string
  • options?: { force?: boolean; } optional

Returns

boolean

true if the files could be deleted, otherwise false.

public doesPathContain(ancestorPath: string, decendantPaths: Array<string>): boolean

Are all descendant path(s) contained within the specified ancestor path?

Parameters

  • ancestorPath: string
  • decendantPaths: Array<string>

Returns

boolean

public exists(path: string, append?: Array<string>): boolean

Does the given path exist?

Parameters

  • path: string
  • append?: Array<string> optional

Returns

boolean

public expand(patterns: Array<string>): Array<string>

Return a unique array of all file or directory paths that match the given globbing pattern(s). This method accepts either comma separated globbing patterns or an array of globbing patterns. Paths matching patterns that begin with ! will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant.

File paths are relative to the Gruntfile unless the current working directory is changed with grunt.file.setBase or the --base command-line option.

Parameters

  • patterns: Array<string>

Returns

Array<string>

public expand(options: IFilesConfig, patterns: Array<string>): Array<string>

Parameters

Returns

Array<string>

public expandMapping(patterns: Array<string>, dest: string, options: IExpandedFilesConfig): IFileMap[]

Returns an array of src-dest file mapping objects. For each source file matched by a specified pattern, join that file path to the specified dest. This file path may be flattened or renamed, depending on the options specified.

see

FileModule.expand method documentation for an explanation of how the patterns and options arguments may be specified.

Parameters

Returns

IFileMap[]

public isDir(path: string, append?: Array<string>): boolean

Is the given path a symbolic link?

Parameters

  • path: string
  • append?: Array<string> optional

Returns

boolean

public isFile(path: string, append?: Array<string>): boolean

Is the given path a file?

Parameters

  • path: string
  • append?: Array<string> optional

Returns

boolean

public isLink(path: string, append?: Array<string>): boolean

Is the given path a symbolic link?

Parameters

  • path: string
  • append?: Array<string> optional

Returns

boolean

public isMatch(pattern: string, filepath: string): boolean

This method contains the same signature and logic as the grunt.file.match method, but simply returns true if any files were matched, otherwise false.

see

FileModule.match

Parameters

  • pattern: string
  • filepath: string

Returns

boolean

public isMatch(pattern: string, filepaths: Array<string>): boolean

Parameters

  • pattern: string
  • filepaths: Array<string>

Returns

boolean

public isMatch(patterns: Array<string>, filepath: string): boolean

Parameters

  • patterns: Array<string>
  • filepath: string

Returns

boolean

public isMatch(patterns: Array<string>, filepaths: Array<string>): boolean

Parameters

  • patterns: Array<string>
  • filepaths: Array<string>

Returns

boolean

public isMatch(options: IMinimatchOptions, pattern: string, filepath: string): boolean

Parameters

Returns

boolean

public isMatch(options: IMinimatchOptions, pattern: string, filepaths: Array<string>): boolean

Parameters

Returns

boolean

public isMatch(options: IMinimatchOptions, patterns: Array<string>, filepath: string): boolean

Parameters

Returns

boolean

public isMatch(options: IMinimatchOptions, patterns: Array<string>, filepaths: Array<string>): boolean

Parameters

Returns

boolean

public isPathAbsolute(path: string, append?: Array<string>): boolean

Is a given file path absolute?

Parameters

  • path: string
  • append?: Array<string> optional

Returns

boolean

public isPathCwd(path: string, append?: Array<string>): boolean

Is a given file path the current working directory (CWD)?

Parameters

  • path: string
  • append?: Array<string> optional

Returns

boolean

public match(pattern: string, filepath: string): Array<string>

Match one or more globbing patterns against one or more file paths. Returns a uniqued array of all file paths that match any of the specified globbing patterns. Both the patterns and filepaths argument can be a single string or array of strings. Paths matching patterns that begin with ! will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant.

Parameters

  • pattern: string
  • filepath: string

Returns

Array<string>

public match(pattern: string, filepaths: Array<string>): Array<string>

Parameters

  • pattern: string
  • filepaths: Array<string>

Returns

Array<string>

public match(patterns: Array<string>, filepath: string): Array<string>

Parameters

  • patterns: Array<string>
  • filepath: string

Returns

Array<string>

public match(patterns: Array<string>, filepaths: Array<string>): Array<string>

Parameters

  • patterns: Array<string>
  • filepaths: Array<string>

Returns

Array<string>

public match(options: IMinimatchOptions, pattern: string, filepath: string): Array<string>

Parameters

Returns

Array<string>

public match(options: IMinimatchOptions, pattern: string, filepaths: Array<string>): Array<string>

Parameters

Returns

Array<string>

public match(options: IMinimatchOptions, patterns: Array<string>, filepath: string): Array<string>

Parameters

Returns

Array<string>

public match(options: IMinimatchOptions, patterns: Array<string>, filepaths: Array<string>): Array<string>

Parameters

Returns

Array<string>

public mkdir(dirpath: string, mode?: string)

Works like mkdir -p. Create a directory along with any intermediate directories. If mode isn't specified, it defaults to 0777 & (~process.umask()).

Parameters

  • dirpath: string
  • mode?: string optional

public read(filepath: string): string

Read and return a file's contents. Returns a string, unless options.encoding is null in which case it returns a Buffer.

Parameters

  • filepath: string

Returns

string

public read(filepath: string, options: IFileEncodedOption): Buffer

Parameters

Returns

Buffer

public readJSON(filepath: string): any

Read a file's contents, parsing the data as JSON and returning the result.

see

FileModule.read for a list of supported options.

Parameters

  • filepath: string

Returns

any

public readJSON(filepath: string, options: IFileEncodedOption): Buffer

Parameters

Returns

Buffer

public readYAML(filepath: string): any

Read a file's contents, parsing the data as YAML and returning the result.

see

FileModule.read for a list of supported options.

Parameters

  • filepath: string

Returns

any

public readYAML(filepath: string, options: IFileEncodedOption): Buffer

Parameters

Returns

Buffer

public recurse(rootdir: string, callback: (abspath: string, rootdir: string, subdir: string, filename: string) => void)

Recurse into a directory, executing callback for each file.

Callback args: abspath - The full path to the current file, which is nothing more than the rootdir + subdir + filename arguments, joined. rootdir - The root director, as originally specified. subdir - The current file's directory, relative to rootdir. filename - The filename of the current file, without any directory parts.

Parameters

  • rootdir: string
  • callback: (abspath: string, rootdir: string, subdir: string, filename: string) => void

public setBase(path: string, append?: Array<string>)

Change grunt's current working directory (CWD). By default, all file paths are relative to the Gruntfile. This works just like the --base command-line option.

Parameters

  • path: string
  • append?: Array<string> optional

public write(filepath: string, contents: string, options?: IFileEncodedOption)

Write the specified contents to a file, creating intermediate directories if necessary. Strings will be encoded using the specified character encoding, Buffers will be written to disk as-specified.

Parameters

  • filepath: string
  • contents: string

    If contents is a Buffer, encoding is ignored.

  • options?: IFileEncodedOption optional

    If an encoding is not specified, default to grunt.file.defaultEncoding.

public write(filepath: string, contents: Buffer)

Parameters

  • filepath: string
  • contents: Buffer