stream-copy-dir
v1.0.0
Published
Streaming copy of directory to destination - no globs and no recursion. In addition can pass a 'plugin' function to modify the contents of each file - perfect place for template engines.
Downloads
32
Readme
stream-copy-dir
Streaming copy of directory to destination - no globs and no recursion. In addition can pass a 'plugin' function to modify the contents of each file - perfect place for template engines.
Install
Install with npm
$ npm i stream-copy-dir --save
Usage
For more use-cases see the tests
const streamCopyDir = require('stream-copy-dir')
API
streamCopyDir
Copy files from
src
todest
directory without globs and recursion. Can provideplugin
function to modify file contents, which is useful for template engines. Theplugin
function gets two arguments -file
andcb
, wherefile
is vinyl file andcb
is optional, but it's recommended to pass the file like socb(null, file)
Params
<src>
{String|Buffer}: source directory with files, passed to create-readdir-stream<dest>
{String|Buffer}: destination folder for (modified) files, passed to write-file[plugin]
{Function}: perfect place to access and modify contents of each filereturns
{Stream}: transform stream, through2
Example
var copyFolder = require('stream-copy-dir')
var handlebars = require('handlebars')
function plugin (file, cb) {
var contents = file.toString()
var template = handlebars.compile(contents)
contents = template({
name: 'Charlike',
baz: 'qux'
})
// Buffer constructor is deprecated
// so don't use `new Buffer` anymore in new code/projects
// instead use `Buffer.from`
file.contents = new Buffer(contents)
cb(null, file)
}
copyFolder('./src/templates', './my-project', plugin)
.once('error', console.error)
.once('finish', function () {
console.log('copied and modified without errors')
})
Related
- always-done: Handle completion and errors with elegance! Support for streams, callbacks, promises, child processes, async/await and sync functions… more | homepage
- callback2stream: Transform sync, async or generator function to Stream. Correctly handle errors and optional arguments. | homepage
- create-readdir-stream: Streaming
fs.readdir
, extensible with smart plugins. No recursion and no globs by default - use plugins. Does… more | homepage - minibase: MiniBase is minimalist approach to Base - @node-base, the awesome framework. Foundation for building complex APIs with… more | homepage
- promise2stream: Transform ES2015 Promise to Stream - specifically, Transform Stream using through2. Works in object mode by default… more | homepage
- try-catch-core: Low-level package to handle completion and errors of sync or asynchronous functions, using once and dezalgo libs… more | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.