"use strict";
/// <reference path="../typings/main.d.ts" />
var command_run_1 = require('./command.run');
var Immutable = require('immutable');
var Rx = require('rx');
var watch_utils_1 = require("./watch.utils");
var watch_resolve_1 = require("./watch.resolve");
var watch_runner_1 = require("./watch.runner");
var reporter_resolve_1 = require("./reporter.resolve");
function execute(trigger) {
    var input = trigger.input, config = trigger.config, reporter = trigger.reporter;
    var topLevelWatchers = watch_utils_1.stripBlacklisted(Object.keys(input.watch));
    if (!topLevelWatchers.length) {
        reporter(reporter_resolve_1.ReportNames.NoWatchersAvailable);
        return;
    }
    var watchTasks = watch_resolve_1.resolveWatchTasks(topLevelWatchers, trigger);
    var runners = watch_runner_1.createWatchRunners(watchTasks, trigger);
    /**
     * Never continue if any runners are invalid
     */
    if (runners.invalid.length) {
        /**
         * Log valid runners first, so that errors are not lost in the console output
         * // todo, again, is it confusing to have none-errored watchers listed here
         */
        // runners.valid.forEach(runner => {
        //     _reporter.reportWatchTaskTasksErrors(runner._tasks.all, runner, config)
        // });
        /**
         * Now log the invalid runners
         */
        runners.invalid.forEach(function (runner) {
            reporter(reporter_resolve_1.ReportNames.WatchTaskTasksErrors, runner._tasks.all, runner, config);
        });
        return;
    }
    reporter(reporter_resolve_1.ReportNames.WatcherNames, runners, trigger);
}
function handleIncomingWatchersCommand(cli, input, config, reporter) {
    execute({
        shared: new Rx.BehaviorSubject(Immutable.Map({})),
        cli: cli,
        input: input,
        config: config,
        reporter: reporter,
        type: command_run_1.TriggerTypes.command
    });
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = handleIncomingWatchersCommand;
//# sourceMappingURL=command.watchers.js.map