Skip to content

Latest commit

 

History

History
160 lines (96 loc) · 7.6 KB

API.md

File metadata and controls

160 lines (96 loc) · 7.6 KB

Table of Contents

syncGlob

Synchronise files, directories and/or glob patterns, optionally watching for changes.

Parameters

  • sources (string | Array<string>) A list of files, directories and/or glob patterns.
  • target string The destination directory.
  • options Object? An optional configuration object.
    • options.watch bool? Enable or disable watch mode. (optional, default false)
    • options.delete bool? Whether to delete the target's content initially. (optional, default true)
    • options.depth bool? Chokidars depth (If set, limits how many levels of subdirectories will be traversed). (optional, default Infinity)
    • options.transform string? A module path resolved by node's require. (optional, default false)
  • notify NotifyCallback? An optional notification callback.

Returns CloseFunc Returns a close function which cancels active promises and watch mode.

NotifyCallback

This callback notifies you about various steps, like:

  • copy: File or directory has been copied to target.
  • remove: File or directory has been removed from target.
  • no-delete: No initial deletion of targets contents.
  • mirror: Initial copy of all sources to target done.
  • watch: Watch mode has started.
  • error: Any error which may occurred during program execution.

Type: Function

Parameters

  • type string The type of notification.
  • args ...any Event specific variadic arguments.

CloseFunc

A cleanup function which cancels all active promises and closes watch mode if enabled.

Type: function

copyFile

Copy file from source to target.

Parameters

  • source string A file to be copied.
  • target string A destination path where to copy.
  • transform TransformFunc? Optional transformation function.

Returns Promise

copyDir

Copy a directory from source to target (w/o contents).

Parameters

  • source string A directory to be copied.
  • target string A destination path where to copy.

Returns Promise

remove

Remove a file or directory.

Parameters

  • fileordir string The file or directory to remove.

Returns Promise

TransformFunc

A custom function which transforms a given file contents and/or target.

Type: function

Parameters

  • file File A file object obtained by fs.readFile.
  • target string The destination where to copy this file.

Returns (File | {data: File, target: string}) Returns the transformed file and/or renamed target.

isGlob

Determines whether a provided string contains a glob pattern.

Parameters

  • str string The string to test for glob patterns.

Returns number Returns the index of the first glob pattern or -1 if it is not a glob.

resolveTarget

Determines the target structure by resolving a given source against a list of base paths.

Parameters

Returns ResolveTargetFunc Returns an source to target resolving function.

ResolveTargetFunc

A function which resolves a given source to a given target based on list of base paths.

Type: function

Parameters

  • source string A file or dir to be resolved against a list of base paths.
  • target string A destination folder where to append the diff of source and bases.

Returns string Returns an expanded target.

sourcesBases

Determine the base paths of sources like:

  • files: foo/bar.txt -> foo
  • directories: foo/bar/ -> foo/bar
  • globs: foo/* -> foo

Parameters

Returns Array<string> Returns the base paths of sources.

trimQuotes

Trim quotes of a given string.

Parameters

Returns string Returns str, but trimmed from quotes like ', ".