copy-newer
Copy newer files only.
Usage
API
const copyNewer =
copyNewer(pattern, dest, [opts])
Copies files to a destination directory.
pattern
: array|string - One or more glob patterns to select for the files to copy.dest
: string - The directory to copy to.opts
: object - Optional. Options to send directly toglob
.opts.interval
: number - Optional. The number of milliseconds to wait before a file is considered 'new'. Default: 1000opts.cwd
: string - Same as glob's. The current working directory in which to search. Defaults toprocess.cwd()
. (Included here because you'll most likely need it.)opts.verbose
: boolean - enable verbose logging to stdout. Defaults tofalse
: no output ever occurs.- Other options can be found on glob's documentation.
- Returns:
Promise
: Resolved when all file operations complete. Note: The resolved value is not empty, but it isn't useful either, for now. It's just an array of booleans that indicate whether each copy operation was done or skipped. For directories, a literal stringdir
will be represented in the output.
Note: fs.stat
has a millisecond resolution while fs.utimes
has a second resolution, hence the 1000 ms opts.interval
. While node.js stays this way, changing opts.interval
to a value lower than 1000 is not recommended.
CLI
copy-newer pattern dest [[--cwd] cwd]
Globs files with pattern
mounted on cwd
and copies them to dest
.
Example
Copy the contents of "folder1" to "folder2":
copy-newer --cwd folder1 ** folder2
Options
pattern
- (See API)dest
- (See API)cwd
- Setsopts.cwd
. (See API)-v
,--verbose
- Setsopts.verbose
(See API)
All options are passed-through to glob
via minimist, although only --cwd
will be officially supported. (The issue here is glob isn't a CLI in the first place. Again, if anyone wants to discuss, hit up on Github.)
copy-newer-dir dirtocopy parentdest [pattern]
Takes a directory dirtocopy
and copies it (and all of its contents) under parentdest
.
Options
dirtocopy
- The directory to copy.parentdest
- The directory to which to copy the directory and its contents.pattern
- Optional. The pattern to match files in the directory. Defaults to**
.-v
,--verbose
- setsopts.verbose
Again, all options are passed-through to glob
, except --cwd
won't have any effect.
Gotchas
Globbing directories won't copy their contents! You must glob their contents using **
.
Similar packages
License
MIT