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 { isMiddleware } from '../middleware/middleware-component';
|
9 | import { isWebApp } from '../webapp/webapp-component';
|
10 | import { isRoute } from '../route/route-component';
|
11 |
|
12 | import { getChildrenArray } from '../libs';
|
13 |
|
14 | import { SpaPlugin } from './spa-plugin';
|
15 | import { WebAppPlugin } from '../webapp/webapp-plugin';
|
16 | import { EnvironmentPlugin } from '../environment/environment-plugin';
|
17 |
|
18 |
|
19 | export const SINGLEPAGE_INSTANCE_TYPE = "SinglePageComponent";
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | export interface ISinglePageArgs {
|
25 |
|
26 | |
27 |
|
28 |
|
29 | stackName: string,
|
30 |
|
31 | |
32 |
|
33 |
|
34 | buildPath: string,
|
35 |
|
36 | |
37 |
|
38 |
|
39 | region: string
|
40 | }
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | export interface ISinglePageProps {
|
47 | |
48 |
|
49 |
|
50 | id: string,
|
51 |
|
52 | |
53 |
|
54 |
|
55 | routes: Array<any>,
|
56 |
|
57 | |
58 |
|
59 |
|
60 | redirects: Array<any>
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | export default (props: ISinglePageArgs | any) => {
|
69 |
|
70 | const infProps: IInfrastructure & IConfiguration = {
|
71 |
|
72 |
|
73 | infrastructureType: Types.INFRASTRUCTURE_TYPE_CONFIGURATION,
|
74 |
|
75 | instanceId: props.stackName,
|
76 |
|
77 | instanceType: SINGLEPAGE_INSTANCE_TYPE,
|
78 |
|
79 |
|
80 | createPlugins: (configPath: string, stage: string | undefined, parserMode: string) => props.infrastructureMode === "COMPILATION" ? [
|
81 |
|
82 | SpaPlugin({
|
83 | stage: stage,
|
84 | parserMode: parserMode,
|
85 | buildPath: props.buildPath,
|
86 | configFilePath: configPath
|
87 | }),
|
88 |
|
89 |
|
90 | EnvironmentPlugin({
|
91 | stage: stage,
|
92 | parserMode: parserMode
|
93 | }),
|
94 |
|
95 |
|
96 | ] : []
|
97 | };
|
98 |
|
99 |
|
100 | const spaProps: ISinglePageProps = {
|
101 | id: props.stackName,
|
102 |
|
103 | routes: getChildrenArray(props.children)
|
104 | .filter(child => isRoute(child)),
|
105 |
|
106 | redirects: []
|
107 | }
|
108 |
|
109 |
|
110 | return Object.assign(props, infProps, spaProps);
|
111 |
|
112 |
|
113 | };
|
114 |
|
115 | export function isSinglePageApp(component) {
|
116 | return component !== undefined &&
|
117 | component.instanceType === SINGLEPAGE_INSTANCE_TYPE
|
118 | } |
\ | No newline at end of file |