1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getValueOfPath = exports.getValueOrDefault = void 0;
|
4 | function getValueOrDefault(configuration, propertyPath, appName, key, options = [], defaultValue) {
|
5 | const item = options.find((option) => option.name === key);
|
6 | const origValue = item && item.value;
|
7 | if (origValue !== undefined && origValue !== null) {
|
8 | return origValue;
|
9 | }
|
10 | if (configuration.projects && configuration.projects[appName]) {
|
11 |
|
12 |
|
13 | appName = appName && !appName.includes('"') ? `"${appName}"` : appName;
|
14 | const perAppValue = getValueOfPath(configuration, `projects.${appName}.`.concat(propertyPath));
|
15 | if (perAppValue !== undefined) {
|
16 | return perAppValue;
|
17 | }
|
18 | }
|
19 | let value = getValueOfPath(configuration, propertyPath);
|
20 | if (value === undefined) {
|
21 | value = defaultValue;
|
22 | }
|
23 | return value;
|
24 | }
|
25 | exports.getValueOrDefault = getValueOrDefault;
|
26 | function getValueOfPath(object, propertyPath) {
|
27 | const fragments = propertyPath.split('.');
|
28 | let propertyValue = object;
|
29 | let isConcatInProgress = false;
|
30 | let path = '';
|
31 | for (const fragment of fragments) {
|
32 | if (!propertyValue) {
|
33 | break;
|
34 | }
|
35 | |
36 |
|
37 |
|
38 |
|
39 |
|
40 | if (fragment.startsWith('"') && fragment.endsWith('"')) {
|
41 | path = stripDoubleQuotes(fragment);
|
42 | }
|
43 | else if (fragment.startsWith('"')) {
|
44 | path += stripDoubleQuotes(fragment) + '.';
|
45 | isConcatInProgress = true;
|
46 | continue;
|
47 | }
|
48 | else if (isConcatInProgress && !fragment.endsWith('"')) {
|
49 | path += fragment + '.';
|
50 | continue;
|
51 | }
|
52 | else if (fragment.endsWith('"')) {
|
53 | path += stripDoubleQuotes(fragment);
|
54 | isConcatInProgress = false;
|
55 | }
|
56 | else {
|
57 | path = fragment;
|
58 | }
|
59 | propertyValue = propertyValue[path];
|
60 | path = '';
|
61 | }
|
62 | return propertyValue;
|
63 | }
|
64 | exports.getValueOfPath = getValueOfPath;
|
65 | function stripDoubleQuotes(text) {
|
66 | return text.replace(/"/g, '');
|
67 | }
|