1 |
|
2 | import React, { ReactNode } from 'react';
|
3 |
|
4 | import Types from '../types';
|
5 | import { IConfiguration } from "../types/configuration";
|
6 | import { IInfrastructure } from "../types";
|
7 |
|
8 | import { isRoute } from '../route/route-component';
|
9 |
|
10 | import {getChildrenArray, findComponentRecursively} from '../libs';
|
11 |
|
12 | import { SoaPlugin } from './soa-plugin';
|
13 | import { EnvironmentPlugin } from '../environment/environment-plugin';
|
14 | import { ServicePlugin } from "../service/service-plugin";
|
15 | import { isService } from "../service/service-component";
|
16 | import {DataLayerPlugin} from "../datalayer/datalayer-plugin";
|
17 | import {isDataLayer} from "../datalayer/datalayer-component";
|
18 | import {StoragePlugin} from "../storage/storage-plugin";
|
19 | import {isStorage} from "../storage/storage-component";
|
20 |
|
21 | export const SERVICEORIENTED_INSTANCE_TYPE = "ServiceOrientedComponent";
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export interface IServiceOrientedArgs {
|
27 |
|
28 | |
29 |
|
30 |
|
31 | stackName: string,
|
32 |
|
33 | |
34 |
|
35 |
|
36 | buildPath: string,
|
37 |
|
38 | |
39 |
|
40 |
|
41 | region: string
|
42 | }
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | export interface IServiceOrientedProps {
|
49 | |
50 |
|
51 |
|
52 | id: string,
|
53 |
|
54 | |
55 |
|
56 |
|
57 | routes: Array<any>,
|
58 |
|
59 | |
60 |
|
61 |
|
62 | redirects: Array<any>,
|
63 |
|
64 | |
65 |
|
66 |
|
67 | services: Array<any>,
|
68 |
|
69 | |
70 |
|
71 |
|
72 | dataLayerId?: string,
|
73 |
|
74 | |
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | iamRoleStatements?: Array<any>
|
85 | }
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | export default (props: IServiceOrientedArgs | any) => {
|
93 |
|
94 |
|
95 |
|
96 | const infProps: IInfrastructure & IConfiguration = {
|
97 |
|
98 |
|
99 | infrastructureType: Types.INFRASTRUCTURE_TYPE_CONFIGURATION,
|
100 |
|
101 | instanceId: props.stackName,
|
102 |
|
103 | instanceType: SERVICEORIENTED_INSTANCE_TYPE,
|
104 |
|
105 |
|
106 | createPlugins: (configPath: string, stage: string | undefined, parserMode: string) => props.infrastructureMode === "COMPILATION" ? [
|
107 |
|
108 | SoaPlugin({
|
109 | stage: stage,
|
110 | parserMode: parserMode,
|
111 | buildPath: props.buildPath,
|
112 | configFilePath: configPath
|
113 | }),
|
114 |
|
115 |
|
116 | EnvironmentPlugin({
|
117 | stage: stage,
|
118 | parserMode: parserMode
|
119 | }),
|
120 |
|
121 | ServicePlugin({}),
|
122 |
|
123 | DataLayerPlugin({
|
124 | buildPath: props.buildPath,
|
125 | configFilePath: configPath,
|
126 | }),
|
127 |
|
128 |
|
129 | StoragePlugin({
|
130 | buildPath: props.buildPath,
|
131 | parserMode: parserMode
|
132 | })
|
133 |
|
134 | ] : []
|
135 | };
|
136 |
|
137 |
|
138 | const spaProps: IServiceOrientedProps = {
|
139 | id: props.stackName,
|
140 |
|
141 | routes: getChildrenArray(props.children)
|
142 | .filter(child => isRoute(child)),
|
143 |
|
144 | redirects: [],
|
145 |
|
146 | services: findComponentRecursively(props.children, c => isService(c) || isStorage(c)),
|
147 |
|
148 | dataLayerId: findComponentRecursively(props.children, isDataLayer).reduce((res, dl) => res ? res : dl.id, undefined)
|
149 | }
|
150 |
|
151 |
|
152 | return Object.assign(props, infProps, spaProps);
|
153 |
|
154 |
|
155 | };
|
156 |
|
157 | export function isServiceOrientedApp(component) {
|
158 | return component !== undefined &&
|
159 | component.instanceType === SERVICEORIENTED_INSTANCE_TYPE
|
160 | } |
\ | No newline at end of file |