5etools-utils 0.16.34 → 0.16.36

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.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {BrewTester} from "../lib/BrewTester.js";
4
+
5
+ await BrewTester.pTestDependencies();
@@ -0,0 +1,111 @@
1
+ import Um from "../UtilMisc.js";
2
+ import * as Uf from "../UtilFs.js";
3
+ import {UtilSource} from "../UtilSource.js";
4
+ import {BrewTesterBase} from "./BrewTesterBase.js";
5
+
6
+ export class BrewTesterDependencies extends BrewTesterBase {
7
+ _LOG_TAG = "DEPENDENCY";
8
+
9
+ static _PROPS_CLASS = new Set([
10
+ "class",
11
+ "classFeature",
12
+ "classFluff",
13
+ "subclass",
14
+ "subclassFeature",
15
+ "subclassFluff",
16
+ ]);
17
+
18
+ static _PROPS_CLASS__NAME = new Set([
19
+ "class",
20
+ "classFluff",
21
+ ]);
22
+
23
+ static _CLASS_IDS_OFFICIAL = new Set([
24
+ "artificer",
25
+ "barbarian",
26
+ "bard",
27
+ "cleric",
28
+ "druid",
29
+ "fighter",
30
+ "monk",
31
+ "mystic",
32
+ "paladin",
33
+ "ranger",
34
+ "rogue",
35
+ "sidekick",
36
+ "sorcerer",
37
+ "warlock",
38
+ "wizard",
39
+ ]);
40
+
41
+ static _getEntityDependency ({prop, ent}) {
42
+ if (!this._PROPS_CLASS.has(prop)) return ent._copy.source;
43
+
44
+ if (!UtilSource.isSiteSource(ent._copy.source)) return ent._copy.source;
45
+
46
+ const classId = (this._PROPS_CLASS__NAME.has(prop) ? ent._copy.name : ent._copy.className).toLowerCase().trim();
47
+ if (this._CLASS_IDS_OFFICIAL.has(classId)) return classId;
48
+
49
+ return ent._copy.source;
50
+ }
51
+
52
+ static _getDependenciesMissing ({json}) {
53
+ const jsonDeps = json._meta?.dependencies || {};
54
+ const srcsFile = new Set((json._meta?.sources || []).map(source => source.json));
55
+
56
+ const depsMissing = {};
57
+
58
+ Object.entries(json)
59
+ .forEach(([prop, arr]) => {
60
+ if (!(arr instanceof Array)) return;
61
+
62
+ arr.forEach(ent => {
63
+ if (!ent._copy) return;
64
+ if (srcsFile.has(ent._copy.source)) return;
65
+
66
+ const dep = this._getEntityDependency({prop, ent});
67
+ if ((jsonDeps[prop] || []).includes(dep)) return;
68
+
69
+ (depsMissing[prop] ||= new Set()).add(dep);
70
+ });
71
+ });
72
+
73
+ return depsMissing;
74
+ }
75
+
76
+ static _getFileError ({filePath, json}) {
77
+ const errorPt = Object.entries(this._getDependenciesMissing({json}))
78
+ .flatMap(([prop, depsSet]) => [
79
+ `\t\t"${prop}"`,
80
+ ...[...depsSet]
81
+ .sort((a, b) => a.localeCompare(b, {sensitivity: "base"}))
82
+ .map(dependency => `\t\t\t"${dependency}"`),
83
+ ])
84
+ .join("\n");
85
+ if (!errorPt) return null;
86
+
87
+ return `\t"${filePath}" had missing dependencies!\n${errorPt}`;
88
+ }
89
+
90
+ async _pRun () {
91
+ Um.info(this._LOG_TAG, "Checking dependencies...");
92
+
93
+ const results = [];
94
+ Uf.runOnDirs(dir => {
95
+ Um.info(this._LOG_TAG, `Checking dir "${dir}"...`);
96
+
97
+ Uf.listJsonFiles(dir)
98
+ .forEach(filePath => {
99
+ const result = this.constructor._getFileError({filePath, json: Uf.readJsonSync(filePath)});
100
+ if (result) results.push(result);
101
+ });
102
+ });
103
+
104
+ if (results.length) {
105
+ results.forEach(result => Um.error(this._LOG_TAG, result));
106
+ throw new Error(`${results.length} file${results.length === 1 ? " had" : "s had"} missing dependencies! See above for more info.`);
107
+ }
108
+
109
+ Um.info(this._LOG_TAG, "Complete.");
110
+ }
111
+ }
package/lib/BrewTester.js CHANGED
@@ -5,6 +5,7 @@ import {BrewTesterFileProps} from "./BrewTester/BrewTesterFileProps.js";
5
5
  import {BrewTesterEdition} from "./BrewTester/BrewTesterEdition.js";
