5etools-utils 0.5.17 → 0.6.0
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/BrewCleaner.js +1 -1
- package/lib/BrewIndexGenerator.js +1 -1
- package/lib/BrewTimestamper.js +1 -1
- package/lib/TestData.js +2 -2
- package/lib/TestJson.js +3 -3
- package/lib/UtilFs.js +63 -3
- package/package.json +1 -1
- package/schema/brew/bestiary/bestiary.json +61 -1
- package/schema/brew/spells/spells.json +1 -1
- package/schema/brew-fast/bestiary/bestiary.json +61 -1
- package/schema/brew-fast/spells/spells.json +1 -1
- package/schema/site/bestiary/bestiary.json +1 -1
- package/schema/site/spells/spells.json +1 -1
- package/schema/site-fast/bestiary/bestiary.json +1 -1
- package/schema/site-fast/spells/spells.json +1 -1
package/lib/BrewCleaner.js
CHANGED
|
@@ -23,7 +23,7 @@ class BrewCleaner {
|
|
|
23
23
|
|
|
24
24
|
const files = Uf.listJsonFiles(folder);
|
|
25
25
|
for (const file of files) {
|
|
26
|
-
let contents = Uf.
|
|
26
|
+
let contents = Uf.readJsonSync(file);
|
|
27
27
|
|
|
28
28
|
if (this._RE_INVALID_WINDOWS_CHARS.test(file.split("/").slice(1).join("/"))) {
|
|
29
29
|
ALL_ERRORS.push(`${file} contained invalid characters!`);
|
package/lib/BrewTimestamper.js
CHANGED
|
@@ -17,7 +17,7 @@ class BrewTimestamper {
|
|
|
17
17
|
static async _pUpdateDir (dir) {
|
|
18
18
|
const promises = Uf.listJsonFiles(dir)
|
|
19
19
|
.map(async file => {
|
|
20
|
-
const fileData = Uf.
|
|
20
|
+
const fileData = Uf.readJsonSync(file, {isIncludeRaw: true});
|
|
21
21
|
|
|
22
22
|
if (!fileData.json._meta) {
|
|
23
23
|
throw new Error(`File "${file}" did not have metadata!`);
|
package/lib/TestData.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
|
-
import {
|
|
2
|
+
import {readJsonSync} from "./UtilFs.js";
|
|
3
3
|
import {ObjectWalker} from "./ObjectWalker.js";
|
|
4
4
|
|
|
5
5
|
/** Runs multiple handlers on each file, to avoid re-reading each file for each handler */
|
|
@@ -37,7 +37,7 @@ class _ParsedJsonChecker {
|
|
|
37
37
|
|
|
38
38
|
if (!filePath.endsWith(".json") || (fnIsIgnoredFile && fnIsIgnoredFile(filePath))) return;
|
|
39
39
|
|
|
40
|
-
const contents =
|
|
40
|
+
const contents = readJsonSync(filePath);
|
|
41
41
|
|
|
42
42
|
ObjectWalker.walk({
|
|
43
43
|
obj: contents,
|
package/lib/TestJson.js
CHANGED
|
@@ -118,7 +118,7 @@ class JsonTester {
|
|
|
118
118
|
const dir = type === "site" ? this._dirSchemaSite : this._dirSchemaBrew;
|
|
119
119
|
|
|
120
120
|
this._ajv.addSchema(
|
|
121
|
-
Uf.
|
|
121
|
+
Uf.readJsonSync(path.join(dir, relativeFilePath)),
|
|
122
122
|
relativeFilePath,
|
|
123
123
|
);
|
|
124
124
|
}
|
|
@@ -133,7 +133,7 @@ class JsonTester {
|
|
|
133
133
|
const relativeFilePath = path.relative(this._dirSchema, filePath)
|
|
134
134
|
.replace(/\\/g, "/");
|
|
135
135
|
|
|
136
|
-
this._ajv.addSchema(Uf.
|
|
136
|
+
this._ajv.addSchema(Uf.readJsonSync(filePath), relativeFilePath);
|
|
137
137
|
});
|
|
138
138
|
|
|
139
139
|
this._isSchemaLoaded = true;
|
|
@@ -149,7 +149,7 @@ class JsonTester {
|
|
|
149
149
|
|
|
150
150
|
Um.info(this._tagLog, `\tValidating "${filePath}"...`);
|
|
151
151
|
|
|
152
|
-
const data = Uf.
|
|
152
|
+
const data = Uf.readJsonSync(filePath);
|
|
153
153
|
this._addImplicits(data);
|
|
154
154
|
|
|
155
155
|
const isValid = this._ajv.validate(this._fnGetSchemaId(filePath), data);
|
package/lib/UtilFs.js
CHANGED
|
@@ -5,7 +5,7 @@ function isDirectory (path) {
|
|
|
5
5
|
return fs.lstatSync(path).isDirectory();
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
function
|
|
8
|
+
function readJsonSync (path, {isIncludeRaw = false} = {}) {
|
|
9
9
|
try {
|
|
10
10
|
if (fs.existsSync(path)) {
|
|
11
11
|
let str = fs.readFileSync(path, "utf8");
|
|
@@ -21,7 +21,7 @@ function readJSON (path, {isIncludeRaw = false} = {}) {
|
|
|
21
21
|
const filenames = fs.readdirSync(dir, "utf8");
|
|
22
22
|
const filename = filenames.find(it => it.toLowerCase() === originalName.toLowerCase());
|
|
23
23
|
if (!filename) throw new Error(`Could not find file "${path}"`);
|
|
24
|
-
return
|
|
24
|
+
return readJsonSync(`${dir}/${filename}`, {isIncludeRaw});
|
|
25
25
|
}
|
|
26
26
|
} catch (e) {
|
|
27
27
|
e.message += ` (Path: ${path})`;
|
|
@@ -29,6 +29,10 @@ function readJSON (path, {isIncludeRaw = false} = {}) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
function writeJsonSync (filePath, data) {
|
|
33
|
+
return fs.writeFileSync(filePath, `${JSON.stringify(data, null, "\t")}\n`, "utf-8");
|
|
34
|
+
}
|
|
35
|
+
|
|
32
36
|
/**
|
|
33
37
|
* @param dir
|
|
34
38
|
* @param [opts]
|
|
@@ -86,10 +90,66 @@ function mkDirs (pathToCreate) {
|
|
|
86
90
|
}, "");
|
|
87
91
|
}
|
|
88
92
|
|
|
93
|
+
function removeSync (path) {
|
|
94
|
+
if (fs.existsSync(path)) {
|
|
95
|
+
fs.readdirSync(path).forEach(file => {
|
|
96
|
+
const curPath = `${path}/${file}`;
|
|
97
|
+
if (fs.lstatSync(curPath).isDirectory()) removeSync(curPath);
|
|
98
|
+
else fs.unlinkSync(curPath);
|
|
99
|
+
});
|
|
100
|
+
fs.rmdirSync(path);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param src
|
|
106
|
+
* @param dest
|
|
107
|
+
* @param [opts]
|
|
108
|
+
* @param [opts.isForce]
|
|
109
|
+
* @param [opts.isDryRun]
|
|
110
|
+
*/
|
|
111
|
+
function copySync (src, dest, opts) {
|
|
112
|
+
opts = opts || {};
|
|
113
|
+
if (fs.existsSync(src) && fs.statSync(src).isDirectory()) {
|
|
114
|
+
if (opts.isDryRun) console.log(`Creating directory ${dest}`);
|
|
115
|
+
else fs.mkdirSync(dest, {recursive: true});
|
|
116
|
+
|
|
117
|
+
fs.readdirSync(src).forEach(child => copySync(`${src}/${child}`, `${dest}/${child}`, opts));
|
|
118
|
+
} else {
|
|
119
|
+
if (opts.isForce) {
|
|
120
|
+
if (opts.isDryRun) {
|
|
121
|
+
console.log(`\tRemoving ${dest}`);
|
|
122
|
+
} else {
|
|
123
|
+
if (fs.existsSync(dest)) fs.unlinkSync(dest);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (opts.isDryRun) console.log(`\tCopying ${src} to ${dest}`);
|
|
128
|
+
else {
|
|
129
|
+
const dirName = path.dirname(dest);
|
|
130
|
+
if (dirName && !fs.existsSync(dirName)) fs.mkdirSync(dirName, {recursive: true});
|
|
131
|
+
fs.copyFileSync(src, dest);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function lsRecursiveSync (dir, fileList = []) {
|
|
137
|
+
fs.readdirSync(dir).forEach(file => {
|
|
138
|
+
fileList = fs.statSync(path.join(dir, file)).isDirectory()
|
|
139
|
+
? lsRecursiveSync(path.join(dir, file), fileList)
|
|
140
|
+
: fileList.concat(path.join(dir, file));
|
|
141
|
+
});
|
|
142
|
+
return fileList;
|
|
143
|
+
}
|
|
144
|
+
|
|
89
145
|
export {
|
|
90
|
-
|
|
146
|
+
readJsonSync,
|
|
147
|
+
writeJsonSync,
|
|
91
148
|
listJsonFiles,
|
|
92
149
|
runOnDirs,
|
|
93
150
|
pRunOnDirs,
|
|
94
151
|
mkDirs,
|
|
152
|
+
removeSync,
|
|
153
|
+
copySync,
|
|
154
|
+
lsRecursiveSync,
|
|
95
155
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.11",
|
|
4
4
|
"title": "Bestiary Schema",
|
|
5
5
|
"$id": "bestiary.json",
|
|
6
6
|
"type": "object",
|
|
@@ -1146,6 +1146,26 @@
|
|
|
1146
1146
|
"additionalProperties": false
|
|
1147
1147
|
}
|
|
1148
1148
|
},
|
|
1149
|
+
"resource": {
|
|
1150
|
+
"type": "array",
|
|
1151
|
+
"items": {
|
|
1152
|
+
"type": "object",
|
|
1153
|
+
"properties": {
|
|
1154
|
+
"value": {
|
|
1155
|
+
"type": "integer"
|
|
1156
|
+
},
|
|
1157
|
+
"formula": {
|
|
1158
|
+
"type": "string"
|
|
1159
|
+
}
|
|
1160
|
+
},
|
|
1161
|
+
"required": [
|
|
1162
|
+
"value"
|
|
1163
|
+
],
|
|
1164
|
+
"additionalProperties": false
|
|
1165
|
+
},
|
|
1166
|
+
"uniqueItems": true,
|
|
1167
|
+
"minItems": 1
|
|
1168
|
+
},
|
|
1149
1169
|
"fluff": {
|
|
1150
1170
|
"description": "This is intended to be used for Homebrew only - site data should include a fluff file per source",
|
|
1151
1171
|
"anyOf": [
|
|
@@ -2248,6 +2268,26 @@
|
|
|
2248
2268
|
"additionalProperties": false
|
|
2249
2269
|
}
|
|
2250
2270
|
},
|
|
2271
|
+
"resource": {
|
|
2272
|
+
"type": "array",
|
|
2273
|
+
"items": {
|
|
2274
|
+
"type": "object",
|
|
2275
|
+
"properties": {
|
|
2276
|
+
"value": {
|
|
2277
|
+
"type": "integer"
|
|
2278
|
+
},
|
|
2279
|
+
"formula": {
|
|
2280
|
+
"type": "string"
|
|
2281
|
+
}
|
|
2282
|
+
},
|
|
2283
|
+
"required": [
|
|
2284
|
+
"value"
|
|
2285
|
+
],
|
|
2286
|
+
"additionalProperties": false
|
|
2287
|
+
},
|
|
2288
|
+
"uniqueItems": true,
|
|
2289
|
+
"minItems": 1
|
|
2290
|
+
},
|
|
2251
2291
|
"fluff": {
|
|
2252
2292
|
"description": "This is intended to be used for Homebrew only - site data should include a fluff file per source",
|
|
2253
2293
|
"anyOf": [
|
|
@@ -3365,6 +3405,26 @@
|
|
|
3365
3405
|
"additionalProperties": false
|
|
3366
3406
|
}
|
|
3367
3407
|
},
|
|
3408
|
+
"resource": {
|
|
3409
|
+
"type": "array",
|
|
3410
|
+
"items": {
|
|
3411
|
+
"type": "object",
|
|
3412
|
+
"properties": {
|
|
3413
|
+
"value": {
|
|
3414
|
+
"type": "integer"
|
|
3415
|
+
},
|
|
3416
|
+
"formula": {
|
|
3417
|
+
"type": "string"
|
|
3418
|
+
}
|
|
3419
|
+
},
|
|
3420
|
+
"required": [
|
|
3421
|
+
"value"
|
|
3422
|
+
],
|
|
3423
|
+
"additionalProperties": false
|
|
3424
|
+
},
|
|
3425
|
+
"uniqueItems": true,
|
|
3426
|
+
"minItems": 1
|
|
3427
|
+
},
|
|
3368
3428
|
"fluff": {
|
|
3369
3429
|
"description": "This is intended to be used for Homebrew only - site data should include a fluff file per source",
|
|
3370
3430
|
"anyOf": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.11",
|
|
4
4
|
"title": "Bestiary Schema",
|
|
5
5
|
"$id": "bestiary.json",
|
|
6
6
|
"type": "object",
|
|
@@ -1146,6 +1146,26 @@
|
|
|
1146
1146
|
"additionalProperties": false
|
|
1147
1147
|
}
|
|
1148
1148
|
},
|
|
1149
|
+
"resource": {
|
|
1150
|
+
"type": "array",
|
|
1151
|
+
"items": {
|
|
1152
|
+
"type": "object",
|
|
1153
|
+
"properties": {
|
|
1154
|
+
"value": {
|
|
1155
|
+
"type": "integer"
|
|
1156
|
+
},
|
|
1157
|
+
"formula": {
|
|
1158
|
+
"type": "string"
|
|
1159
|
+
}
|
|
1160
|
+
},
|
|
1161
|
+
"required": [
|
|
1162
|
+
"value"
|
|
1163
|
+
],
|
|
1164
|
+
"additionalProperties": false
|
|
1165
|
+
},
|
|
1166
|
+
"uniqueItems": true,
|
|
1167
|
+
"minItems": 1
|
|
1168
|
+
},
|
|
1149
1169
|
"fluff": {
|
|
1150
1170
|
"description": "This is intended to be used for Homebrew only - site data should include a fluff file per source",
|
|
1151
1171
|
"anyOf": [
|
|
@@ -2248,6 +2268,26 @@
|
|
|
2248
2268
|
"additionalProperties": false
|
|
2249
2269
|
}
|
|
2250
2270
|
},
|
|
2271
|
+
"resource": {
|
|
2272
|
+
"type": "array",
|
|
2273
|
+
"items": {
|
|
2274
|
+
"type": "object",
|
|
2275
|
+
"properties": {
|
|
2276
|
+
"value": {
|
|
2277
|
+
"type": "integer"
|
|
2278
|
+
},
|
|
2279
|
+
"formula": {
|
|
2280
|
+
"type": "string"
|
|
2281
|
+
}
|
|
2282
|
+
},
|
|
2283
|
+
"required": [
|
|
2284
|
+
"value"
|
|
2285
|
+
],
|
|
2286
|
+
"additionalProperties": false
|
|
2287
|
+
},
|
|
2288
|
+
"uniqueItems": true,
|
|
2289
|
+
"minItems": 1
|
|
2290
|
+
},
|
|
2251
2291
|
"fluff": {
|
|
2252
2292
|
"description": "This is intended to be used for Homebrew only - site data should include a fluff file per source",
|
|
2253
2293
|
"anyOf": [
|
|
@@ -3365,6 +3405,26 @@
|
|
|
3365
3405
|
"additionalProperties": false
|
|
3366
3406
|
}
|
|
3367
3407
|
},
|
|
3408
|
+
"resource": {
|
|
3409
|
+
"type": "array",
|
|
3410
|
+
"items": {
|
|
3411
|
+
"type": "object",
|
|
3412
|
+
"properties": {
|
|
3413
|
+
"value": {
|
|
3414
|
+
"type": "integer"
|
|
3415
|
+
},
|
|
3416
|
+
"formula": {
|
|
3417
|
+
"type": "string"
|
|
3418
|
+
}
|
|
3419
|
+
},
|
|
3420
|
+
"required": [
|
|
3421
|
+
"value"
|
|
3422
|
+
],
|
|
3423
|
+
"additionalProperties": false
|
|
3424
|
+
},
|
|
3425
|
+
"uniqueItems": true,
|
|
3426
|
+
"minItems": 1
|
|
3427
|
+
},
|
|
3368
3428
|
"fluff": {
|
|
3369
3429
|
"description": "This is intended to be used for Homebrew only - site data should include a fluff file per source",
|
|
3370
3430
|
"anyOf": [
|