Created
February 3, 2017 01:29
-
-
Save misterbrownlee/2e1ad4d1a4be09e24abc4c6004f591db to your computer and use it in GitHub Desktop.
How to copy using fs-promise and globby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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? ❤️