module.exports = function(grunt) {
'use strict';
var path = require('path');
grunt.registerMultiTask('copy', 'Copy files.', function() {
var kindOf = grunt.util.kindOf;
var options = this.options({
processContent: false,
processContentExclude: []
});
var copyOptions = {
process: options.processContent,
noProcess: options.processContentExclude
};
grunt.verbose.writeflags(options, 'Options');
var dest;
var isExpandedPair;
var tally = {
dirs: 0,
files: 0
};
this.files.forEach(function(filePair) {
isExpandedPair = filePair.orig.expand || false;
filePair.src.forEach(function(src) {
if (detectDestType(filePair.dest) === 'directory') {
dest = (isExpandedPair) ? filePair.dest : unixifyPath(path.join(filePair.dest, src));
} else {
dest = filePair.dest;
}
if (grunt.file.isDir(src)) {
grunt.verbose.writeln('Creating ' + dest.cyan);
grunt.file.mkdir(dest);
tally.dirs++;
} else {
grunt.verbose.writeln('Copying ' + src.cyan + ' -> ' + dest.cyan);
grunt.file.copy(src, dest, copyOptions);
tally.files++;
}
});
});
Since expand is a part of Grunt, and not specific for grunt-contrib-copy, information about it can be found in Grunt's file configuration API:
Set
expandtotrueto enable the following options:
cwdAllsrcmatches are relative to (but don't include) this path.srcPattern(s) to match, relative to thecwd.destDestination path prefix.extReplace any existing extension with this value in generateddestpaths.extDotUsed to indicate where the period indicating the extension is located. Can take either'first'(extension begins after the first period in the file name) or'last'(extension begins after the last period), and is set by default to'first'.flattenRemove all path parts from generateddestpaths.renameThis function is called for each matchedsrcfile, (after extension renaming and flattening). Thedestand matchedsrcpath are passed in, and this function must return a newdestvalue. If the samedestis returned more than once, eachsrcwhich used it will be added to an array of sources for it.
Additionally it seems like dest will always be considered to be a destination directory if setting expand to true.
Expand lets you specify whether you want to create the destination path in full (e.g: /path/missing1/missing2), or only create the last directory when its parent exists (/path/existing/missing).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With