From 01e916cfc41f9dea8ed5921515c9263a4490c947 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 28 Aug 2018 19:33:33 +0100 Subject: [PATCH] chore(refactor): simplify data.files creation Follows code review of pull #262. --- tasks/grunt-karma.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/tasks/grunt-karma.js b/tasks/grunt-karma.js index 97b1cf0..c516da6 100644 --- a/tasks/grunt-karma.js +++ b/tasks/grunt-karma.js @@ -71,27 +71,29 @@ module.exports = function (grunt) { data.configFile = path.resolve(data.configFile) } - if (this.files.length || options.files) { - data.files = [].concat.apply( - // For the 'files' option, we support nested arrays as a convenient - // way to specify files without needing the user to concat or - // flatten them ahead of time. - _.flattenDeep(options.files || []), - this.files.map(function (file) { - return file.src.map(function (src) { - var obj = { - pattern: src + // Combines both sets of files. The order should be: + // - first, values from options.files, + // - then, values from this.files. + if (options.files || this.files.length) { + // For our 'files' option, we support arbitrarily nested arrays, + // as a convenient way to specify files without the user needing to + // concat or flatten anything within their Gruntfile. + data.files = _.flattenDeep(options.files || []) + // The 'files' task data expanded by Grunt internally produces + // a structure that is exactly 2 levels deep. + this.files.forEach((file) => { + file.src.forEach((src) => { + let obj = { + pattern: src + }; + ['watched', 'served', 'included'].forEach((opt) => { + if (opt in file) { + obj[opt] = file[opt] } - var opts = ['watched', 'served', 'included'] - opts.forEach(function (opt) { - if (opt in file) { - obj[opt] = file[opt] - } - }) - return obj }) + data.files.push(obj) }) - ) + }) } // Allow the use of templates in preprocessors