UNPKG

2.2 kBPlain TextView Raw
1
2import * as deepmerge from 'deepmerge';
3
4import { IPlugin } from './plugin';
5import { IConfigParseResult, mergeParseResults } from './config-parse-result'
6import { extractPlugins, isConfiguration } from "../types/configuration";
7import { getChildrenArray } from './index';
8import { INFRASTRUCTURE_MODES, loadInfrastructureComponent } from './loader';
9
10export 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 * parses the configuration for plugins and returns a list of the plugins (objects)
19 *
20 * @param configPath the path to the compiled and evaluable configuration
21 * @param origConfigPath the path to the original uncompiled configuration source!
22 */
23export function parseForPlugins (
24 parsedComponent: any,
25 origConfigPath: string,
26 stage: string | undefined,
27 parserMode: string): Array<IPlugin> {
28
29 //console.log("configPath: ", configPath);
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 * parses a configuration, this configuration must export the main component as default
44 *
45 *
46 * @param component (main component of the configuration)
47 * @param compileMode set to true to run the parser with a statically loaded configuration (without objects)
48 */
49
50export function extractConfigs(parsedComponent, plugins, infrastructureMode: string | undefined): IConfigParseResult {
51
52 const results: Array<IConfigParseResult> = plugins
53
54 // check for plugins to apply
55 .filter(plugin => plugin.applies(parsedComponent))
56
57 // apply applicable plugins
58 .map(plugin => {
59 const childConfigs = getChildrenArray(parsedComponent).map(child => extractConfigs(child, plugins, infrastructureMode))
60 const r= plugin.process(parsedComponent, childConfigs, infrastructureMode);
61 //console.log("result: ", r);
62 return r;
63 })
64
65 //console.log("extract Configs result: ", results);
66
67 return mergeParseResults(results);
68
69};