Skip to content

Instantly share code, notes, and snippets.

@misterbrownlee
Created February 3, 2017 01:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misterbrownlee/2e1ad4d1a4be09e24abc4c6004f591db to your computer and use it in GitHub Desktop.
Save misterbrownlee/2e1ad4d1a4be09e24abc4c6004f591db to your computer and use it in GitHub Desktop.
How to copy using fs-promise and globby
require('any-promise/register/bluebird');
var globby = require('globby');
var path = require('path');
var fsx = require('fs-promise');
var Promise = require('any-promise');
var outputRoot = path.resolve('copy', 'here');
var globbyPaths = [
config.resourcesCopyPath,
config.fontCopyPath,
config.cssCopyPath
];
var sourceFiles = globby(globbyPaths);
return Promise.map(sourceFiles, function(sourceFile) {
var destFile = path.join(outputRoot, path.basename(sourceFile))
return fsx.copy(sourceFile, destFile)
.catch(function(error) {
console.error('doh', error);
})
.then(function() {
console.log('copy is done');
});
});
});
@misterbrownlee
Copy link
Author

This is slightly cleaned up from what I have in my project. It assumes you have some 'config' to get some of the paths from, so this isn't just grab and go, but it's darn close.

LMK if there's dumb mistakes? ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment