5etools-utils 0.1.14 → 0.1.17
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 +14 -11
- package/lib/UtilFs.js +18 -2
- package/package.json +1 -1
package/lib/TestJson.js
CHANGED
|
@@ -109,17 +109,17 @@ class JsonTester {
|
|
|
109
109
|
this._isSchemaLoaded = true;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
_doRunOnDir ({dir, errors, errorsFull, ...opts} = {}) {
|
|
113
|
-
uf.listJsonFiles(dir, opts)
|
|
114
|
-
.
|
|
115
|
-
um.info(this._tagLog, `\tValidating "${filePath}"...`);
|
|
112
|
+
_doRunOnDir ({isFailFast, dir, errors, errorsFull, ...opts} = {}) {
|
|
113
|
+
for (const filePath of uf.listJsonFiles(dir, opts)) {
|
|
114
|
+
um.info(this._tagLog, `\tValidating "${filePath}"...`);
|
|
116
115
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
const data = uf.readJSON(filePath);
|
|
117
|
+
this._addImplicits(data);
|
|
118
|
+
const valid = this._ajv.validate(this._fnGetSchemaId(filePath), data);
|
|
120
119
|
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
if (!valid) this._handleError({filePath, errors, errorsFull, data});
|
|
121
|
+
if (isFailFast) break;
|
|
122
|
+
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
/**
|
|
@@ -140,7 +140,7 @@ class JsonTester {
|
|
|
140
140
|
return {errors, errorsFull};
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
getErrorsOnDirs () {
|
|
143
|
+
getErrorsOnDirs ({isFailFast = false} = {}) {
|
|
144
144
|
um.info(this._tagLog, `Validating JSON against schema`);
|
|
145
145
|
|
|
146
146
|
this._doLoadSchema();
|
|
@@ -148,7 +148,10 @@ class JsonTester {
|
|
|
148
148
|
const errors = [];
|
|
149
149
|
const errorsFull = [];
|
|
150
150
|
|
|
151
|
-
uf.runOnDirs((dir) =>
|
|
151
|
+
uf.runOnDirs((dir) => {
|
|
152
|
+
if (isFailFast && errors.length) return;
|
|
153
|
+
return this._doRunOnDir({isFailFast, errors, errorsFull, dir});
|
|
154
|
+
});
|
|
152
155
|
|
|
153
156
|
return {errors, errorsFull};
|
|
154
157
|
}
|
package/lib/UtilFs.js
CHANGED
|
@@ -48,12 +48,27 @@ 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
|
|
|
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)));
|
|
70
|
+
}
|
|
71
|
+
|
|
57
72
|
function mkDirs (pathToCreate) {
|
|
58
73
|
pathToCreate
|
|
59
74
|
.split(/[\\/]/g)
|
|
@@ -70,5 +85,6 @@ export {
|
|
|
70
85
|
readJSON,
|
|
71
86
|
listJsonFiles,
|
|
72
87
|
runOnDirs,
|
|
88
|
+
pRunOnDirs,
|
|
73
89
|
mkDirs,
|
|
74
90
|
};
|