"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const config_parse_result_1 = require("./config-parse-result");
const configuration_1 = require("../types/configuration");
const index_1 = require("./index");
exports.PARSER_MODES = {
    MODE_BUILD: "MODE_BUILD",
    MODE_START: "MODE_START",
    MODE_DEPLOY: "MODE_DEPLOY",
    MODE_DOMAIN: "MODE_DOMAIN"
};
/**
 * parses the configuration for plugins and returns a list of the plugins (objects)
 *
 * @param configPath the path to the compiled and evaluable configuration
 * @param origConfigPath the path to the original uncompiled configuration source!
 */
function parseForPlugins(parsedComponent, origConfigPath, stage, parserMode) {
    //console.log("configPath: ", configPath);
    if (configuration_1.isConfiguration(parsedComponent)) {
        return configuration_1.extractPlugins(parsedComponent, origConfigPath, stage, parserMode);
    }
    else {
        console.error("main component is not a valid app!");
        return [];
    }
}
exports.parseForPlugins = parseForPlugins;
;
/**
 * parses a configuration, this configuration must export the main component as default
 *
 *
 * @param component (main component of the configuration)
 * @param compileMode set to true to run the parser with a statically loaded configuration (without objects)
 */
function extractConfigs(parsedComponent, plugins, infrastructureMode) {
    const results = plugins
        // check for plugins to apply
        .filter(plugin => plugin.applies(parsedComponent))
        // apply applicable plugins
        .map(plugin => {
        const childConfigs = index_1.getChildrenArray(parsedComponent).map(child => extractConfigs(child, plugins, infrastructureMode));
        const r = plugin.process(parsedComponent, childConfigs, infrastructureMode);
        //console.log("result: ", r);
        return r;
    });
    //console.log("extract Configs result: ", results);
    return config_parse_result_1.mergeParseResults(results);
}
exports.extractConfigs = extractConfigs;
;
//# sourceMappingURL=parser.js.map