@nzz/q-cli 1.9.1 → 1.9.2
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.
- package/.history/bin/commands/qItem/itemService_20220627113036.js +302 -0
- package/.history/bin/commands/qItem/itemService_20221105174223.js +304 -0
- package/.history/bin/commands/qItem/itemService_20221105174236.js +304 -0
- package/.history/bin/commands/qItem/itemService_20221105174311.js +304 -0
- package/.history/bin/commands/qItem/itemService_20221105174605.js +306 -0
- package/.history/bin/commands/qItem/itemService_20221105174809.js +309 -0
- package/.history/bin/commands/qItem/itemService_20221107071956.js +317 -0
- package/.history/bin/commands/qItem/itemService_20221107072130.js +310 -0
- package/.history/bin/commands/qItem/itemService_20221107072222.js +312 -0
- package/.history/bin/commands/qItem/itemService_20221107072621.js +316 -0
- package/.history/bin/commands/qItem/itemService_20221107072850.js +315 -0
- package/.history/bin/commands/qItem/itemService_20221107073051.js +315 -0
- package/.history/bin/commands/qItem/itemService_20221107073244.js +315 -0
- package/.history/bin/commands/qItem/itemService_20221107075352.js +323 -0
- package/.history/bin/commands/qItem/itemService_20221107075536.js +316 -0
- package/.history/bin/commands/qItem/itemService_20221107075700.js +312 -0
- package/.history/bin/commands/qItem/itemService_20221107111951.js +312 -0
- package/.history/bin/commands/qItem/itemService_20221107113745.js +310 -0
- package/.history/bin/commands/qItem/itemService_20221107113901.js +310 -0
- package/.history/bin/commands/qItem/updateItem/updateItem_20220627113036.js +64 -0
- package/.history/bin/commands/qItem/updateItem/updateItem_20221105173137.js +66 -0
- package/.history/bin/commands/qItem/updateItem/updateItem_20221105173239.js +68 -0
- package/.history/bin/commands/qItem/updateItem/updateItem_20221105173610.js +69 -0
- package/.history/bin/commands/qItem/updateItem/updateItem_20221105173646.js +74 -0
- package/.history/bin/commands/qItem/updateItem/updateItem_20221105174010.js +74 -0
- package/.history/bin/commands/qItem/updateItem/updateItem_20221105174054.js +75 -0
- package/.history/package_20220808135115.json +43 -0
- package/.history/package_20221105171707.json +43 -0
- package/.history/package_20221105173355.json +43 -0
- package/.history/package_20221107112303.json +43 -0
- package/bin/commands/qItem/itemService.js +12 -4
- package/package.json +2 -2
@@ -0,0 +1,310 @@
|
|
1
|
+
const resourcesService = require("./resourcesService.js");
|
2
|
+
const schemaService = require("./schemaService.js");
|
3
|
+
const deepmerge = require("deepmerge");
|
4
|
+
const fetch = require("node-fetch");
|
5
|
+
const chalk = require("chalk");
|
6
|
+
const errorColor = chalk.red;
|
7
|
+
|
8
|
+
async function createItem(item, environment, config) {
|
9
|
+
const qServer = config.get(`${environment.name}.qServer`);
|
10
|
+
const accessToken = config.get(`${environment.name}.accessToken`);
|
11
|
+
const cookie = config.get(`${environment.name}.cookie`);
|
12
|
+
|
13
|
+
try {
|
14
|
+
const response = await fetch(`${qServer}item`, {
|
15
|
+
method: "POST",
|
16
|
+
body: JSON.stringify(item),
|
17
|
+
headers: {
|
18
|
+
"user-agent": "Q Command-line Tool",
|
19
|
+
Authorization: `Bearer ${accessToken}`,
|
20
|
+
"Content-Type": "application/json",
|
21
|
+
Cookie: cookie ? cookie : "",
|
22
|
+
},
|
23
|
+
});
|
24
|
+
if (response.ok) {
|
25
|
+
return await response.json();
|
26
|
+
} else {
|
27
|
+
throw new Error(
|
28
|
+
`A problem occured while creating item on ${environment.name} environment. Please check your connection and try again.`
|
29
|
+
);
|
30
|
+
}
|
31
|
+
} catch (error) {
|
32
|
+
console.error(errorColor(error.message));
|
33
|
+
process.exit(1);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
async function getItem(qServer, environment, accessToken, cookie) {
|
38
|
+
try {
|
39
|
+
const response = await fetch(`${qServer}item/${environment.id}`, {
|
40
|
+
headers: {
|
41
|
+
"user-agent": "Q Command-line Tool",
|
42
|
+
Authorization: `Bearer ${accessToken}`,
|
43
|
+
Cookie: cookie ? cookie : "",
|
44
|
+
},
|
45
|
+
});
|
46
|
+
if (response.ok) {
|
47
|
+
return await response.json();
|
48
|
+
} else {
|
49
|
+
throw new Error(
|
50
|
+
`A problem occured while getting item with id ${environment.id} on ${environment.name} environment. Please make sure that the id is correct, you have an internet connection and try again.`
|
51
|
+
);
|
52
|
+
}
|
53
|
+
} catch (error) {
|
54
|
+
console.error(errorColor(error.message));
|
55
|
+
process.exit(1);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
function getItems(qConfig, environmentFilter) {
|
60
|
+
const items = qConfig.items
|
61
|
+
.filter((item) => {
|
62
|
+
if (environmentFilter) {
|
63
|
+
return item.environments.some(
|
64
|
+
(environment) => environment.name === environmentFilter
|
65
|
+
);
|
66
|
+
}
|
67
|
+
|
68
|
+
return true;
|
69
|
+
})
|
70
|
+
.map((item) => {
|
71
|
+
if (environmentFilter) {
|
72
|
+
item.environments = item.environments.filter(
|
73
|
+
(environment) => environment.name === environmentFilter
|
74
|
+
);
|
75
|
+
}
|
76
|
+
|
77
|
+
return item;
|
78
|
+
});
|
79
|
+
|
80
|
+
return items;
|
81
|
+
}
|
82
|
+
|
83
|
+
function getDefaultOrNull(schema) {
|
84
|
+
if (schema.hasOwnProperty("default")) {
|
85
|
+
if (typeof schema.default === "object") {
|
86
|
+
return JSON.parse(JSON.stringify(schema.default));
|
87
|
+
}
|
88
|
+
return schema.default;
|
89
|
+
}
|
90
|
+
return null;
|
91
|
+
}
|
92
|
+
|
93
|
+
// Returns a default item based on the tool schema
|
94
|
+
// The default item is used to derive the file properties of a certain file type
|
95
|
+
// These file properties are specified by the tool and are specific to the file type
|
96
|
+
// For example an image file has height/width file properties
|
97
|
+
function getDefaultItem(schema) {
|
98
|
+
schema = JSON.parse(JSON.stringify(schema));
|
99
|
+
if (schema.type === "array") {
|
100
|
+
let array = [];
|
101
|
+
schema.minItems = 1;
|
102
|
+
for (let i = 0; i < schema.minItems; i++) {
|
103
|
+
let value = getDefaultItem(schema.items);
|
104
|
+
if (value) {
|
105
|
+
if (
|
106
|
+
schema["Q:type"] &&
|
107
|
+
schema["Q:type"] === "files" &&
|
108
|
+
schema["Q:options"] &&
|
109
|
+
schema["Q:options"].fileProperties
|
110
|
+
) {
|
111
|
+
array.push(Object.assign(value, schema["Q:options"].fileProperties));
|
112
|
+
} else {
|
113
|
+
array.push(value);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
const defaultValue = getDefaultOrNull(schema);
|
119
|
+
if (array === null && defaultValue !== null) {
|
120
|
+
array = defaultValue;
|
121
|
+
}
|
122
|
+
return array;
|
123
|
+
} else if (schema.type === "object") {
|
124
|
+
const defaultValue = getDefaultOrNull(schema);
|
125
|
+
if (defaultValue !== null) {
|
126
|
+
return defaultValue;
|
127
|
+
}
|
128
|
+
|
129
|
+
if (
|
130
|
+
schema["Q:type"] &&
|
131
|
+
schema["Q:type"] === "files" &&
|
132
|
+
schema["Q:options"] &&
|
133
|
+
schema["Q:options"].fileProperties
|
134
|
+
) {
|
135
|
+
return schema["Q:options"].fileProperties;
|
136
|
+
}
|
137
|
+
|
138
|
+
if (!schema.hasOwnProperty("properties")) {
|
139
|
+
return undefined;
|
140
|
+
}
|
141
|
+
let object = {};
|
142
|
+
Object.keys(schema.properties).forEach((propertyName) => {
|
143
|
+
const property = schema.properties[propertyName];
|
144
|
+
let value = getDefaultItem(property);
|
145
|
+
if (value !== undefined) {
|
146
|
+
object[propertyName] = value;
|
147
|
+
} else if (
|
148
|
+
property["Q:type"] &&
|
149
|
+
property["Q:type"] === "files" &&
|
150
|
+
property["Q:options"] &&
|
151
|
+
property["Q:options"].fileProperties
|
152
|
+
) {
|
153
|
+
object[propertyName] = property["Q:options"].fileProperties;
|
154
|
+
}
|
155
|
+
});
|
156
|
+
return object;
|
157
|
+
}
|
158
|
+
|
159
|
+
// if this is not an array or object, we just get the default if any
|
160
|
+
const defaultValue = getDefaultOrNull(schema);
|
161
|
+
if (defaultValue !== null) {
|
162
|
+
return defaultValue;
|
163
|
+
}
|
164
|
+
return undefined;
|
165
|
+
}
|
166
|
+
|
167
|
+
async function updateItem(item, environment, config, qConfigPath) {
|
168
|
+
const qServer = config.get(`${environment.name}.qServer`);
|
169
|
+
const accessToken = config.get(`${environment.name}.accessToken`);
|
170
|
+
const cookie = config.get(`${environment.name}.cookie`);
|
171
|
+
const existingItem = await getItem(qServer, environment, accessToken, cookie);
|
172
|
+
const updatedItem = await getUpdatedItem(
|
173
|
+
qServer,
|
174
|
+
accessToken,
|
175
|
+
cookie,
|
176
|
+
existingItem,
|
177
|
+
item,
|
178
|
+
environment,
|
179
|
+
qConfigPath
|
180
|
+
);
|
181
|
+
return await saveItem(qServer, environment, accessToken, cookie, updatedItem);
|
182
|
+
}
|
183
|
+
|
184
|
+
async function getUpdatedItem(
|
185
|
+
qServer,
|
186
|
+
accessToken,
|
187
|
+
cookie,
|
188
|
+
existingItem,
|
189
|
+
item,
|
190
|
+
environment,
|
191
|
+
qConfigPath
|
192
|
+
) {
|
193
|
+
try {
|
194
|
+
const toolSchema = await schemaService.getToolSchema(
|
195
|
+
qServer,
|
196
|
+
existingItem.tool
|
197
|
+
);
|
198
|
+
// Removes additional properties not defined in the schema on the top level object of the item
|
199
|
+
toolSchema.additionalProperties = false;
|
200
|
+
|
201
|
+
if(existingItem.customSchema) {
|
202
|
+
toolSchema.properties = {...toolSchema.properties, ...existingItem.customSchema}
|
203
|
+
}
|
204
|
+
|
205
|
+
if(existingItem.customSchemaDefinitions) {
|
206
|
+
toolSchema.definitions = {...toolSchema.definitions, ...existingItem.customSchemaDefinitions}
|
207
|
+
}
|
208
|
+
// If options object is available additional properties not defined in the schema are removed
|
209
|
+
if (toolSchema.properties && toolSchema.properties.options) {
|
210
|
+
toolSchema.properties.options.additionalProperties = false;
|
211
|
+
}
|
212
|
+
const defaultItem = getDefaultItem(toolSchema);
|
213
|
+
item = JSON.parse(JSON.stringify(item));
|
214
|
+
item = await resourcesService.handleResources(
|
215
|
+
qServer,
|
216
|
+
accessToken,
|
217
|
+
cookie,
|
218
|
+
item,
|
219
|
+
defaultItem,
|
220
|
+
qConfigPath,
|
221
|
+
environment
|
222
|
+
);
|
223
|
+
|
224
|
+
// Merge options:
|
225
|
+
// File of files property will be updated (if file exists on destination)
|
226
|
+
// If it doesn't exist it is appended to the files array
|
227
|
+
// All other properties are overwritten from source config
|
228
|
+
const options = {
|
229
|
+
arrayMerge: (destArr, srcArr) => srcArr,
|
230
|
+
customMerge: (key) => {
|
231
|
+
if (key === "files") {
|
232
|
+
return (destArr, srcArr) => {
|
233
|
+
if (destArr.length <= 0) {
|
234
|
+
return srcArr;
|
235
|
+
}
|
236
|
+
|
237
|
+
srcArr.forEach((fileObj) => {
|
238
|
+
let destIndex = destArr.findIndex(
|
239
|
+
(destFileObj) =>
|
240
|
+
destFileObj.file.originalName === fileObj.file.originalName
|
241
|
+
);
|
242
|
+
|
243
|
+
if (destIndex !== -1) {
|
244
|
+
destArr[destIndex] = fileObj;
|
245
|
+
} else {
|
246
|
+
destArr.push(fileObj);
|
247
|
+
}
|
248
|
+
});
|
249
|
+
return destArr;
|
250
|
+
};
|
251
|
+
}
|
252
|
+
},
|
253
|
+
};
|
254
|
+
|
255
|
+
// merges existing item with the item defined in q.config.json
|
256
|
+
const updatedItem = deepmerge(existingItem, item, options);
|
257
|
+
// normalizes the item which removes additional properties not defined in the schema
|
258
|
+
// and validates the item against the schema
|
259
|
+
const normalizedItem = schemaService.getNormalizedItem(
|
260
|
+
toolSchema,
|
261
|
+
updatedItem,
|
262
|
+
environment
|
263
|
+
);
|
264
|
+
// the normalized item is merged with the existing item. This is done because properties such as _id and _rev
|
265
|
+
// defined in the existing item are removed during normalization, because they are not defined in the schema
|
266
|
+
return deepmerge(existingItem, normalizedItem, options);
|
267
|
+
} catch (error) {
|
268
|
+
console.error(errorColor(error.message));
|
269
|
+
process.exit(1);
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
async function saveItem(
|
274
|
+
qServer,
|
275
|
+
environment,
|
276
|
+
accessToken,
|
277
|
+
cookie,
|
278
|
+
updatedItem
|
279
|
+
) {
|
280
|
+
try {
|
281
|
+
delete updatedItem.updatedDate;
|
282
|
+
const response = await fetch(`${qServer}item`, {
|
283
|
+
method: "PUT",
|
284
|
+
body: JSON.stringify(updatedItem),
|
285
|
+
headers: {
|
286
|
+
"user-agent": "Q Command-line Tool",
|
287
|
+
Authorization: `Bearer ${accessToken}`,
|
288
|
+
"Content-Type": "application/json",
|
289
|
+
Cookie: cookie ? cookie : "",
|
290
|
+
},
|
291
|
+
});
|
292
|
+
if (response.ok) {
|
293
|
+
return await response.json();
|
294
|
+
} else {
|
295
|
+
throw new Error(
|
296
|
+
`A problem occured while saving item with id ${environment.id} on ${environment.name} environment. Please check your connection and try again.`
|
297
|
+
);
|
298
|
+
}
|
299
|
+
} catch (error) {
|
300
|
+
console.error(errorColor(error.message));
|
301
|
+
process.exit(1);
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
module.exports = {
|
306
|
+
createItem: createItem,
|
307
|
+
getItem: getItem,
|
308
|
+
getItems: getItems,
|
309
|
+
updateItem: updateItem,
|
310
|
+
};
|
@@ -0,0 +1,64 @@
|
|
1
|
+
const schemaService = require("./../schemaService.js");
|
2
|
+
const configStore = require("./../configStore.js");
|
3
|
+
const itemService = require("./../itemService.js");
|
4
|
+
const fs = require("fs");
|
5
|
+
const path = require("path");
|
6
|
+
const chalk = require("chalk");
|
7
|
+
const errorColor = chalk.red;
|
8
|
+
const successColor = chalk.green;
|
9
|
+
|
10
|
+
module.exports = async function (command) {
|
11
|
+
try {
|
12
|
+
const qConfigPath = path.resolve(command.config);
|
13
|
+
if (fs.existsSync(qConfigPath)) {
|
14
|
+
const qConfig = JSON.parse(fs.readFileSync(qConfigPath));
|
15
|
+
const validationResult = schemaService.validateConfig(qConfig);
|
16
|
+
|
17
|
+
if (validationResult.isValid) {
|
18
|
+
const config = await configStore.setupStore(
|
19
|
+
qConfig,
|
20
|
+
command.environment,
|
21
|
+
command.reset
|
22
|
+
);
|
23
|
+
|
24
|
+
for (const item of itemService.getItems(qConfig, command.environment)) {
|
25
|
+
for (const environment of item.environments) {
|
26
|
+
const result = await itemService.updateItem(
|
27
|
+
item.item,
|
28
|
+
environment,
|
29
|
+
config,
|
30
|
+
qConfigPath
|
31
|
+
);
|
32
|
+
|
33
|
+
if (result) {
|
34
|
+
console.log(
|
35
|
+
successColor(
|
36
|
+
`Successfully updated item with id ${environment.id} on ${environment.name} environment`
|
37
|
+
)
|
38
|
+
);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
} else {
|
43
|
+
console.error(
|
44
|
+
errorColor(
|
45
|
+
`A problem occured while validating the config file: ${validationResult.errorsText}`
|
46
|
+
)
|
47
|
+
);
|
48
|
+
process.exit(1);
|
49
|
+
}
|
50
|
+
} else {
|
51
|
+
console.error(
|
52
|
+
errorColor(
|
53
|
+
"Couldn't find config file named q.config.json in the current directory. Create a config file in the current directory or pass the path to the config file with the option -c <path>"
|
54
|
+
)
|
55
|
+
);
|
56
|
+
}
|
57
|
+
} catch (error) {
|
58
|
+
console.error(
|
59
|
+
errorColor(
|
60
|
+
`A problem occured while parsing the config file at ${command.config}. Please make sure it is valid JSON.`
|
61
|
+
)
|
62
|
+
);
|
63
|
+
}
|
64
|
+
};
|
@@ -0,0 +1,66 @@
|
|
1
|
+
const schemaService = require("./../schemaService.js");
|
2
|
+
const configStore = require("./../configStore.js");
|
3
|
+
const itemService = require("./../itemService.js");
|
4
|
+
const fs = require("fs");
|
5
|
+
const path = require("path");
|
6
|
+
const chalk = require("chalk");
|
7
|
+
const errorColor = chalk.red;
|
8
|
+
const successColor = chalk.green;
|
9
|
+
|
10
|
+
module.exports = async function (command) {
|
11
|
+
try {
|
12
|
+
const qConfigPath = path.resolve(command.config);
|
13
|
+
if (fs.existsSync(qConfigPath)) {
|
14
|
+
const qConfig = JSON.parse(fs.readFileSync(qConfigPath));
|
15
|
+
console.log(qConfig)
|
16
|
+
const validationResult = schemaService.validateConfig(qConfig);
|
17
|
+
console.log(validationResult)
|
18
|
+
|
19
|
+
if (validationResult.isValid) {
|
20
|
+
const config = await configStore.setupStore(
|
21
|
+
qConfig,
|
22
|
+
command.environment,
|
23
|
+
command.reset
|
24
|
+
);
|
25
|
+
|
26
|
+
for (const item of itemService.getItems(qConfig, command.environment)) {
|
27
|
+
for (const environment of item.environments) {
|
28
|
+
const result = await itemService.updateItem(
|
29
|
+
item.item,
|
30
|
+
environment,
|
31
|
+
config,
|
32
|
+
qConfigPath
|
33
|
+
);
|
34
|
+
|
35
|
+
if (result) {
|
36
|
+
console.log(
|
37
|
+
successColor(
|
38
|
+
`Successfully updated item with id ${environment.id} on ${environment.name} environment`
|
39
|
+
)
|
40
|
+
);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
} else {
|
45
|
+
console.error(
|
46
|
+
errorColor(
|
47
|
+
`A problem occured while validating the config file: ${validationResult.errorsText}`
|
48
|
+
)
|
49
|
+
);
|
50
|
+
process.exit(1);
|
51
|
+
}
|
52
|
+
} else {
|
53
|
+
console.error(
|
54
|
+
errorColor(
|
55
|
+
"Couldn't find config file named q.config.json in the current directory. Create a config file in the current directory or pass the path to the config file with the option -c <path>"
|
56
|
+
)
|
57
|
+
);
|
58
|
+
}
|
59
|
+
} catch (error) {
|
60
|
+
console.error(
|
61
|
+
errorColor(
|
62
|
+
`A problem occured while parsing the config file at ${command.config}. Please make sure it is valid JSON.`
|
63
|
+
)
|
64
|
+
);
|
65
|
+
}
|
66
|
+
};
|
@@ -0,0 +1,68 @@
|
|
1
|
+
const schemaService = require("./../schemaService.js");
|
2
|
+
const configStore = require("./../configStore.js");
|
3
|
+
const itemService = require("./../itemService.js");
|
4
|
+
const fs = require("fs");
|
5
|
+
const path = require("path");
|
6
|
+
const chalk = require("chalk");
|
7
|
+
const errorColor = chalk.red;
|
8
|
+
const successColor = chalk.green;
|
9
|
+
|
10
|
+
module.exports = async function (command) {
|
11
|
+
try {
|
12
|
+
const qConfigPath = path.resolve(command.config);
|
13
|
+
if (fs.existsSync(qConfigPath)) {
|
14
|
+
const qConfig = JSON.parse(fs.readFileSync(qConfigPath));
|
15
|
+
console.log("----------------")
|
16
|
+
console.log(qConfig)
|
17
|
+
const validationResult = schemaService.validateConfig(qConfig);
|
18
|
+
console.log(validationResult)
|
19
|
+
|
20
|
+
console.log("----------------")
|
21
|
+
if (validationResult.isValid) {
|
22
|
+
const config = await configStore.setupStore(
|
23
|
+
qConfig,
|
24
|
+
command.environment,
|
25
|
+
command.reset
|
26
|
+
);
|
27
|
+
|
28
|
+
for (const item of itemService.getItems(qConfig, command.environment)) {
|
29
|
+
for (const environment of item.environments) {
|
30
|
+
const result = await itemService.updateItem(
|
31
|
+
item.item,
|
32
|
+
environment,
|
33
|
+
config,
|
34
|
+
qConfigPath
|
35
|
+
);
|
36
|
+
|
37
|
+
if (result) {
|
38
|
+
console.log(
|
39
|
+
successColor(
|
40
|
+
`Successfully updated item with id ${environment.id} on ${environment.name} environment`
|
41
|
+
)
|
42
|
+
);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
} else {
|
47
|
+
console.error(
|
48
|
+
errorColor(
|
49
|
+
`A problem occured while validating the config file: ${validationResult.errorsText}`
|
50
|
+
)
|
51
|
+
);
|
52
|
+
process.exit(1);
|
53
|
+
}
|
54
|
+
} else {
|
55
|
+
console.error(
|
56
|
+
errorColor(
|
57
|
+
"Couldn't find config file named q.config.json in the current directory. Create a config file in the current directory or pass the path to the config file with the option -c <path>"
|
58
|
+
)
|
59
|
+
);
|
60
|
+
}
|
61
|
+
} catch (error) {
|
62
|
+
console.error(
|
63
|
+
errorColor(
|
64
|
+
`A problem occured while parsing the config file at ${command.config}. Please make sure it is valid JSON.`
|
65
|
+
)
|
66
|
+
);
|
67
|
+
}
|
68
|
+
};
|
@@ -0,0 +1,69 @@
|
|
1
|
+
const schemaService = require("./../schemaService.js");
|
2
|
+
const configStore = require("./../configStore.js");
|
3
|
+
const itemService = require("./../itemService.js");
|
4
|
+
const fs = require("fs");
|
5
|
+
const path = require("path");
|
6
|
+
const chalk = require("chalk");
|
7
|
+
const errorColor = chalk.red;
|
8
|
+
const successColor = chalk.green;
|
9
|
+
|
10
|
+
module.exports = async function (command) {
|
11
|
+
try {
|
12
|
+
const qConfigPath = path.resolve(command.config);
|
13
|
+
if (fs.existsSync(qConfigPath)) {
|
14
|
+
const qConfig = JSON.parse(fs.readFileSync(qConfigPath));
|
15
|
+
console.log("----------------")
|
16
|
+
console.log(qConfig)
|
17
|
+
const validationResult = schemaService.validateConfig(qConfig);
|
18
|
+
console.log(validationResult)
|
19
|
+
|
20
|
+
console.log("----------------")
|
21
|
+
if (validationResult.isValid) {
|
22
|
+
const config = await configStore.setupStore(
|
23
|
+
qConfig,
|
24
|
+
command.environment,
|
25
|
+
command.reset
|
26
|
+
);
|
27
|
+
|
28
|
+
for (const item of itemService.getItems(qConfig, command.environment)) {
|
29
|
+
for (const environment of item.environments) {
|
30
|
+
const result = await itemService.updateItem(
|
31
|
+
item.item,
|
32
|
+
environment,
|
33
|
+
config,
|
34
|
+
qConfigPath
|
35
|
+
);
|
36
|
+
|
37
|
+
if (result) {
|
38
|
+
console.log("safljadsölkfjasdölk")
|
39
|
+
console.log(
|
40
|
+
successColor(
|
41
|
+
`Successfully updated item with id ${environment.id} on ${environment.name} environment`
|
42
|
+
)
|
43
|
+
);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
} else {
|
48
|
+
console.error(
|
49
|
+
errorColor(
|
50
|
+
`A problem occured while validating the config file: ${validationResult.errorsText}`
|
51
|
+
)
|
52
|
+
);
|
53
|
+
process.exit(1);
|
54
|
+
}
|
55
|
+
} else {
|
56
|
+
console.error(
|
57
|
+
errorColor(
|
58
|
+
"Couldn't find config file named q.config.json in the current directory. Create a config file in the current directory or pass the path to the config file with the option -c <path>"
|
59
|
+
)
|
60
|
+
);
|
61
|
+
}
|
62
|
+
} catch (error) {
|
63
|
+
console.error(
|
64
|
+
errorColor(
|
65
|
+
`A problem occured while parsing the config file at ${command.config}. Please make sure it is valid JSON.`
|
66
|
+
)
|
67
|
+
);
|
68
|
+
}
|
69
|
+
};
|
@@ -0,0 +1,74 @@
|
|
1
|
+
const schemaService = require("./../schemaService.js");
|
2
|
+
const configStore = require("./../configStore.js");
|
3
|
+
const itemService = require("./../itemService.js");
|
4
|
+
const fs = require("fs");
|
5
|
+
const path = require("path");
|
6
|
+
const chalk = require("chalk");
|
7
|
+
const errorColor = chalk.red;
|
8
|
+
const successColor = chalk.green;
|
9
|
+
|
10
|
+
module.exports = async function (command) {
|
11
|
+
try {
|
12
|
+
const qConfigPath = path.resolve(command.config);
|
13
|
+
if (fs.existsSync(qConfigPath)) {
|
14
|
+
const qConfig = JSON.parse(fs.readFileSync(qConfigPath));
|
15
|
+
console.log("----------------")
|
16
|
+
console.log(qConfig)
|
17
|
+
const validationResult = schemaService.validateConfig(qConfig);
|
18
|
+
console.log(validationResult)
|
19
|
+
|
20
|
+
console.log("----------------")
|
21
|
+
if (validationResult.isValid) {
|
22
|
+
const config = await configStore.setupStore(
|
23
|
+
qConfig,
|
24
|
+
command.environment,
|
25
|
+
command.reset
|
26
|
+
);
|
27
|
+
|
28
|
+
for (const item of itemService.getItems(qConfig, command.environment)) {
|
29
|
+
for (const environment of item.environments) {
|
30
|
+
const result = await itemService.updateItem(
|
31
|
+
item.item,
|
32
|
+
environment,
|
33
|
+
config,
|
34
|
+
qConfigPath
|
35
|
+
);
|
36
|
+
|
37
|
+
if (result) {
|
38
|
+
console.log(
|
39
|
+
successColor(
|
40
|
+
`--------------------`
|
41
|
+
)
|
42
|
+
);
|
43
|
+
|
44
|
+
console.log(
|
45
|
+
successColor(
|
46
|
+
`Successfully updated item with id ${environment.id} on ${environment.name} environment`
|
47
|
+
)
|
48
|
+
);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
} else {
|
53
|
+
console.error(
|
54
|
+
errorColor(
|
55
|
+
`A problem occured while validating the config file: ${validationResult.errorsText}`
|
56
|
+
)
|
57
|
+
);
|
58
|
+
process.exit(1);
|
59
|
+
}
|
60
|
+
} else {
|
61
|
+
console.error(
|
62
|
+
errorColor(
|
63
|
+
"Couldn't find config file named q.config.json in the current directory. Create a config file in the current directory or pass the path to the config file with the option -c <path>"
|
64
|
+
)
|
65
|
+
);
|
66
|
+
}
|
67
|
+
} catch (error) {
|
68
|
+
console.error(
|
69
|
+
errorColor(
|
70
|
+
`A problem occured while parsing the config file at ${command.config}. Please make sure it is valid JSON.`
|
71
|
+
)
|
72
|
+
);
|
73
|
+
}
|
74
|
+
};
|