-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfolderParser.js
124 lines (103 loc) · 3.54 KB
/
folderParser.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const fs = require("fs");
const path = require("path");
const glob = require("glob");
const search = require("recursive-search");
const error = require("./error");
const findImplementationFiles = appFolder => {
let usualFile = path.join(appFolder, "implementation.xml");
let muleflows = glob.sync(path.join(appFolder, "muleflows", "*.xml"));
if (fs.existsSync(usualFile)) {
muleflows.unshift(usualFile);
}
return muleflows;
};
const folderParser = apiBasePath => {
if (!fs.existsSync(apiBasePath)) {
error.fatal(`apiBasePath "${apiBasePath}" not found`);
}
const apiAbsoluteBasePath = path.resolve(apiBasePath);
const apiName = path.basename(apiAbsoluteBasePath);
const projectFolder = path.join(apiAbsoluteBasePath, "impl", apiName);
const pomFile = path.join(projectFolder, "pom.xml");
const gitignoreFile = path.join(projectFolder, ".gitignore");
const appFolder = path.join(projectFolder, "src", "main", "app");
const globalFile = path.join(appFolder, "global.xml");
const implementationFiles = findImplementationFiles(appFolder);
const apiPattern = "*-api.xml";
const apiFiles = glob.sync(path.join(appFolder, apiPattern));
const muleAppPropertiesFile = path.join(appFolder, "mule-app.properties");
const resourcesFolder = path.join(projectFolder, "src", "main", "resources");
const localPropertiesFile = path.join(
resourcesFolder,
"api.local.properties"
);
const serverPropertiesFile = path.join(
resourcesFolder,
"api.server.properties"
);
const oldPropertiesFile = path.join(
resourcesFolder,
"api.Development.properties"
);
const log4jFile = path.join(resourcesFolder, "log4j2.xml");
if (!fs.existsSync(projectFolder)) {
error.fatal(`Project folder "${projectFolder}" not found`);
}
if (!fs.existsSync(appFolder)) {
error.fatal(`App folder "${appFolder}" not found`);
}
if (!fs.existsSync(resourcesFolder)) {
error.fatal(`Resources folder "${resourcesFolder}" not found`);
}
if (!fs.existsSync(pomFile)) {
error.fatal(`POM file "${pomFile}" not found`);
}
if (!fs.existsSync(gitignoreFile)) {
error.fatal(`.gitignore file "${gitignoreFile}" not found`);
}
const gitIgnoredFoldersAndFilesRegEx = /src[/\\]main[/\\]api[/\\]\.repository[/\\]|src[/\\]main[/\\]api[/\\]\.gitignore|[/\\]target[/\\]/;
if (
search
.recursiveSearchSync(".gitignore", projectFolder, { all: true })
.filter(file => !gitIgnoredFoldersAndFilesRegEx.test(file)).length > 1
) {
error.fatal("Multiple .gitignore files found");
}
if (!fs.existsSync(globalFile)) {
error.fatal(`Global file "${globalFile}" not found`);
}
if (implementationFiles.length === 0) {
error.fatal("No implementation files found");
}
if (apiFiles.length === 0) {
error.fatal(`No ${apiPattern} files found`);
}
if (!fs.existsSync(localPropertiesFile)) {
error.fatal(`Local properties file "${localPropertiesFile}" not found`);
}
if (!fs.existsSync(serverPropertiesFile)) {
error.fatal(`Server properties file "${serverPropertiesFile}" not found`);
}
if (fs.existsSync(oldPropertiesFile)) {
error.fatal(`Old properties file "${oldPropertiesFile}" found`);
}
if (!fs.existsSync(log4jFile)) {
error.fatal(`Log4j file "${log4jFile}" not found`);
}
return {
apiName,
projectFolder,
pomFile,
gitignoreFile,
appFolder,
globalFile,
implementationFiles,
apiFiles,
muleAppPropertiesFile,
resourcesFolder,
localPropertiesFile,
serverPropertiesFile,
log4jFile
};
};
module.exports = folderParser;