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` Nomi-CEu Mod Information ${formatModList(modList)}
Nomi-CEu Mod List (${modList.length} Mods):
Mod Name Mod Version Client? Server? Author(s)
`; return fs.promises.writeFile( upath.join(clientDestDirectory, "modlist.html"), formattedModList, ); } /** * Formats the mod list. */ function formatModList(modList: ModFileInfo[]): string { const output: string[] = []; modList.forEach((modFile) => { output.push(dedent` ${modFile.modInfo.name} v${cleanupVersion(modFile.fileInfo.displayName)} ${getTickCross(modFile.inClient)} ${getTickCross(modFile.inServer)} ${modFile.modInfo.authors.map((author) => `${author.name}`).join(", ")} `); }); return output.join("\n"); } /** * Gets the tick/cross used in the mod list. */ function getTickCross(bool: boolean): string { if (bool) { return '✔'; } return '✖'; } export default series( clientCleanUp, createClientDirs, copyClientOverrides, exportModpackManifest, copyClientLicense, copyClientOverrides, copyClientChangelog, copyClientUpdateNotes, fetchModList, );