-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
92 lines (79 loc) · 2.33 KB
/
index.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
/*=============================================>>>>>
= Check the integrity of csproj file =
= author: mantovanig =
===============================================>>>>>*/
"use strict";
// vendor modules
const fs = require("fs");
// sub modules
const response = require("./libs/response");
const parseCsproj = require("./libs/parseCsproj");
const compareFiles = require("./libs/compareFiles");
const checkDuplicated = require("./libs/checkDuplicated");
const csprojIntegrity = {
checkExist(file) {
try {
fs.accessSync(file, fs.F_OK);
return false;
} catch (e) {
return true;
}
},
checkFiles(files) {
return parseCsproj()
.then(fileIncludes => {
return compareFiles(files, fileIncludes);
})
.then(function(result) {
if (!result || result.length > 0) {
return Promise.resolve(
response("error", "Files that are not included:", result)
);
} else {
return Promise.resolve(
response("success", "OK! All files are included!", result)
);
}
})
.catch(function(err) {
return Promise.resolve(
response("fail", "Failing during checking", err)
);
});
},
checkIntegrity() {
let status = {
notFound: false,
duplicated: false
};
return parseCsproj()
.then(fileIncludes => {
let fileNotFound = [];
let duplicatedFiles = [];
fileNotFound = fileIncludes.filter(this.checkExist);
duplicatedFiles = fileIncludes.filter(checkDuplicated);
status.notFound =
!fileNotFound || fileNotFound.length > 0 ? true : false;
status.duplicated =
!duplicatedFiles || duplicatedFiles.length > 0 ? true : false;
if (status.duplicated || status.notFound) {
return Promise.resolve(
response("error", "There are some problems in your csproj file", {
fileNotFound,
duplicatedFiles
})
);
} else {
return Promise.resolve(
response("success", "OK! Your csproj file is good!", fileIncludes)
);
}
})
.catch(function(err) {
return Promise.resolve(
response("fail", "Failing during checking", err)
);
});
}
};
module.exports = csprojIntegrity;