'use strict';

var _keys = require('babel-runtime/core-js/object/keys');

var _keys2 = _interopRequireDefault(_keys);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var minimatch = require('minimatch');

module.exports = function generateTasks(config, files) {
  var trackers = config.trackers !== undefined ? config.trackers : config;
  var resolve = function resolve(file) {
    return files[file];
  };

  return (0, _keys2.default)(trackers).map(function (pattern) {
    var commands = trackers[pattern];
    var filter = minimatch.filter(pattern, { matchBase: true, dot: true });
    var fileList = (0, _keys2.default)(files).filter(filter).map(resolve);
    if (fileList.length) {
      return { pattern: pattern, commands: commands, fileList: fileList };
    }
    return undefined;
  }).filter(Boolean); // Filter undefined values
};