copy-newer

2.1.2 • Public • Published

copy-newer

Copy newer files only.

npm Build Status Coverage Status Dependency Status devDependency Status node

Usage

API

const copyNewer = require('copy-newer')

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 to glob.
    • opts.interval: number - Optional. The number of milliseconds to wait before a file is considered 'new'. Default: 1000
    • opts.cwd: string - Same as glob's. The current working directory in which to search. Defaults to process.cwd(). (Included here because you'll most likely need it.)
    • opts.verbose: boolean - enable verbose logging to stdout. Defaults to false: 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 string dir 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 - Sets opts.cwd. (See API)
  • -v, --verbose - Sets opts.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 - sets opts.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

Package Sidebar

Install

npm i copy-newer

Weekly Downloads

54

Version

2.1.2

License

MIT

Last publish

Collaborators

  • seangenabe