"use strict";
var Immutable = require('immutable');
var fromJS = Immutable.fromJS, Map = Immutable.Map;
var Rx = require('rx');
/**
 * A task context is just an Immutable Map of key=>value pairs
 * that may be used to provide addition context to the task running
 * environment. This is especially useful in situations where you need
 * to do something that MUST block the task running altogether. An example
 * would be hashing files/directories to determine if a task/group of tasks should
 * run.
 */
function getContext(tasks, trigger) {
    /**
     * Define a list of async actions
     * that must complete before any tasks are executed
     * @type {Array}
     */
    var preExecutionTasks = [
        require('./command.run.pre-execution').createHashes
    ];
    /**
     * Now wrap each Function in an observable
     * @type {Rx.Observable<PreExecutionTask>[]}
     */
    var observables = preExecutionTasks.map(function (fn) {
        return Rx.Observable.create(function (obs) {
            fn(tasks, trigger).subscribe(obs);
        });
    });
    /**
     * Run each item in sequence
     * finally producing an Immutable Map from all the gathered values
     */
    return Rx.Observable
        .from(observables)
        .concatAll()
        .toArray()
        .map(function (xs) {
        return (_a = Map({})).mergeDeep.apply(_a, xs.map(function (x) { return fromJS(x); }));
        var _a;
    });
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = getContext;
//# sourceMappingURL=command.run.context.js.map