5etools-utils 0.5.18 → 0.6.1
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/adventures.json +3 -2
- package/schema/brew/bestiary/bestiary.json +265 -181
- package/schema/brew-fast/adventures.json +3 -2
- package/schema/brew-fast/bestiary/bestiary.json +265 -181
- package/schema/site/adventures.json +3 -2
- package/schema/site/bestiary/bestiary.json +265 -181
- package/schema/site-fast/adventures.json +3 -2
- package/schema/site-fast/bestiary/bestiary.json +265 -181
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,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.
|
|
4
|
+
"version": "1.10.11",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"properties": {
|
|
7
7
|
"adventure": {
|
|
@@ -190,7 +190,8 @@
|
|
|
190
190
|
"Critical Role",
|
|
191
191
|
"Journeys through the Radiant Citadel",
|
|
192
192
|
"Spelljammer",
|
|
193
|
-
"Dragonlance"
|
|
193
|
+
"Dragonlance",
|
|
194
|
+
"Keys from the Golden Vault"
|
|
194
195
|
]
|
|
195
196
|
},
|
|
196
197
|
"alAveragePlayerLevel": {
|