1 |
|
2 | import * as deepmerge from 'deepmerge';
|
3 |
|
4 | import { IPlugin } from './plugin';
|
5 | import { IConfigParseResult, mergeParseResults } from './config-parse-result'
|
6 | import { extractPlugins, isConfiguration } from "../types/configuration";
|
7 | import { getChildrenArray } from './index';
|
8 | import { INFRASTRUCTURE_MODES, loadInfrastructureComponent } from './loader';
|
9 |
|
10 | export const PARSER_MODES = {
|
11 | MODE_BUILD: "MODE_BUILD",
|
12 | MODE_START: "MODE_START",
|
13 | MODE_DEPLOY: "MODE_DEPLOY",
|
14 | MODE_DOMAIN: "MODE_DOMAIN"
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | export function parseForPlugins (
|
24 | parsedComponent: any,
|
25 | origConfigPath: string,
|
26 | stage: string | undefined,
|
27 | parserMode: string): Array<IPlugin> {
|
28 |
|
29 |
|
30 |
|
31 | if (isConfiguration(parsedComponent)) {
|
32 | return extractPlugins(parsedComponent, origConfigPath, stage, parserMode);
|
33 |
|
34 | } else {
|
35 | console.error("main component is not a valid app!")
|
36 | return [];
|
37 | }
|
38 |
|
39 | };
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | export function extractConfigs(parsedComponent, plugins, infrastructureMode: string | undefined): IConfigParseResult {
|
51 |
|
52 | const results: Array<IConfigParseResult> = plugins
|
53 |
|
54 |
|
55 | .filter(plugin => plugin.applies(parsedComponent))
|
56 |
|
57 |
|
58 | .map(plugin => {
|
59 | const childConfigs = getChildrenArray(parsedComponent).map(child => extractConfigs(child, plugins, infrastructureMode))
|
60 | const r= plugin.process(parsedComponent, childConfigs, infrastructureMode);
|
61 |
|
62 | return r;
|
63 | })
|
64 |
|
65 |
|
66 |
|
67 | return mergeParseResults(results);
|
68 |
|
69 | };
|