6
6
  import {BrewTesterFileContents} from "./BrewTester/BrewTesterFileContents.js";
7
7
  import {BrewTesterImgDirectories} from "./BrewTester/BrewTesterImgDirectories.js";
8
+ import {BrewTesterDependencies} from "./BrewTester/BrewTesterDependencies.js";
8
9
 
9
10
  export class BrewTester {
10
11
  static async pTestJson ({mode, filepath, dir}) { return (new BrewTesterJson({mode, filepath, dir})).pRun(); }
@@ -14,4 +15,5 @@ export class BrewTester {
14
15
  static pTestFileContents ({imgRepoName, urlPrefixExpected, pathErrorLog}) { return (new BrewTesterFileContents({imgRepoName, urlPrefixExpected, pathErrorLog})).pRun(); }
15
16
  static pTestImgDirectories ({dirAllowlist, pathImgDir} = {}) { return (new BrewTesterImgDirectories({dirAllowlist, pathImgDir})).pRun(); }
16
17
  static pTestEditionSources () { return (new BrewTesterEdition()).pRun(); }
18
+ static pTestDependencies () { return (new BrewTesterDependencies()).pRun(); }
17
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "5etools-utils",
3
- "version": "0.16.34",
3
+ "version": "0.16.36",
4
4
  "description": "Shared utilities for the 5etools ecosystem.",
5
5
  "type": "module",
6
6
  "main": "lib/Api.js",
@@ -29,6 +29,7 @@
29
29
  "test-file-locations": "bin/test-file-locations.js",
30
30
  "test-file-props": "bin/test-file-props.js",
31
31
  "test-edition-sources": "bin/test-edition-sources.js",
32
+ "test-dependencies": "bin/test-dependencies.js",
32
33
  "test-img-file-extensions": "bin/test-img-file-extensions.js",
33
34
  "test-img-file-sizes": "bin/test-img-file-sizes.js",
34
35
  "test-img-source-names-brew": "bin/test-img-source-names-brew.js",
@@ -1,9 +1,112 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "decks.json",
4
- "version": "1.0.7",
4
+ "version": "1.0.9",
5
5
  "type": "object",
6
6
  "$defs": {
7
+ "_deckSpreadOutcomesCardMap": {
8
+ "type": "object",
9
+ "propertyNames": {
10
+ "pattern": "^[^A-Z|]+\\|[^A-Z|]+\\|[^A-Z|]+$"
11
+ },
12
+ "additionalProperties": {
13
+ "type": "string"
14
+ },
15
+ "minProperties": 1
16
+ },
17
+ "_deckSpreadOutcomesCorpusMap": {
18
+ "type": "object",
19
+ "additionalProperties": {
20
+ "$ref": "#/$defs/_deckSpreadOutcomesCardMap"
21
+ },
22
+ "minProperties": 1
23
+ },
24
+ "_deckSpreadOutcomes": {
25
+ "type": "object",
26
+ "properties": {
27
+ "adventure": {
28
+ "$ref": "#/$defs/_deckSpreadOutcomesCorpusMap"
29
+ },
30
+ "book": {
31
+ "$ref": "#/$defs/_deckSpreadOutcomesCorpusMap"
32
+ }
33
+ },
34
+ "minProperties": 1,
35
+ "additionalProperties": false
36
+ },
37
+ "_deckSpreadPosition": {
38
+ "type": "object",
39
+ "properties": {
40
+ "name": {
41
+ "type": "string"
42
+ },
43
+ "entries": {
44
+ "type": "array",
45
+ "items": {
46
+ "$ref": "entry.json"
47
+ },
48
+ "minItems": 1
49
+ },
50
+ "suits": {
51
+ "$comment": "The suits this position may draw from; `null` matches cards which have no suit. Omit to draw from the whole deck.",
52
+ "type": "array",
53
+ "items": {
54
+ "type": [
55
+ "string",
56
+ "null"
57
+ ]
58
+ },
59
+ "minItems": 1,
60
+ "uniqueItems": true
61
+ },
62
+ "outcomes": {
63
+ "$comment": "Card outcomes specific to this position. These override spread-level outcomes.",
64
+ "$ref": "#/$defs/_deckSpreadOutcomes"
65
+ }
66
+ },
67
+ "required": [
68
+ "name",
69
+ "entries"
70
+ ],
71
+ "additionalProperties": false
72
+ },
73
+ "_deckSpread": {
74
+ "type": "object",
75
+ "properties": {
76
+ "name": {
77
+ "type": "string"
78
+ },
79
+ "source": {
80
+ "$ref": "util.json#/$defs/source"
81
+ },
82
+ "page": {
83
+ "$ref": "util.json#/$defs/page"
84
+ },
85
+ "entries": {
86
+ "type": "array",
87
+ "items": {
88
+ "$ref": "entry.json"
89
+ }
90
+ },
91
+ "positions": {
92
+ "type": "array",
93
+ "items": {
94
+ "$ref": "#/$defs/_deckSpreadPosition"
95
+ },
96
+ "minItems": 1
97
+ },
98
+ "outcomes": {
99
+ "$comment": "Card outcomes shared by all positions.",
100
+ "$ref": "#/$defs/_deckSpreadOutcomes"
101
+ }
102
+ },
103
+ "required": [
104
+ "name",
105
+ "source",
106
+ "positions"
107
+ ],
108
+ "additionalProperties": false
109
+ },
7
110
  "deckData": {
8
111
  "type": "object",
9
112
  "properties": {
@@ -65,6 +168,14 @@
65
168
  "$ref": "entry.json"
66
169
  }
67
170
  },
171
+ "spreads": {
172
+ "type": "array",
173
+ "items": {
174
+ "$ref": "#/$defs/_deckSpread"
175
+ },
176
+ "minItems": 1,
177
+ "uniqueItems": true
178
+ },
68
179
  "back": {
69
180
  "$ref": "entry.json#/$defs/entryImage"
70
181
  },
@@ -139,6 +250,14 @@
139
250
  "$ref": "entry.json"
140
251
  }
141
252
  },
253
+ "spreads": {
254
+ "type": "array",
255
+ "items": {
256
+ "$ref": "#/$defs/_deckSpread"
257
+ },
258
+ "minItems": 1,
259
+ "uniqueItems": true
260
+ },
142
261
  "back": {
143
262
  "$ref": "entry.json#/$defs/entryImage"
144
263
  },
@@ -216,6 +335,14 @@
216
335
  "$ref": "entry.json"
217
336
  }
