cyclops-infobook-html 5.1.0 → 5.2.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 (52) hide show
  1. package/README.md +12 -12
  2. package/bin/compress-icons.js +42 -7
  3. package/bin/convert-pom-to-modpack.d.ts +2 -0
  4. package/bin/convert-pom-to-modpack.js +96 -0
  5. package/bin/generate-icons.js +50 -15
  6. package/bin/generate-infobook-html.js +46 -10
  7. package/bin/generate-mod-metadata.js +52 -14
  8. package/index.d.ts +25 -25
  9. package/lib/icon/IconsCompressor.js +43 -12
  10. package/lib/icon/IconsGenerator.d.ts +42 -20
  11. package/lib/icon/IconsGenerator.js +156 -70
  12. package/lib/infobook/FileWriter.d.ts +3 -3
  13. package/lib/infobook/FileWriter.js +5 -5
  14. package/lib/infobook/IFileWriter.d.ts +2 -2
  15. package/lib/infobook/IInfoAppendix.d.ts +3 -3
  16. package/lib/infobook/IInfoBook.d.ts +2 -4
  17. package/lib/infobook/IInfoSection.d.ts +1 -1
  18. package/lib/infobook/IInfobookPlugin.d.ts +5 -5
  19. package/lib/infobook/InfoBookInitializer.d.ts +7 -9
  20. package/lib/infobook/InfoBookInitializer.js +1 -1
  21. package/lib/infobook/appendix/IInfoBookAppendixHandler.d.ts +2 -2
  22. package/lib/infobook/appendix/InfoBookAppendixAd.d.ts +3 -3
  23. package/lib/infobook/appendix/InfoBookAppendixAd.js +7 -2
  24. package/lib/infobook/appendix/InfoBookAppendixHandlerAbstractRecipe.d.ts +12 -14
  25. package/lib/infobook/appendix/InfoBookAppendixHandlerAbstractRecipe.js +41 -8
  26. package/lib/infobook/appendix/InfoBookAppendixHandlerAdvancementRewards.d.ts +3 -3
  27. package/lib/infobook/appendix/InfoBookAppendixHandlerAdvancementRewards.js +5 -4
  28. package/lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe.d.ts +6 -5
  29. package/lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe.js +4 -3
  30. package/lib/infobook/appendix/InfoBookAppendixHandlerImage.d.ts +3 -3
  31. package/lib/infobook/appendix/InfoBookAppendixHandlerImage.js +4 -4
  32. package/lib/infobook/appendix/InfoBookAppendixHandlerKeybinding.d.ts +3 -3
  33. package/lib/infobook/appendix/InfoBookAppendixHandlerKeybinding.js +3 -2
  34. package/lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe.d.ts +6 -5
  35. package/lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe.js +3 -2
  36. package/lib/infobook/appendix/InfoBookAppendixHandlerTextfield.d.ts +3 -3
  37. package/lib/infobook/appendix/InfoBookAppendixHandlerTextfield.js +4 -5
  38. package/lib/infobook/appendix/InfoBookAppendixTagIndex.d.ts +4 -4
  39. package/lib/infobook/appendix/InfoBookAppendixTagIndex.js +2 -1
  40. package/lib/modloader/ModLoader.d.ts +13 -2
  41. package/lib/modloader/ModLoader.js +164 -69
  42. package/lib/modloader/PomConverter.d.ts +28 -0
  43. package/lib/modloader/PomConverter.js +194 -0
  44. package/lib/parse/XmlInfoBookParser.d.ts +5 -7
  45. package/lib/parse/XmlInfoBookParser.js +42 -9
  46. package/lib/resource/ResourceHandler.d.ts +7 -13
  47. package/lib/resource/ResourceHandler.js +16 -11
  48. package/lib/resource/ResourceLoader.d.ts +4 -5
  49. package/lib/resource/ResourceLoader.js +35 -33
  50. package/lib/serialize/HtmlInfoBookSerializer.d.ts +10 -16
  51. package/lib/serialize/HtmlInfoBookSerializer.js +83 -80
  52. package/package.json +33 -27
