Wrap MinecraftVersion in its own object.
This commit is contained in:
27
src/index.ts
27
src/index.ts
@@ -9,6 +9,7 @@ import { DistributionStructure } from './model/struct/model/distribution.struct'
|
||||
import { ServerStructure } from './model/struct/model/server.struct'
|
||||
import { VersionSegmentedRegistry } from './util/VersionSegmentedRegistry'
|
||||
import { VersionUtil } from './util/versionutil'
|
||||
import { MinecraftVersion } from './util/MinecraftVersion'
|
||||
|
||||
dotenv.config()
|
||||
|
||||
@@ -145,10 +146,12 @@ const generateServerCommand: yargs.CommandModule = {
|
||||
`\n\t├ Forge version: ${argv.forge}`,
|
||||
`\n\t└ LiteLoader version: ${argv.liteloader}`)
|
||||
|
||||
const minecraftVersion = new MinecraftVersion(argv.version as string)
|
||||
|
||||
if(argv.forge != null) {
|
||||
if (VersionUtil.isPromotionVersion(argv.forge as string)) {
|
||||
console.debug(`Resolving ${argv.forge} Forge Version..`)
|
||||
const version = await VersionUtil.getPromotedForgeVersion(argv.version as string, argv.forge as string)
|
||||
const version = await VersionUtil.getPromotedForgeVersion(minecraftVersion, argv.forge as string)
|
||||
console.debug(`Forge version set to ${version}`)
|
||||
argv.forge = version
|
||||
}
|
||||
@@ -157,7 +160,7 @@ const generateServerCommand: yargs.CommandModule = {
|
||||
const serverStruct = new ServerStructure(argv.root as string, getBaseURL())
|
||||
serverStruct.createServer(
|
||||
argv.id as string,
|
||||
argv.version as string,
|
||||
minecraftVersion,
|
||||
{
|
||||
forgeVersion: argv.forge as string,
|
||||
liteloaderVersion: argv.liteloader as string
|
||||
@@ -225,7 +228,8 @@ const latestForgeCommand: yargs.CommandModule = {
|
||||
handler: async (argv) => {
|
||||
console.debug(`Invoked latest-forge with version ${argv.version}.`)
|
||||
|
||||
const forgeVer = await VersionUtil.getPromotedForgeVersion(argv.version as string, 'latest')
|
||||
const minecraftVersion = new MinecraftVersion(argv.version as string)
|
||||
const forgeVer = await VersionUtil.getPromotedForgeVersion(minecraftVersion, 'latest')
|
||||
console.log(`Latest version: Forge ${forgeVer} (${argv.version})`)
|
||||
}
|
||||
}
|
||||
@@ -237,18 +241,18 @@ const recommendedForgeCommand: yargs.CommandModule = {
|
||||
console.debug(`Invoked recommended-forge with version ${argv.version}.`)
|
||||
|
||||
const index = await VersionUtil.getPromotionIndex()
|
||||
const mcVer = argv.version as string
|
||||
const minecraftVersion = new MinecraftVersion(argv.version as string)
|
||||
|
||||
let forgeVer = VersionUtil.getPromotedVersionStrict(index, mcVer, 'recommended')
|
||||
let forgeVer = VersionUtil.getPromotedVersionStrict(index, minecraftVersion, 'recommended')
|
||||
if (forgeVer != null) {
|
||||
console.log(`Recommended version: Forge ${forgeVer} (${mcVer})`)
|
||||
console.log(`Recommended version: Forge ${forgeVer} (${minecraftVersion})`)
|
||||
} else {
|
||||
console.log(`No recommended build for ${mcVer}. Checking for latest version..`)
|
||||
forgeVer = VersionUtil.getPromotedVersionStrict(index, mcVer, 'latest')
|
||||
console.log(`No recommended build for ${minecraftVersion}. Checking for latest version..`)
|
||||
forgeVer = VersionUtil.getPromotedVersionStrict(index, minecraftVersion, 'latest')
|
||||
if (forgeVer != null) {
|
||||
console.log(`Latest version: Forge ${forgeVer} (${mcVer})`)
|
||||
console.log(`Latest version: Forge ${forgeVer} (${minecraftVersion})`)
|
||||
} else {
|
||||
console.log(`No build available for ${mcVer}.`)
|
||||
console.log(`No build available for ${minecraftVersion}.`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +268,8 @@ const testCommand: yargs.CommandModule = {
|
||||
handler: async (argv) => {
|
||||
console.debug(`Invoked test with mcVer ${argv.mcVer} forgeVer ${argv.forgeVer}`)
|
||||
console.log(process.cwd())
|
||||
const resolver = VersionSegmentedRegistry.getForgeResolver(argv.mcVer as string,
|
||||
const mcVer = new MinecraftVersion(argv.mcVer as string)
|
||||
const resolver = VersionSegmentedRegistry.getForgeResolver(mcVer,
|
||||
argv.forgeVer as string, getRoot(), '', getBaseURL())
|
||||
if (resolver != null) {
|
||||
const mdl = await resolver.getModule()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface VersionManifest17 {
|
||||
export interface VersionManifestFG2 {
|
||||
|
||||
id: string
|
||||
time: string
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface VersionManifest113 {
|
||||
export interface VersionManifestFG3 {
|
||||
|
||||
id: string
|
||||
time: string
|
||||
@@ -4,6 +4,7 @@ import { join } from 'path'
|
||||
import { resolve } from 'url'
|
||||
import { VersionSegmented } from '../../../../util/VersionSegmented'
|
||||
import { ModuleStructure } from './module.struct'
|
||||
import { MinecraftVersion } from '../../../../util/MinecraftVersion'
|
||||
|
||||
export abstract class BaseForgeModStructure extends ModuleStructure implements VersionSegmented {
|
||||
|
||||
@@ -15,7 +16,7 @@ export abstract class BaseForgeModStructure extends ModuleStructure implements V
|
||||
super(absoluteRoot, relativeRoot, 'forgemods', baseUrl, Type.ForgeMod)
|
||||
}
|
||||
|
||||
public abstract isForVersion(version: string): boolean
|
||||
public abstract isForVersion(version: MinecraftVersion): boolean
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
protected async getModuleUrl(name: string, path: string, stats: Stats): Promise<string> {
|
||||
|
||||
@@ -5,12 +5,13 @@ import { capitalize } from '../../../../../util/stringutils'
|
||||
import { VersionUtil } from '../../../../../util/versionutil'
|
||||
import { ModsToml } from '../../../../forge/modstoml'
|
||||
import { BaseForgeModStructure } from '../forgemod.struct'
|
||||
import { MinecraftVersion } from '../../../../../util/MinecraftVersion'
|
||||
|
||||
export class ForgeModStructure113 extends BaseForgeModStructure {
|
||||
|
||||
public static readonly IMPLEMENTATION_VERSION_REGEX = /^Implementation-Version: (.+)[\r\n]/
|
||||
|
||||
public static isForVersion(version: string): boolean {
|
||||
public static isForVersion(version: MinecraftVersion): boolean {
|
||||
return VersionUtil.isVersionAcceptable(version, [13, 14, 15])
|
||||
}
|
||||
|
||||
@@ -24,7 +25,7 @@ export class ForgeModStructure113 extends BaseForgeModStructure {
|
||||
super(absoluteRoot, relativeRoot, baseUrl)
|
||||
}
|
||||
|
||||
public isForVersion(version: string): boolean {
|
||||
public isForVersion(version: MinecraftVersion): boolean {
|
||||
return ForgeModStructure113.isForVersion(version)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,11 @@ import { VersionUtil } from '../../../../../util/versionutil'
|
||||
import { McModInfo } from '../../../../forge/mcmodinfo'
|
||||
import { McModInfoList } from '../../../../forge/mcmodinfolist'
|
||||
import { BaseForgeModStructure } from '../forgemod.struct'
|
||||
import { MinecraftVersion } from '../../../../../util/MinecraftVersion'
|
||||
|
||||
export class ForgeModStructure17 extends BaseForgeModStructure {
|
||||
|
||||
public static isForVersion(version: string): boolean {
|
||||
public static isForVersion(version: MinecraftVersion): boolean {
|
||||
return VersionUtil.isVersionAcceptable(version, [7, 8, 9, 10, 11, 12])
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ export class ForgeModStructure17 extends BaseForgeModStructure {
|
||||
super(absoluteRoot, relativeRoot, baseUrl)
|
||||
}
|
||||
|
||||
public isForVersion(version: string): boolean {
|
||||
public isForVersion(version: MinecraftVersion): boolean {
|
||||
return ForgeModStructure17.isForVersion(version)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { BaseModelStructure } from './basemodel.struct'
|
||||
import { MiscFileStructure } from './module/file.struct'
|
||||
import { LiteModStructure } from './module/litemod.struct'
|
||||
import { LibraryStructure } from './module/library.struct'
|
||||
import { MinecraftVersion } from '../../../util/MinecraftVersion'
|
||||
|
||||
export class ServerStructure extends BaseModelStructure<Server> {
|
||||
|
||||
@@ -29,7 +30,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
|
||||
|
||||
public async createServer(
|
||||
id: string,
|
||||
minecraftVersion: string,
|
||||
minecraftVersion: MinecraftVersion,
|
||||
options: {
|
||||
forgeVersion?: string
|
||||
liteloaderVersion?: string
|
||||
@@ -107,7 +108,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
|
||||
|
||||
// Read server meta
|
||||
const serverMeta: ServerMeta = JSON.parse(await readFile(resolvePath(absoluteServerRoot, 'servermeta.json'), 'utf-8'))
|
||||
const minecraftVersion = match[2]
|
||||
const minecraftVersion = new MinecraftVersion(match[2])
|
||||
|
||||
const forgeResolver = VersionSegmentedRegistry.getForgeResolver(
|
||||
minecraftVersion,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { join } from 'path'
|
||||
import { resolve as resolveURL } from 'url'
|
||||
import { BaseFileStructure } from '../BaseFileStructure'
|
||||
import { MinecraftVersion } from '../../../util/MinecraftVersion'
|
||||
|
||||
export class VersionRepoStructure extends BaseFileStructure {
|
||||
|
||||
@@ -11,16 +12,16 @@ export class VersionRepoStructure extends BaseFileStructure {
|
||||
super(absoluteRoot, relativeRoot, 'versions')
|
||||
}
|
||||
|
||||
public getFileName(minecraftVersion: string, forgeVersion: string): string {
|
||||
public getFileName(minecraftVersion: MinecraftVersion, forgeVersion: string): string {
|
||||
return `${minecraftVersion}-forge-${forgeVersion}`
|
||||
}
|
||||
|
||||
public getVersionManifest(minecraftVersion: string, forgeVersion: string): string {
|
||||
public getVersionManifest(minecraftVersion: MinecraftVersion, forgeVersion: string): string {
|
||||
const fileName = this.getFileName(minecraftVersion, forgeVersion)
|
||||
return join(this.containerDirectory, fileName, `${fileName}.json`)
|
||||
}
|
||||
|
||||
public getVersionManifestURL(url: string, minecraftVersion: string, forgeVersion: string): string {
|
||||
public getVersionManifestURL(url: string, minecraftVersion: MinecraftVersion, forgeVersion: string): string {
|
||||
const fileName = this.getFileName(minecraftVersion, forgeVersion)
|
||||
return resolveURL(url, join(this.relativeRoot, fileName, `${fileName}.json`))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Module } from 'helios-distribution-types'
|
||||
import { VersionSegmented } from '../util/VersionSegmented'
|
||||
import { Resolver } from './resolver'
|
||||
import { MinecraftVersion } from '../util/MinecraftVersion'
|
||||
|
||||
export abstract class BaseResolver implements Resolver, VersionSegmented {
|
||||
|
||||
@@ -11,7 +12,6 @@ export abstract class BaseResolver implements Resolver, VersionSegmented {
|
||||
) {}
|
||||
|
||||
public abstract getModule(): Promise<Module>
|
||||
|
||||
public abstract isForVersion(version: string): boolean
|
||||
public abstract isForVersion(version: MinecraftVersion): boolean
|
||||
|
||||
}
|
||||
|
||||
@@ -3,16 +3,17 @@ import { createHash } from 'crypto'
|
||||
import { copy, lstat, mkdirs, pathExists, readFile, remove } from 'fs-extra'
|
||||
import { Module, Type } from 'helios-distribution-types'
|
||||
import { basename, join } from 'path'
|
||||
import { VersionManifest17 } from '../../../model/forge/versionmanifest17'
|
||||
import { VersionManifestFG2 } from '../../../model/forge/versionmanifestFG2'
|
||||
import { LibRepoStructure } from '../../../model/struct/repo/librepo.struct'
|
||||
import { MavenUtil } from '../../../util/maven'
|
||||
import { PackXZExtractWrapper } from '../../../util/PackXZExtractWrapper'
|
||||
import { VersionUtil } from '../../../util/versionutil'
|
||||
import { ForgeResolver } from '../forge.resolver'
|
||||
import { MinecraftVersion } from '../../../util/MinecraftVersion'
|
||||
|
||||
export class Forge17Adapter extends ForgeResolver {
|
||||
export class ForgeGradle2Adapter extends ForgeResolver {
|
||||
|
||||
public static isForVersion(version: string): boolean {
|
||||
public static isForVersion(version: MinecraftVersion): boolean {
|
||||
return VersionUtil.isVersionAcceptable(version, [7, 8, 9, 10, 11, 12])
|
||||
}
|
||||
|
||||
@@ -20,7 +21,7 @@ export class Forge17Adapter extends ForgeResolver {
|
||||
absoluteRoot: string,
|
||||
relativeRoot: string,
|
||||
baseUrl: string,
|
||||
minecraftVersion: string,
|
||||
minecraftVersion: MinecraftVersion,
|
||||
forgeVersion: string
|
||||
) {
|
||||
super(absoluteRoot, relativeRoot, baseUrl, minecraftVersion, forgeVersion)
|
||||
@@ -30,8 +31,8 @@ export class Forge17Adapter extends ForgeResolver {
|
||||
return this.getForgeByVersion()
|
||||
}
|
||||
|
||||
public isForVersion(version: string): boolean {
|
||||
return Forge17Adapter.isForVersion(version)
|
||||
public isForVersion(version: MinecraftVersion): boolean {
|
||||
return ForgeGradle2Adapter.isForVersion(version)
|
||||
}
|
||||
|
||||
public async getForgeByVersion(): Promise<Module> {
|
||||
@@ -67,7 +68,7 @@ export class Forge17Adapter extends ForgeResolver {
|
||||
throw new Error('Failed to find version.json in forge universal jar.')
|
||||
}
|
||||
|
||||
versionManifest = JSON.parse(versionManifest) as VersionManifest17
|
||||
versionManifest = JSON.parse(versionManifest) as VersionManifestFG2
|
||||
|
||||
const forgeModule: Module = {
|
||||
id: MavenUtil.mavenComponentsToIdentifier(
|
||||
@@ -2,16 +2,17 @@ import { spawn } from 'child_process'
|
||||
import { copy, lstat, mkdirs, move, pathExists, readFile, remove, writeFile } from 'fs-extra'
|
||||
import { Module, Type } from 'helios-distribution-types'
|
||||
import { basename, dirname, join } from 'path'
|
||||
import { VersionManifest113 } from '../../../model/forge/versionmanifest113'
|
||||
import { VersionManifestFG3 } from '../../../model/forge/versionmanifestFG3'
|
||||
import { LibRepoStructure } from '../../../model/struct/repo/librepo.struct'
|
||||
import { JavaUtil } from '../../../util/javautil'
|
||||
import { MavenUtil } from '../../../util/maven'
|
||||
import { VersionUtil } from '../../../util/versionutil'
|
||||
import { ForgeResolver } from '../forge.resolver'
|
||||
import { MinecraftVersion } from '../../../util/MinecraftVersion'
|
||||
|
||||
export class Forge113Adapter extends ForgeResolver {
|
||||
export class ForgeGradle3Adapter extends ForgeResolver {
|
||||
|
||||
public static isForVersion(version: string): boolean {
|
||||
public static isForVersion(version: MinecraftVersion): boolean {
|
||||
return VersionUtil.isVersionAcceptable(version, [13, 14, 15])
|
||||
}
|
||||
|
||||
@@ -19,7 +20,7 @@ export class Forge113Adapter extends ForgeResolver {
|
||||
absoluteRoot: string,
|
||||
relativeRoot: string,
|
||||
baseUrl: string,
|
||||
minecraftVersion: string,
|
||||
minecraftVersion: MinecraftVersion,
|
||||
forgeVersion: string
|
||||
) {
|
||||
super(absoluteRoot, relativeRoot, baseUrl, minecraftVersion, forgeVersion)
|
||||
@@ -29,8 +30,8 @@ export class Forge113Adapter extends ForgeResolver {
|
||||
return this.process()
|
||||
}
|
||||
|
||||
public isForVersion(version: string): boolean {
|
||||
return Forge113Adapter.isForVersion(version)
|
||||
public isForVersion(version: MinecraftVersion): boolean {
|
||||
return ForgeGradle3Adapter.isForVersion(version)
|
||||
}
|
||||
|
||||
private async process(): Promise<Module> {
|
||||
@@ -77,7 +78,7 @@ export class Forge113Adapter extends ForgeResolver {
|
||||
|
||||
console.debug('Processing Version Manifest')
|
||||
const versionManifestTuple = await this.processVersionManifest()
|
||||
const versionManifest = versionManifestTuple[0] as VersionManifest113
|
||||
const versionManifest = versionManifestTuple[0] as VersionManifestFG3
|
||||
|
||||
console.debug('Processing generated forge files.')
|
||||
const forgeModule = await this.processForgeModule(versionManifest)
|
||||
@@ -95,7 +96,7 @@ export class Forge113Adapter extends ForgeResolver {
|
||||
return forgeModule
|
||||
}
|
||||
|
||||
private async processLibraries(manifest: VersionManifest113): Promise<Module[]> {
|
||||
private async processLibraries(manifest: VersionManifestFG3): Promise<Module[]> {
|
||||
|
||||
const libDir = join(this.repoStructure.getWorkDirectory(), 'libraries')
|
||||
const libRepo = this.repoStructure.getLibRepoStruct()
|
||||
@@ -149,7 +150,7 @@ export class Forge113Adapter extends ForgeResolver {
|
||||
|
||||
}
|
||||
|
||||
private async processForgeModule(versionManifest: VersionManifest113): Promise<Module> {
|
||||
private async processForgeModule(versionManifest: VersionManifestFG3): Promise<Module> {
|
||||
|
||||
const libDir = join(this.repoStructure.getWorkDirectory(), 'libraries')
|
||||
const mcpVersion = this.getMCPVersion(versionManifest.arguments.game)
|
||||
@@ -180,7 +181,7 @@ export class Forge113Adapter extends ForgeResolver {
|
||||
name: 'client slim',
|
||||
group: LibRepoStructure.MINECRAFT_GROUP,
|
||||
artifact: LibRepoStructure.MINECRAFT_CLIENT_ARTIFACT,
|
||||
version: this.minecraftVersion,
|
||||
version: this.minecraftVersion.toString(),
|
||||
classifiers: [
|
||||
'slim',
|
||||
'slim-stable'
|
||||
@@ -190,7 +191,7 @@ export class Forge113Adapter extends ForgeResolver {
|
||||
name: 'client data',
|
||||
group: LibRepoStructure.MINECRAFT_GROUP,
|
||||
artifact: LibRepoStructure.MINECRAFT_CLIENT_ARTIFACT,
|
||||
version: this.minecraftVersion,
|
||||
version: this.minecraftVersion.toString(),
|
||||
classifiers: ['data'],
|
||||
skipIfNotPresent: true
|
||||
},
|
||||
@@ -198,7 +199,7 @@ export class Forge113Adapter extends ForgeResolver {
|
||||
name: 'client extra',
|
||||
group: LibRepoStructure.MINECRAFT_GROUP,
|
||||
artifact: LibRepoStructure.MINECRAFT_CLIENT_ARTIFACT,
|
||||
version: this.minecraftVersion,
|
||||
version: this.minecraftVersion.toString(),
|
||||
classifiers: [
|
||||
'extra',
|
||||
'extra-stable'
|
||||
@@ -285,14 +286,14 @@ export class Forge113Adapter extends ForgeResolver {
|
||||
return forgeModule
|
||||
}
|
||||
|
||||
private async processVersionManifest(): Promise<[VersionManifest113, Module]> {
|
||||
private async processVersionManifest(): Promise<[VersionManifestFG3, Module]> {
|
||||
const workDir = this.repoStructure.getWorkDirectory()
|
||||
const versionRepo = this.repoStructure.getVersionRepoStruct()
|
||||
const versionName = versionRepo.getFileName(this.minecraftVersion, this.forgeVersion)
|
||||
const versionManifestPath = join(workDir, 'versions', versionName, `${versionName}.json`)
|
||||
|
||||
const versionManifestBuf = await readFile(versionManifestPath)
|
||||
const versionManifest = JSON.parse(versionManifestBuf.toString()) as VersionManifest113
|
||||
const versionManifest = JSON.parse(versionManifestBuf.toString()) as VersionManifestFG3
|
||||
|
||||
const versionManifestModule: Module = {
|
||||
id: this.artifactVersion,
|
||||
@@ -3,6 +3,7 @@ import { Stats } from 'fs-extra'
|
||||
import { Artifact } from 'helios-distribution-types'
|
||||
import { RepoStructure } from '../../model/struct/repo/repo.struct'
|
||||
import { BaseResolver } from '../baseresolver'
|
||||
import { MinecraftVersion } from '../../util/MinecraftVersion'
|
||||
|
||||
export abstract class ForgeResolver extends BaseResolver {
|
||||
|
||||
@@ -15,7 +16,7 @@ export abstract class ForgeResolver extends BaseResolver {
|
||||
absoluteRoot: string,
|
||||
relativeRoot: string,
|
||||
baseUrl: string,
|
||||
protected minecraftVersion: string,
|
||||
protected minecraftVersion: MinecraftVersion,
|
||||
protected forgeVersion: string
|
||||
) {
|
||||
super(absoluteRoot, relativeRoot, baseUrl)
|
||||
|
||||
30
src/util/MinecraftVersion.ts
Normal file
30
src/util/MinecraftVersion.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
export class MinecraftVersion {
|
||||
|
||||
private static readonly MINECRAFT_VERSION_REGEX = /(\d+).(\d+).(\d+)/
|
||||
|
||||
private readonly major: number
|
||||
private readonly minor: number
|
||||
private readonly revision: number
|
||||
|
||||
constructor(version: string) {
|
||||
const res = MinecraftVersion.MINECRAFT_VERSION_REGEX.exec(version)
|
||||
if(res != null) {
|
||||
this.major = Number(res[1])
|
||||
this.minor = Number(res[2])
|
||||
this.revision = Number(res[3])
|
||||
} else {
|
||||
throw new Error(`${version} is not a valid minecraft version!`)
|
||||
}
|
||||
}
|
||||
|
||||
public static isMinecraftVersion(version: string): boolean {
|
||||
return MinecraftVersion.MINECRAFT_VERSION_REGEX.test(version)
|
||||
}
|
||||
|
||||
public getMajor(): number { return this.major }
|
||||
public getMinor(): number { return this.minor }
|
||||
public getRevision(): number { return this.revision }
|
||||
|
||||
public toString(): string { return `${this.major}.${this.minor}.${this.revision}`}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { MinecraftVersion } from './MinecraftVersion'
|
||||
|
||||
export interface VersionSegmented {
|
||||
|
||||
isForVersion(version: string): boolean
|
||||
isForVersion(version: MinecraftVersion): boolean
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { ForgeModStructure113 } from '../model/struct/model/module/forgemod/forgemod113.struct'
|
||||
import { ForgeModStructure17 } from '../model/struct/model/module/forgemod/forgemod17.struct'
|
||||
import { Forge113Adapter } from '../resolver/forge/adapter/forge113.resolver'
|
||||
import { Forge17Adapter } from '../resolver/forge/adapter/forge17.resolver'
|
||||
import { ForgeGradle3Adapter } from '../resolver/forge/adapter/ForgeGradle3.resolver'
|
||||
import { ForgeGradle2Adapter } from '../resolver/forge/adapter/ForgeGradle2.resolver'
|
||||
import { ForgeResolver } from '../resolver/forge/forge.resolver'
|
||||
import { BaseForgeModStructure } from '../model/struct/model/module/forgemod.struct'
|
||||
import { MinecraftVersion } from './MinecraftVersion'
|
||||
|
||||
export class VersionSegmentedRegistry {
|
||||
|
||||
public static readonly FORGE_ADAPTER_IMPL = [
|
||||
Forge17Adapter,
|
||||
Forge113Adapter
|
||||
ForgeGradle2Adapter,
|
||||
ForgeGradle3Adapter
|
||||
]
|
||||
|
||||
public static readonly FORGEMOD_STRUCT_IML = [
|
||||
@@ -18,7 +19,7 @@ export class VersionSegmentedRegistry {
|
||||
]
|
||||
|
||||
public static getForgeResolver(
|
||||
minecraftVersion: string,
|
||||
minecraftVersion: MinecraftVersion,
|
||||
forgeVersion: string,
|
||||
absoluteRoot: string,
|
||||
relativeRoot: string,
|
||||
@@ -33,7 +34,7 @@ export class VersionSegmentedRegistry {
|
||||
}
|
||||
|
||||
public static getForgeModStruct(
|
||||
minecraftVersion: string,
|
||||
minecraftVersion: MinecraftVersion,
|
||||
absoluteRoot: string,
|
||||
relativeRoot: string,
|
||||
baseUrl: string
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Axios from 'axios'
|
||||
import { PromotionsSlim } from '../model/forge/promotionsslim'
|
||||
import { MinecraftVersion } from './MinecraftVersion'
|
||||
|
||||
export class VersionUtil {
|
||||
|
||||
@@ -10,28 +11,9 @@ export class VersionUtil {
|
||||
|
||||
public static readonly MINECRAFT_VERSION_REGEX = /(\d+).(\d+).(\d+)/
|
||||
|
||||
public static isMinecraftVersion(version: string): boolean {
|
||||
return VersionUtil.MINECRAFT_VERSION_REGEX.test(version)
|
||||
}
|
||||
|
||||
public static getMinecraftVersionComponents(version: string): { major: number, minor: number, revision: number } {
|
||||
if (VersionUtil.isMinecraftVersion(version)) {
|
||||
const result = VersionUtil.MINECRAFT_VERSION_REGEX.exec(version)
|
||||
if (result != null) {
|
||||
return {
|
||||
major: Number(result[1]),
|
||||
minor: Number(result[2]),
|
||||
revision: Number(result[3])
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error(`${version} is not a valid minecraft version!`)
|
||||
}
|
||||
|
||||
public static isVersionAcceptable(version: string, acceptable: number[]): boolean {
|
||||
const versionComponents = VersionUtil.getMinecraftVersionComponents(version)
|
||||
if (versionComponents != null && versionComponents.major === 1) {
|
||||
return acceptable.find((element) => versionComponents.minor === element) != null
|
||||
public static isVersionAcceptable(version: MinecraftVersion, acceptable: number[]): boolean {
|
||||
if (version.getMajor() === 1) {
|
||||
return acceptable.find((element) => version.getMinor() === element) != null
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -49,12 +31,12 @@ export class VersionUtil {
|
||||
return response.data as PromotionsSlim
|
||||
}
|
||||
|
||||
public static getPromotedVersionStrict(index: PromotionsSlim, minecraftVersion: string, promotion: string): string {
|
||||
public static getPromotedVersionStrict(index: PromotionsSlim, minecraftVersion: MinecraftVersion, promotion: string): string {
|
||||
const workingPromotion = promotion.toLowerCase()
|
||||
return index.promos[`${minecraftVersion}-${workingPromotion}`]
|
||||
}
|
||||
|
||||
public static async getPromotedForgeVersion(minecraftVersion: string, promotion: string): Promise<string> {
|
||||
public static async getPromotedForgeVersion(minecraftVersion: MinecraftVersion, promotion: string): Promise<string> {
|
||||
const workingPromotion = promotion.toLowerCase()
|
||||
const res = await VersionUtil.getPromotionIndex()
|
||||
let version = res.promos[`${minecraftVersion}-${workingPromotion}`]
|
||||
|
||||
Reference in New Issue
Block a user