218
337
  },
338
+ "spreads": {
339
+ "type": "array",
340
+ "items": {
341
+ "$ref": "#/$defs/_deckSpread"
342
+ },
343
+ "minItems": 1,
344
+ "uniqueItems": true
345
+ },
219
346
  "back": {
220
347
  "$ref": "entry.json#/$defs/entryImage"
221
348
  },
@@ -3,7 +3,7 @@
3
3
  "$id": "entry.json",
4
4
  "title": "Entry",
5
5
  "description": "A recursively renderable object.",
6
- "version": "1.10.00",
6
+ "version": "1.10.1",
7
7
  "$defs": {
8
8
  "_arrayOfSpell": {
9
9
  "type": "array",
@@ -3796,34 +3796,76 @@
3796
3796
  "additionalProperties": false
3797
3797
  },
3798
3798
  "entryWrapped": {
3799
- "type": "object",
3800
- "properties": {
3801
- "name": {
3802
- "type": "string"
3803
- },
3804
- "type": {
3805
- "type": "string",
3806
- "const": "wrapper"
3807
- },
3808
- "source": {
3809
- "$ref": "util.json#/$defs/source"
3810
- },
3811
- "page": {
3812
- "$ref": "util.json#/$defs/page"
3813
- },
3814
- "data": {
3815
- "$ref": "#/$defs/_entryDataData"
3816
- },
3817
- "id": {
3818
- "type": "string"
3799
+ "oneOf": [
3800
+ {
3801
+ "type": "object",
3802
+ "properties": {
3803
+ "name": {
3804
+ "type": "string"
3805
+ },
3806
+ "type": {
3807
+ "type": "string",
3808
+ "const": "wrapper"
3809
+ },
3810
+ "source": {
3811
+ "$ref": "util.json#/$defs/source"
3812
+ },
3813
+ "page": {
3814
+ "$ref": "util.json#/$defs/page"
3815
+ },
3816
+ "data": {
3817
+ "$ref": "#/$defs/_entryDataData"
3818
+ },
3819
+ "id": {
3820
+ "type": "string"
3821
+ },
3822
+ "wrapped": {
3823
+ "$ref": "#"
3824
+ }
3825
+ },
3826
+ "required": [
3827
+ "type",
3828
+ "wrapped"
3829
+ ],
3830
+ "additionalProperties": false
3819
3831
  },
3820
- "wrapped": {}
3821
- },
3822
- "required": [
3823
- "type",
3824
- "wrapped"
3825
- ],
3826
- "additionalProperties": false
3832
+ {
3833
+ "type": "object",
3834
+ "properties": {
3835
+ "name": {
3836
+ "type": "string"
3837
+ },
3838
+ "type": {
3839
+ "type": "string",
3840
+ "const": "wrapper"
3841
+ },
3842
+ "source": {
3843
+ "$ref": "util.json#/$defs/source"
3844
+ },
3845
+ "page": {
3846
+ "$ref": "util.json#/$defs/page"
3847
+ },
3848
+ "data": {
3849
+ "$ref": "#/$defs/_entryDataData"
3850
+ },
3851
+ "id": {
3852
+ "type": "string"
3853
+ },
3854
+ "wrappeds": {
3855
+ "type": "array",
3856
+ "items": {
3857
+ "$ref": "#"
3858
+ },
3859
+ "minItems": 1
3860
+ }
3861
+ },
3862
+ "required": [
3863
+ "type",
3864
+ "wrappeds"
3865
+ ],
3866
+ "additionalProperties": false
3867
+ }
3868
+ ]
3827
3869
  },
3828
3870
  "dataDamImmune": {
3829
3871
  "oneOf": [
@@ -1,9 +1,112 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "decks.json",
4
- "version": "1.0.7",
4
+ "version": "1.0.9",
5
5
  "type": "object",
6
6
  "$defs": {
7
+ "_deckSpreadOutcomesCardMap": {
8
+ "type": "object",
9
+ "propertyNames": {
10
+ "pattern": "^[^A-Z|]+\\|[^A-Z|]+\\|[^A-Z|]+$"
11
+ },
12
+ "additionalProperties": {
13
+ "type": "string"
14
+ },
15
+ "minProperties": 1
16
+ },
17
+ "_deckSpreadOutcomesCorpusMap": {
18
+ "type": "object",
19
+ "additionalProperties": {
20
+ "$ref": "#/$defs/_deckSpreadOutcomesCardMap"
21
+ },
22
+ "minProperties": 1
23
+ },
24
+ "_deckSpreadOutcomes": {
25
+ "type": "object",
26
+ "properties": {
27
+ "adventure": {
28
+ "$ref": "#/$defs/_deckSpreadOutcomesCorpusMap"
29
+ },
30
+ "book": {
31
+ "$ref": "#/$defs/_deckSpreadOutcomesCorpusMap"
32
+ }
33
+ },
34
+ "minProperties": 1,
35
+ "additionalProperties": false
36
+ },
37
+ "_deckSpreadPosition": {
38
+ "type": "object",
39
+ "properties": {
40
+ "name": {
41
+ "type": "string"
42
+ },
43
+ "entries": {
44
+ "type": "array",
45
+ "items": {
46
+ "$ref": "entry.json"
47
+ },
48
+ "minItems": 1
49
+ },
50
+ "suits": {
51
+ "$comment": "The suits this position may draw from; `null` matches cards which have no suit. Omit to draw from the whole deck.",
52
+ "type": "array",
53
+ "items": {
54
+ "type": [
55
+ "string",
56
+ "null"
57
+ ]
58
+ },
59
+ "minItems": 1,
60
+ "uniqueItems": true
61
+ },
62
+ "outcomes": {
63
+ "$comment": "Card outcomes specific to this position. These override spread-level outcomes.",
64
+ "$ref": "#/$defs/_deckSpreadOutcomes"
65
+ }
66
+ },
67
+ "required": [
68
+ "name",
69
+ "entries"
70
+ ],
71
+ "additionalProperties": false
72
+ },
73
+ "_deckSpread": {
74
+ "type": "object",
75
+ "properties": {
76
+ "name": {
77
+ "type": "string"
78
+ },
79
+ "source": {
80
+ "$ref": "util.json#/$defs/source"
81
+ },
82
+ "page": {
83
+ "$ref": "util.json#/$defs/page"
84
+ },
85
+ "entries": {
86
+ "type": "array",
87
+ "items": {
88
+ "$ref": "entry.json"
89
+ }
90
+ },
91
+ "positions": {
92
+ "type": "array",
93
+ "items": {
94
+ "$ref": "#/$defs/_deckSpreadPosition"
95
+ },
96
+ "minItems": 1
97
+ },
98
+ "outcomes": {
99
+ "$comment": "Card outcomes shared by all positions.",
100
+ "$ref": "#/$defs/_deckSpreadOutcomes"
101
+ }
102
+ },
103
+ "required": [
104
+ "name",
105
+ "source",
106
+ "positions"
107
+ ],
108
+ "additionalProperties": false
109
+ },
7
110
  "deckData": {
8
111
  "type": "object",
9
112
  "properties": {
@@ -65,6 +168,14 @@
65
168
  "$ref": "entry.json"
66
169
  }
67
170
  },
171
+ "spreads": {
172
+ "type": "array",
173
+ "items": {
174
+ "$ref": "#/$defs/_deckSpread"
175
+ },
176
+ "minItems": 1,
177
+ "uniqueItems": true
178
+ },
68
179
  "back": {
69
180
  "$ref": "entry.json#/$defs/entryImage"
70
181
  },
@@ -139,6 +250,14 @@
139
250
  "$ref": "entry.json"
140
251
  }
141
252
  },
253
+ "spreads": {
254
+ "type": "array",
255
+ "items": {
256
+ "$ref": "#/$defs/_deckSpread"
257
+ },
258
+ "minItems": 1,
259
+ "uniqueItems": true
260
+ },
142
261
  "back": {
143
262
  "$ref": "entry.json#/$defs/entryImage"
144
263
  },
@@ -216,6 +335,14 @@
216
335
  "$ref": "entry.json"
217
336
  }
218
337
  },
338
+ "spreads": {
339
+ "type": "array",
340
+ "items": {
341
+ "$ref": "#/$defs/_deckSpread"
342
+ },
343
+ "minItems": 1,
344
+ "uniqueItems": true
345
+ },
219
346
  "back": {
220
347
  "$ref": "entry.json#/$defs/entryImage"
221
348
  },
@@ -3,7 +3,7 @@
3
3
  "$id": "entry.json",
4
4
  "title": "Entry",
5
5
  "description": "A recursively renderable object.",
6
- "version": "1.10.00",
6
+ "version": "1.10.1",
7
7
  "$defs": {
8
8
  "_arrayOfSpell": {
9
9
  "type": "array",
@@ -3796,34 +3796,76 @@
3796
3796
  "additionalProperties": false
3797
3797
  },
3798
3798
  "entryWrapped": {
3799
- "type": "object",
3800
- "properties": {
3801
- "name": {
3802
- "type": "string"
3803
- },
3804
- "type": {
3805
- "type": "string",
3806
- "const": "wrapper"
3807
- },
3808
- "source": {
3809
- "$ref": "util.json#/$defs/source"
3810
- },
3811
- "page": {
3812
- "$ref": "util.json#/$defs/page"
3813
- },
3814
- "data": {
3815
- "$ref": "#/$defs/_entryDataData"
3816
- },
3817
- "id": {
3818
- "type": "string"
3799
+ "oneOf": [
3800
+ {
3801
+ "type": "object",
3802
+ "properties": {
3803
+ "name": {
3804
+ "type": "string"
3805
+ },
3806
+ "type": {
3807
+ "type": "string",
3808
+ "const": "wrapper"
3809
+ },
3810
+ "source": {
3811
+ "$ref": "util.json#/$defs/source"
3812
+ },
3813
+ "page": {
3814
+ "$ref": "util.json#/$defs/page"
3815
+ },
3816
+ "data": {
3817
+ "$ref": "#/$defs/_entryDataData"
3818
+ },
3819
+ "id": {
3820
+ "type": "string"
3821
+ },
3822
+ "wrapped": {
3823
+ "$ref": "#"
3824
+ }
3825
+ },
3826
+ "required": [
3827
+ "type",
3828
+ "wrapped"
3829
+ ],
3830
+ "additionalProperties": false
3819
3831
  },
3820
- "wrapped": {}
3821
- },
3822
- "required": [
3823
- "type",
3824
- "wrapped"
3825
- ],
3826
- "additionalProperties": false
3832
+ {
3833
+ "type": "object",
3834
+ "properties": {
3835
+ "name": {
3836
+ "type": "string"
3837
+ },
3838
+ "type": {
3839
+ "type": "string",
3840
+ "const": "wrapper"
3841
+ },
3842
+ "source": {
3843
+ "$ref": "util.json#/$defs/source"
3844
+ },
3845
+ "page": {
3846
+ "$ref": "util.json#/$defs/page"
3847
+ },
3848
+ "data": {
3849
+ "$ref": "#/$defs/_entryDataData"
3850
+ },
3851
+ "id": {
3852
+ "type": "string"
3853
+ },
3854
+ "wrappeds": {
3855
+ "type": "array",
3856
+ "items": {
3857
+ "$ref": "#"
3858
+ },
3859
+ "minItems": 1
3860
+ }
3861
+ },
3862
+ "required": [
3863
+ "type",
3864
+ "wrappeds"
3865
+ ],
3866
+ "additionalProperties": false
3867
+ }
3868
+ ]
3827
3869
  },
3828
3870
  "dataDamImmune": {
3829
3871
  "oneOf": [