5etools-utils 0.15.18 → 0.16.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.
Files changed (41) hide show
  1. package/bin/lint-js-changed.js +17 -0
  2. package/lib/Lint/LintJsChanged.js +33 -0
  3. package/lib/UtilGit.js +39 -0
  4. package/lib/eslint/eslint-plugin-jquery.js +49 -0
  5. package/package.json +16 -6
  6. package/schema/brew/books.json +2 -1
  7. package/schema/brew/fluff-homecrafts.json +15 -0
  8. package/schema/brew/homebrew.json +9 -3
  9. package/schema/brew/homecrafts.json +597 -0
  10. package/schema/brew/util-copy.json +4 -2
  11. package/schema/brew/util.json +29 -27
  12. package/schema/brew-fast/books.json +2 -1
  13. package/schema/brew-fast/fluff-homecrafts.json +15 -0
  14. package/schema/brew-fast/homebrew.json +9 -3
  15. package/schema/brew-fast/homecrafts.json +597 -0
  16. package/schema/brew-fast/util-copy.json +4 -2
  17. package/schema/brew-fast/util.json +29 -27
  18. package/schema/site/books.json +2 -1
  19. package/schema/site/fluff-homecrafts.json +15 -0
  20. package/schema/site/homebrew.json +7 -4
  21. package/schema/site/homecrafts.json +570 -0
  22. package/schema/site/util-copy.json +4 -2
  23. package/schema/site/util.json +29 -27
  24. package/schema/site-fast/books.json +2 -1
  25. package/schema/site-fast/fluff-homecrafts.json +15 -0
  26. package/schema/site-fast/homebrew.json +7 -4
  27. package/schema/site-fast/homecrafts.json +570 -0
  28. package/schema/site-fast/util-copy.json +4 -2
  29. package/schema/site-fast/util.json +29 -27
  30. package/schema/ua/books.json +2 -1
  31. package/schema/ua/fluff-homecrafts.json +15 -0
  32. package/schema/ua/homebrew.json +9 -3
  33. package/schema/ua/homecrafts.json +570 -0
  34. package/schema/ua/util-copy.json +4 -2
  35. package/schema/ua/util.json +29 -27
  36. package/schema/ua-fast/books.json +2 -1
  37. package/schema/ua-fast/fluff-homecrafts.json +15 -0
  38. package/schema/ua-fast/homebrew.json +9 -3
  39. package/schema/ua-fast/homecrafts.json +570 -0
  40. package/schema/ua-fast/util-copy.json +4 -2
  41. package/schema/ua-fast/util.json +29 -27
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {Command} from "commander";
4
+ import {pDoLintJsChanged} from "../lib/Lint/LintJsChanged.js";
5
+
6
+ const program = new Command()
7
+ .option("--additional-root <path...>", "Additional git root to scan for changed files")
8
+ ;
9
+
10
+ program.parse(process.argv);
11
+ const opts = program.opts();
12
+
13
+ const isSuccess = await pDoLintJsChanged({
14
+ additionalRoots: opts.additionalRoot?.length ? opts.additionalRoot : null,
15
+ });
16
+
17
+ if (!isSuccess) process.exit(1);
@@ -0,0 +1,33 @@
1
+ import fs from "fs";
2
+ import {ESLint} from "eslint";
3
+ import {pGetModifiedFiles} from "../UtilGit.js";
4
+
5
+ /**
6
+ * @see https://eslint.org/docs/latest/integrate/nodejs-api
7
+ */
8
+ export const pDoLintJsChanged = async ({additionalRoots = null} = {}) => {
9
+ const fileList = (await pGetModifiedFiles({additionalRoots}))
10
+ .filter(file => /\.(js|cjs|mjs)$/.test(file) && fs.existsSync(file));
11
+
12
+ if (!fileList.length) {
13
+ console.warn(`Nothing to lint!`);
14
+ return true;
15
+ }
16
+
17
+ console.log(`Linting:\n${fileList.map(it => `\t${it}`).join("\n")}`);
18
+
19
+ const eslint = new ESLint({
20
+ fix: true,
21
+ });
22
+
23
+ const results = await eslint.lintFiles(fileList);
24
+
25
+ await ESLint.outputFixes(results);
26
+
27
+ const formatter = await eslint.loadFormatter("stylish");
28
+ const resultText = formatter.format(results);
29
+
30
+ if (resultText) console.log(resultText);
31
+
32
+ return !results.some(res => res.errorCount);
33
+ };
package/lib/UtilGit.js ADDED
@@ -0,0 +1,39 @@
1
+ import fs from "fs";
2
+ import simpleGit from "simple-git";
3
+
4
+ const pGetDiffSummaryFiles = async ({dir = null} = {}) => {
5
+ const git = dir ? simpleGit(dir) : simpleGit();
6
+
7
+ const filesUnstaged = (await git.diffSummary()).files
8
+ .map(file => file.file);
9
+ const filesStaged = (await git.diffSummary(["--staged"])).files
10
+ .map(file => file.file);
11
+
12
+ return Object.keys(
13
+ Object.fromEntries(
14
+ [...filesStaged, ...filesUnstaged]
15
+ .map(file => [dir ? `${dir}/${file}` : file, true]),
16
+ ),
17
+ );
18
+ };
19
+
20
+ /**
21
+ * @param {?Array<string>} additionalRoots
22
+ */
23
+ export const pGetModifiedFiles = async ({additionalRoots = null} = {}) => {
24
+ return [
25
+ ...await pGetDiffSummaryFiles(),
26
+
27
+ ...(
28
+ await Promise.all(
29
+ (additionalRoots || [])
30
+ .map(async altDir => {
31
+ return fs.existsSync(altDir)
32
+ ? pGetDiffSummaryFiles({dir: altDir})
33
+ : [];
34
+ }),
35
+ )
36
+ )
37
+ .flat(),
38
+ ];
39
+ };
@@ -0,0 +1,49 @@
1
+ export default {
2
+ meta: {
3
+ name: "vet-jquery",
4
+ version: "1.0.0",
5
+ },
6
+
7
+ rules: {
8
+ "jquery": {
9
+ meta: {
10
+ type: "problem",
11
+ docs: {
12
+ description: "likely jQuery usage",
13
+ },
14
+ schema: [
15
+ {
16
+ type: "object",
17
+ properties: {
18
+ isFlagOnly: {
19
+ type: "boolean",
20
+ },
21
+ },
22
+ additionalProperties: false,
23
+ },
24
+ ],
25
+ },
26
+ create (context) {
27
+ const [{isFlagOnly = false} = {}] = context.options;
28
+
29
+ let isAnyFound = false;
30
+ return {
31
+ "Identifier": node => {
32
+ if (
33
+ node.name === "jQuery"
34
+ || node.name.includes("$")
35
+ ) {
36
+ if (isAnyFound && isFlagOnly) return;
37
+ isAnyFound = true;
38
+
39
+ context.report({
40
+ node: node,
41
+ message: `likely jQuery usage (${node.name})`,
42
+ });
43
+ }
44
+ },
45
+ };
46
+ },
47
+ },
48
+ },
49
+ };
package/package.json CHANGED
@@ -1,10 +1,19 @@
1
1
  {
2
2
  "name": "5etools-utils",
3
- "version": "0.15.18",
3
+ "version": "0.16.1",
4
4
  "description": "Shared utilities for the 5etools ecosystem.",
5
5
  "type": "module",
6
6
  "main": "lib/Api.js",
7
+ "exports": {
8
+ ".": "./lib/Api.js",
9
+ "./eslint": "./lib/eslint/eslint-plugin-jquery.js",
10
+ "./eslint/*": "./lib/eslint/*",
11
+ "./lib/*": "./lib/*",
12
+ "./schema/*": "./schema/*",
13
+ "./package.json": "./package.json"
14
+ },
7
15
  "files": [
16
+ "bin",
8
17
  "lib",
9
18
  "schema"
10
19
  ],
@@ -23,7 +32,8 @@
23
32
  "test-img-file-extensions": "bin/test-img-file-extensions.js",
24
33
  "test-img-file-sizes": "bin/test-img-file-sizes.js",
25
34
  "test-img-source-names-brew": "bin/test-img-source-names-brew.js",
26
- "test-img-source-names-ua": "bin/test-img-source-names-ua.js"
35
+ "test-img-source-names-ua": "bin/test-img-source-names-ua.js",
36
+ "lint-js-changed": "bin/lint-js-changed.js"
27
37
  },
