5etools-utils 0.1.5 → 0.1.8

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
@@ -9,17 +9,23 @@ 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
- tagLog = "JSON",
20
+ dir = ".",
21
+ tagLog = LOG_TAG,
22
+ fnGetSchemaId = () => "homebrew.json",
19
23
  },
20
24
  ) {
21
25
  this._dirSchema = dirSchema;
26
+ this._dir = dir;
22
27
  this._tagLog = tagLog;
28
+ this._fnGetSchemaId = fnGetSchemaId;
23
29
 
24
30
  // region Set up validator
25
31
  this._ajv = new Ajv({
@@ -103,19 +109,22 @@ class JsonTester {
103
109
  const errors = [];
104
110
  const errorsFull = [];
105
111
 
106
- uf.runOnDirs((dir) => {
107
- uf.listJsonFiles(dir)
108
- .forEach(filePath => {
109
- const data = uf.readJSON(filePath);
110
- this._addImplicits(data);
111
- const valid = this._ajv.validate("homebrew.json", data);
112
+ uf.runOnDirs(
113
+ (dir) => {
114
+ uf.listJsonFiles(dir)
115
+ .forEach(filePath => {
116
+ const data = uf.readJSON(filePath);
117
+ this._addImplicits(data);
118
+ const valid = this._ajv.validate(this._fnGetSchemaId(filePath), data);
112
119
 
113
- if (!valid) this._handleError({filePath, errors, errorsFull, data});
114
- });
115
- });
120
+ if (!valid) this._handleError({filePath, errors, errorsFull, data});
121
+ });
122
+ },
123
+ this._dir,
124
+ );
116
125
 
117
126
  return {errors, errorsFull};
118
127
  }
119
128
  }
120
129
 
121
- export {JsonTester};
130
+ 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(".", "utf8")
43
- .filter(dir => isDirectory(dir) && !dir.startsWith(".") && !dir.startsWith("_") && dir !== "node_modules")
44
- .forEach(dir => fn(dir));
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "5etools-utils",
3
- "version": "0.1.5",
3
+ "version": "0.1.8",
4
4
  "description": "Shared utilities for the 5etools ecosystem.",
5
5
  "type": "module",
6
6
  "main": "lib/Api.js",