https://github.com/morganconrad/metalsmith-cp-r
A Metalsmith plugin to copy files recursively.
https://github.com/morganconrad/metalsmith-cp-r
copy metalsmith metalsmith-plugin
Last synced: 3 months ago
JSON representation
A Metalsmith plugin to copy files recursively.
- Host: GitHub
- URL: https://github.com/morganconrad/metalsmith-cp-r
- Owner: MorganConrad
- License: mit
- Created: 2016-12-08T22:16:16.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T12:27:10.000Z (over 2 years ago)
- Last Synced: 2025-07-06T14:02:59.348Z (4 months ago)
- Topics: copy, metalsmith, metalsmith-plugin
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](http://travis-ci.org/MorganConrad/metalsmith-cp-r)
[](https://github.com/MorganConrad/metalsmith-cp-r)
[](https://www.npmjs.org/package/metalsmith-cp-r)
[](https://snyk.io/test/github/morganconrad/metalsmith-cp-r)
# metalsmith-cp-r
A [Metalsmith](http://www.metalsmith.io/) plugin to copy files recursively. Similar to [metalsmith-assets](https://www.npmjs.com/package/metalsmith-assets) but:
* cp-r has minimal dependencies (only debug)
* cp-r offers several additional options and controls
### Usage
Install as usual, `npm install metalsmith-cp-r`.
Javascript: `use(metalsmith-cp-r(options))`
CLI: You'll lose a few options since you can't pass functions.
#### Options
**from**: the _contents_ of this directory, or this file, will be copied. Defaults to "_directory/assets" (see below).
**to**: into this _directory_. It will be created if necessary. Defaults to "_destination/assets".
If **from** or **to** starts with _XXX/, they will be relative to that metalsmith property. Common ones are:
- _destination see [metalsmith.destination()](https://github.com/metalsmith/metalsmith#destinationpath)
- _source see [metalsmith.source()](https://github.com/metalsmith/metalsmith#sourcepath)
- _directory see metalsmith.directory() or the constructor [Metalsmith(__dirname)](https://github.com/metalsmith/metalsmith#new-metalsmithdir)
**Warning** If you use this feature, _you must use '/' (not a Windows '\\\\') as your folder delimiter._
_e.g._ to copy from the working directory into the folder you set in `metalsmith.destination()` use
`{ from: "_directory/pathto/assets", to: "_destination/pathto/assets"}`.
Otherwise, the path will be resolved normally using `path.resolve()`. (Sorry, if you really want to copy to or from a folder starting with _, the workaround is to start the path with a . or / or something...)
#### Less common options, all default to null
**noclobber**: if truthy, don't overwrite existing files. (Note: cp-r never overwrites existing folders)
**dirMode** e.g. 0o777 copied dirs will have this "mode", default = use same mode as existing dir.
**fileMode** e.g. 0o666 copied files will have this "mode", default = use same mode as existing file.
**ignoreDir** a string or Regex, if present, ignore directories matching this pattern.
**ignoreFile** a string or Regex, if present, ignore files matching this pattern.
### Notes, Todos, and Caveats
cp-r doesn't do any fancy async stuff - didn't seem worth it for a simple build script. (It really feels "un-nody" because of all the synch stuff!)
cp-r has not been tested with links, locked directories, bad inputs, other weird stuff.
The "unit-test" is pretty lame. In package.json, please set scripts.test to the value for testWindows or testUnix as appropriate.
I wrote this because [metalsmith-assets](https://www.npmjs.com/package/metalsmith-assets) had a ton of obsolete dependencies and wasn't actively processing issues and pull requests. cp-r uses an absolute minimum of dependencies (only debug) and implements a few features from metalsmith-assets' feature requests.
[metalsmith-assets-improved](https://www.npmjs.com/package/metalsmith-assets-improved) looks comparable.
[metalsmith-copy-assets-540](https://www.npmjs.com/package/metalsmith-copy-assets-540) isn't recursive.
It's possible that [metalsmith-copy](https://github.com/mattwidmann/metalsmith-copy) does this better.