"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugin_1 = require("../libs/plugin");
const webapp_component_1 = require("./webapp-component");
const parser_1 = require("../libs/parser");
/**
 * 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.WebAppPlugin = (props) => {
    const path = require('path');
    const result = {
        // identify Isomorphic-App-Components
        applies: (component) => {
            return webapp_component_1.isWebApp(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: [],
                // a webapp has its own webpack configuration
                webpackConfigs: [
                    (args) => {
                        //console.log("web-app-plugin args: ", args);
                        return require("../../../infrastructure-scripts/dist/infra-comp-utils/webpack-libs").complementWebpackConfig(require("../../../infrastructure-scripts/dist/infra-comp-utils/webpack-libs").createClientWebpackConfig("./" + path.join("node_modules", "infrastructure-components", "dist", "assets", "client.js"), //entryPath: string,
                        path.join(require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").currentAbsolutePath(), props.buildPath), //use the buildpath from the parent plugin
                        component.id, // appName
                        props.assetsPath, //assetsPath
                        args["stagePath"], // stagePath
                        {
                            __CONFIG_FILE_PATH__: require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").pathToConfigFile(props.configFilePath),
                            // required of data-layer, makes the context match!
                            "infrastructure-components": path.join(require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").currentAbsolutePath(), "node_modules", "infrastructure-components", "dist", "index.js"),
                            // required of the routed-app
                            "react-router-dom": path.join(require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").currentAbsolutePath(), "node_modules", "react-router-dom"),
                            // required of the data-layer / apollo
                            "react-apollo": path.join(require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").currentAbsolutePath(), "node_modules", "react-apollo"),
                        }, {
                            __ISOMORPHIC_ID__: `"${component.instanceId}"`,
                            // when there is a DataLayer, we provide it, otherwise an empty string
                            __DATALAYER_ID__: `"${args["datalayerid"] !== undefined ? args["datalayerid"] : ""}"`
                        }), props.parserMode === parser_1.PARSER_MODES.MODE_DEPLOY //isProd
                        );
                    }
                ],
                postBuilds: [],
                iamRoleStatements: plugin_1.forwardChildIamRoleStatements(childConfigs)
            };
        }
    };
    return result;
};
//# sourceMappingURL=webapp-plugin.js.map