"use strict";
var debug = require('debug')('cb:task.transform');
var task_resolve_1 = require("./task.resolve");
/**
 * Task Transformations
 * This gives an opportunity to change a task just before error collection
 */
exports.transforms = {
    /**
     * If an external file was matched, and it has the .sh extension,
     * load it as an @sh adaptor task
     */
    '@sh from File': {
        predicate: function (incoming) {
            return incoming.type === task_resolve_1.TaskTypes.ExternalTask &&
                incoming.externalTasks[0].parsed.ext === '.sh';
        },
        fn: function (incoming) {
            incoming.type = task_resolve_1.TaskTypes.Adaptor;
            incoming.origin = task_resolve_1.TaskOriginTypes.FileSystem;
            incoming.adaptor = 'sh';
            incoming.command = ''; // Will read later
            return incoming;
        }
    }
};
/**
 * Allow transformations on tasks before error collections
 */
function applyTransforms(incoming) {
    return Object.keys(exports.transforms).reduce(function (task, key) {
        var transform = exports.transforms[key];
        if (transform.predicate(task)) {
            debug("Applying transform " + key);
            return transform.fn(task);
        }
        return incoming;
    }, incoming);
}
exports.applyTransforms = applyTransforms;
//# sourceMappingURL=task.transforms.js.map