"use strict";
var task_resolve_1 = require("./task.resolve");
var seq = require("./task.sequence");
var Rx = require('rx');
function getRunCommandSetup(trigger) {
    var cliInput = trigger.cli.input.slice(1);
    /**
     * Task Tracker for external observers
     * @type {Subject<T>}
     */
    trigger.tracker = new Rx.Subject();
    trigger.tracker$ = trigger.tracker.share();
    /**
     * First Resolve the task names given in input.
     */
    var tasks = task_resolve_1.resolveTasks(cliInput, trigger);
    var topLevelParallel = tasks.all.some(function (task) {
        return task.runMode === task_resolve_1.TaskRunModes.parallel;
    });
    /**
     * If only 1 task is being run, check if any sub-tasks
     * are trying to be run in parallel mode and if so, set the runMode
     * This is done to ensure if a child errors, it doesn't affect children.
     * (as it's only a single task via the cli, it wouldn't be expected)
     */
    if (cliInput.length === 1 && topLevelParallel) {
        trigger.config.runMode = task_resolve_1.TaskRunModes.parallel;
    }
    /**
     * All this point, all given task names have been resolved
     * to either modules on disk, or @adaptor tasks, so we can
     * go ahead and create a flattened run-sequence
     */
    var sequence = seq.createFlattenedSequence(tasks.valid, trigger);
    /**
     * With the flattened sequence, we can create nested collections
     * of Rx Observables
     */
    var runner = seq.createRunner(sequence, trigger);
    /**
     * Check if the user intends to handle running the tasks themselves,
     * if thats the case we give them the resolved tasks along with
     * the sequence and the primed runner
     */
    return { tasks: tasks, sequence: sequence, runner: runner, cli: trigger.cli };
}
exports.getRunCommandSetup = getRunCommandSetup;
//# sourceMappingURL=command.run.setup.js.map