-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidations.js
57 lines (41 loc) · 1.88 KB
/
validations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const fs = require("fs-extra");
const path = require("path");
async function isConfigurationJsonValid() {
const configurationsFileLocation = path.join(__dirname, "configuration.json");
if (!fs.existsSync(configurationsFileLocation)) {
console.log(`[configurations.json] The file configurations.json is missing`);
return false;
}
async function getConfigurations() {
const configurations = await fs.readJSON(configurationsFileLocation
);
return configurations;
}
const errorsMessages = [];
const { ejbServerComponents, webClientComponents, skipComponents } = await getConfigurations();
if (!webClientComponents) {
errorsMessages.push(`[configurations.json] The field "webClientComponents" is missing in the file configurations.json`);
}
if (!ejbServerComponents) {
errorsMessages.push(`[configurations.json] The field "ejbServerComponents" is missing in the file configurations.json`);
}
if (skipComponents && !Array.isArray(skipComponents)) {
errorsMessages.push(`[configurations.json] The field "skipComponents" in the file configurations.json must be an array of strings`);
}
// test paths
if (webClientComponents && !fs.existsSync(webClientComponents)) {
errorsMessages.push(`[configurations.json] The path in "webClientComponents" does not exist. Update the file configurations.json`);
}
if (ejbServerComponents && !fs.existsSync(ejbServerComponents)) {
errorsMessages.push(`[configurations.json] The path in "ejbServerComponents" does not exist. Update the file configurations.json`);
}
if (errorsMessages.length) {
console.error("Errors found:")
errorsMessages.forEach(message => {
console.error(`* ${message}`);
})
return false;
}
return true;
}
module.exports = { isConfigurationJsonValid };