@@ -1,7 +1,7 @@
1
- import { IInfoBookAppendixHandler } from "../infobook/appendix/IInfoBookAppendixHandler";
2
- import { IInfoAppendix } from "../infobook/IInfoAppendix";
3
- import { IInfoBook } from "../infobook/IInfoBook";
4
- import { IInfoSection } from "../infobook/IInfoSection";
1
+ import type { IInfoBookAppendixHandler } from '../infobook/appendix/IInfoBookAppendixHandler';
2
+ import type { IInfoAppendix } from '../infobook/IInfoAppendix';
3
+ import type { IInfoBook } from '../infobook/IInfoBook';
4
+ import type { IInfoSection } from '../infobook/IInfoSection';
5
5
  /**
6
6
  * Parses an XML file into an {@link IInfoBook}.
7
7
  */
@@ -34,9 +34,7 @@ export declare class XmlInfoBookParser {
34
34
  * @param {string} modId The owning mod.
35
35
  * @returns {IInfoSection} A section.
36
36
  */
37
- jsonToSection(data: any, sections: {
38
- [id: string]: IInfoSection;
39
- }, modId: string): IInfoSection;
37
+ jsonToSection(data: any, sections: Record<string, IInfoSection>, modId: string): IInfoSection;
40
38
  /**
41
39
  * Convert a data object to a paragraph.
42
40
  * @param data A data object.
@@ -1,7 +1,40 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.XmlInfoBookParser = void 0;
4
- const fs = require("fs");
37
+ const fs = __importStar(require("node:fs"));
5
38
  const xml2js_1 = require("xml2js");
6
39
  /**
7
40
  * Parses an XML file into an {@link IInfoBook}.
@@ -29,7 +62,7 @@ class XmlInfoBookParser {
29
62
  */
30
63
  parse(path, modId) {
31
64
  return new Promise((resolve, reject) => {
32
- (0, xml2js_1.parseString)(fs.readFileSync(path), (error, data) => {
65
+ (0, xml2js_1.parseString)(fs.readFileSync(path, 'utf8'), (error, data) => {
33
66
  if (error) {
34
67
  return reject(error);
35
68
  }
@@ -58,14 +91,15 @@ class XmlInfoBookParser {
58
91
  * @returns {IInfoSection} A section.
59
92
  */
60
93
  jsonToSection(data, sections, modId) {
61
- // tslint:disable:object-literal-sort-keys
62
94
  const section = {
63
95
  nameTranslationKey: data.$.name,
64
96
  subSections: (data.section || []).map((subData) => this.jsonToSection(subData, sections, modId)),
65
97
  paragraphTranslationKeys: (data.paragraph || []).map((subData) => this.jsonToParagraph(subData)),
66
- appendix: ((data.appendix || []).concat(data.appendix_list || []))
67
- .map((subData) => this.jsonToAppendix(subData, modId)),
68
- tags: (data.tag ? data.tag.filter((entry) => typeof entry === 'string') : undefined) || [],
98
+ appendix: [
99
+ ...(data.appendix || []),
100
+ ...(data.appendix_list || []),
101
+ ].map((subData) => this.jsonToAppendix(subData, modId)),
102
+ tags: (data.tag ? data.tag.filter((entry) => typeof entry === 'string') : []),
69
103
  modId,
70
104
  };
71
105
  sections[section.nameTranslationKey] = section;
@@ -89,13 +123,12 @@ class XmlInfoBookParser {
89
123
  if (!data.$ || (!data.$.type && !data.$.factory)) {
90
124
  throw new Error(`No type or factory was found for the appendix ${JSON.stringify(data)}.`);
91
125
  }
92
- const type = data.$.type || data.$.factory;
126
+ const type = (data.$.type || data.$.factory);
93
127
  const handler = this.appendixHandlers[type];
94
128
  if (handler) {
95
129
  return handler.createAppendix(data, modId);
96
130
  }
97
- // tslint:disable-next-line:no-console
98
- console.error(`Could not find an appendix handler for type '${type}'`);
131
+ process.stderr.write(`Could not find an appendix handler for type '${type}'\n`);
99
132
  return null;
100
133
  }
101
134
  }
@@ -1,10 +1,10 @@
1
- import { IFluid } from "../infobook/IFluid";
2
- import { IItem } from "../infobook/IItem";
1
+ import type { IFluid } from '../infobook/IFluid';
2
+ import type { IItem } from '../infobook/IItem';
3
3
  /**
4
4
  * Allows Minecraft resources to be used.
5
5
  */
6
6
  export declare class ResourceHandler {
7
- private static readonly TRANSLATION_DEFAULTS;
7
+ private static readonly translationDefaults;
8
8
  private readonly translations;
9
9
  private readonly languages;
10
10
  private readonly resourcePackBasePaths;
@@ -25,6 +25,7 @@ export declare class ResourceHandler {
25
25
  };
26
26
  /**
27
27
  * Add an entry to a {@llink IItemKeyedRegistry}.
28
+ * @param {IItemKeyedRegistry} registry The registry.
28
29
  * @param {string} namespace The namespace.
29
30
  * @param {string} path The path.
30
31
  * @param {string} nbt The NBT. (empty string represents no NBT)
@@ -33,6 +34,7 @@ export declare class ResourceHandler {
33
34
  protected static addItemKeyedRegistryEntry(registry: IItemKeyedRegistry, namespace: string, path: string, nbt: string, value: string): void;
34
35
  /**
35
36
  * Get an value from a {@llink IItemKeyedRegistry}.
37
+ * @param {IItemKeyedRegistry} registry The registry.
36
38
  * @param {string} namespace The namespace.
37
39
  * @param {string} path The path.
38
40
  * @param {string} nbt The NBT. (empty string represents no NBT)
@@ -48,9 +50,7 @@ export declare class ResourceHandler {
48
50
  * @param {string} language A language key.
49
51
  * @param {{[p: string]: string}} translations A mapping from translation key to translated value.
50
52
  */
51
- addTranslations(language: string, translations: {
52
- [key: string]: string;
53
- }, excludedModLanguage: boolean): void;
53
+ addTranslations(language: string, translations: Record<string, string>, excludedModLanguage: boolean): void;
54
54
  /**
55
55
  * Get the translation for the given key.
56
56
  * @param {string} translationKey A translation key.
@@ -146,13 +146,7 @@ export declare class ResourceHandler {
146
146
  */
147
147
  getKeybinding(id: string): string;
148
148
  }
149
- export interface IItemKeyedRegistry {
150
- [namespace: string]: {
151
- [path: string]: {
152
- [nbt: string]: string;
153
- };
154
- };
155
- }
149
+ export type IItemKeyedRegistry = Record<string, Record<string, Record<string, string>>>;
156
150
  export interface IAdvancement {
157
151
  itemIcon: IItem;
158
152
  title: string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ResourceHandler = void 0;
4
- const path_1 = require("path");
4
+ const node_path_1 = require("node:path");
5
5
  /**
6
6
  * Allows Minecraft resources to be used.
7
7
  */
@@ -30,6 +30,7 @@ class ResourceHandler {
30
30
  }
31
31
  /**
32
32
  * Add an entry to a {@llink IItemKeyedRegistry}.
33
+ * @param {IItemKeyedRegistry} registry The registry.
33
34
  * @param {string} namespace The namespace.
34
35
  * @param {string} path The path.
35
36
  * @param {string} nbt The NBT. (empty string represents no NBT)
@@ -48,6 +49,7 @@ class ResourceHandler {
48
49
  }
49
50
  /**
50
51
  * Get an value from a {@llink IItemKeyedRegistry}.
52
+ * @param {IItemKeyedRegistry} registry The registry.
51
53
  * @param {string} namespace The namespace.
52
54
  * @param {string} path The path.
53
55
  * @param {string} nbt The NBT. (empty string represents no NBT)
@@ -64,7 +66,8 @@ class ResourceHandler {
64
66
  }
65
67
  let file = nbts[nbt];
66
68
  if (!file) {
67
- file = nbts[Object.keys(nbts)[0]]; // Take the first NBT-tagged item if none without NBT could be found
69
+ // Take the first NBT-tagged item if none without NBT could be found
70
+ file = nbts[Object.keys(nbts)[0]];
68
71
  }
69
72
  return file;
70
73
  }
@@ -82,14 +85,14 @@ class ResourceHandler {
82
85
  addTranslations(language, translations, excludedModLanguage) {
83
86
  language = language.toLowerCase();
84
87
  const existingTranslations = this.translations[language];
85
- if (!existingTranslations) {
86
- this.translations[language] = translations;
87
- }
88
- else {
88
+ if (existingTranslations) {
89
89
  for (const key in translations) {
90
90
  existingTranslations[key] = translations[key];
91
91
  }
92
92
  }
93
+ else {
94
+ this.translations[language] = translations;
95
+ }
93
96
  if (!excludedModLanguage && Object.keys(translations).length > 0) {
94
97
  this.languages[language] = true;
95
98
  }
@@ -104,7 +107,7 @@ class ResourceHandler {
104
107
  const entries = this.translations[languageKey] || this.translations.en_us;
105
108
  let value = entries[translationKey];
106
109
  if (!value) {
107
- value = this.translations.en_us[translationKey] || ResourceHandler.TRANSLATION_DEFAULTS[translationKey];
110
+ value = this.translations.en_us[translationKey] || ResourceHandler.translationDefaults[translationKey];
108
111
  if (!value) {
109
112
  throw new Error(`Could not find translation key ${translationKey} in ${languageKey}`);
110
113
  }
@@ -132,13 +135,13 @@ class ResourceHandler {
132
135
  if (separator < 0) {
133
136
  throw new Error(`Invalid resource key for expansion: ${resourceKey}`);
134
137
  }
135
- const resourcePackId = resourceKey.substr(0, separator);
138
+ const resourcePackId = resourceKey.slice(0, Math.max(0, separator));
136
139
  const basePath = this.resourcePackBasePaths[resourcePackId];
137
140
  if (!basePath) {
138
141
  throw new Error(`Failed to expand unknown resource pack id for resource path: ${resourceKey}`);
139
142
  }
140
- const suffix = resourceKey.substr(separator + 1);
141
- return (0, path_1.join)(basePath, suffix);
143
+ const suffix = resourceKey.slice(separator + 1);
144
+ return (0, node_path_1.join)(basePath, suffix);
142
145
  }
143
146
  /**
144
147
  * Add an item icon file.
@@ -258,8 +261,10 @@ class ResourceHandler {
258
261
  }
259
262
  }
260
263
  exports.ResourceHandler = ResourceHandler;
261
- ResourceHandler.TRANSLATION_DEFAULTS = {
264
+ ResourceHandler.translationDefaults = {
265
+ // eslint-disable-next-line ts/naming-convention
262
266
  'fluid.tile.lava': 'Lava',
267
+ // eslint-disable-next-line ts/naming-convention
263
268
  'fluid.tile.water': 'Water',
264
269
  };
265
270
  //# sourceMappingURL=ResourceHandler.js.map
@@ -1,4 +1,4 @@
1
- import { ResourceHandler } from "./ResourceHandler";
1
+ import { ResourceHandler } from './ResourceHandler';
2
2
  /**
3
3
  * Loads Minecraft resources in-memory.
4
4
  */
@@ -30,7 +30,8 @@ export declare class ResourceLoader {
30
30
  /**
31
31
  * Load all resources within the given paths.
32
32
  * @param {string} baseDir A base directory.
33
- * @param {string[]} paths An array of paths to traverse to look for resources.
33
+ * @param {string} path A path.
34
+ * @param {string[]} excludedModLanguages Excluded mod languages.
34
35
  * @returns {Promise<void>} A promise resolving when loading is done.
35
36
  */
36
37
  loadAll(baseDir: string, path: string, excludedModLanguages: string[]): Promise<void>;
@@ -83,7 +84,5 @@ export declare class ResourceLoader {
83
84
  * Load the given keybindings.
84
85
  * @param {{[p: string]: string}} keybindings Keybindings.
85
86
  */
86
- loadKeybindings(keybindings: {
87
- [key: string]: string;
88
- }): void;
87
+ loadKeybindings(keybindings: Record<string, string>): void;
89
88
  }
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ResourceLoader = void 0;
13
- const fs_1 = require("fs");
14
- const path_1 = require("path");
13
+ const node_fs_1 = require("node:fs");
14
+ const node_path_1 = require("node:path");
15
15
  const ResourceHandler_1 = require("./ResourceHandler");
16
16
  /**
17
17
  * Loads Minecraft resources in-memory.
@@ -33,23 +33,23 @@ class ResourceLoader {
33
33
  */
34
34
  loadIcons(iconsPath) {
35
35
  return __awaiter(this, void 0, void 0, function* () {
36
- const iconNames = yield fs_1.promises.readdir(iconsPath);
36
+ const iconNames = yield node_fs_1.promises.readdir(iconsPath);
37
37
  for (const iconName of iconNames) {
38
- const iconFile = (0, path_1.join)(iconsPath, iconName);
38
+ const iconFile = (0, node_path_1.join)(iconsPath, iconName);
39
39
  if (iconName.startsWith('fluid__')) {
40
- this.resourceHandler.addFluidIcon(iconName.substring(7, iconName.length - 4), iconFile);
40
+ this.resourceHandler.addFluidIcon(iconName.slice(7, -4), iconFile);
41
41
  }
42
42
  else {
43
- const split = iconName.split("__");
43
+ const split = iconName.split('__');
44
44
  const namespace = split[0];
45
45
  let path = split[1];
46
46
  let nbt = '';
47
47
  if (split.length > 2) {
48
- nbt = split.slice(2, split.length).join(":");
49
- nbt = nbt.substr(0, nbt.length - 4);
48
+ nbt = split.slice(2, split.length).join(':');
49
+ nbt = nbt.slice(0, Math.max(0, nbt.length - 4));
50
50
  }
51
51
  else {
52
- path = path.substr(0, path.length - 4);
52
+ path = path.slice(0, Math.max(0, path.length - 4));
53
53
  }
54
54
  this.resourceHandler.addItemIcon(namespace, path, nbt, iconFile);
55
55
  }
@@ -63,7 +63,7 @@ class ResourceLoader {
63
63
  */
64
64
  loadItemTranslationKeys(registriesPath) {
65
65
  return __awaiter(this, void 0, void 0, function* () {
66
- const registry = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(registriesPath, 'item_translation_keys.json'), "utf8"));
66
+ const registry = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(registriesPath, 'item_translation_keys.json'), 'utf8'));
67
67
  for (const entry of registry.items) {
68
68
  this.resourceHandler.addItemTranslationKey(entry.item, entry.translationKey);
69
69
  }
@@ -76,7 +76,7 @@ class ResourceLoader {
76
76
  */
77
77
  loadFluidTranslationKeys(registriesPath) {
78
78
  return __awaiter(this, void 0, void 0, function* () {
79
- const registry = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(registriesPath, 'fluid_translation_keys.json'), "utf8"));
79
+ const registry = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(registriesPath, 'fluid_translation_keys.json'), 'utf8'));
80
80
  for (const entry of registry.fluids) {
81
81
  this.resourceHandler.addFluidTranslationKey(entry.fluid, entry.translationKey);
82
82
  }
@@ -85,12 +85,13 @@ class ResourceLoader {
85
85
  /**
86
86
  * Load all resources within the given paths.
87
87
  * @param {string} baseDir A base directory.
88
- * @param {string[]} paths An array of paths to traverse to look for resources.
88
+ * @param {string} path A path.
89
+ * @param {string[]} excludedModLanguages Excluded mod languages.
89
90
  * @returns {Promise<void>} A promise resolving when loading is done.
90
91
  */
91
92
  loadAll(baseDir, path, excludedModLanguages) {
92
93
  return __awaiter(this, void 0, void 0, function* () {
93
- yield this.load((0, path_1.join)(baseDir, path), excludedModLanguages);
94
+ yield this.load((0, node_path_1.join)(baseDir, path), excludedModLanguages);
94
95
  });
95
96
  }
96
97
  /**
@@ -103,12 +104,12 @@ class ResourceLoader {
103
104
  */
104
105
  load(fullPath, excludedModLanguages) {
105
106
  return __awaiter(this, void 0, void 0, function* () {
106
- const entries = yield fs_1.promises.readdir(fullPath);
107
+ const entries = yield node_fs_1.promises.readdir(fullPath);
107
108
  // Look for a valid pack
108
109
  for (const modid of entries) {
109
110
  const excludedModLanguage = excludedModLanguages.includes(modid);
110
- const modPath = (0, path_1.join)(fullPath, modid);
111
- if ((yield fs_1.promises.stat(modPath)).isDirectory()) {
111
+ const modPath = (0, node_path_1.join)(fullPath, modid);
112
+ if ((yield node_fs_1.promises.stat(modPath)).isDirectory()) {
112
113
  yield this.loadAssets(modid, modPath, excludedModLanguage);
113
114
  }
114
115
  }
@@ -125,23 +126,23 @@ class ResourceLoader {
125
126
  // Set base path
126
127
  this.resourceHandler.setResourcePackBasePath(modid, fullPath);
127
128
  // Handle languages
128
- const langDir = (0, path_1.join)(fullPath, 'lang');
129
+ const langDir = (0, node_path_1.join)(fullPath, 'lang');
129
130
  try {
130
- if ((yield fs_1.promises.stat(langDir)).isDirectory()) {
131
+ if ((yield node_fs_1.promises.stat(langDir)).isDirectory()) {
131
132
  yield this.loadAssetsLang(modid, langDir, excludedModLanguage);
132
133
  }
133
134
  }
134
- catch (e) {
135
+ catch (_a) {
135
136
  // Ignore mods without language files
136
137
  }
137
138
  // Handle advancements
138
- const advancementsDir = (0, path_1.join)(fullPath, 'advancement');
139
+ const advancementsDir = (0, node_path_1.join)(fullPath, 'advancement');
139
140
  try {
140
- if ((yield fs_1.promises.stat(langDir)).isDirectory()) {
141
+ if ((yield node_fs_1.promises.stat(langDir)).isDirectory()) {
141
142
  yield this.loadAssetsAdvancements(modid, advancementsDir, '');
142
143
  }
143
144
  }
144
- catch (e) {
145
+ catch (_b) {
145
146
  // Ignore mods without advancements
146
147
  }
147
148
  });
@@ -154,10 +155,10 @@ class ResourceLoader {
154
155
  */
155
156
  loadAssetsLang(modid, langDir, excludedModLanguage) {
156
157
  return __awaiter(this, void 0, void 0, function* () {
157
- const entries = yield fs_1.promises.readdir(langDir);
158
+ const entries = yield node_fs_1.promises.readdir(langDir);
158
159
  for (const entry of entries) {
159
- const language = entry.substring(0, entry.indexOf('.'));
160
- yield this.loadAssetsLangFile(modid, language, (0, path_1.join)(langDir, entry), excludedModLanguage);
160
+ const language = entry.slice(0, Math.max(0, entry.indexOf('.')));
161
+ yield this.loadAssetsLangFile(modid, language, (0, node_path_1.join)(langDir, entry), excludedModLanguage);
161
162
  }
162
163
  });
163
164
  }
@@ -170,7 +171,7 @@ class ResourceLoader {
170
171
  */
171
172
  loadAssetsLangFile(modid, language, fullFilePath, excludedModLanguage) {
172
173
  return __awaiter(this, void 0, void 0, function* () {
173
- const translations = JSON.parse((yield fs_1.promises.readFile(fullFilePath)).toString('utf8'));
174
+ const translations = JSON.parse((yield node_fs_1.promises.readFile(fullFilePath)).toString('utf8'));
174
175
  this.resourceHandler.addTranslations(language, translations, excludedModLanguage);
175
176
  });
176
177
  }
@@ -182,11 +183,11 @@ class ResourceLoader {
182
183
  */
183
184
  loadAssetsAdvancements(modid, advancementsDir, idPrefix) {
184
185
  return __awaiter(this, void 0, void 0, function* () {
185
- const entries = yield fs_1.promises.readdir(advancementsDir);
186
+ const entries = yield node_fs_1.promises.readdir(advancementsDir);
186
187
  for (const entry of entries) {
187
- const entryFullPath = (0, path_1.join)(advancementsDir, entry);
188
- const entryId = idPrefix + '/' + entry;
189
- if ((yield fs_1.promises.stat(entryFullPath)).isDirectory()) {
188
+ const entryFullPath = (0, node_path_1.join)(advancementsDir, entry);
189
+ const entryId = `${idPrefix}/${entry}`;
190
+ if ((yield node_fs_1.promises.stat(entryFullPath)).isDirectory()) {
190
191
  yield this.loadAssetsAdvancements(modid, entryFullPath, entryId);
191
192
  }
192
193
  else {
@@ -203,13 +204,14 @@ class ResourceLoader {
203
204
  */
204
205
  loadAssetsAdvancement(modid, advancementsFile, id) {
205
206
  return __awaiter(this, void 0, void 0, function* () {
206
- const contents = JSON.parse((yield fs_1.promises.readFile(advancementsFile)).toString('utf8'));
207
+ const contentsData = (yield node_fs_1.promises.readFile(advancementsFile)).toString('utf8');
208
+ const contents = JSON.parse(contentsData);
207
209
  const itemIcon = contents.display.icon;
208
210
  const title = contents.display.title.translate;
209
211
  const description = contents.display.description.translate;
210
212
  // Remove first slash and '.json' suffix.
211
- id = id.substr(1, id.length - 6);
212
- this.resourceHandler.addAdvancement({ itemIcon, title, description }, modid + ':' + id);
213
+ id = id.slice(1, 1 + id.length - 6);
214
+ this.resourceHandler.addAdvancement({ itemIcon, title, description }, `${modid}:${id}`);
213
215
  });
214
216
  }
215
217
  /**
@@ -1,10 +1,10 @@
1
- import { compileTemplate } from "pug";
2
- import { IFileWriter } from "../infobook/IFileWriter";
3
- import { IFluid } from "../infobook/IFluid";
4
- import { IInfoBook } from "../infobook/IInfoBook";
5
- import { IInfoSection } from "../infobook/IInfoSection";
6
- import { IItem } from "../infobook/IItem";
7
- import { ResourceHandler } from "../resource/ResourceHandler";
1
+ import type { compileTemplate } from 'pug';
2
+ import type { IFileWriter } from '../infobook/IFileWriter';
3
+ import type { IFluid } from '../infobook/IFluid';
4
+ import type { IInfoBook } from '../infobook/IInfoBook';
5
+ import type { IInfoSection } from '../infobook/IInfoSection';
6
+ import type { IItem } from '../infobook/IItem';
7
+ import type { ResourceHandler } from '../resource/ResourceHandler';
8
8
  /**
9
9
  * Serializes an infobook to a collection of HTML files.
10
10
  */
@@ -53,9 +53,7 @@ export interface ISerializeContext {
53
53
  path: string;
54
54
  modId: string;
55
55
  resourceHandler: ResourceHandler;
56
- colors: {
57
- [key: string]: string;
58
- };
56
+ colors: Record<string, string>;
59
57
  headSuffixGetters: ((context: ISerializeContext) => string)[];
60
58
  sectionIndex?: ISectionIndex;
61
59
  root: boolean;
@@ -98,13 +96,9 @@ export interface ISectionIndex {
98
96
  /**
99
97
  * Mapping from url to page index within linkedPagesList.
100
98
  */
101
- urlIndex: {
102
- [url: string]: number;
103
- };
99
+ urlIndex: Record<string, number>;
104
100
  /**
105
101
  * Mapping from tag to page URL.
106
102
  */
107
- tags: {
108
- [tag: string]: string;
109
- };
103
+ tags: Record<string, string>;
110
104
  }