/
checker.js
61 lines (55 loc) · 1.29 KB
/
checker.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
var fs = require('fs'),
path = require('path'),
cmdList = require('../include/default.js').cmdList,
forbiddenWords = require('../include/default.js').forbiddenWords;
exports.isIDUnique = function(config) {
var unique = true, ecosystems;
ecosystems = JSON.parse(fs.readFileSync(config.recordFile, 'utf8')).ecosystems;
ecosystems.forEach(function(e) {
if (e.id === config.id) {
unique = false;
}
});
return unique;
};
exports.isIDValid = function(config) {
var valid = true;
forbiddenWords.forEach(function(w) {
if (w === config.id) {
valid = false;
}
});
return valid;
};
exports.isCMDValid = function(command) {
var valid = false;
cmdList.forEach(function(c) {
if (c === command) {
valid = true;
}
});
return valid;
};
exports.isIDExsit = function(config) {
var exist = false, ecosystems;
ecosystems = JSON.parse(fs.readFileSync(config.recordFile, 'utf8')).ecosystems;
ecosystems.forEach(function(e) {
if (e.id === config.id) {
exist = true;
}
});
return exist;
};
exports.isActive = function(config) {
var basename;
if (config.ecosystem === undefined) {
return false;
} else {
basename = path.basename(config.ecosystem);
if (basename === id) {
return true;
} else {
return false;
}
}
};