"use strict";
var task_resolve_1 = require("./task.resolve");
var seq = require("./task.sequence");
var debug = require('debug')('cb:watch.runner');
var _ = require('../lodash.custom');
function createWatchRunners(watchTasks, ctx) {
    var runners = watchTasks.valid.reduce(function (acc, item) {
        return acc.concat(item.watchers.map(function (watcher) {
            var tasks = task_resolve_1.resolveTasks(watcher.tasks, ctx);
            var subject = _.assign({}, watcher, {
                _tasks: tasks,
                parent: item.name
            });
            if (tasks.invalid.length) {
                return subject;
            }
            subject._sequence = seq.createFlattenedSequence(tasks.valid, ctx);
            subject._runner = seq.createRunner(subject._sequence, ctx);
            return subject;
        }));
    }, []);
    return {
        all: runners,
        valid: runners.filter(function (x) { return validateRunner(x); }),
        invalid: runners.filter(function (x) { return !validateRunner(x); }),
    };
}
exports.createWatchRunners = createWatchRunners;
function validateRunner(x) {
    return x._tasks.invalid.length === 0;
}
//# sourceMappingURL=watch.runner.js.map