Automatic resolution of latest and recommended forge builds.

You can now use 'latest' or 'recommended' as the forge version option in the generate commands.
Two new commands are provided to query the latest/recommended version of forge.
This commit is contained in:
Daniel Scalzi
2020-01-19 15:40:52 -05:00
parent f7173c4f5c
commit 8911f54039
4 changed files with 114 additions and 1 deletions

View File

@@ -1,5 +1,13 @@
import Axios from 'axios'
import { PromotionsSlim } from '../model/forge/promotionsslim'
export class VersionUtil {
public static readonly PROMOTION_TYPE = [
'recommended',
'latest'
]
public static readonly MINECRAFT_VERSION_REGEX = /(\d+).(\d+).(\d+)/
public static isMinecraftVersion(version: string) {
@@ -28,4 +36,37 @@ export class VersionUtil {
return false
}
public static isPromotionVersion(version: string) {
return VersionUtil.PROMOTION_TYPE.indexOf(version.toLowerCase()) > -1
}
public static async getPromotionIndex() {
const response = await Axios({
method: 'get',
url: 'https://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json',
responseType: 'json'
})
return response.data as PromotionsSlim
}
public static getPromotedVersionStrict(index: PromotionsSlim, minecraftVersion: string, promotion: string) {
const workingPromotion = promotion.toLowerCase()
return index.promos[`${minecraftVersion}-${workingPromotion}`]
}
public static async getPromotedForgeVersion(minecraftVersion: string, promotion: string) {
const workingPromotion = promotion.toLowerCase()
const res = await VersionUtil.getPromotionIndex()
let version = res.promos[`${minecraftVersion}-${workingPromotion}`]
if (version == null) {
console.warn(`No ${workingPromotion} version found for Forge ${minecraftVersion}.`)
console.warn(`Attempting to pull latest version instead.`)
version = res.promos[`${minecraftVersion}-latest`]
if (version == null) {
throw new Error(`No latest version found for Forge ${minecraftVersion}.`)
}
}
return version
}
}