import { src, dest, series } from "gulp"; import { clientDestDirectory, modpackManifest, sharedDestDirectory, } from "#globals"; import fs from "fs"; import upath from "upath"; import buildConfig from "#buildConfig"; import { deleteAsync } from "del"; import { createModList, ModFileInfo } from "../misc/createModList.ts"; import dedent from "dedent-js"; import { cleanupVersion } from "#utils/util.ts"; async function clientCleanUp() { return deleteAsync(upath.join(clientDestDirectory, "*"), { force: true }); } /** * Checks and creates all necessary directories so we can build the client safely. */ async function createClientDirs() { if (!fs.existsSync(clientDestDirectory)) { return fs.promises.mkdir(clientDestDirectory, { recursive: true }); } } /** * Exports the modpack manifest. */ async function exportModpackManifest() { const manifestPath = upath.join(clientDestDirectory, "manifest.json"); // Filter client side files only and prune build-specific fields. const newFiles = modpackManifest.files .map((file) => { if (file.sides) { if (!file.sides.includes("client")) return; const newFile = Object.assign({}, file); delete newFile.sides; return newFile; } return file; }) .filter(Boolean); return fs.promises.writeFile( manifestPath, JSON.stringify( { ...modpackManifest, files: newFiles, }, null, " ", ), ); } /** * Copies the license file. */ async function copyClientLicense() { return src("../LICENSE").pipe(dest(clientDestDirectory)); } /** * Copies the update notes file. */ function copyClientUpdateNotes() { return src("../UPDATENOTES.md", { allowEmpty: true }).pipe( dest(clientDestDirectory), ); } /** * Copies the changelog file. */ function copyClientChangelog() { return src( upath.join(buildConfig.buildDestinationDirectory, "CHANGELOG.md"), ).pipe(dest(clientDestDirectory)); } /** * Copies modpack overrides. */ function copyClientOverrides() { return src(buildConfig.copyFromSharedClientGlobs, { cwd: sharedDestDirectory, allowEmpty: true, resolveSymlinks: true, encoding: false, }).pipe(dest(upath.join(clientDestDirectory, "overrides"))); } /** * Fetches mod links and builds modlist.html. */ async function fetchModList() { const modList = await createModList(); const formattedModList = dedent`
Mod Name | Mod Version | Client? | Server? | Author(s) |
---|