@nzz/q-cli 1.5.2 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -84,20 +84,49 @@ async function getUpdatedItem(
84
84
  environment
85
85
  );
86
86
 
87
- const updatedItem = deepmerge(existingItem, item, {
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
- const validationResult = validateItem(toolSchema, updatedItem);
92
- if (validationResult.isValid) {
93
- return deepmerge(existingItem, updatedItem, {
94
- arrayMerge: (destArr, srcArr) => srcArr,
95
- });
96
- } else {
97
- throw new Error(
98
- `A problem occured while validating item with id ${environment.id} on ${environment.name} environment: ${validationResult.errorsText}`
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 validateItem(schema, item) {
200
+ function getNormalizedItem(schema, item, environment) {
172
201
  const isValid = ajv.validate(schema, item);
173
- return {
174
- isValid: isValid,
175
- errorsText: ajv.errorsText(),
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nzz/q-cli",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "Cli tool to setup new Q tools, new Q server implementations and start Q dev server to test developing Q tools",
5
5
  "main": "index.js",
6
6
  "scripts": {