5etools-utils 0.1.9 → 0.1.12

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
@@ -18,12 +18,14 @@ class JsonTester {
18
18
  {
19
19
  dirSchema,
20
20
  dir = ".",
21
+ dirWhitelist = null,
21
22
  tagLog = LOG_TAG,
22
23
  fnGetSchemaId = () => "homebrew.json",
23
24
  },
24
25
  ) {
25
26
  this._dirSchema = dirSchema;
26
27
  this._dir = dir;
28
+ this._dirWhitelist = dirWhitelist;
27
29
  this._tagLog = tagLog;
28
30
  this._fnGetSchemaId = fnGetSchemaId;
29
31
 
@@ -113,6 +115,8 @@ class JsonTester {
113
115
  (dir) => {
114
116
  uf.listJsonFiles(dir)
115
117
  .forEach(filePath => {
118
+ um.info(this._tagLog, `\tValidating "${filePath}"...`);
119
+
116
120
  const data = uf.readJSON(filePath);
117
121
  this._addImplicits(data);
118
122
  const valid = this._ajv.validate(this._fnGetSchemaId(filePath), data);
@@ -120,7 +124,10 @@ class JsonTester {
120
124
  if (!valid) this._handleError({filePath, errors, errorsFull, data});
121
125
  });
122
126
  },
123
- this._dir,
127
+ {
128
+ root: this._dir,
129
+ dirWhitelist: this._dirWhitelist,
130
+ },
124
131
  );
125
132
 
126
133
  return {errors, errorsFull};
package/lib/UtilFs.js CHANGED
@@ -30,7 +30,7 @@ function readJSON (path, {isIncludeRaw = false} = {}) {
30
30
 
31
31
  function listJsonFiles (dir) {
32
32
  const dirContent = fs.readdirSync(dir, "utf8")
33
- .map(file => `${dir}/${file}`);
33
+ .map(file => dir === "." ? file : `${dir}/${file}`);
34
34
  return dirContent.reduce((acc, file) => {
35
35
  if (isDirectory(file)) acc.push(...listJsonFiles(file));
36
36
  else {
@@ -40,10 +40,10 @@ function listJsonFiles (dir) {
40
40
  }, []);
41
41
  }
42
42
 
43
- function runOnDirs (fn, root = ".") {
43
+ function runOnDirs (fn, {root = ".", dirWhitelist = null} = {}) {
44
44
  fs.readdirSync(root, "utf8")
45
- .map(dir => ({dir, dirPath: `${root}/${dir}`}))
46
- .filter(({dir, dirPath}) => isDirectory(dirPath) && !dir.startsWith(".") && !dir.startsWith("_") && dir !== "node_modules")
45
+ .map(dir => ({dir, dirPath: root === "." ? dir : `${root}/${dir}`}))
46
+ .filter(({dir, dirPath}) => isDirectory(dirPath) && !dir.startsWith(".") && !dir.startsWith("_") && dir !== "node_modules" && (!dirWhitelist || dirWhitelist.has(dir)))
47
47
  .forEach(({dirPath}) => fn(dirPath));
48
48
  }
49
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "5etools-utils",
3
- "version": "0.1.9",
3
+ "version": "0.1.12",
4
4
  "description": "Shared utilities for the 5etools ecosystem.",
5
5
  "type": "module",
6
6
  "main": "lib/Api.js",