UNPKG

2.97 kBPlain TextView Raw
1
2import React, { ReactNode} from 'react';
3
4import Types from '../types';
5import { IConfiguration } from "../types/configuration";
6import { IInfrastructure } from "../types";
7
8import { isMiddleware } from '../middleware/middleware-component';
9import { isWebApp } from '../webapp/webapp-component';
10import { isRoute } from '../route/route-component';
11
12import { getChildrenArray } from '../libs';
13
14import { SpaPlugin } from './spa-plugin';
15import { WebAppPlugin } from '../webapp/webapp-plugin';
16import { EnvironmentPlugin } from '../environment/environment-plugin';
17
18
19export const SINGLEPAGE_INSTANCE_TYPE = "SinglePageComponent";
20
21/**
22 * Specifies all the properties that an SinglePage-Component must get from the user, as args
23 */
24export interface ISinglePageArgs {
25
26 /**
27 * name of the Cloudformation Stack
28 */
29 stackName: string,
30
31 /**
32 * Local, relative directory specifies where to put the final bundles
33 */
34 buildPath: string,
35
36 /**
37 * The AWS region
38 */
39 region: string
40}
41
42/**
43 * specifies the properties that an SinglePage-Component has during runtime
44 * nothing else than we get from the user!
45 */
46export interface ISinglePageProps {
47 /**
48 * the SPA is webapp and must have an id
49 */
50 id: string,
51
52 /**
53 * Routes of the webapp
54 */
55 routes: Array<any>,
56
57 /**
58 * redirects of the webapp
59 */
60 redirects: Array<any>
61}
62
63/**
64 * The SinglePageApp is an infrastructure and must implement [[IInfrastructure]]
65 *
66 * @param props
67 */
68export default (props: ISinglePageArgs | any) => {
69
70 const infProps: IInfrastructure & IConfiguration = {
71
72 // allows to identify this component as Infrastructure
73 infrastructureType: Types.INFRASTRUCTURE_TYPE_CONFIGURATION,
74
75 instanceId: props.stackName,
76
77 instanceType: SINGLEPAGE_INSTANCE_TYPE,
78
79 // only load plugins during compilation
80 createPlugins: (configPath: string, stage: string | undefined, parserMode: string) => props.infrastructureMode === "COMPILATION" ? [
81 // be able to process IsomorphicApps (as top-level-node)
82 SpaPlugin({
83 stage: stage,
84 parserMode: parserMode,
85 buildPath: props.buildPath,
86 configFilePath: configPath
87 }),
88
89 // Single Page apps can have different environments
90 EnvironmentPlugin({
91 stage: stage,
92 parserMode: parserMode
93 }),
94
95
96 ] : []
97 };
98
99 // TODO maybe edit to support the web-mode?!
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
115export function isSinglePageApp(component) {
116 return component !== undefined &&
117 component.instanceType === SINGLEPAGE_INSTANCE_TYPE
118}
\No newline at end of file