- syncGlob
- NotifyCallback
- CloseFunc
- copyFile
- copyDir
- remove
- TransformFunc
- isGlob
- resolveTarget
- ResolveTargetFunc
- sourcesBases
- trimQuotes
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, defaultfalse
)options.delete
bool? Whether to delete thetarget
's content initially. (optional, defaulttrue
)options.depth
bool? Chokidarsdepth
(If set, limits how many levels of subdirectories will be traversed). (optional, defaultInfinity
)options.transform
string? A module path resolved by node'srequire
. (optional, defaultfalse
)
notify
NotifyCallback? An optional notification callback.
Returns CloseFunc Returns a close function which cancels active promises and watch mode.
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
target
s contents. - mirror: Initial copy of all
sources
totarget
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.
A cleanup function which cancels all active promises and closes watch mode if enabled.
Type: function
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
Copy a directory from source
to target
(w/o contents).
Parameters
Returns Promise
Remove a file or directory.
Parameters
fileordir
string The file or directory to remove.
Returns Promise
A custom function which transforms a given file
contents and/or target
.
Type: function
Parameters
file
File A file object obtained byfs.readFile
.target
string The destination where to copy thisfile
.
Returns (File | {data: File, target: string}) Returns the transformed file
and/or renamed target
.
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.
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.
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 ofsource
andbases
.
Returns string Returns an expanded target
.
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
.
Trim quotes of a given string.
Parameters
str
string A string.
Returns string Returns str
, but trimmed from quotes like '
, "
.