mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2025-01-04 04:44:50 -05:00
Implemented ModMetadata for Forge
This commit is contained in:
parent
05a29057ca
commit
ddc460484e
1 changed files with 41 additions and 0 deletions
41
src/metadata/forge/forge-mod-metadata.ts
Normal file
41
src/metadata/forge/forge-mod-metadata.ts
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import ModConfig from "../../metadata/mod-config";
|
||||||
|
import ModConfigDependency from "../../metadata/mod-config-dependency";
|
||||||
|
import Dependency from "../../metadata/dependency";
|
||||||
|
import DependencyKind from "../../metadata/dependency-kind";
|
||||||
|
|
||||||
|
function createDependency(body: any): Dependency {
|
||||||
|
return new ModConfigDependency({
|
||||||
|
...body,
|
||||||
|
id: body.modId,
|
||||||
|
version: body.versionRange,
|
||||||
|
kind: body.incompatible && DependencyKind.Breaks || body.embedded && DependencyKind.Includes || body.mandatory && DependencyKind.Depends || DependencyKind.Recommends
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class ForgeModMetadata extends ModConfig {
|
||||||
|
public readonly id: string;
|
||||||
|
public readonly name: string;
|
||||||
|
public readonly version: string;
|
||||||
|
public readonly loaders: string[];
|
||||||
|
public readonly dependencies: Dependency[];
|
||||||
|
|
||||||
|
constructor(config: Record<string, unknown>) {
|
||||||
|
super(config);
|
||||||
|
const mods = Array.isArray(this.config.mods) && <any[]>this.config.mods || [];
|
||||||
|
const mod = mods[0];
|
||||||
|
if (!mod) {
|
||||||
|
throw new Error("At least one mod should be specified");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.id = mod.modId;
|
||||||
|
this.name = mod.displayName || this.id;
|
||||||
|
this.version = mod.version || "*";
|
||||||
|
this.loaders = ["forge"];
|
||||||
|
this.dependencies = Object
|
||||||
|
.values(this.config.dependencies || {})
|
||||||
|
.filter(Array.isArray)
|
||||||
|
.flatMap(x => x)
|
||||||
|
.map(createDependency)
|
||||||
|
.filter((x, i, self) => self.findIndex(y => x.id === y.id && x.kind === y.kind) === i);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue