https://github.com/seangenabe/copy-newer
Copy newer files only.
https://github.com/seangenabe/copy-newer
cli filesystem glob newer newer-files
Last synced: 6 days ago
JSON representation
Copy newer files only.
- Host: GitHub
- URL: https://github.com/seangenabe/copy-newer
- Owner: seangenabe
- License: mit
- Created: 2015-09-16T11:49:36.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-05-09T13:17:31.000Z (over 8 years ago)
- Last Synced: 2025-09-27T07:23:07.249Z (13 days ago)
- Topics: cli, filesystem, glob, newer, newer-files
- Language: JavaScript
- Size: 19.5 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# copy-newer
Copy newer files only.
[](https://www.npmjs.com/package/copy-newer)
[](https://travis-ci.org/seangenabe/copy-newer)
[](https://coveralls.io/github/seangenabe/copy-newer?branch=master)
[](https://david-dm.org/seangenabe/copy-newer)
[](https://david-dm.org/seangenabe/copy-newer#info=devDependencies)
[](https://nodejs.org/en/download/)## Usage
### API
```javascript
const copyNewer = require('copy-newer')
```### copyNewer(pattern, dest, [opts])
Copies files to a destination directory.
* `pattern`: array|string - One or more [glob patterns](https://github.com/isaacs/minimatch#usage) 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](https://github.com/isaacs/minimatch)'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":
```bash
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
* [gulp-newer](https://www.npmjs.com/package/gulp-newer)
* [grunt-newer](https://www.npmjs.com/package/grunt-newer)## License
MIT