Plato on Github
Report Home
misc/copy.js
Maintainability
75.25
Lines of code
56
Difficulty
11.65
Estimated Errors
0.32
Function weight
By Complexity
By SLOC
'use strict'; var packagePath = __dirname + '/../../package.json'; var gulp = require('gulp'); var path = require('path'); var $ = require('gulp-load-plugins')({config: path.normalize(packagePath)}); var config = { name: 'misc:copy', callback: callback }; /** * Task to copy files from any source to any destination * Gulpfile example: * misc: { * copy: [ * 'anyfile.txt>>build/', * 'folder_content/*>>build/folder_content' * ] * }, */ module.exports = config; ///////////////////////////// /*jshint unused:false*/ function callback(settings, done) { // "settings.copy" array contais strings instead of objects due a hash limitation from templetize if (!Array.isArray(settings.copy)) { console.error('Please supply an array for which files you want to copy'); return false; } settings.copy.forEach(function (str) { if (typeof str !== 'string') { console.err('Please set your copy mapping with strings following the pattern:'); console.err('"(src)>>(dest)" without parenthesis'); return false; } var paths = str.split('>>'); gulp.src(paths[0]) .pipe(gulp.dest(paths[1])); }); return gulp.src(filterFiles(settings.copy)) .pipe($.size({title: 'misc:copied'})); } function filterFiles(array) { return array.map(function (str) { return str.split('>>')[0]; }); }