5etools-utils 0.1.16 → 0.1.19

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 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
- .forEach(filePath => {
115
- um.info(this._tagLog, `\tValidating "${filePath}"...`);
116
-
117
- const data = uf.readJSON(filePath);
118
- this._addImplicits(data);
119
- const valid = this._ajv.validate(this._fnGetSchemaId(filePath), data);
120
-
121
- if (!valid) this._handleError({filePath, errors, errorsFull, data});
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) => this._doRunOnDir({errors, errorsFull, 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
@@ -1,4 +1,5 @@
1
1
  import * as fs from "fs";
2
+ import * as path from "path";
2
3
 
3
4
  function isDirectory (path) {
4
5
  return fs.lstatSync(path).isDirectory();
@@ -35,12 +36,13 @@ function readJSON (path, {isIncludeRaw = false} = {}) {
35
36
  */
36
37
  function listJsonFiles (dir, opts) {
37
38
  const {dirBlacklist = null} = opts || {};
39
+ const dirBlacklist_ = dirBlacklist ? new Set(dirBlacklist.map(it => path.normalize(it))) : new Set();
38
40
 
39
41
  const dirContent = fs.readdirSync(dir, "utf8")
40
42
  .map(file => dir === "." ? file : `${dir}/${file}`);
41
43
  return dirContent.reduce((acc, file) => {
42
44
  if (isDirectory(file)) {
43
- if (dirBlacklist == null || !dirBlacklist.has(file)) acc.push(...listJsonFiles(file, opts));
45
+ if (!dirBlacklist_.has(path.normalize(file))) acc.push(...listJsonFiles(file, opts));
44
46
  } else {
45
47
  if (file.toLowerCase().endsWith(".json")) acc.push(file);
46
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "5etools-utils",
3
- "version": "0.1.16",
3
+ "version": "0.1.19",
4
4
  "description": "Shared utilities for the 5etools ecosystem.",
5
5
  "type": "module",
6
6
  "main": "lib/Api.js",