UNPKG

infrastructure-components

Version:

Infrastructure-Components configure the infrastructure of your React-App as part of your React-Components.

68 lines 3.97 kB
"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 }); /** * This module must not import anything globally not workin in web-mode! if needed, require it within the functions */ const iso_component_1 = require("./iso-component"); const iso_libs_1 = require("../libs/iso-libs"); const deepmerge = __importStar(require("deepmerge")); /** * A Plugin to detect Isomorphic-App-Components * @param props */ exports.IsoPlugin = (props) => { //console.log("configFilePath: " , props.configFilePath); const result = { // identify Isomorphic-App-Components applies: (component) => { return iso_component_1.isIsomorphicApp(component); }, // convert the component into configuration parts process: (component, childConfigs, infrastructureMode) => { const path = require('path'); // we use the hardcoded name `server` as name const serverName = "server"; const serverBuildPath = path.join(require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").currentAbsolutePath(), props.buildPath); // the isomorphic app has a server application const serverWebPack = require("../../../infrastructure-scripts/dist/infra-comp-utils/webpack-libs").complementWebpackConfig(require("../../../infrastructure-scripts/dist/infra-comp-utils/webpack-libs").createServerWebpackConfig("./" + path.join("node_modules", "infrastructure-components", "dist", "assets", "server.js"), //entryPath: string, serverBuildPath, //use the buildpath from the parent plugin serverName, // name of the server { __CONFIG_FILE_PATH__: require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").pathToConfigFile(props.configFilePath), }, { __ISOMORPHIC_ID__: `"${component.instanceId}"`, __ASSETS_PATH__: `"${component.assetsPath}"`, __RESOLVED_ASSETS_PATH__: `"${iso_libs_1.resolveAssetsPath(component.buildPath, serverName, component.assetsPath)}"` })); // provide all client configs in a flat list const webpackConfigs = childConfigs.reduce((result, config) => result.concat(config.webpackConfigs), []); const copyAssetsPostBuild = () => { console.log("now copy the assets!"); webpackConfigs.map(config => require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").copyAssets(config.output.path, path.join(serverBuildPath, serverName, component.assetsPath))); }; return { slsConfigs: deepmerge.all([ require("../../../infrastructure-scripts/dist/infra-comp-utils/sls-libs").toSlsConfig(component.stackName, serverName, component.buildPath, component.assetsPath, component.region), ...childConfigs.map(config => config.slsConfigs) ]), // add the server config webpackConfigs: webpackConfigs.concat([serverWebPack]), postBuilds: childConfigs.reduce((result, config) => result.concat(config.postBuilds), [copyAssetsPostBuild]), environments: childConfigs.reduce((result, config) => (result !== undefined ? result : []).concat(config.environments !== undefined ? config.environments : []), []), stackName: component.stackName, assetsPath: component.assetsPath, buildPath: component.buildPath, region: component.region }; } }; return result; }; //# sourceMappingURL=iso-plugin.js.map