Skip to content

Commit

Permalink
chore(refactor): simplify data.files creation
Browse files Browse the repository at this point in the history
Follows code review of pull #262.
  • Loading branch information
Krinkle committed Aug 28, 2018
1 parent 0174ca8 commit 01e916c
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions tasks/grunt-karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 01e916c

Please sign in to comment.