5etools-utils 0.15.1 → 0.15.3
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.
|
File without changes
|
|
File without changes
|
package/bin/test-file-names.js
CHANGED
|
File without changes
|
package/bin/test-file-props.js
CHANGED
|
File without changes
|
package/bin/test-json-brew.js
CHANGED
|
File without changes
|
package/bin/test-json-ua.js
CHANGED
|
File without changes
|
package/lib/BrewCleaner.js
CHANGED
|
@@ -131,12 +131,12 @@ export class BrewCleaner {
|
|
|
131
131
|
// - Characters which have significance in a URL
|
|
132
132
|
static _RE_INVALID_CHARS = /[<>:"/\\|?*#%@]/;
|
|
133
133
|
|
|
134
|
-
static _cleanFolder (
|
|
134
|
+
static _cleanFolder ({dir, isDry = false}) {
|
|
135
135
|
const ALL_ERRORS = [];
|
|
136
136
|
|
|
137
|
-
const files = Uf.listJsonFiles(
|
|
137
|
+
const files = Uf.listJsonFiles(dir);
|
|
138
138
|
for (const file of files) {
|
|
139
|
-
|
|
139
|
+
const {raw, json} = Uf.readJsonSync(file, {isIncludeRaw: true});
|
|
140
140
|
|
|
141
141
|
if (this._RE_INVALID_CHARS.test(file.split("/").slice(1).join("/"))) {
|
|
142
142
|
ALL_ERRORS.push(`${file} contained invalid characters!`);
|
|
@@ -148,15 +148,21 @@ export class BrewCleaner {
|
|
|
148
148
|
if (!this._IS_FAIL_SLOW) break;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
_BrewFileTester.testFile({ALL_ERRORS, file, contents});
|
|
151
|
+
let jsonOut = _BrewFileCleaner.cleanFile({file, contents: json});
|
|
152
|
+
_BrewFileTester.testFile({ALL_ERRORS, file, contents: jsonOut});
|
|
153
153
|
|
|
154
154
|
if (!this._IS_FAIL_SLOW && ALL_ERRORS.length) break;
|
|
155
155
|
|
|
156
156
|
Um.info(`CLEANER`, `\t- "${file}"...`);
|
|
157
|
-
contents = getCleanJson(contents);
|
|
158
157
|
|
|
159
|
-
|
|
158
|
+
jsonOut = getCleanJson(jsonOut);
|
|
159
|
+
|
|
160
|
+
if (isDry) {
|
|
161
|
+
if (jsonOut !== raw) ALL_ERRORS.push(`${file} would be reformatted!`);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
fs.writeFileSync(file, jsonOut);
|
|
160
166
|
}
|
|
161
167
|
|
|
162
168
|
if (ALL_ERRORS.length) {
|
|
@@ -164,19 +170,27 @@ export class BrewCleaner {
|
|
|
164
170
|
throw new Error(`Errors were found. See above.`);
|
|
165
171
|
}
|
|
166
172
|
|
|
167
|
-
return files.length;
|
|
173
|
+
return {cntFiles: files.length, cntErrors: ALL_ERRORS.length};
|
|
168
174
|
}
|
|
169
175
|
|
|
170
|
-
static run () {
|
|
176
|
+
static run ({isDry = false} = {}) {
|
|
171
177
|
const tStart = Date.now();
|
|
172
178
|
|
|
173
|
-
let
|
|
179
|
+
let ttlFiles = 0;
|
|
180
|
+
let ttlErrors = 0;
|
|
174
181
|
|
|
175
182
|
Uf.runOnDirs((dir) => {
|
|
176
|
-
Um.info(`CLEANER`,
|
|
177
|
-
|
|
183
|
+
Um.info(`CLEANER`, `${isDry ? "Checking" : "Cleaning"} dir "${dir}"...`);
|
|
184
|
+
const {cntFiles, cntErrors} = this._cleanFolder({dir, isDry});
|
|
185
|
+
ttlFiles += cntFiles;
|
|
186
|
+
ttlErrors += cntErrors;
|
|
178
187
|
});
|
|
179
188
|
|
|
180
|
-
Um.info(`CLEANER`,
|
|
189
|
+
Um.info(`CLEANER`, `${isDry ? "Check" : "Cleaning"} complete. ${isDry ? "Checked" : "Cleaned"} ${ttlFiles} file${ttlFiles === 1 ? "" : "s"}. Ran in ${((Date.now() - tStart) / 1000).toFixed(2)}s.`);
|
|
190
|
+
|
|
191
|
+
if (ttlErrors && isDry) {
|
|
192
|
+
Um.info(`CLEANER`, `Found ${ttlErrors} error${ttlErrors === 1 ? "" : "s"}!`);
|
|
193
|
+
process.exit(1);
|
|
194
|
+
}
|
|
181
195
|
}
|
|
182
196
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "5etools-utils",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3",
|
|
4
4
|
"description": "Shared utilities for the 5etools ecosystem.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/Api.js",
|
|
@@ -39,16 +39,17 @@
|
|
|
39
39
|
},
|
|
40
40
|
"homepage": "https://github.com/TheGiddyLimit/5etools-utils#readme",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"ajv": "^8.
|
|
43
|
-
"ajv-formats": "^
|
|
44
|
-
"commander": "^
|
|
45
|
-
"hasha": "^
|
|
42
|
+
"ajv": "^8.18.0",
|
|
43
|
+
"ajv-formats": "^3.0.1",
|
|
44
|
+
"commander": "^14.0.3",
|
|
45
|
+
"hasha": "^7.0.0",
|
|
46
46
|
"json-source-map": "^0.6.1",
|
|
47
47
|
"number-precision": "^1.6.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"eslint": "^
|
|
51
|
-
"
|
|
52
|
-
"
|
|
50
|
+
"@eslint/js": "^10.0.1",
|
|
51
|
+
"eslint": "^10.0.1",
|
|
52
|
+
"jest": "^30.2.0",
|
|
53
|
+
"simple-git": "^3.32.1"
|
|
53
54
|
}
|
|
54
55
|
}
|