28
38
  "scripts": {
29
39
  "build:dangerous:sources": "node node/fetch-5etools-sources.js",
@@ -48,16 +58,16 @@
48
58
  "ajv": "^8.18.0",
49
59
  "ajv-formats": "^3.0.1",
50
60
  "commander": "^14.0.3",
61
+ "eslint": "^10.0.1",
51
62
  "hasha": "^7.0.0",
52
63
  "he": "^1.2.0",
53
64
  "json-source-map": "^0.6.1",
54
65
  "number-precision": "^1.6.0",
55
- "sanitize-html": "^2.17.1"
66
+ "sanitize-html": "^2.17.1",
67
+ "simple-git": "^3.32.1"
56
68
  },
57
69
  "devDependencies": {
58
70
  "@eslint/js": "^10.0.1",
59
- "eslint": "^10.0.1",
60
- "jest": "^30.2.0",
61
- "simple-git": "^3.32.1"
71
+ "jest": "^30.2.0"
62
72
  }
63
73
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "books.json",
4
- "version": "1.2.19",
4
+ "version": "1.2.20",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "book": {
@@ -43,6 +43,7 @@
43
43
  "screen",
44
44
  "organized-play",
45
45
  "recipe",
46
+ "homecraft",
46
47
  "other"
47
48
  ],
