modded7/tools/tasks/mmc/index.ts
IntegerLimit 5aecff8b4d
Allow for QB Translations of Normal and Expert Quest Books (#432)
[FEATURE]

/* Description: */
Also moves all nodejs stuff into `tools` package.

Also adds a basic `CONTRIBUTING.md` file. 

Superseeds https://github.com/Nomi-CEu/Nomi-CEu/pull/431, which was closed as the branch needed to be renamed, due to the last two items on this list.

TODO:
- [x] Make it only run on master repo.
- [x] Remove qb-lang-revamp branch from the events
- [x] Allow workflow to run on all branches starting with test_buildscript?

/* Commits: */

* Buildscript Changes

* Make Contributing Docs a .md file

* updateqb.yml v1

* Test QB change

* Add lang file to commit file list

* Another Test Change

* Test with only lang path, + `./` at beginning of path

* Test QB change

* updateqb.yml v3

* Test QB Change

* Add some debug settings

* Remove debug, branch input. Switch to auto-commit action

* Make activate: branches prefix `test_buildscript`, commit author GHA bot

* Add branch prefix note into CONTRIBUTING.md

* Make workflow only run if on master repo
2023-09-17 22:44:48 +10:00

119 lines
2.6 KiB
TypeScript

import { clientDestDirectory, mmcDestDirectory, modpackManifest } from "../../globals";
import { fetchMods } from "../../util/curseForgeAPI";
import * as upath from "upath";
import { series, src, symlink } from "gulp";
import * as fs from "fs";
async function mmcCleanUp(cb) {
if (fs.existsSync(mmcDestDirectory)) {
await fs.promises.rm(mmcDestDirectory, { recursive: true });
}
cb();
}
/**
* Checks and creates all necessary directories so we can build the client safely.
*/
async function createMMCDirs(cb) {
if (!fs.existsSync(mmcDestDirectory)) {
await fs.promises.mkdir(mmcDestDirectory, { recursive: true });
}
cb();
}
/**
* Copies modpack overrides.
*/
function copyOverrides() {
return src(upath.join(clientDestDirectory, "**/*"), {
nodir: true,
resolveSymlinks: false,
}).pipe(symlink(upath.join(mmcDestDirectory)));
}
/**
* Copies modpack overrides.
*/
async function renameOverrides() {
await fs.promises.rename(upath.join(mmcDestDirectory, "overrides"), upath.join(mmcDestDirectory, ".minecraft"));
return fs.promises.rm(upath.join(mmcDestDirectory, "manifest.json"));
}
/**
* Downloads client mods according to manifest.json and checks hashes.
*/
async function fetchModJars() {
return fetchMods(
modpackManifest.files.filter((f) => !f.sides || f.sides.includes("client")),
upath.join(mmcDestDirectory, ".minecraft"),
);
}
async function createMMCConfig() {
const cfg = {
InstanceType: "OneSix",
iconKey: "default",
name: modpackManifest.name,
};
return fs.promises.writeFile(
upath.join(mmcDestDirectory, "instance.cfg"),
Object.keys(cfg)
.map((key) => {
return `${key}=${cfg[key]}`;
})
.join("\n"),
);
}
async function createMMCManifest() {
const manifest = {
components: [],
formatVersion: 1,
};
manifest.components.push({
cachedName: "Minecraft",
cachedVersion: modpackManifest.minecraft.version,
important: true,
uid: "net.minecraft",
version: modpackManifest.minecraft.version,
});
const forgeLoader = modpackManifest.minecraft.modLoaders
.map((x) => x.id.match(/forge-(.+)/))
.filter(Boolean)
.shift();
if (forgeLoader) {
const ver = forgeLoader[1];
manifest.components.push({
cachedName: "Forge",
cachedRequires: [
{
equals: `${modpackManifest.minecraft.version}`,
uid: "net.minecraft",
},
],
cachedVersion: ver,
uid: "net.minecraftforge",
version: ver,
});
}
return fs.promises.writeFile(upath.join(mmcDestDirectory, "mmc-pack.json"), JSON.stringify(manifest, null, "\t"));
}
export default series(
mmcCleanUp,
createMMCDirs,
copyOverrides,
renameOverrides,
createMMCConfig,
createMMCManifest,
fetchModJars,
);