-
这是自述文件和示例:https://github.com/gruntjs/grunt-contrib-copy/blob/master/README.md .
-
以下是https://github.com/gruntjs/grunt-contrib-copy/blob/master/tasks/copy.js代码的相关部分(我显然无法理解):
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++;
}
});
});
2 回答
Expand允许您指定是要完整创建目标路径(例如:
/path/missing1/missing2
),还是仅在其父项存在时创建最后一个目录(/path/existing/missing
) .由于
expand
是Grunt的一部分,并不是特定于grunt-contrib-copy,因此可以在_1489247中找到有关它的信息:此外,如果将
expand
设置为true
,似乎始终将dest
视为目标目录 .