5etools-utils 0.16.34 → 0.16.35
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,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.
|
|
3
|
+
"version": "0.16.35",
|
|
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",
|