"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugin_1 = require("../libs/plugin");
const service_component_1 = require("./service-component");
const deepmerge = __importStar(require("deepmerge"));
/**
 * A Plugin to detect WebApp-Components
 *
 * IMPORTANT: The WebAppPlugin provides as webPackConfigs a list of functions (to take further args!)
 * This must be considered when being forwarded!
 *
 * @param props
 */
exports.ServicePlugin = (props) => {
    const path = require('path');
    const result = {
        // identify Isomorphic-App-Components
        applies: (component) => {
            return service_component_1.isService(component);
        },
        // convert the component into configuration parts
        // while the component is of Type `any`, its props must be of type `IWebApp`
        process: (component, childConfigs, infrastructureMode) => {
            return {
                slsConfigs: deepmerge.all(childConfigs.map(config => config.slsConfigs)),
                // add the server config
                webpackConfigs: childConfigs.reduce((result, config) => result.concat(config.webpackConfigs), []),
                postBuilds: childConfigs.reduce((result, config) => result.concat(config.postBuilds), []),
                iamRoleStatements: plugin_1.forwardChildIamRoleStatements(childConfigs)
            };
        }
    };
    return result;
};
//# sourceMappingURL=service-plugin.js.map