5etools-utils 0.4.0 → 0.4.2

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/Api.js CHANGED
@@ -4,6 +4,7 @@ import * as Uf from "./UtilFs.js";
4
4
  import {BrewIndexGenerator} from "./BrewIndexGenerator.js";
5
5
  import {BrewCleaner} from "./BrewCleaner.js";
6
6
  import {BrewTimestamper} from "./BrewTimestamper.js";
7
+ import {BrewTester} from "./BrewTester.js";
7
8
  import {SITE_SOURCES} from "./UtilSources.js";
8
9
  import {getCleanJson} from "./UtilClean.js";
9
10
 
@@ -14,6 +15,7 @@ export {
14
15
  BrewIndexGenerator,
15
16
  BrewCleaner,
16
17
  BrewTimestamper,
18
+ BrewTester,
17
19
  SITE_SOURCES,
18
20
  getCleanJson,
19
21
  };
@@ -0,0 +1,65 @@
1
+ import * as fs from "fs";
2
+ import {Command} from "commander";
3
+ import Um from "./UtilMisc.js";
4
+ import {JsonTester} from "./TestJson.js";
5
+
6
+ class _BrewTesterJson {
7
+ static _LOG_TAG = "JSON";
8
+ static _IS_FAIL_SLOW = !!process.env.FAIL_SLOW;
9
+
10
+ static async pRun (args) {
11
+ const program = new Command()
12
+ .argument("[file]", "File to test")
13
+ ;
14
+
15
+ program.parse(args);
16
+
17
+ const jsonTester = new JsonTester({isBrew: true, tagLog: this._LOG_TAG, fnGetSchemaId: () => "homebrew.json"});
18
+
19
+ let results;
20
+ if (program.args[0]) {
21
+ results = jsonTester.getFileErrors({filePath: program.args[0]});
22
+ } else {
23
+ results = await jsonTester.pGetErrorsOnDirsWorkers({isFailFast: !this._IS_FAIL_SLOW});
24
+ }
25
+
26
+ const {errors, errorsFull} = results;
27
+
28
+ if (errors.length) {
29
+ if (!process.env.CI) fs.writeFileSync(`_test/test-json.error.log`, errorsFull.join("\n\n=====\n\n"));
30
+ console.error(`Schema test failed (${errors.length} failure${errors.length === 1 ? "" : "s"}).`);
31
+ process.exit(1);
32
+ }
33
+
34
+ if (!errors.length) Um.info(this._LOG_TAG, `Schema test passed.`);
35
+ }
36
+ }
37
+
38
+ class _BrewTesterFileLocations {
39
+ static _ROOT_JSON_FILES = new Set([
40
+ "package.json",
41
+ "package-lock.json",
42
+ ]);
43
+
44
+ static _LOG_TAG = `FILES_ROOT`;
45
+
46
+ static run () {
47
+ Um.info(this._LOG_TAG, `Testing for unwanted JSON files in root dir...`);
48
+
49
+ const errors = fs.readdirSync(".", "utf8")
50
+ .filter(it => it.toLowerCase().endsWith(".json") && !this._ROOT_JSON_FILES.has(it))
51
+ .map(it => `Unwanted JSON file in root directory: ${it}`);
52
+
53
+ if (!errors.length) return Um.info(this._LOG_TAG, `No unwanted JSON files found.`);
54
+
55
+ errors.forEach(it => console.error(it));
56
+ process.exit(1);
57
+ }
58
+ }
59
+
60
+ class BrewTester {
61
+ static async pTestJson (args) { return _BrewTesterJson.pRun(args); }
62
+ static testFileLocations () { return _BrewTesterFileLocations.run(); }
63
+ }
64
+
65
+ export {BrewTester};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "5etools-utils",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Shared utilities for the 5etools ecosystem.",
5
5
  "type": "module",
6
6
  "main": "lib/Api.js",
@@ -30,11 +30,11 @@
30
30
  "dependencies": {
31
31
  "ajv": "^8.11.2",
32
32
  "ajv-formats": "^2.1.1",
33
+ "commander": "^9.4.1",
33
34
  "hasha": "^5.2.2",
34
35
  "json-source-map": "^0.6.1"
35
36
  },
36
37
  "devDependencies": {
37
- "commander": "^9.4.1",
38
38
  "eslint": "^8.11.0",
39
39
  "jest": "^29.3.1"
40
40
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "adventures.json",
4
- "version": "1.10.9",
4
+ "version": "1.10.10",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "adventure": {
@@ -34,6 +34,7 @@
34
34
  "enum": [
35
35
  "supplement",
36
36
  "supplement-alt",
37
+ "prerelease",
37
38
  "homebrew",
38
39
  "other"
39
40
  ]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "books.json",
4
- "version": "1.2.7",
4
+ "version": "1.2.8",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "book": {
@@ -32,6 +32,7 @@
32
32
  "supplement",
33
33
  "supplement-alt",
34
34
  "setting",
35
+ "prerelease",
35
36
  "homebrew",
36
37
  "screen",
37
38
  "other"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "adventures.json",
4
- "version": "1.10.9",
4
+ "version": "1.10.10",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "adventure": {
@@ -34,6 +34,7 @@
34
34
  "enum": [
35
35
  "supplement",
36
36
  "supplement-alt",
37
+ "prerelease",
37
38
  "homebrew",
38
39
  "other"
39
40
  ]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "books.json",
4
- "version": "1.2.7",
4
+ "version": "1.2.8",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "book": {
@@ -32,6 +32,7 @@
32
32
  "supplement",
33
33
  "supplement-alt",
34
34
  "setting",
35
+ "prerelease",
35
36
  "homebrew",
36
37
  "screen",
37
38
  "other"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "adventures.json",
4
- "version": "1.10.9",
4
+ "version": "1.10.10",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "adventure": {
@@ -34,6 +34,7 @@
34
34
  "enum": [
35
35
  "supplement",
36
36
  "supplement-alt",
37
+ "prerelease",
37
38
  "homebrew",
38
39
  "other"
39
40
  ]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "books.json",
4
- "version": "1.2.7",
4
+ "version": "1.2.8",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "book": {
@@ -32,6 +32,7 @@
32
32
  "supplement",
33
33
  "supplement-alt",
34
34
  "setting",
35
+ "prerelease",
35
36
  "homebrew",
36
37
  "screen",
37
38
  "other"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "adventures.json",
4
- "version": "1.10.9",
4
+ "version": "1.10.10",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "adventure": {
@@ -34,6 +34,7 @@
34
34
  "enum": [
35
35
  "supplement",
36
36
  "supplement-alt",
37
+ "prerelease",
37
38
  "homebrew",
38
39
  "other"
39
40
  ]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "books.json",
4
- "version": "1.2.7",
4
+ "version": "1.2.8",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "book": {
@@ -32,6 +32,7 @@
32
32
  "supplement",
33
33
  "supplement-alt",
34
34
  "setting",
35
+ "prerelease",
35
36
  "homebrew",
36
37
  "screen",
37
38
  "other"