npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

recursive-copy

v2.0.14

Published

Simple, flexible file copy utility

Downloads

686,785

Readme

recursive-copy

npm version Stability Build Status Windows Build Status

Simple, flexible file copy utility

Features

  • Recursively copy whole directory hierarchies
  • Choose which files are copied by passing a filter function, regular expression or glob
  • Rename files dynamically, including changing the output path
  • Transform file contents using streams
  • Choose whether to overwrite existing files
  • Choose whether to copy system files
  • Filters out junk files by default
  • Uses graceful-fs and mkdirp to avoid filesystem errors
  • Emits start, finish and error events for each file that is processed
  • Optional promise-based interface

Examples

Node-style callback interface

var copy = require('recursive-copy');

copy('src', 'dest', function(error, results) {
	if (error) {
		console.error('Copy failed: ' + error);
	} else {
		console.info('Copied ' + results.length + ' files');
	}
});

Promise interface

var copy = require('recursive-copy');

copy('src', 'dest')
	.then(function(results) {
		console.info('Copied ' + results.length + ' files');
	})
	.catch(function(error) {
		console.error('Copy failed: ' + error);
	});

ES2015+ usage

import copy from 'recursive-copy';

try {
	const results = await copy('src', 'dest');
	console.info('Copied ' + results.length + ' files');
} catch (error) {
	console.error('Copy failed: ' + error);
}

Advanced options

var copy = require('recursive-copy');

var path = require('path');
var through = require('through2');

var options = {
	overwrite: true,
	expand: true,
	dot: true,
	junk: true,
	filter: [
		'**/*',
		'!.htpasswd'
	],
	rename: function(filePath) {
		return filePath + '.orig';
	},
	transform: function(src, dest, stats) {
		if (path.extname(src) !== '.txt') { return null; }
		return through(function(chunk, enc, done)  {
			var output = chunk.toString().toUpperCase();
			done(null, output);
		});
	}
};

copy('src', 'dest', options)
	.on(copy.events.COPY_FILE_START, function(copyOperation) {
		console.info('Copying file ' + copyOperation.src + '...');
	})
	.on(copy.events.COPY_FILE_COMPLETE, function(copyOperation) {
		console.info('Copied to ' + copyOperation.dest);
	})
	.on(copy.events.ERROR, function(error, copyOperation) {
		console.error('Unable to copy ' + copyOperation.dest);
	})
	.then(function(results) {
		console.info(results.length + ' file(s) copied');
	})
	.catch(function(error) {
		return console.error('Copy failed: ' + error);
	});

Usage

copy(src, dest, [options], [callback])

Recursively copy files and folders from src to dest

Arguments:

| Name | Type | Required | Default | Description | | ---- | ---- | -------- | ------- | ----------- | | src | string | Yes | N/A | Source file/folder path | | dest | string | Yes | N/A | Destination file/folder path | | options.overwrite | boolean | No | false | Whether to overwrite destination files | | options.expand | boolean | No | false | Whether to expand symbolic links | | options.dot | boolean | No | false | Whether to copy files beginning with a . | | options.junk | boolean | No | false | Whether to copy OS junk files (e.g. .DS_Store, Thumbs.db) | | options.filter | function, RegExp, string, array | No | null | Filter function / regular expression / glob that determines which files to copy (uses maximatch) | | options.rename | function | No | null | Function that maps source paths to destination paths | | options.transform | function | No | null | Function that returns a transform stream used to modify file contents | | options.results | boolean | No | true | Whether to return an array of copy results | | options.concurrency | number | No | 255 | Maximum number of simultaneous copy operations | | options.debug | boolean | No | false | Whether to log debug information | | callback | function | No | null | Callback, invoked on success/failure |

Returns:

Promise<Array> Promise, fulfilled with array of copy results:

[
	{
		"src": "/path/to/src",
		"dest": "/path/to/dest",
		"stats": <Stats>
	},
	{
		"src": "/path/to/src/file.txt",
		"dest": "/path/to/dest/file.txt",
		"stats": <Stats>
	},
	{
		"src": "/path/to/src/subfolder",
		"dest": "/path/to/dest/subfolder",
		"stats": <Stats>
	},
	{
		"src": "/path/to/src/subfolder/nested.txt",
		"dest": "/path/to/dest/subfolder/nested.txt",
		"stats": <Stats>
	}
]

Events

The value returned by the copy function implements the EventEmitter interface, and emits the following events:

| Event | Handler signature | | ----- | ----------------- | | copy.events.ERROR | function(error, ErrorInfo) | | copy.events.COMPLETE | function(Array<CopyOperation>) | | copy.events.CREATE_DIRECTORY_START | function(CopyOperation) | | copy.events.CREATE_DIRECTORY_ERROR | function(error, CopyOperation) | | copy.events.CREATE_DIRECTORY_COMPLETE | function(CopyOperation) | | copy.events.CREATE_SYMLINK_START | function(CopyOperation) | | copy.events.CREATE_SYMLINK_ERROR | function(error, CopyOperation) | | copy.events.CREATE_SYMLINK_COMPLETE | function(CopyOperation) | | copy.events.COPY_FILE_START | function(CopyOperation) | | copy.events.COPY_FILE_ERROR | function(error, CopyOperation) | | copy.events.COPY_FILE_COMPLETE | function(CopyOperation) |

...where the types referred to in the handler signature are as follows:

ErrorInfo

| Property | Type | Description | | -------- | ---- | ----------- | | src | string | Source path of the file/folder/symlink that failed to copy | | dest | string | Destination path of the file/folder/symlink that failed to copy |

CopyOperation

| Property | Type | Description | | -------- | ---- | ----------- | | src | string | Source path of the relevant file/folder/symlink | | dest | string | Destination path of the relevant file/folder/symlink | | stats | fs.Stats | Stats for the relevant file/folder/symlink |