5etools-utils 0.1.4 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/TestJson.js +19 -12
- package/lib/UtilFs.js +5 -4
- package/package.json +1 -1
package/lib/TestJson.js
CHANGED
|
@@ -9,16 +9,20 @@ import * as um from "./UtilMisc.js";
|
|
|
9
9
|
const _IS_SORT_RESULTS = !process.env.VET_TEST_JSON_RESULTS_UNSORTED;
|
|
10
10
|
const _IS_TRIM_RESULTS = !process.env.VET_TEST_JSON_RESULTS_UNTRIMMED;
|
|
11
11
|
|
|
12
|
+
const LOG_TAG = "JSON";
|
|
13
|
+
|
|
12
14
|
class JsonTester {
|
|
13
15
|
static _RE_DATE = /^\d\d\d\d-\d\d-\d\d$/;
|
|
14
16
|
|
|
15
17
|
constructor (
|
|
16
18
|
{
|
|
17
19
|
dirSchema,
|
|
18
|
-
|
|
20
|
+
dir = ".",
|
|
21
|
+
tagLog = LOG_TAG,
|
|
19
22
|
},
|
|
20
23
|
) {
|
|
21
24
|
this._dirSchema = dirSchema;
|
|
25
|
+
this._dir = dir;
|
|
22
26
|
this._tagLog = tagLog;
|
|
23
27
|
|
|
24
28
|
// region Set up validator
|
|
@@ -55,7 +59,7 @@ class JsonTester {
|
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
_getFileErrors ({filePath}) { return `${filePath}\n${JSON.stringify(
|
|
62
|
+
_getFileErrors ({filePath}) { return `${filePath}\n${JSON.stringify(this._ajv.errors, null, 2)}`; }
|
|
59
63
|
|
|
60
64
|
_handleError ({filePath, errors, errorsFull, data}) {
|
|
61
65
|
if (!process.env.CI) errorsFull.push(this._getFileErrors({filePath}));
|
|
@@ -103,19 +107,22 @@ class JsonTester {
|
|
|
103
107
|
const errors = [];
|
|
104
108
|
const errorsFull = [];
|
|
105
109
|
|
|
106
|
-
uf.runOnDirs(
|
|
107
|
-
|
|
108
|
-
.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
uf.runOnDirs(
|
|
111
|
+
(dir) => {
|
|
112
|
+
uf.listJsonFiles(dir)
|
|
113
|
+
.forEach(filePath => {
|
|
114
|
+
const data = uf.readJSON(filePath);
|
|
115
|
+
this._addImplicits(data);
|
|
116
|
+
const valid = this._ajv.validate("homebrew.json", data);
|
|
112
117
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
118
|
+
if (!valid) this._handleError({filePath, errors, errorsFull, data});
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
this._dir,
|
|
122
|
+
);
|
|
116
123
|
|
|
117
124
|
return {errors, errorsFull};
|
|
118
125
|
}
|
|
119
126
|
}
|
|
120
127
|
|
|
121
|
-
export {JsonTester};
|
|
128
|
+
export {JsonTester, LOG_TAG};
|
package/lib/UtilFs.js
CHANGED
|
@@ -38,10 +38,11 @@ function listJsonFiles (dir) {
|
|
|
38
38
|
}, []);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
function runOnDirs (fn) {
|
|
42
|
-
fs.readdirSync(
|
|
43
|
-
.
|
|
44
|
-
.
|
|
41
|
+
function runOnDirs (fn, root = ".") {
|
|
42
|
+
fs.readdirSync(root, "utf8")
|
|
43
|
+
.map(dir => ({dir, dirPath: `${root}/${dir}`}))
|
|
44
|
+
.filter(({dir, dirPath}) => isDirectory(dirPath) && !dir.startsWith(".") && !dir.startsWith("_") && dir !== "node_modules")
|
|
45
|
+
.forEach(({dirPath}) => fn(dirPath));
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
function mkDirs (pathToCreate) {
|