|
| 1 | +/** |
| 2 | + * A utility that allows copying one file to multiple directories, such |
| 3 | + * as the LICENSE file. |
| 4 | + */ |
| 5 | +var path = require('path'); |
| 6 | +var util = require('./util'); |
| 7 | +var ternaryStream = require('ternary-stream'); |
| 8 | +var minimatch = require('minimatch'); |
| 9 | + |
| 10 | +module.exports = { |
| 11 | + multicopy: multicopy, |
| 12 | + copy: copy |
| 13 | +}; |
| 14 | + |
| 15 | +function createCopyPipe(gulp, plugins, config) { |
| 16 | + var pipe = gulp.src(config.src); |
| 17 | + Object.keys(config.pipes).forEach(function(pattern) { |
| 18 | + pipe = pipe.pipe(ternaryStream(function(file) { |
| 19 | + return minimatch(file.relative, pattern); |
| 20 | + }, config.pipes[pattern])); |
| 21 | + }); |
| 22 | + return pipe; |
| 23 | +} |
| 24 | + |
| 25 | +function copy(gulp, plugins, config) { |
| 26 | + return function() { |
| 27 | + return createCopyPipe(gulp, plugins, config) |
| 28 | + .pipe(gulp.dest(config.dest)); |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +function multicopy(gulp, plugins, config) { |
| 33 | + return function() { |
| 34 | + var pipe = createCopyPipe(gulp, plugins, config); |
| 35 | + var modules = util.subDirs('modules'); |
| 36 | + if (config.exclude) { |
| 37 | + modules = modules.filter(function(module) { |
| 38 | + return config.exclude.indexOf(module) === -1; |
| 39 | + }); |
| 40 | + } |
| 41 | + modules.map(function(module) { |
| 42 | + pipe = pipe.pipe(gulp.dest(path.join(config.dest, module))); |
| 43 | + }); |
| 44 | + return pipe; |
| 45 | + }; |
| 46 | +} |
0 commit comments