Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

cpr

davglass357.5kBSD-3-Clause3.0.1TypeScript support: included

cp -R

copy, recursive, cp -r, cp

readme

CPR (cp -R)

There are other modules out there that attempt this, but none did it the way I needed it to be done or they had issues and the author failed to fix them in a timely manner.

Install

npm install cpr

Build Status

Build Status

Usage

var cpr = require('cpr');
//or
var cpr = require('cpr').cpr; //Back compat

cpr('/path/from', '/path/to', {
    deleteFirst: true, //Delete "to" before
    overwrite: true, //If the file exists, overwrite it
    confirm: true //After the copy, stat all the copied files to make sure they are there
}, function(err, files) {
    //err - The error if any (err.list might be available with an array of errors for more detailed information)
    //files - List of files that we copied
});

cpr('/path/from', '/path/to', function(err, files) {
    //err - The error if any (err.list might be available with an array of errors for more detailed information)
    //      In the case of an error, cpr continues to copy files but returns this error object with all of the files that it failed to copy.
    //files - List of files that we copied
});

Options

All options default to false.

  • deleteFirst: Delete the to directory with rimraf
  • overwrite: If the destination exists, overwrite it
  • confirm: After the copy operation, stat all the files and report errors if any are missing
  • filter: RegExp or function to test each file against before copying

Filtering

If you give it a RegExp, it will use that to test the full absolute pathnames of the files and directories as they are being gathered. If any of them passes, it will not be copied. If you give it a function, it will use that with Array.filter on the list of full absolute pathnames of files and directories.

CLI

cpr can also be used from the command line which is useful for cross platform support.

Usage:

cpr <source> <destination> [options]

Copies files from source to destination.

Options:

  • -d, --delete-first: Delete the destination directory before copying.
  • -f <regex>, --filter <regex>: Filter out any items that match <regex>, a case-insensitive regex pattern.
  • -h, --help: Display this usage info.
  • -o, --overwrite: Overwrite the destination exists if it exists.
  • -v, --version: Display the cpr version.

Note that the CLI's filter option is simpler than the original NodeJS API, only accepting case-insensitive regular expression patterns and not functions.

cpr

changelog

Change Log

v3.0.1 (2017/10/31 15:12 +00:00)

  • 1c802c9 3.0.1 (@davglass)
  • 8d285b8 stablizing test (@davglass)
  • 55fa41d adding Dockerfile for testing (@davglass)
  • 008532b Dropping Node 4.x testing (@davglass)
  • 66108f7 changelog (@davglass)

v3.0.0 (2017/10/31 13:08 +00:00)

  • e3cd84b 3.0.0 (@davglass)
  • 17b0494 Manually porting #43 (@davglass)
  • #57 Fixing a race condition that can occur when a file has been read but the write buffer has not been flushed when copying a file. (#57) (@PlutoMatt)
  • #52 Amend filtering info for more clarity. (#52) (@jrpool)
  • b0e8f40 added node.js specific build info (@davglass)
  • 01efad1 added node.js specific build info (@davglass)
  • e2395ba added appveyor build config (@davglass)
  • #50 various changes (#50) (@stevenvachon)

v2.2.0 (2017/06/26 12:15 +00:00)

  • 4520872 2.2.0 (@davglass)
  • 0686492 changelog (@davglass)
  • #48 Various changes (#48) (@stevenvachon)
  • 724900c changelog (@davglass)

