Last active
August 29, 2015 14:22
-
-
Save anselmh/51286cdf3b28913b14b5 to your computer and use it in GitHub Desktop.
Clean directory and Copy files from one to another location (similar to grunt-contrib-copy)
This file contains 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
{ | |
"devDependencies": { | |
"del": "^1.2.0", | |
"recursive-copy": "^1.0.10" | |
}, | |
"scripts": { | |
"copy": "node task.copy.js", | |
} | |
} |
This file contains 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
// Copy file | |
var copy = require('recursive-copy'); | |
var del = require('del'); | |
var srcPath = 'src/'; | |
var destPath = 'dist/'; | |
var options = { | |
overwrite: true, | |
dot: true, | |
filter: /.*\.(html|htaccess|md|txt|ico|svg|png|jpg)/g | |
}; | |
var copiedFiles = 0; | |
// Delete all matching files before copying | |
del(['dist/*.html', 'dist/*.md', 'dist/.htaccess', 'dist/*.txt', 'dist/*.ico', 'dist/*.png', 'dist/*.jpg', 'dist/*.svg'], function (err, paths) { | |
console.log('Deleted files/folders:\n', paths.join('\n')); | |
}); | |
// Copy files now | |
copy(srcPath, destPath, options) | |
.on(copy.events.COPY_FILE_START, function(copyOperation) { | |
console.info('Copying file ' + copyOperation.src + '...'); | |
}) | |
.on(copy.events.COPY_FILE_COMPLETE, function(copyOperation) { | |
copiedFiles = copiedFiles + 1; | |
console.info('Copied to ' + copyOperation.dest); | |
}) | |
.on(copy.events.ERROR, function(error, copyOperation) { | |
console.error('Unable to copy ' + copyOperation.dest); | |
}) | |
.then(function(results) { | |
console.info(copiedFiles + ' file(s) copied'); | |
}) | |
.catch(function(error) { | |
return console.error('Copy failed: ' + error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment