5etools-utils 0.1.15 → 0.1.18
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 +18 -13
- package/lib/UtilFs.js +15 -8
- package/package.json +1 -1
package/lib/TestJson.js
CHANGED
|
@@ -109,17 +109,19 @@ class JsonTester {
|
|
|
109
109
|
this._isSchemaLoaded = true;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
_doRunOnDir ({dir, errors, errorsFull, ...opts} = {}) {
|
|
113
|
-
uf.listJsonFiles(dir, opts)
|
|
114
|
-
.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
112
|
+
_doRunOnDir ({isFailFast, dir, errors, errorsFull, ...opts} = {}) {
|
|
113
|
+
for (const filePath of uf.listJsonFiles(dir, opts)) {
|
|
114
|
+
um.info(this._tagLog, `\tValidating "${filePath}"...`);
|
|
115
|
+
|
|
116
|
+
const data = uf.readJSON(filePath);
|
|
117
|
+
this._addImplicits(data);
|
|
118
|
+
const valid = this._ajv.validate(this._fnGetSchemaId(filePath), data);
|
|
119
|
+
|
|
120
|
+
if (!valid) {
|
|
121
|
+
this._handleError({filePath, errors, errorsFull, data});
|
|
122
|
+
if (isFailFast) break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
/**
|
|
@@ -140,7 +142,7 @@ class JsonTester {
|
|
|
140
142
|
return {errors, errorsFull};
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
getErrorsOnDirs () {
|
|
145
|
+
getErrorsOnDirs ({isFailFast = false} = {}) {
|
|
144
146
|
um.info(this._tagLog, `Validating JSON against schema`);
|
|
145
147
|
|
|
146
148
|
this._doLoadSchema();
|
|
@@ -148,7 +150,10 @@ class JsonTester {
|
|
|
148
150
|
const errors = [];
|
|
149
151
|
const errorsFull = [];
|
|
150
152
|
|
|
151
|
-
uf.runOnDirs((dir) =>
|
|
153
|
+
uf.runOnDirs((dir) => {
|
|
154
|
+
if (isFailFast && errors.length) return;
|
|
155
|
+
return this._doRunOnDir({isFailFast, errors, errorsFull, dir});
|
|
156
|
+
});
|
|
152
157
|
|
|
153
158
|
return {errors, errorsFull};
|
|
154
159
|
}
|
package/lib/UtilFs.js
CHANGED
|
@@ -48,18 +48,25 @@ function listJsonFiles (dir, opts) {
|
|
|
48
48
|
}, []);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
function _runOnDirs_getDirs () {
|
|
52
|
+
return fs.readdirSync(".", "utf8")
|
|
53
|
+
.filter(dir => isDirectory(dir) && !dir.startsWith(".") && !dir.startsWith("_") && dir !== "node_modules");
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
function runOnDirs (fn) {
|
|
52
|
-
|
|
53
|
-
.filter(dir => isDirectory(dir) && !dir.startsWith(".") && !dir.startsWith("_") && dir !== "node_modules")
|
|
57
|
+
_runOnDirs_getDirs()
|
|
54
58
|
.forEach(dir => fn(dir));
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
async function pRunOnDirs (pFn) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
async function pRunOnDirs (pFn, {isSerial = false} = {}) {
|
|
62
|
+
const dirs = _runOnDirs_getDirs();
|
|
63
|
+
|
|
64
|
+
if (isSerial) {
|
|
65
|
+
for (const dir of dirs) await pFn(dir);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
await Promise.allSettled(dirs.map(dir => pFn(dir)));
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
function mkDirs (pathToCreate) {
|