v2.1.0 (2017/05/29 12:56 +00:00)

  • 57e7c2e 2.1.0 (@davglass)
  • 8d3c003 [fixes #44] - don't error when no callback given (@davglass)
  • #40 Merge pull request #40 from oferh/cpr-typings (@oferh)
  • 55dc201 typings for cpr (@oferh)
  • #37 Merge pull request #37 from davglass/tests (@davglass)
  • b4f8c00 fixing travis build (@davglass)
  • 0f2c8b5 changelog (@davglass)

v2.0.2 (2016/12/21 18:14 +00:00)

  • 3fa3af0 2.0.2 (@davglass)
  • #36 Merge pull request #36 from benelliott/master (@benelliott)
  • 0443d51 Include CLI documentation in README.md, update usage.txt to reflect CLI filter option (@benelliott)
  • 14233bf Added changelog [skip ci] (@davglass)

v2.0.1 (2016/12/19 15:47 +00:00)

  • 4225fc6 2.0.1 (@davglass)
  • f05f162 added contrib (@davglass)
  • #35 Merge pull request #35 from benelliott/master (@benelliott)
  • 42e6e57 Add simplified version of filter functionality to CLI (@benelliott)
  • 6ad0023 [Fixes #31] Added changelog [skip ci] (@davglass)

v2.0.0 (2016/08/15 19:08 +00:00)

  • #30 Merge pull request #30 from stevenvachon/master (@stevenvachon)
  • e7c4db1 2.0.0 (@stevenvachon)
  • 82dcffb added cli options (@stevenvachon)
  • bf5d1ce adding new collaborator to package.json (@davglass)

v1.1.2 (2016/06/09 14:26 +00:00)

  • 0584e7c 1.1.2 (@davglass)
  • #29 Merge pull request #29 from happinov/single-file-copy (@happinov)
  • a79261d Fixed behavior in case to has trailing path separator. (@ldanet)
  • 128570a Single files are now copied without creating a directory first. (@ldanet)

v1.1.1 (2016/04/06 13:51 +00:00)

  • e691cb3 1.1.1 (@davglass)
  • e4bddfd updating tests again (@davglass)
  • bf0f79a fix tests based on npm 3.x file tree (@davglass)
  • f9c413e removed the .x from the node version in travis.yml (@davglass)
  • eb41753 adding more node.js testing support (@davglass)
  • de5cf9a more test tweaks (@davglass)
  • ac6cccf Fixes #25 - Catching errors on copy properly (@davglass)
  • a4153f7 converting tests from vows to mocha (@davglass)

v1.1.0 (2016/04/05 13:35 +00:00)

  • 5435bd2 1.1.0 (@davglass)
  • bb2912d added contributor (@davglass)
  • 1173261 fixed formatting and added -v/--version (@davglass)
  • 135216e Add basic CLI support (@jonnyreeves)

v1.0.0 (2015/11/12 19:58 +00:00)

  • 2d04135 1.0.0 (@davglass)
  • 1390d0a updated travis with iojs (@davglass)
  • 2cd5e30 Fixes #18 - Fixed overwrite deleting existing directories (@davglass)

v0.4.3 (2015/10/11 21:01 +00:00)

  • 845fb91 0.4.3 (@davglass)
  • f005cd2 added contributors (@davglass)
  • #17 Merge pull request #17 from soyuka/fix-overwrite-singlefile (@soyuka)
  • 3adcb91 Fix single file copy override (@soyuka)
  • #16 Merge pull request #16 from fresheneesz/patch-2 (@fresheneesz)
  • fa3cd1d Clarifications for issue #s 14 and 15 (@fresheneesz)

v0.4.2 (2015/09/12 14:43 +00:00)

v0.4.1 (2015/05/26 15:48 +00:00)

  • 28ffe61 0.4.1 (@davglass)
  • #12 Merge pull request #12 from pdehaan/patch-1 (@pdehaan)
  • 6ddd41f Update license attribute (@pdehaan)

v0.4.0 (2015/02/15 14:15 +00:00)

  • 98acf24 0.4.0 (@davglass)
  • 294c282 fixed #11 - empty directory handling (@davglass)

v0.3.3 (2015/02/10 14:58 +00:00)

  • 76b0f84 0.3.3 (@davglass)
  • 892dff3 updated deps (@davglass)
  • 20ab662 updated dev deps (@davglass)
  • bbdfb84 adding image [fixes #10] (@davglass)

v0.3.2 (2014/07/02 20:53 +00:00)

  • c805cc8 0.3.2 (@davglass)
  • 4a2621f Forgot to put the err in the callback.. (@davglass)

v0.3.1 (2014/07/02 01:10 +00:00)

  • 1daff3c 0.3.1 (@davglass)
  • 74dff64 confirm: fixed missing files return when confirm is set and filter is not. Fixes #8 (@davglass)

v0.3.0 (2014/06/30 14:12 +00:00)

  • 888ccb4 0.3.0 (@davglass)
  • 5d139cb Added support for single file copy and more tests. (@davglass)

v0.2.0 (2014/05/13 13:33 +00:00)

  • aceebf3 0.2.0 (@davglass)
  • 810d399 Updated deps and travis config (@davglass)
  • c48d130 Standardise errors to be more node-like. (@satazor)
  • #4 Merge pull request #4 from brianloveswords/readme-readability (@brianloveswords)
  • 540ba2d Update readme with syntax highlighting. (@brianloveswords)
  • 09e943d Updated Travis Config (@davglass)
  • cec7c7b Updated Travis Config (@davglass)
  • b586aa2 Version Bump and added @tmpvar credits (@davglass)
  • 4068056 Updated README (@davglass)
  • 6deea9a Adding in back compat support (@davglass)
  • 3a902c8 export a single function (@tmpvar)
  • e5a81af Version Bump (@davglass)
  • 4c1ff62 Updated test logic (@davglass)
  • 263d3d5 Fixed issue with empty dirs (@davglass)
  • b1f824c Fixed issue with Node 9 (@davglass)
  • 7959698 Updated dep (@davglass)
  • fc0cd12 Forgot license requirements (@davglass)
  • 1f99e6f Version Bump (@davglass)
  • 915ded3 And added a test for it (@davglass)
  • 2cbeb0e Fixed issue with cpr is given a file instead of a dir (@davglass)
  • f3d6302 Added windows-test script to test on windows without istanbul (@davglass)
  • f80e3c6 Added missing toHash entries for dirs, mkdirp must handle this under the hood better on unix than windows (@davglass)
  • e7b5ddb Version Bump (@davglass)
  • f3e5ea4 Removed unusable error throw (@davglass)
  • c400722 New Istanbul for coverage (@davglass)
  • 8a603cd MOAR TEST COVERAGE (@davglass)
  • dfd4cc1 Fixed a few issues that appeared with more tests (@davglass)
  • 5ceed85 Version Bump (@davglass)
  • 3380124 Added istanbul code coverage reporting (@davglass)
  • 861fece Added coverage report to gitignore (@davglass)
  • 9e6c416 Break reference with options object for multi processing (@davglass)
  • d225a74 Version Bump (@davglass)
  • aa4d814 Added check for string before stat (@davglass)
  • 1c91806 Added Travis Build Button (@davglass)
  • f4b748b Version Bump (@davglass)
  • 2dd7815 Added jshint to devDeps for Travis (@davglass)
  • 2504edd MOAR TESTS (@davglass)
  • b960127 Trap EMFILE on both read and write streams (@davglass)
  • 0d2bc35 Added test suite (@davglass)
  • 5758825 Fixed some callback issues (@davglass)
  • 4e186f7 Added test dirs to ignore (@davglass)
  • 6c709f1 Initial Commit (@davglass)