CurseForgePublisher makes use of relations now

I hope so...
This commit is contained in:
Kir_Antipov 2021-12-08 16:44:57 +03:00
parent 5e7fd885b0
commit 6e417e8ee2

View file

@ -2,13 +2,23 @@ import { File } from "../../utils/file";
import ModPublisher from "../mod-publisher";
import PublisherTarget from "../publisher-target";
import { convertToCurseForgeVersions, uploadFile } from "../../utils/curseforge-utils";
import Dependency from "../../metadata/dependency";
import DependencyKind from "../../metadata/dependency-kind";
const forgeDependencyKinds = new Map([
[DependencyKind.Depends, "requiredDependency"],
[DependencyKind.Recommends, "optionalDependency"],
[DependencyKind.Suggests, "optionalDependency"],
[DependencyKind.Includes, "embeddedLibrary"],
[DependencyKind.Breaks, "incompatible"],
]);
export default class CurseForgePublisher extends ModPublisher {
public get target(): PublisherTarget {
return PublisherTarget.CurseForge;
}
protected async publishMod(id: string, token: string, name: string, _version: string, channel: string, loaders: string[], gameVersions: string[], java: string[], changelog: string, files: File[]): Promise<void> {
protected async publishMod(id: string, token: string, name: string, _version: string, channel: string, loaders: string[], gameVersions: string[], java: string[], changelog: string, files: File[], dependencies: Dependency[]): Promise<void> {
let parentFileId = undefined;
const versions = await convertToCurseForgeVersions(gameVersions, loaders, java, token);
@ -19,7 +29,16 @@ export default class CurseForgePublisher extends ModPublisher {
displayName: (parentFileId || !name) ? file.name : name,
parentFileID: parentFileId,
releaseType: channel,
gameVersions: parentFileId ? undefined : versions
gameVersions: parentFileId ? undefined : versions,
relations: parentFileId ? undefined : {
projects: dependencies
.filter((x, _, self) => x.kind !== DependencyKind.Suggests || !self.find(y => y.id === x.id && y.kind !== DependencyKind.Suggests))
.map(x => ({
slug: x.getProjectSlug(this.target),
type: forgeDependencyKinds.get(x.kind)
}))
.filter(x => x.slug && x.type)
}
};
const fileId = await uploadFile(id, data, file, token);