-
Notifications
You must be signed in to change notification settings - Fork 2
/
validate.js
53 lines (45 loc) · 1.51 KB
/
validate.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
'use strict';
const fs = require('fs');
const Validator = require('slack-rpg-addon-validator');
const ignoreFolders = ['schema', '.git', 'node_modules'];
fs.readdir(process.env.PWD, (err, files) => {
if (err) {
console.log('Could not read directory!');
process.exitCode = 1;
return;
}
files.forEach((fileName) => {
const fileStat = fs.statSync(fileName);
if (fileStat.isDirectory() && ignoreFolders.indexOf(fileName) === -1) {
fs.readdir(`${process.env.PWD}/${fileName}`, (err, dirFiles) => {
if (err) {
console.log(`Could not read directory: ${fileName}`);
process.exitCode = 1;
return;
}
console.log(`${fileName}:`);
dirFiles.forEach((dirFileName) => {
fs.readFile(`${process.env.PWD}/${fileName}/${dirFileName}`, (dirErr, content) => {
if (dirErr) {
console.log(`Could not read file: ${fileName}/${dirFileName}`);
process.exitCode = 1;
return;
}
try {
if (Validator.check(content.toString())) {
console.log(`- ${dirFileName} is OK!`);
} else {
console.log(`- ${dirFileName} is NOT OK!\nUnknown Error!`);
process.exitCode = 1;
}
} catch (error) {
console.log(`- ${dirFileName} is NOT OK!`);
console.log(`${error.message}`);
process.exitCode = 1;
}
});
});
});
}
});
});