@nzz/q-cli 1.5.2 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -84,20 +84,49 @@ async function getUpdatedItem(
|
|
84
84
|
environment
|
85
85
|
);
|
86
86
|
|
87
|
-
|
87
|
+
// Merge options:
|
88
|
+
// File of files property will be updated (if file exists on destination)
|
89
|
+
// If it doesn't exist it is appended to the files array
|
90
|
+
// All other properties are overwritten from source config
|
91
|
+
const options = {
|
88
92
|
arrayMerge: (destArr, srcArr) => srcArr,
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
93
|
+
customMerge: (key) => {
|
94
|
+
if (key === "files") {
|
95
|
+
return (destArr, srcArr) => {
|
96
|
+
if (destArr.length <= 0) {
|
97
|
+
return srcArr;
|
98
|
+
}
|
99
|
+
|
100
|
+
srcArr.forEach((fileObj) => {
|
101
|
+
let destIndex = destArr.findIndex(
|
102
|
+
(destFileObj) =>
|
103
|
+
destFileObj.file.originalName === fileObj.file.originalName
|
104
|
+
);
|
105
|
+
|
106
|
+
if (destIndex !== -1) {
|
107
|
+
destArr[destIndex] = fileObj;
|
108
|
+
} else {
|
109
|
+
destArr.push(fileObj);
|
110
|
+
}
|
111
|
+
});
|
112
|
+
return destArr;
|
113
|
+
};
|
114
|
+
}
|
115
|
+
},
|
116
|
+
};
|
117
|
+
|
118
|
+
// merges existing item with the item defined in q.config.json
|
119
|
+
const updatedItem = deepmerge(existingItem, item, options);
|
120
|
+
// normalizes the item which removes additional properties not defined in the schema
|
121
|
+
// and validates the item against the schema
|
122
|
+
const normalizedItem = getNormalizedItem(
|
123
|
+
toolSchema,
|
124
|
+
updatedItem,
|
125
|
+
environment
|
126
|
+
);
|
127
|
+
// the normalized item is merged with the existing item. This is done because properties such as _id and _rev
|
128
|
+
// defined in the existing item are removed during normalization, because they are not defined in the schema
|
129
|
+
return deepmerge(existingItem, normalizedItem, options);
|
101
130
|
} catch (error) {
|
102
131
|
console.error(errorColor(error.message));
|
103
132
|
process.exit(1);
|
@@ -168,12 +197,17 @@ function validateConfig(config) {
|
|
168
197
|
};
|
169
198
|
}
|
170
199
|
|
171
|
-
function
|
200
|
+
function getNormalizedItem(schema, item, environment) {
|
172
201
|
const isValid = ajv.validate(schema, item);
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
202
|
+
if (!isValid) {
|
203
|
+
throw new Error(
|
204
|
+
`A problem occured while validating item with id ${environment.id} on ${
|
205
|
+
environment.name
|
206
|
+
} environment: ${ajv.errorsText()}`
|
207
|
+
);
|
208
|
+
}
|
209
|
+
|
210
|
+
return item;
|
177
211
|
}
|
178
212
|
|
179
213
|
function getEnvironments(qConfig, environmentFilter) {
|