cyclops-infobook-html 5.0.0 → 5.1.0
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 +23 -2
- package/bin/compress-icons.d.ts +2 -0
- package/bin/compress-icons.js +47 -0
- package/bin/generate-icons.d.ts +2 -0
- package/bin/generate-icons.js +68 -0
- package/bin/generate-infobook-html.js +15 -7
- package/bin/generate-mod-metadata.js +15 -7
- package/index.d.ts +2 -0
- package/index.js +39 -24
- package/lib/icon/IconsCompressor.d.ts +18 -0
- package/lib/icon/IconsCompressor.js +81 -0
- package/lib/icon/IconsGenerator.d.ts +128 -0
- package/lib/icon/IconsGenerator.js +597 -0
- package/lib/infobook/FileWriter.d.ts +0 -1
- package/lib/infobook/FileWriter.js +11 -3
- package/lib/infobook/IFileWriter.d.ts +0 -1
- package/lib/infobook/InfoBookInitializer.js +10 -2
- package/lib/infobook/appendix/InfoBookAppendixAd.js +11 -3
- package/lib/infobook/appendix/InfoBookAppendixHandlerAbstractRecipe.js +11 -3
- package/lib/infobook/appendix/InfoBookAppendixHandlerAdvancementRewards.js +11 -3
- package/lib/infobook/appendix/InfoBookAppendixHandlerCraftingRecipe.js +11 -3
- package/lib/infobook/appendix/InfoBookAppendixHandlerImage.js +12 -4
- package/lib/infobook/appendix/InfoBookAppendixHandlerKeybinding.js +11 -3
- package/lib/infobook/appendix/InfoBookAppendixHandlerSmeltingRecipe.js +11 -3
- package/lib/infobook/appendix/InfoBookAppendixHandlerTextfield.js +10 -2
- package/lib/infobook/appendix/InfoBookAppendixTagIndex.js +11 -3
- package/lib/modloader/ModLoader.d.ts +2 -3
- package/lib/modloader/ModLoader.js +56 -48
- package/lib/parse/XmlInfoBookParser.js +1 -1
- package/lib/resource/ResourceHandler.js +1 -1
- package/lib/resource/ResourceLoader.js +28 -20
- package/lib/serialize/HtmlInfoBookSerializer.js +39 -31
- package/package.json +10 -6
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.InfoBookAppendixAd = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
13
|
const pug_1 = require("pug");
|
|
6
14
|
/**
|
|
7
15
|
* An appendix with an add
|
|
@@ -9,10 +17,10 @@ const pug_1 = require("pug");
|
|
|
9
17
|
class InfoBookAppendixAd {
|
|
10
18
|
constructor() {
|
|
11
19
|
this.skipWrapper = true;
|
|
12
|
-
this.templateTagIndex = pug_1.compileFile(__dirname + '/../../../template/appendix/ad.pug');
|
|
20
|
+
this.templateTagIndex = (0, pug_1.compileFile)(__dirname + '/../../../template/appendix/ad.pug');
|
|
13
21
|
}
|
|
14
22
|
toHtml(context, fileWriter, serializer) {
|
|
15
|
-
return
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
24
|
return this.templateTagIndex(context.googleAdsense);
|
|
17
25
|
});
|
|
18
26
|
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.InfoBookAppendixHandlerAbstractRecipe = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
13
|
const fs = require("fs");
|
|
6
14
|
const path_1 = require("path");
|
|
7
15
|
/**
|
|
@@ -11,7 +19,7 @@ class InfoBookAppendixHandlerAbstractRecipe {
|
|
|
11
19
|
constructor(id, resourceHandler, registriesPath, recipeOverrides) {
|
|
12
20
|
this.id = id;
|
|
13
21
|
this.resourceHandler = resourceHandler;
|
|
14
|
-
this.registry = InfoBookAppendixHandlerAbstractRecipe.indexRegistry(JSON.parse(fs.readFileSync(path_1.join(registriesPath, id.replace(/:/g, '__') + '.json'), "utf8")));
|
|
22
|
+
this.registry = InfoBookAppendixHandlerAbstractRecipe.indexRegistry(JSON.parse(fs.readFileSync((0, path_1.join)(registriesPath, id.replace(/:/g, '__') + '.json'), "utf8")));
|
|
15
23
|
if (recipeOverrides) {
|
|
16
24
|
this.registry = Object.assign(Object.assign({}, this.registry), (recipeOverrides[id] || {}));
|
|
17
25
|
}
|
|
@@ -42,7 +50,7 @@ class InfoBookAppendixHandlerAbstractRecipe {
|
|
|
42
50
|
}
|
|
43
51
|
return {
|
|
44
52
|
getName: (context) => this.resourceHandler.getTranslation(this.getRecipeNameUnlocalized(), context.language),
|
|
45
|
-
toHtml: (context, fileWriter, serializer) =>
|
|
53
|
+
toHtml: (context, fileWriter, serializer) => __awaiter(this, void 0, void 0, function* () {
|
|
46
54
|
return (yield Promise.all(recipes.map((recipe) => this.serializeRecipe(recipe, context, fileWriter, serializer)))).join('<hr />');
|
|
47
55
|
}),
|
|
48
56
|
};
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.InfoBookAppendixHandlerAdvancementRewards = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
13
|
const pug_1 = require("pug");
|
|
6
14
|
/**
|
|
7
15
|
* Handles advancement rewards appendices.
|
|
@@ -9,7 +17,7 @@ const pug_1 = require("pug");
|
|
|
9
17
|
class InfoBookAppendixHandlerAdvancementRewards {
|
|
10
18
|
constructor(resourceHandler) {
|
|
11
19
|
this.resourceHandler = resourceHandler;
|
|
12
|
-
this.templateAdvancementRewards = pug_1.compileFile(__dirname + '/../../../template/appendix/advancement_rewards.pug');
|
|
20
|
+
this.templateAdvancementRewards = (0, pug_1.compileFile)(__dirname + '/../../../template/appendix/advancement_rewards.pug');
|
|
13
21
|
}
|
|
14
22
|
createAppendix(data) {
|
|
15
23
|
const advancementsData = [];
|
|
@@ -27,7 +35,7 @@ class InfoBookAppendixHandlerAdvancementRewards {
|
|
|
27
35
|
}
|
|
28
36
|
return {
|
|
29
37
|
getName: (context) => this.resourceHandler.getTranslation('gui.advancements', context.language),
|
|
30
|
-
toHtml: (context, fileWriter, serializer) =>
|
|
38
|
+
toHtml: (context, fileWriter, serializer) => __awaiter(this, void 0, void 0, function* () {
|
|
31
39
|
const advancements = advancementsData
|
|
32
40
|
.map((advancement) => ({
|
|
33
41
|
description: this.resourceHandler.getTranslation(advancement.description, context.language),
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.InfoBookAppendixHandlerCraftingRecipe = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
13
|
const pug_1 = require("pug");
|
|
6
14
|
const InfoBookAppendixHandlerAbstractRecipe_1 = require("./InfoBookAppendixHandlerAbstractRecipe");
|
|
7
15
|
/**
|
|
@@ -10,13 +18,13 @@ const InfoBookAppendixHandlerAbstractRecipe_1 = require("./InfoBookAppendixHandl
|
|
|
10
18
|
class InfoBookAppendixHandlerCraftingRecipe extends InfoBookAppendixHandlerAbstractRecipe_1.InfoBookAppendixHandlerAbstractRecipe {
|
|
11
19
|
constructor(resourceHandler, registriesPath, recipeOverrides) {
|
|
12
20
|
super('minecraft:crafting', resourceHandler, registriesPath, recipeOverrides);
|
|
13
|
-
this.templateCraftingRecipe = pug_1.compileFile(__dirname + '/../../../template/appendix/crafting_recipe.pug');
|
|
21
|
+
this.templateCraftingRecipe = (0, pug_1.compileFile)(__dirname + '/../../../template/appendix/crafting_recipe.pug');
|
|
14
22
|
}
|
|
15
23
|
getRecipeNameUnlocalized() {
|
|
16
24
|
return 'block.minecraft.crafting_table';
|
|
17
25
|
}
|
|
18
26
|
serializeRecipe(recipe, context, fileWriter, serializer) {
|
|
19
|
-
return
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
28
|
// Prepare input array
|
|
21
29
|
const inputs = "|".repeat(9).split("|").map(() => []);
|
|
22
30
|
// Define custom dimensions for shapeless recipes
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.InfoBookAppendixHandlerImage = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
13
|
const fs_1 = require("fs");
|
|
6
14
|
const path_1 = require("path");
|
|
7
15
|
/**
|
|
@@ -13,11 +21,11 @@ class InfoBookAppendixHandlerImage {
|
|
|
13
21
|
}
|
|
14
22
|
createAppendix(data) {
|
|
15
23
|
const fullPath = this.resourceHandler.expandResourcePath(data._);
|
|
16
|
-
const fileName = path_1.basename(data._);
|
|
24
|
+
const fileName = (0, path_1.basename)(data._);
|
|
17
25
|
const { width, height } = data.$;
|
|
18
26
|
return {
|
|
19
|
-
toHtml: (context, fileWriter) =>
|
|
20
|
-
const writtenPath = yield fileWriter.write(fileName, () => fs_1.createReadStream(fullPath));
|
|
27
|
+
toHtml: (context, fileWriter) => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const writtenPath = yield fileWriter.write(fileName, () => (0, fs_1.createReadStream)(fullPath));
|
|
21
29
|
return `<canvas class="appendix-image" style="background: url(${writtenPath}); width: ${width * 2}px; height: ${height * 2}px; background-size: 512px 512px;"></canvas>`;
|
|
22
30
|
}),
|
|
23
31
|
};
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.InfoBookAppendixHandlerKeybinding = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
13
|
const pug_1 = require("pug");
|
|
6
14
|
/**
|
|
7
15
|
* Handles keybindings appendices.
|
|
@@ -9,14 +17,14 @@ const pug_1 = require("pug");
|
|
|
9
17
|
class InfoBookAppendixHandlerKeybinding {
|
|
10
18
|
constructor(resourceHandler) {
|
|
11
19
|
this.resourceHandler = resourceHandler;
|
|
12
|
-
this.templateKeybinding = pug_1.compileFile(__dirname + '/../../../template/appendix/keybinding.pug');
|
|
20
|
+
this.templateKeybinding = (0, pug_1.compileFile)(__dirname + '/../../../template/appendix/keybinding.pug');
|
|
13
21
|
}
|
|
14
22
|
createAppendix(data) {
|
|
15
23
|
const id = data._;
|
|
16
24
|
const key = this.resourceHandler.getKeybinding(id);
|
|
17
25
|
return {
|
|
18
26
|
getName: (context) => this.resourceHandler.getTranslation(`infobook.cyclopscore.keybinding`, context.language),
|
|
19
|
-
toHtml: (context) =>
|
|
27
|
+
toHtml: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
20
28
|
const name = this.resourceHandler.getTranslation(id, context.language);
|
|
21
29
|
return this.templateKeybinding({ name, key });
|
|
22
30
|
}),
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.InfoBookAppendixHandlerSmeltingRecipe = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
13
|
const pug_1 = require("pug");
|
|
6
14
|
const InfoBookAppendixHandlerAbstractRecipe_1 = require("./InfoBookAppendixHandlerAbstractRecipe");
|
|
7
15
|
/**
|
|
@@ -10,13 +18,13 @@ const InfoBookAppendixHandlerAbstractRecipe_1 = require("./InfoBookAppendixHandl
|
|
|
10
18
|
class InfoBookAppendixHandlerSmeltingRecipe extends InfoBookAppendixHandlerAbstractRecipe_1.InfoBookAppendixHandlerAbstractRecipe {
|
|
11
19
|
constructor(resourceHandler, registriesPath, recipeOverrides) {
|
|
12
20
|
super('minecraft:smelting', resourceHandler, registriesPath, recipeOverrides);
|
|
13
|
-
this.templateFurnaceRecipe = pug_1.compileFile(__dirname + '/../../../template/appendix/furnace_recipe.pug');
|
|
21
|
+
this.templateFurnaceRecipe = (0, pug_1.compileFile)(__dirname + '/../../../template/appendix/furnace_recipe.pug');
|
|
14
22
|
}
|
|
15
23
|
getRecipeNameUnlocalized() {
|
|
16
24
|
return 'block.minecraft.furnace';
|
|
17
25
|
}
|
|
18
26
|
serializeRecipe(recipe, context, fileWriter, serializer) {
|
|
19
|
-
return
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
28
|
const input = yield Promise.all(recipe.input.map((item) => serializer.createItemDisplay(this.resourceHandler, context, fileWriter, item, true)));
|
|
21
29
|
const output = yield serializer.createItemDisplay(this.resourceHandler, context, fileWriter, recipe.output, true);
|
|
22
30
|
const appendixIcon = yield serializer.createItemDisplay(this.resourceHandler, context, fileWriter, { item: 'minecraft:furnace' }, false);
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.InfoBookAppendixHandlerTextfield = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
13
|
/**
|
|
6
14
|
* Handles text field appendices.
|
|
7
15
|
*/
|
|
@@ -15,7 +23,7 @@ class InfoBookAppendixHandlerTextfield {
|
|
|
15
23
|
.replace(/\n/g, '<br \>');
|
|
16
24
|
const scale = data.$.scale || 1;
|
|
17
25
|
return {
|
|
18
|
-
toHtml: (context, fileWriter) =>
|
|
26
|
+
toHtml: (context, fileWriter) => __awaiter(this, void 0, void 0, function* () {
|
|
19
27
|
return `<div class="appendix-textfield" style="font-size: ${scale}em">${contents}</div>`;
|
|
20
28
|
}),
|
|
21
29
|
};
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.InfoBookAppendixTagIndex = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
13
|
const pug_1 = require("pug");
|
|
6
14
|
/**
|
|
7
15
|
* An appendix that lists all tags with links to them
|
|
@@ -9,10 +17,10 @@ const pug_1 = require("pug");
|
|
|
9
17
|
class InfoBookAppendixTagIndex {
|
|
10
18
|
constructor(resourceHandler) {
|
|
11
19
|
this.resourceHandler = resourceHandler;
|
|
12
|
-
this.templateTagIndex = pug_1.compileFile(__dirname + '/../../../template/appendix/tag_index.pug');
|
|
20
|
+
this.templateTagIndex = (0, pug_1.compileFile)(__dirname + '/../../../template/appendix/tag_index.pug');
|
|
13
21
|
}
|
|
14
22
|
toHtml(context, fileWriter, serializer) {
|
|
15
|
-
return
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
24
|
const links = [];
|
|
17
25
|
for (const tag in context.sectionIndex.tags) {
|
|
18
26
|
const url = context.sectionIndex.tags[tag];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { ChildProcess } from "child_process";
|
|
3
2
|
/**
|
|
4
3
|
* Takes care of installing Forge, installing mods, starting a Forge server, and fetching metadata.
|
|
@@ -79,12 +78,12 @@ export interface IModLoaderArgs {
|
|
|
79
78
|
loader: ILoader;
|
|
80
79
|
versionMinecraft: string;
|
|
81
80
|
}
|
|
82
|
-
export
|
|
81
|
+
export type ILoader = {
|
|
83
82
|
versionForge: string;
|
|
84
83
|
} | {
|
|
85
84
|
versionNeoForge: string;
|
|
86
85
|
};
|
|
87
|
-
export
|
|
86
|
+
export type IMod = IModMaven | IModCurseforge | IModRaw;
|
|
88
87
|
export interface IModMaven {
|
|
89
88
|
type: 'maven';
|
|
90
89
|
artifact: string;
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.ModLoader = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
13
|
const child_process_1 = require("child_process");
|
|
6
14
|
const fs_1 = require("fs");
|
|
7
15
|
const fs = require("fs");
|
|
@@ -33,7 +41,7 @@ class ModLoader {
|
|
|
33
41
|
* Download and install Forge.
|
|
34
42
|
*/
|
|
35
43
|
installForge() {
|
|
36
|
-
return
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
45
|
if (!fs.existsSync(this.path)) {
|
|
38
46
|
yield fs.promises.mkdir(this.path);
|
|
39
47
|
}
|
|
@@ -42,33 +50,33 @@ class ModLoader {
|
|
|
42
50
|
// Download Forge installer
|
|
43
51
|
process.stdout.write('Downloading Forge...\n');
|
|
44
52
|
const forgeInstaller = `https://files.minecraftforge.net/maven/net/minecraftforge/forge/${this.versionMinecraft}-${this.loader.versionForge}/forge-${this.versionMinecraft}-${this.loader.versionForge}-installer.jar`;
|
|
45
|
-
const res = yield node_fetch_1.default(forgeInstaller);
|
|
53
|
+
const res = yield (0, node_fetch_1.default)(forgeInstaller);
|
|
46
54
|
if (!res.ok) {
|
|
47
55
|
throw new Error(`Failed to fetch (${res.statusText}): ${forgeInstaller}`);
|
|
48
56
|
}
|
|
49
|
-
installerFile = path_1.join(this.path, 'forge-installer.jar');
|
|
50
|
-
yield new Promise((resolve, reject) =>
|
|
57
|
+
installerFile = (0, path_1.join)(this.path, 'forge-installer.jar');
|
|
58
|
+
yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
51
59
|
return fs.writeFile(installerFile, yield res.buffer(), (err) => err ? reject(err) : resolve());
|
|
52
60
|
}));
|
|
53
61
|
// Install Forge
|
|
54
62
|
process.stdout.write('Installing Forge...\n');
|
|
55
|
-
yield new Promise((resolve, reject) => child_process_1.exec(`cd ${this.path} && java -jar forge-installer.jar --installServer`).on('exit', resolve));
|
|
63
|
+
yield new Promise((resolve, reject) => (0, child_process_1.exec)(`cd ${this.path} && java -jar forge-installer.jar --installServer`).on('exit', resolve));
|
|
56
64
|
}
|
|
57
65
|
else {
|
|
58
66
|
// Download NeoForge installer
|
|
59
67
|
process.stdout.write('Downloading NeoForge...\n');
|
|
60
68
|
const installer = `https://maven.neoforged.net/releases/net/neoforged/neoforge/${this.loader.versionNeoForge}/neoforge-${this.loader.versionNeoForge}-installer.jar`;
|
|
61
|
-
const res = yield node_fetch_1.default(installer);
|
|
69
|
+
const res = yield (0, node_fetch_1.default)(installer);
|
|
62
70
|
if (!res.ok) {
|
|
63
71
|
throw new Error(`Failed to fetch (${res.statusText}): ${installer}`);
|
|
64
72
|
}
|
|
65
|
-
installerFile = path_1.join(this.path, 'neoforge-installer.jar');
|
|
66
|
-
yield new Promise((resolve, reject) =>
|
|
73
|
+
installerFile = (0, path_1.join)(this.path, 'neoforge-installer.jar');
|
|
74
|
+
yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
67
75
|
return fs.writeFile(installerFile, yield res.buffer(), (err) => err ? reject(err) : resolve());
|
|
68
76
|
}));
|
|
69
77
|
// Install Forge
|
|
70
78
|
process.stdout.write('Installing NeoForge...\n');
|
|
71
|
-
yield new Promise((resolve, reject) => child_process_1.exec(`cd ${this.path} && java -jar neoforge-installer.jar --installServer`).on('exit', resolve));
|
|
79
|
+
yield new Promise((resolve, reject) => (0, child_process_1.exec)(`cd ${this.path} && java -jar neoforge-installer.jar --installServer`).on('exit', resolve));
|
|
72
80
|
}
|
|
73
81
|
// Wait a bit, because otherwise some files don't exist yet (while they should...)
|
|
74
82
|
process.stdout.write('Wait a bit after mod loader installation...\n');
|
|
@@ -83,24 +91,24 @@ class ModLoader {
|
|
|
83
91
|
* Accept the Minecraft EULA
|
|
84
92
|
*/
|
|
85
93
|
acceptEula() {
|
|
86
|
-
return
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
95
|
process.stdout.write('Accepting EULA...\n');
|
|
88
|
-
yield fs.promises.writeFile(path_1.join(this.path, 'eula.txt'), 'eula=true');
|
|
96
|
+
yield fs.promises.writeFile((0, path_1.join)(this.path, 'eula.txt'), 'eula=true');
|
|
89
97
|
});
|
|
90
98
|
}
|
|
91
99
|
/**
|
|
92
100
|
* @returns {boolean} If mods are installed.
|
|
93
101
|
*/
|
|
94
102
|
areModsInstalled() {
|
|
95
|
-
return fs.existsSync(path_1.join(this.path, 'mods'));
|
|
103
|
+
return fs.existsSync((0, path_1.join)(this.path, 'mods'));
|
|
96
104
|
}
|
|
97
105
|
/**
|
|
98
106
|
* Download and install mods.
|
|
99
107
|
*/
|
|
100
108
|
installMods() {
|
|
101
|
-
return
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
110
|
process.stdout.write('Downloading mods...\n');
|
|
103
|
-
const modsDir = path_1.join(this.path, 'mods');
|
|
111
|
+
const modsDir = (0, path_1.join)(this.path, 'mods');
|
|
104
112
|
if (!fs.existsSync(modsDir)) {
|
|
105
113
|
yield fs.promises.mkdir(modsDir);
|
|
106
114
|
}
|
|
@@ -114,10 +122,10 @@ class ModLoader {
|
|
|
114
122
|
}
|
|
115
123
|
else if (mod.type === 'maven') {
|
|
116
124
|
process.stdout.write(` - ${mod.artifact} from ${mod.repo}...\n`);
|
|
117
|
-
const name = yield mvn_artifact_download_1.default(mod.artifact, modsDir, mod.repo);
|
|
125
|
+
const name = yield (0, mvn_artifact_download_1.default)(mod.artifact, modsDir, mod.repo);
|
|
118
126
|
// Rename file if needed
|
|
119
127
|
if ('name' in mod) {
|
|
120
|
-
fs.renameSync(name, path_1.join(modsDir, mod.name));
|
|
128
|
+
fs.renameSync(name, (0, path_1.join)(modsDir, mod.name));
|
|
121
129
|
}
|
|
122
130
|
}
|
|
123
131
|
else if (mod.type === 'raw') {
|
|
@@ -131,8 +139,8 @@ class ModLoader {
|
|
|
131
139
|
});
|
|
132
140
|
}
|
|
133
141
|
downloadFile(url, fileName, modsDir) {
|
|
134
|
-
return
|
|
135
|
-
const response = yield node_fetch_1.default(url);
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
const response = yield (0, node_fetch_1.default)(url);
|
|
136
144
|
if (response.status !== 200) {
|
|
137
145
|
throw new Error(response.statusText + ' on ' + url);
|
|
138
146
|
}
|
|
@@ -140,7 +148,7 @@ class ModLoader {
|
|
|
140
148
|
response.body
|
|
141
149
|
.on('error', reject)
|
|
142
150
|
.on('end', resolve)
|
|
143
|
-
.pipe(fs.createWriteStream(path_1.join(modsDir, fileName)));
|
|
151
|
+
.pipe(fs.createWriteStream((0, path_1.join)(modsDir, fileName)));
|
|
144
152
|
});
|
|
145
153
|
});
|
|
146
154
|
}
|
|
@@ -148,10 +156,10 @@ class ModLoader {
|
|
|
148
156
|
* Start the server and execute a command to dump all registries
|
|
149
157
|
*/
|
|
150
158
|
startServer() {
|
|
151
|
-
return
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
160
|
// Start the Forge server
|
|
153
161
|
process.stdout.write('Starting server...\n');
|
|
154
|
-
const proc = child_process_1.exec(`cd ${this.path} && ./run.sh nogui`);
|
|
162
|
+
const proc = (0, child_process_1.exec)(`cd ${this.path} && ./run.sh nogui`);
|
|
155
163
|
// Ignore stdout: proc.stdout.pipe(process.stdout);
|
|
156
164
|
proc.stderr.pipe(process.stderr);
|
|
157
165
|
const onDone = new Promise((resolve, reject) => {
|
|
@@ -189,22 +197,22 @@ class ModLoader {
|
|
|
189
197
|
* @param {string} target A target path.
|
|
190
198
|
*/
|
|
191
199
|
copyRegistries(target) {
|
|
192
|
-
return
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
193
201
|
process.stdout.write('Copying registries...\n');
|
|
194
|
-
if (!fs.existsSync(path_1.join(this.path, 'cyclops_registries'))) {
|
|
195
|
-
yield fs.promises.mkdir(path_1.join(this.path, 'cyclops_registries'));
|
|
202
|
+
if (!fs.existsSync((0, path_1.join)(this.path, 'cyclops_registries'))) {
|
|
203
|
+
yield fs.promises.mkdir((0, path_1.join)(this.path, 'cyclops_registries'));
|
|
196
204
|
}
|
|
197
|
-
yield util_1.promisify(ncp_1.ncp)(path_1.join(this.path, 'cyclops_registries'), target);
|
|
205
|
+
yield (0, util_1.promisify)(ncp_1.ncp)((0, path_1.join)(this.path, 'cyclops_registries'), target);
|
|
198
206
|
});
|
|
199
207
|
}
|
|
200
208
|
/**
|
|
201
209
|
* Extract the Minecraft assets from the server jar
|
|
202
210
|
*/
|
|
203
211
|
extractMinecraftAssets() {
|
|
204
|
-
return
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
213
|
process.stdout.write('Extracting minecraft assets...\n');
|
|
206
|
-
if (!fs.existsSync(path_1.join(this.path, 'mc_assets'))) {
|
|
207
|
-
yield fs.promises.mkdir(path_1.join(this.path, 'mc_assets'));
|
|
214
|
+
if (!fs.existsSync((0, path_1.join)(this.path, 'mc_assets'))) {
|
|
215
|
+
yield fs.promises.mkdir((0, path_1.join)(this.path, 'mc_assets'));
|
|
208
216
|
}
|
|
209
217
|
// Find Minecraft jar
|
|
210
218
|
let jar = null;
|
|
@@ -213,7 +221,7 @@ class ModLoader {
|
|
|
213
221
|
if (dir.indexOf('-') > 0) {
|
|
214
222
|
for (const file of yield fs.promises.readdir(Path.join(subPath, dir))) {
|
|
215
223
|
if (file.startsWith('server') && file.endsWith('extra.jar')) {
|
|
216
|
-
jar = path_1.join(subPath, dir, file);
|
|
224
|
+
jar = (0, path_1.join)(subPath, dir, file);
|
|
217
225
|
}
|
|
218
226
|
}
|
|
219
227
|
}
|
|
@@ -231,16 +239,16 @@ class ModLoader {
|
|
|
231
239
|
* Extract assets from all mod jars
|
|
232
240
|
*/
|
|
233
241
|
extractModsAssets() {
|
|
234
|
-
return
|
|
242
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
235
243
|
process.stdout.write('Extracting mod assets...\n');
|
|
236
|
-
if (!fs.existsSync(path_1.join(this.path, 'mod_assets'))) {
|
|
237
|
-
yield fs.promises.mkdir(path_1.join(this.path, 'mod_assets'));
|
|
244
|
+
if (!fs.existsSync((0, path_1.join)(this.path, 'mod_assets'))) {
|
|
245
|
+
yield fs.promises.mkdir((0, path_1.join)(this.path, 'mod_assets'));
|
|
238
246
|
}
|
|
239
247
|
// Loop over all mods
|
|
240
|
-
const modsDir = path_1.join(this.path, 'mods');
|
|
248
|
+
const modsDir = (0, path_1.join)(this.path, 'mods');
|
|
241
249
|
for (const mod of yield fs.promises.readdir(modsDir)) {
|
|
242
250
|
if (mod.endsWith('.jar')) {
|
|
243
|
-
const modFile = path_1.join(modsDir, mod);
|
|
251
|
+
const modFile = (0, path_1.join)(modsDir, mod);
|
|
244
252
|
process.stdout.write(` - ${mod}...\n`);
|
|
245
253
|
yield this.extractModAssets(modFile);
|
|
246
254
|
}
|
|
@@ -252,9 +260,9 @@ class ModLoader {
|
|
|
252
260
|
* @param {string} modFile A mod file path.
|
|
253
261
|
*/
|
|
254
262
|
extractModAssets(modFile) {
|
|
255
|
-
return
|
|
263
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
256
264
|
const zipFile = yield new Promise((resolve, reject) => {
|
|
257
|
-
yauzl_1.open(modFile, { lazyEntries: true, autoClose: true }, (e, f) => {
|
|
265
|
+
(0, yauzl_1.open)(modFile, { lazyEntries: true, autoClose: true }, (e, f) => {
|
|
258
266
|
if (e) {
|
|
259
267
|
reject(e);
|
|
260
268
|
}
|
|
@@ -271,14 +279,14 @@ class ModLoader {
|
|
|
271
279
|
else {
|
|
272
280
|
// File
|
|
273
281
|
if (entry.fileName.startsWith('assets/') || entry.fileName.startsWith('data/')) {
|
|
274
|
-
const targetFile = path_1.join(this.path, 'mod_assets', entry.fileName.substring(entry.fileName.startsWith('assets/') ? 7 : 5, entry.fileName.length));
|
|
275
|
-
const targetDir = path_1.dirname(targetFile);
|
|
282
|
+
const targetFile = (0, path_1.join)(this.path, 'mod_assets', entry.fileName.substring(entry.fileName.startsWith('assets/') ? 7 : 5, entry.fileName.length));
|
|
283
|
+
const targetDir = (0, path_1.dirname)(targetFile);
|
|
276
284
|
this.ensureDirExists(targetDir).then(() => {
|
|
277
285
|
zipFile.openReadStream(entry, (e, readStream) => {
|
|
278
286
|
if (e) {
|
|
279
287
|
throw e;
|
|
280
288
|
}
|
|
281
|
-
readStream.pipe(fs_1.createWriteStream(targetFile));
|
|
289
|
+
readStream.pipe((0, fs_1.createWriteStream)(targetFile));
|
|
282
290
|
readStream.on('end', () => zipFile.readEntry());
|
|
283
291
|
});
|
|
284
292
|
});
|
|
@@ -296,32 +304,32 @@ class ModLoader {
|
|
|
296
304
|
* @param {string} target A target path.
|
|
297
305
|
*/
|
|
298
306
|
copyModAssets(target) {
|
|
299
|
-
return
|
|
307
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
300
308
|
process.stdout.write('Copying mod assets...\n');
|
|
301
|
-
yield util_1.promisify(ncp_1.ncp)(path_1.join(this.path, 'mod_assets'), target);
|
|
309
|
+
yield (0, util_1.promisify)(ncp_1.ncp)((0, path_1.join)(this.path, 'mod_assets'), target);
|
|
302
310
|
});
|
|
303
311
|
}
|
|
304
312
|
/**
|
|
305
313
|
* Remove the server files.
|
|
306
314
|
*/
|
|
307
315
|
removeServer() {
|
|
308
|
-
return
|
|
309
|
-
yield util_1.promisify(rimraf)(this.path);
|
|
316
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
+
yield (0, util_1.promisify)(rimraf)(this.path);
|
|
310
318
|
});
|
|
311
319
|
}
|
|
312
320
|
/**
|
|
313
321
|
* Remove the mod directory.
|
|
314
322
|
*/
|
|
315
323
|
removeMods() {
|
|
316
|
-
return
|
|
317
|
-
yield util_1.promisify(rimraf)(path_1.join(this.path, 'mods'));
|
|
324
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
325
|
+
yield (0, util_1.promisify)(rimraf)((0, path_1.join)(this.path, 'mods'));
|
|
318
326
|
});
|
|
319
327
|
}
|
|
320
328
|
ensureDirExists(path) {
|
|
321
|
-
return
|
|
329
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
322
330
|
const segments = path.substr(this.path.length, path.length).split(path_1.sep);
|
|
323
331
|
for (let i = 1; i <= segments.length; i++) {
|
|
324
|
-
const subPath = path_1.join(this.path, segments.slice(0, i).join(path_1.sep));
|
|
332
|
+
const subPath = (0, path_1.join)(this.path, segments.slice(0, i).join(path_1.sep));
|
|
325
333
|
try {
|
|
326
334
|
yield fs.promises.stat(subPath);
|
|
327
335
|
}
|
|
@@ -29,7 +29,7 @@ class XmlInfoBookParser {
|
|
|
29
29
|
*/
|
|
30
30
|
parse(path, modId) {
|
|
31
31
|
return new Promise((resolve, reject) => {
|
|
32
|
-
xml2js_1.parseString(fs.readFileSync(path), (error, data) => {
|
|
32
|
+
(0, xml2js_1.parseString)(fs.readFileSync(path), (error, data) => {
|
|
33
33
|
if (error) {
|
|
34
34
|
return reject(error);
|
|
35
35
|
}
|
|
@@ -138,7 +138,7 @@ class ResourceHandler {
|
|
|
138
138
|
throw new Error(`Failed to expand unknown resource pack id for resource path: ${resourceKey}`);
|
|
139
139
|
}
|
|
140
140
|
const suffix = resourceKey.substr(separator + 1);
|
|
141
|
-
return path_1.join(basePath, suffix);
|
|
141
|
+
return (0, path_1.join)(basePath, suffix);
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
144
|
* Add an item icon file.
|