This is a utility package that does only one thing: copy files in glob patterns to destination and retain the relative directory structure.
It's called lazycopy because I never want to write another set of functions to copy files, and I don't want to use gulp or grunt (or any other task runner) for automating my front-end builds :)
npm install lazycopy
const lazy = require('lazycopy').default; // If you're not using ES6 Modules
import lazy from 'lazycopy'; // If you're using ES6 modules
copy(sources)
Copies an array of sources to their destination, but does so asynchronously. Returns a Promise
that will be
resolved when the copy operations have completed. Rejects promise if an error occurs while copying.
If the required folders do no exist in the destination path, they will be automatically created.
sources - An Array
of objects containing the following properties:
src
- required - Glob pattern for file selectiondest
- required - Output folder where files will be copied tocwd
- optional - Root where lazycopy will look for files to copymaintainStructure
- optional (defaults totrue
) - If set to false, the file's relative structure will not be preserved
Example:
// Copy files async (Promise-based)
lazy.copy([{
src: './someFolder/**/**', // Give me all the files under "someFolder"
dest: './destination',
cwd: __dirname // (Optionally set CWD for scanning for files)
}]).then(() => {
console.info('Done!');
}).catch((error) => {
console.info('Something blew up.');
console.error(error);
});
copySync(sources) Performs a synchronous copy of files.
Example:
// Copy files synchronously
lazy.copySync([{
src: './someFolder/**/**', // Give me all the files under "someFolder"
dest: './destination',
cwd: __dirname // (Optionally set CWD for scanning for files)
}]);