48
49
  "markdownDescription": "The group under which this book should be listed in the navbar."
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "fluff-homecrafts.json",
4
+ "version": "1.0.0",
5
+ "type": "object",
6
+ "properties": {
7
+ "_meta": {
8
+ "$ref": "util.json#/$defs/metaBlock"
9
+ },
10
+ "crochetPatternFluff": {
11
+ "$ref": "util.json#/$defs/genericFluffArray"
12
+ }
13
+ },
14
+ "additionalProperties": false
15
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "type": "object",
5
5
  "description": "Homebrew for 5etools. Should include arrays titled similarly to the main site data, e.g. `spell` or `class`",
6
6
  "$defs": {
@@ -769,6 +769,12 @@
769
769
  "foundryOptionalfeature": {
770
770
  "$ref": "foundry-optionalfeatures.json#/properties/optionalfeature"
771
771
  },
772
+ "crochetPattern": {
773
+ "$ref": "homecrafts.json#/properties/crochetPattern"
774
+ },
775
+ "crochetPatternFluff": {
776
+ "$ref": "fluff-homecrafts.json#/properties/crochetPatternFluff"
777
+ },
772
778
  "psionic": {
773
779
  "$ref": "psionics.json#/properties/psionic"
774
780
  },
@@ -870,8 +876,8 @@
870
876
  }
871
877
  },
872
878
  "additionalProperties": false,
879
+ "markdownDescription": "Homebrew for 5etools. Should include arrays titled similarly to the main site data, e.g. spell or class",
873
880
  "required": [
874
881
  "_meta"
875
- ],
876
- "markdownDescription": "Homebrew for 5etools. Should include arrays titled similarly to the main site data, e.g. spell or class"
882
+ ]
877
883
  }