UNPKG

4.82 kBPlain TextView Raw
1/**
2 * This module must not import anything globally not workin in web-mode! if needed, require it within the functions
3 */
4import { IConfigParseResult } from '../libs/config-parse-result';
5import {IPlugin, forwardChildIamRoleStatements} from '../libs/plugin';
6import { isWebApp } from './webapp-component'
7import { PARSER_MODES } from '../libs/parser';
8
9/**
10 * Parameters that apply to the whole Plugin, passed by other plugins
11 */
12export interface IWebAppPlugin {
13
14 /**
15 * one of the [[PARSER_MODES]]
16 */
17 parserMode: string,
18
19 /**
20 * path to a directory where we put the final bundles
21 */
22 buildPath: string,
23
24 /**
25 * path to the main config file
26 */
27 configFilePath: string,
28
29 /**
30 * relative path to the assets folder
31 */
32 assetsPath: string
33}
34
35/**
36 * A Plugin to detect WebApp-Components
37 *
38 * IMPORTANT: The WebAppPlugin provides as webPackConfigs a list of functions (to take further args!)
39 * This must be considered when being forwarded!
40 *
41 * @param props
42 */
43export const WebAppPlugin = (props: IWebAppPlugin): IPlugin => {
44 const path = require('path');
45
46 const result: IPlugin = {
47 // identify Isomorphic-App-Components
48 applies: (component): boolean => {
49
50 return isWebApp(component);
51 },
52
53 // convert the component into configuration parts
54 // while the component is of Type `any`, its props must be of type `IWebApp`
55 process: (
56 component: any,
57 childConfigs: Array<IConfigParseResult>,
58 infrastructureMode: string | undefined
59 ): IConfigParseResult => {
60
61 return {
62 slsConfigs: [],
63
64 // a webapp has its own webpack configuration
65 webpackConfigs: [
66 (args) => {
67 //console.log("web-app-plugin args: ", args);
68 return require("../../../infrastructure-scripts/dist/infra-comp-utils/webpack-libs").complementWebpackConfig(
69 require("../../../infrastructure-scripts/dist/infra-comp-utils/webpack-libs").createClientWebpackConfig(
70 "./"+path.join("node_modules", "infrastructure-components", "dist" , "assets", "client.js"), //entryPath: string,
71 path.join(require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").currentAbsolutePath(), props.buildPath), //use the buildpath from the parent plugin
72 component.id, // appName
73 props.assetsPath, //assetsPath
74 args["stagePath"], // stagePath
75 {
76 __CONFIG_FILE_PATH__: require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").pathToConfigFile(props.configFilePath), // replace the IsoConfig-Placeholder with the real path to the main-config-bundle
77
78 // required of data-layer, makes the context match!
79 "infrastructure-components": path.join(
80 require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").currentAbsolutePath(),
81 "node_modules", "infrastructure-components", "dist", "index.js"),
82
83 // required of the routed-app
84 "react-router-dom": path.join(
85 require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").currentAbsolutePath(),
86 "node_modules", "react-router-dom"),
87
88 // required of the data-layer / apollo
89 "react-apollo": path.join(
90 require("../../../infrastructure-scripts/dist/infra-comp-utils/system-libs").currentAbsolutePath(),
91 "node_modules", "react-apollo"),
92
93 }, {
94 __ISOMORPHIC_ID__: `"${component.instanceId}"`,
95
96 // when there is a DataLayer, we provide it, otherwise an empty string
97 __DATALAYER_ID__: `"${args["datalayerid"] !== undefined ? args["datalayerid"] : ""}"`
98 }
99 ),
100 props.parserMode === PARSER_MODES.MODE_DEPLOY //isProd
101 )
102 }
103 ],
104
105 postBuilds: [],
106
107 iamRoleStatements: forwardChildIamRoleStatements(childConfigs)
108 }
109 }
110 }
111
112 return result;
113
114};
\No newline at end of file