5etools-utils 0.6.5 → 0.7.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/README.md +7 -0
- package/bin/test-json-brew.js +5 -0
- package/lib/BrewTester.js +14 -1
- package/package.json +4 -1
package/README.md
ADDED
package/lib/BrewTester.js
CHANGED
|
@@ -2,6 +2,8 @@ import * as fs from "fs";
|
|
|
2
2
|
import {Command} from "commander";
|
|
3
3
|
import Um from "./UtilMisc.js";
|
|
4
4
|
import {JsonTester} from "./TestJson.js";
|
|
5
|
+
import {listJsonFiles} from "./UtilFs.js";
|
|
6
|
+
import * as pathlib from "path";
|
|
5
7
|
|
|
6
8
|
class _BrewTesterJson {
|
|
7
9
|
static _LOG_TAG = "JSON";
|
|
@@ -10,15 +12,21 @@ class _BrewTesterJson {
|
|
|
10
12
|
static async pRun (args) {
|
|
11
13
|
const program = new Command()
|
|
12
14
|
.argument("[file]", "File to test")
|
|
15
|
+
.option("--dir <dir>", "Directory to test")
|
|
13
16
|
;
|
|
14
17
|
|
|
15
18
|
program.parse(args);
|
|
19
|
+
const opts = program.opts();
|
|
16
20
|
|
|
17
21
|
const jsonTester = new JsonTester({isBrew: true, tagLog: this._LOG_TAG, fnGetSchemaId: () => "homebrew.json"});
|
|
18
22
|
|
|
19
23
|
let results;
|
|
20
24
|
if (program.args[0]) {
|
|
21
25
|
results = jsonTester.getFileErrors({filePath: program.args[0]});
|
|
26
|
+
} else if (opts.dir) {
|
|
27
|
+
const fileList = listJsonFiles(opts.dir)
|
|
28
|
+
.filter(it => pathlib.basename(it) !== "index.json");
|
|
29
|
+
results = await jsonTester.pGetErrorsOnDirsWorkers({isFailFast: !this._IS_FAIL_SLOW, fileList: fileList});
|
|
22
30
|
} else {
|
|
23
31
|
results = await jsonTester.pGetErrorsOnDirsWorkers({isFailFast: !this._IS_FAIL_SLOW});
|
|
24
32
|
}
|
|
@@ -26,7 +34,12 @@ class _BrewTesterJson {
|
|
|
26
34
|
const {errors, errorsFull} = results;
|
|
27
35
|
|
|
28
36
|
if (errors.length) {
|
|
29
|
-
if (!process.env.CI)
|
|
37
|
+
if (!process.env.CI) {
|
|
38
|
+
const outDir = fs.existsSync("_test") && fs.lstatSync("_test").isDirectory()
|
|
39
|
+
? "_test"
|
|
40
|
+
: ".";
|
|
41
|
+
fs.writeFileSync(`${outDir}/test-json.error.log`, errorsFull.join("\n\n=====\n\n"));
|
|
42
|
+
}
|
|
30
43
|
console.error(`Schema test failed (${errors.length} failure${errors.length === 1 ? "" : "s"}).`);
|
|
31
44
|
process.exit(1);
|
|
32
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "5etools-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Shared utilities for the 5etools ecosystem.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/Api.js",
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"directories": {
|
|
12
12
|
"lib": "./lib"
|
|
13
13
|
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"test-json-brew": "bin/test-json-brew.js"
|
|
16
|
+
},
|
|
14
17
|
"scripts": {
|
|
15
18
|
"build": "node node/compile-schemas.js",
|
|
16
19
|
"test": "npm run lint:js && npm run test:js",
|