[EXPAND] [[messages]] messageTitle = "QB Update for GT 2.8 (#681)" messageBody = """ [QB] [DETAILS] details = ["Fixes many Quest Book issues", "Updates QB with changes in GT 2.8"] [DETAILS] """ [[messages]] messageTitle = "Buildscript Refactor (#681)" messageBody = """ [INTERNAL] [DETAILS] details = ["**Important: Buildscript has changed from `npx gulp...` or `gulp...` to `npm run gulp...`**!", "Moves to Node 16 Package Management + Typescript Strict Mode", "New Port QB, Check QB and Fix QB Tasks"] [DETAILS] """ [EXPAND] Co-authored-by: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Co-authored-by: Ghzdude <44148655+ghzdude@users.noreply.github.com> Co-authored-by: SparkedTheorem <162088357+SparkedTheorem@users.noreply.github.com>
176 lines
4.5 KiB
TypeScript
176 lines
4.5 KiB
TypeScript
import fs from "fs";
|
|
import gulp, { dest, src } from "gulp";
|
|
import upath from "upath";
|
|
import buildConfig from "#buildConfig";
|
|
import {
|
|
modDestDirectory,
|
|
modpackManifest,
|
|
overridesFolder,
|
|
rootDirectory,
|
|
sharedDestDirectory,
|
|
tempDirectory,
|
|
} from "#globals";
|
|
import { deleteAsync } from "del";
|
|
import { FileDef } from "#types/fileDef.ts";
|
|
import {
|
|
downloadFileDef,
|
|
downloadOrRetrieveFileDef,
|
|
isEnvVariableSet,
|
|
} from "#utils/util.ts";
|
|
import transformVersion from "./transformVersion.ts";
|
|
import { createBuildChangelog } from "../changelog/index.ts";
|
|
import mustache from "mustache";
|
|
import { updateBuildRandomPatches } from "../misc/transformFiles.ts";
|
|
import { transformQuestBook } from "./quest.ts";
|
|
import logInfo from "#utils/log.ts";
|
|
|
|
async function sharedCleanUp() {
|
|
await deleteAsync(upath.join(sharedDestDirectory, "*"), { force: true });
|
|
await deleteAsync(upath.join(tempDirectory, "*"), { force: true });
|
|
}
|
|
|
|
/**
|
|
* Checks and creates all necessary directories so we can build everything safely.
|
|
*/
|
|
async function createSharedDirs() {
|
|
if (!fs.existsSync(sharedDestDirectory)) {
|
|
await fs.promises.mkdir(sharedDestDirectory, { recursive: true });
|
|
}
|
|
|
|
if (!fs.existsSync(tempDirectory)) {
|
|
await fs.promises.mkdir(tempDirectory, { recursive: true });
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Copies modpack overrides.
|
|
*/
|
|
async function copyOverrides() {
|
|
// Don't copy server.properties files in config-overrides, it is auto transformed into the server build folder
|
|
// Copy, not Symlink, so we can transform the files as we wish
|
|
return new Promise((resolve) => {
|
|
src(buildConfig.copyToSharedDirGlobs, { cwd: upath.join(rootDirectory) })
|
|
.pipe(dest(upath.join(sharedDestDirectory, overridesFolder)))
|
|
.on("end", resolve);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Fetch external dependencies and remove the field from the manifest file.
|
|
*/
|
|
async function fetchExternalDependencies() {
|
|
const dependencies = modpackManifest.externalDependencies;
|
|
if (dependencies) {
|
|
const destDirectory = upath.join(modDestDirectory, "mods");
|
|
|
|
if (!fs.existsSync(destDirectory)) {
|
|
await fs.promises.mkdir(destDirectory, { recursive: true });
|
|
}
|
|
|
|
// Map dependencies to FileDefs.
|
|
const depDefs: FileDef[] = dependencies.map((dep) => {
|
|
return {
|
|
url: dep.url,
|
|
hashes: [
|
|
{
|
|
hashes: [dep.sha],
|
|
id: "sha1",
|
|
},
|
|
],
|
|
};
|
|
});
|
|
|
|
delete modpackManifest.externalDependencies;
|
|
|
|
await Promise.all(
|
|
depDefs.map(async (depDef) => {
|
|
const dest = upath.join(destDirectory, upath.basename(depDef.url));
|
|
const cachePath = (await downloadOrRetrieveFileDef(depDef)).cachePath;
|
|
|
|
return fs.promises.symlink(upath.resolve(dest, cachePath), dest);
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Either fetches the Changelog File, or makes one.
|
|
*/
|
|
async function fetchOrMakeChangelog() {
|
|
if (
|
|
isEnvVariableSet("CHANGELOG_URL") &&
|
|
isEnvVariableSet("CHANGELOG_CF_URL")
|
|
) {
|
|
logInfo("Using Changelog Files from URL.");
|
|
await downloadChangelogs(
|
|
process.env.CHANGELOG_URL ?? "",
|
|
process.env.CHANGELOG_CF_URL ?? "",
|
|
);
|
|
return;
|
|
}
|
|
if (isEnvVariableSet("CHANGELOG_BRANCH")) {
|
|
logInfo("Using Changelog Files from Branch.");
|
|
const url =
|
|
"https://raw.githubusercontent.com/Nomi-CEu/Nomi-CEu/{{ branch }}/{{ filename }}";
|
|
await downloadChangelogs(
|
|
mustache.render(url, {
|
|
branch: process.env.CHANGELOG_BRANCH,
|
|
filename: "CHANGELOG.md",
|
|
}),
|
|
mustache.render(url, {
|
|
branch: process.env.CHANGELOG_BRNACH,
|
|
filename: "CHANGELOG_CF.md",
|
|
}),
|
|
);
|
|
return;
|
|
}
|
|
logInfo("Creating Changelog Files.");
|
|
await createBuildChangelog();
|
|
}
|
|
|
|
async function downloadChangelogs(
|
|
changelogURL: string,
|
|
changelogCFURL: string,
|
|
) {
|
|
const changelog = await downloadFileDef({ url: changelogURL });
|
|
const changelogCF = await downloadFileDef({ url: changelogCFURL });
|
|
|
|
await writeToChangelog(changelog, "CHANGELOG.md", changelogURL);
|
|
await writeToChangelog(changelogCF, "CHANGELOG_CF.md", changelogCFURL);
|
|
}
|
|
|
|
async function writeToChangelog(
|
|
buffer: Buffer,
|
|
changelogFile: string,
|
|
url: string,
|
|
) {
|
|
let handle: fs.promises.FileHandle | undefined = undefined;
|
|
try {
|
|
handle = await fs.promises.open(
|
|
upath.join(buildConfig.buildDestinationDirectory, changelogFile),
|
|
"w",
|
|
);
|
|
|
|
await handle.write(buffer);
|
|
await handle.close();
|
|
} catch (err) {
|
|
if (handle && (await handle.stat()).isFile()) {
|
|
logInfo(`Couldn't download changelog from URL ${url}, cleaning up...`);
|
|
|
|
await handle.close();
|
|
}
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
export default gulp.series(
|
|
sharedCleanUp,
|
|
createSharedDirs,
|
|
copyOverrides,
|
|
fetchOrMakeChangelog,
|
|
fetchExternalDependencies,
|
|
updateBuildRandomPatches,
|
|
transformVersion,
|
|
transformQuestBook,
|
|
);
|