-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
84 lines (71 loc) · 2.78 KB
/
api.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @fileoverview Heart of the app, making it possible to call programmatically.
* Anything below this should not do any I/O (reads, writes, console, etc.).
* Equivalent to cli.js in https://eslint.org/docs/developer-guide/architecture
*/
const path = require("path");
const fs = require("fs");
const xmlParser = require("./xmlParser");
const reporter = require("./reporter");
const folderParser = require("./folderParser");
const pomParser = require("./pomParser");
const validateApiFile = require("./validateApiFile");
const validatePom = require("./validatePom");
const validateGlobal = require("./validateGlobal");
const validateImplementationFile = require("./validateImplementationFile");
const validateGitignore = require("./validateGitignore");
const validateProperties = require("./validateProperties");
const validateLog4j = require("./validateLog4j");
const { encoding } = require("./constants");
const assert = require("./assert");
const { loadProperties } = require("./loadProperties");
function validateApiFiles(folderInfo, pomInfo) {
folderInfo.apiFiles.forEach(apiFile => {
let apiFileName = path.basename(apiFile);
let { xml } = xmlParser(apiFile);
validateApiFile(apiFileName, xml, pomInfo);
});
}
function validateImplementationFiles(folderInfo) {
folderInfo.implementationFiles.forEach(implementationFile => {
let implementationFileName = path.basename(implementationFile);
let { contents, xml } = xmlParser(implementationFile);
validateImplementationFile(implementationFileName, contents, xml);
});
}
function internalValidateGlobal(folderInfo) {
let { contents, xml } = xmlParser(folderInfo.globalFile);
validateGlobal(contents, xml);
}
function internalValidateProperties(folderInfo, pomInfo) {
let localProperties = loadProperties(folderInfo.localPropertiesFile);
let serverProperties = loadProperties(folderInfo.serverPropertiesFile);
let muleAppProperties = fs.existsSync(folderInfo.muleAppPropertiesFile)
? loadProperties(folderInfo.muleAppPropertiesFile)
: new Map();
validateProperties(
localProperties,
serverProperties,
muleAppProperties,
folderInfo,
pomInfo
);
}
function internalValidateLog4j(folderInfo) {
let { xml } = xmlParser(folderInfo.log4jFile);
validateLog4j(xml, folderInfo);
}
module.exports = {
execute(apiBasePath) {
let folderInfo = folderParser(apiBasePath);
let pomInfo = pomParser(folderInfo.pomFile);
validateApiFiles(folderInfo, pomInfo);
validatePom(folderInfo, pomInfo);
internalValidateGlobal(folderInfo);
validateImplementationFiles(folderInfo);
validateGitignore(fs.readFileSync(folderInfo.gitignoreFile, encoding));
internalValidateProperties(folderInfo, pomInfo);
internalValidateLog4j(folderInfo);
reporter.printSummary(assert.failures);
}
};