Wrap MinecraftVersion in its own object.

This commit is contained in:
Daniel Scalzi
2020-05-29 22:15:56 -04:00
parent 23a452f0b6
commit 00842c9dff
16 changed files with 106 additions and 78 deletions

View File

@@ -9,6 +9,7 @@ import { DistributionStructure } from './model/struct/model/distribution.struct'
import { ServerStructure } from './model/struct/model/server.struct' import { ServerStructure } from './model/struct/model/server.struct'
import { VersionSegmentedRegistry } from './util/VersionSegmentedRegistry' import { VersionSegmentedRegistry } from './util/VersionSegmentedRegistry'
import { VersionUtil } from './util/versionutil' import { VersionUtil } from './util/versionutil'
import { MinecraftVersion } from './util/MinecraftVersion'
dotenv.config() dotenv.config()
@@ -145,10 +146,12 @@ const generateServerCommand: yargs.CommandModule = {
`\n\t├ Forge version: ${argv.forge}`, `\n\t├ Forge version: ${argv.forge}`,
`\n\t└ LiteLoader version: ${argv.liteloader}`) `\n\t└ LiteLoader version: ${argv.liteloader}`)
const minecraftVersion = new MinecraftVersion(argv.version as string)
if(argv.forge != null) { if(argv.forge != null) {
if (VersionUtil.isPromotionVersion(argv.forge as string)) { if (VersionUtil.isPromotionVersion(argv.forge as string)) {
console.debug(`Resolving ${argv.forge} Forge Version..`) 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}`) console.debug(`Forge version set to ${version}`)
argv.forge = version argv.forge = version
} }
@@ -157,7 +160,7 @@ const generateServerCommand: yargs.CommandModule = {
const serverStruct = new ServerStructure(argv.root as string, getBaseURL()) const serverStruct = new ServerStructure(argv.root as string, getBaseURL())
serverStruct.createServer( serverStruct.createServer(
argv.id as string, argv.id as string,
argv.version as string, minecraftVersion,
{ {
forgeVersion: argv.forge as string, forgeVersion: argv.forge as string,
liteloaderVersion: argv.liteloader as string liteloaderVersion: argv.liteloader as string
@@ -225,7 +228,8 @@ const latestForgeCommand: yargs.CommandModule = {
handler: async (argv) => { handler: async (argv) => {
console.debug(`Invoked latest-forge with version ${argv.version}.`) 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})`) 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}.`) console.debug(`Invoked recommended-forge with version ${argv.version}.`)
const index = await VersionUtil.getPromotionIndex() 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) { if (forgeVer != null) {
console.log(`Recommended version: Forge ${forgeVer} (${mcVer})`) console.log(`Recommended version: Forge ${forgeVer} (${minecraftVersion})`)
} else { } else {
console.log(`No recommended build for ${mcVer}. Checking for latest version..`) console.log(`No recommended build for ${minecraftVersion}. Checking for latest version..`)
forgeVer = VersionUtil.getPromotedVersionStrict(index, mcVer, 'latest') forgeVer = VersionUtil.getPromotedVersionStrict(index, minecraftVersion, 'latest')
if (forgeVer != null) { if (forgeVer != null) {
console.log(`Latest version: Forge ${forgeVer} (${mcVer})`) console.log(`Latest version: Forge ${forgeVer} (${minecraftVersion})`)
} else { } 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) => { handler: async (argv) => {
console.debug(`Invoked test with mcVer ${argv.mcVer} forgeVer ${argv.forgeVer}`) console.debug(`Invoked test with mcVer ${argv.mcVer} forgeVer ${argv.forgeVer}`)
console.log(process.cwd()) 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()) argv.forgeVer as string, getRoot(), '', getBaseURL())
if (resolver != null) { if (resolver != null) {
const mdl = await resolver.getModule() const mdl = await resolver.getModule()

View File

@@ -1,4 +1,4 @@
export interface VersionManifest17 { export interface VersionManifestFG2 {
id: string id: string
time: string time: string

View File

@@ -1,4 +1,4 @@
export interface VersionManifest113 { export interface VersionManifestFG3 {
id: string id: string
time: string time: string

View File

@@ -4,6 +4,7 @@ import { join } from 'path'
import { resolve } from 'url' import { resolve } from 'url'
import { VersionSegmented } from '../../../../util/VersionSegmented' import { VersionSegmented } from '../../../../util/VersionSegmented'
import { ModuleStructure } from './module.struct' import { ModuleStructure } from './module.struct'
import { MinecraftVersion } from '../../../../util/MinecraftVersion'
export abstract class BaseForgeModStructure extends ModuleStructure implements VersionSegmented { 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) 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 // eslint-disable-next-line @typescript-eslint/no-unused-vars
protected async getModuleUrl(name: string, path: string, stats: Stats): Promise<string> { protected async getModuleUrl(name: string, path: string, stats: Stats): Promise<string> {

View File

@@ -5,12 +5,13 @@ import { capitalize } from '../../../../../util/stringutils'
import { VersionUtil } from '../../../../../util/versionutil' import { VersionUtil } from '../../../../../util/versionutil'
import { ModsToml } from '../../../../forge/modstoml' import { ModsToml } from '../../../../forge/modstoml'
import { BaseForgeModStructure } from '../forgemod.struct' import { BaseForgeModStructure } from '../forgemod.struct'
import { MinecraftVersion } from '../../../../../util/MinecraftVersion'
export class ForgeModStructure113 extends BaseForgeModStructure { export class ForgeModStructure113 extends BaseForgeModStructure {
public static readonly IMPLEMENTATION_VERSION_REGEX = /^Implementation-Version: (.+)[\r\n]/ 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]) return VersionUtil.isVersionAcceptable(version, [13, 14, 15])
} }
@@ -24,7 +25,7 @@ export class ForgeModStructure113 extends BaseForgeModStructure {
super(absoluteRoot, relativeRoot, baseUrl) super(absoluteRoot, relativeRoot, baseUrl)
} }
public isForVersion(version: string): boolean { public isForVersion(version: MinecraftVersion): boolean {
return ForgeModStructure113.isForVersion(version) return ForgeModStructure113.isForVersion(version)
} }

View File

@@ -5,10 +5,11 @@ import { VersionUtil } from '../../../../../util/versionutil'
import { McModInfo } from '../../../../forge/mcmodinfo' import { McModInfo } from '../../../../forge/mcmodinfo'
import { McModInfoList } from '../../../../forge/mcmodinfolist' import { McModInfoList } from '../../../../forge/mcmodinfolist'
import { BaseForgeModStructure } from '../forgemod.struct' import { BaseForgeModStructure } from '../forgemod.struct'
import { MinecraftVersion } from '../../../../../util/MinecraftVersion'
export class ForgeModStructure17 extends BaseForgeModStructure { 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]) return VersionUtil.isVersionAcceptable(version, [7, 8, 9, 10, 11, 12])
} }
@@ -22,7 +23,7 @@ export class ForgeModStructure17 extends BaseForgeModStructure {
super(absoluteRoot, relativeRoot, baseUrl) super(absoluteRoot, relativeRoot, baseUrl)
} }
public isForVersion(version: string): boolean { public isForVersion(version: MinecraftVersion): boolean {
return ForgeModStructure17.isForVersion(version) return ForgeModStructure17.isForVersion(version)
} }

View File

@@ -8,6 +8,7 @@ import { BaseModelStructure } from './basemodel.struct'
import { MiscFileStructure } from './module/file.struct' import { MiscFileStructure } from './module/file.struct'
import { LiteModStructure } from './module/litemod.struct' import { LiteModStructure } from './module/litemod.struct'
import { LibraryStructure } from './module/library.struct' import { LibraryStructure } from './module/library.struct'
import { MinecraftVersion } from '../../../util/MinecraftVersion'
export class ServerStructure extends BaseModelStructure<Server> { export class ServerStructure extends BaseModelStructure<Server> {
@@ -29,7 +30,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
public async createServer( public async createServer(
id: string, id: string,
minecraftVersion: string, minecraftVersion: MinecraftVersion,
options: { options: {
forgeVersion?: string forgeVersion?: string
liteloaderVersion?: string liteloaderVersion?: string
@@ -107,7 +108,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
// Read server meta // Read server meta
const serverMeta: ServerMeta = JSON.parse(await readFile(resolvePath(absoluteServerRoot, 'servermeta.json'), 'utf-8')) 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( const forgeResolver = VersionSegmentedRegistry.getForgeResolver(
minecraftVersion, minecraftVersion,

View File

@@ -1,6 +1,7 @@
import { join } from 'path' import { join } from 'path'
import { resolve as resolveURL } from 'url' import { resolve as resolveURL } from 'url'
import { BaseFileStructure } from '../BaseFileStructure' import { BaseFileStructure } from '../BaseFileStructure'
import { MinecraftVersion } from '../../../util/MinecraftVersion'
export class VersionRepoStructure extends BaseFileStructure { export class VersionRepoStructure extends BaseFileStructure {
@@ -11,16 +12,16 @@ export class VersionRepoStructure extends BaseFileStructure {
super(absoluteRoot, relativeRoot, 'versions') super(absoluteRoot, relativeRoot, 'versions')
} }
public getFileName(minecraftVersion: string, forgeVersion: string): string { public getFileName(minecraftVersion: MinecraftVersion, forgeVersion: string): string {
return `${minecraftVersion}-forge-${forgeVersion}` return `${minecraftVersion}-forge-${forgeVersion}`
} }
public getVersionManifest(minecraftVersion: string, forgeVersion: string): string { public getVersionManifest(minecraftVersion: MinecraftVersion, forgeVersion: string): string {
const fileName = this.getFileName(minecraftVersion, forgeVersion) const fileName = this.getFileName(minecraftVersion, forgeVersion)
return join(this.containerDirectory, fileName, `${fileName}.json`) 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) const fileName = this.getFileName(minecraftVersion, forgeVersion)
return resolveURL(url, join(this.relativeRoot, fileName, `${fileName}.json`)) return resolveURL(url, join(this.relativeRoot, fileName, `${fileName}.json`))
} }

View File

@@ -1,6 +1,7 @@
import { Module } from 'helios-distribution-types' import { Module } from 'helios-distribution-types'
import { VersionSegmented } from '../util/VersionSegmented' import { VersionSegmented } from '../util/VersionSegmented'
import { Resolver } from './resolver' import { Resolver } from './resolver'
import { MinecraftVersion } from '../util/MinecraftVersion'
export abstract class BaseResolver implements Resolver, VersionSegmented { 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 getModule(): Promise<Module>
public abstract isForVersion(version: MinecraftVersion): boolean
public abstract isForVersion(version: string): boolean
} }

View File

@@ -3,16 +3,17 @@ import { createHash } from 'crypto'
import { copy, lstat, mkdirs, pathExists, readFile, remove } from 'fs-extra' import { copy, lstat, mkdirs, pathExists, readFile, remove } from 'fs-extra'
import { Module, Type } from 'helios-distribution-types' import { Module, Type } from 'helios-distribution-types'
import { basename, join } from 'path' 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 { LibRepoStructure } from '../../../model/struct/repo/librepo.struct'
import { MavenUtil } from '../../../util/maven' import { MavenUtil } from '../../../util/maven'
import { PackXZExtractWrapper } from '../../../util/PackXZExtractWrapper' import { PackXZExtractWrapper } from '../../../util/PackXZExtractWrapper'
import { VersionUtil } from '../../../util/versionutil' import { VersionUtil } from '../../../util/versionutil'
import { ForgeResolver } from '../forge.resolver' 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]) return VersionUtil.isVersionAcceptable(version, [7, 8, 9, 10, 11, 12])
} }
@@ -20,7 +21,7 @@ export class Forge17Adapter extends ForgeResolver {
absoluteRoot: string, absoluteRoot: string,
relativeRoot: string, relativeRoot: string,
baseUrl: string, baseUrl: string,
minecraftVersion: string, minecraftVersion: MinecraftVersion,
forgeVersion: string forgeVersion: string
) { ) {
super(absoluteRoot, relativeRoot, baseUrl, minecraftVersion, forgeVersion) super(absoluteRoot, relativeRoot, baseUrl, minecraftVersion, forgeVersion)
@@ -30,8 +31,8 @@ export class Forge17Adapter extends ForgeResolver {
return this.getForgeByVersion() return this.getForgeByVersion()
} }
public isForVersion(version: string): boolean { public isForVersion(version: MinecraftVersion): boolean {
return Forge17Adapter.isForVersion(version) return ForgeGradle2Adapter.isForVersion(version)
} }
public async getForgeByVersion(): Promise<Module> { 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.') 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 = { const forgeModule: Module = {
id: MavenUtil.mavenComponentsToIdentifier( id: MavenUtil.mavenComponentsToIdentifier(

View File

@@ -2,16 +2,17 @@ import { spawn } from 'child_process'
import { copy, lstat, mkdirs, move, pathExists, readFile, remove, writeFile } from 'fs-extra' import { copy, lstat, mkdirs, move, pathExists, readFile, remove, writeFile } from 'fs-extra'
import { Module, Type } from 'helios-distribution-types' import { Module, Type } from 'helios-distribution-types'
import { basename, dirname, join } from 'path' 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 { LibRepoStructure } from '../../../model/struct/repo/librepo.struct'
import { JavaUtil } from '../../../util/javautil' import { JavaUtil } from '../../../util/javautil'
import { MavenUtil } from '../../../util/maven' import { MavenUtil } from '../../../util/maven'
import { VersionUtil } from '../../../util/versionutil' import { VersionUtil } from '../../../util/versionutil'
import { ForgeResolver } from '../forge.resolver' 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]) return VersionUtil.isVersionAcceptable(version, [13, 14, 15])
} }
@@ -19,7 +20,7 @@ export class Forge113Adapter extends ForgeResolver {
absoluteRoot: string, absoluteRoot: string,
relativeRoot: string, relativeRoot: string,
baseUrl: string, baseUrl: string,
minecraftVersion: string, minecraftVersion: MinecraftVersion,
forgeVersion: string forgeVersion: string
) { ) {
super(absoluteRoot, relativeRoot, baseUrl, minecraftVersion, forgeVersion) super(absoluteRoot, relativeRoot, baseUrl, minecraftVersion, forgeVersion)
@@ -29,8 +30,8 @@ export class Forge113Adapter extends ForgeResolver {
return this.process() return this.process()
} }
public isForVersion(version: string): boolean { public isForVersion(version: MinecraftVersion): boolean {
return Forge113Adapter.isForVersion(version) return ForgeGradle3Adapter.isForVersion(version)
} }
private async process(): Promise<Module> { private async process(): Promise<Module> {
@@ -77,7 +78,7 @@ export class Forge113Adapter extends ForgeResolver {
console.debug('Processing Version Manifest') console.debug('Processing Version Manifest')
const versionManifestTuple = await this.processVersionManifest() const versionManifestTuple = await this.processVersionManifest()
const versionManifest = versionManifestTuple[0] as VersionManifest113 const versionManifest = versionManifestTuple[0] as VersionManifestFG3
console.debug('Processing generated forge files.') console.debug('Processing generated forge files.')
const forgeModule = await this.processForgeModule(versionManifest) const forgeModule = await this.processForgeModule(versionManifest)
@@ -95,7 +96,7 @@ export class Forge113Adapter extends ForgeResolver {
return forgeModule return forgeModule
} }
private async processLibraries(manifest: VersionManifest113): Promise<Module[]> { private async processLibraries(manifest: VersionManifestFG3): Promise<Module[]> {
const libDir = join(this.repoStructure.getWorkDirectory(), 'libraries') const libDir = join(this.repoStructure.getWorkDirectory(), 'libraries')
const libRepo = this.repoStructure.getLibRepoStruct() 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 libDir = join(this.repoStructure.getWorkDirectory(), 'libraries')
const mcpVersion = this.getMCPVersion(versionManifest.arguments.game) const mcpVersion = this.getMCPVersion(versionManifest.arguments.game)
@@ -180,7 +181,7 @@ export class Forge113Adapter extends ForgeResolver {
name: 'client slim', name: 'client slim',
group: LibRepoStructure.MINECRAFT_GROUP, group: LibRepoStructure.MINECRAFT_GROUP,
artifact: LibRepoStructure.MINECRAFT_CLIENT_ARTIFACT, artifact: LibRepoStructure.MINECRAFT_CLIENT_ARTIFACT,
version: this.minecraftVersion, version: this.minecraftVersion.toString(),
classifiers: [ classifiers: [
'slim', 'slim',
'slim-stable' 'slim-stable'
@@ -190,7 +191,7 @@ export class Forge113Adapter extends ForgeResolver {
name: 'client data', name: 'client data',
group: LibRepoStructure.MINECRAFT_GROUP, group: LibRepoStructure.MINECRAFT_GROUP,
artifact: LibRepoStructure.MINECRAFT_CLIENT_ARTIFACT, artifact: LibRepoStructure.MINECRAFT_CLIENT_ARTIFACT,
version: this.minecraftVersion, version: this.minecraftVersion.toString(),
classifiers: ['data'], classifiers: ['data'],
skipIfNotPresent: true skipIfNotPresent: true
}, },
@@ -198,7 +199,7 @@ export class Forge113Adapter extends ForgeResolver {
name: 'client extra', name: 'client extra',
group: LibRepoStructure.MINECRAFT_GROUP, group: LibRepoStructure.MINECRAFT_GROUP,
artifact: LibRepoStructure.MINECRAFT_CLIENT_ARTIFACT, artifact: LibRepoStructure.MINECRAFT_CLIENT_ARTIFACT,
version: this.minecraftVersion, version: this.minecraftVersion.toString(),
classifiers: [ classifiers: [
'extra', 'extra',
'extra-stable' 'extra-stable'
@@ -285,14 +286,14 @@ export class Forge113Adapter extends ForgeResolver {
return forgeModule return forgeModule
} }
private async processVersionManifest(): Promise<[VersionManifest113, Module]> { private async processVersionManifest(): Promise<[VersionManifestFG3, Module]> {
const workDir = this.repoStructure.getWorkDirectory() const workDir = this.repoStructure.getWorkDirectory()
const versionRepo = this.repoStructure.getVersionRepoStruct() const versionRepo = this.repoStructure.getVersionRepoStruct()
const versionName = versionRepo.getFileName(this.minecraftVersion, this.forgeVersion) const versionName = versionRepo.getFileName(this.minecraftVersion, this.forgeVersion)
const versionManifestPath = join(workDir, 'versions', versionName, `${versionName}.json`) const versionManifestPath = join(workDir, 'versions', versionName, `${versionName}.json`)
const versionManifestBuf = await readFile(versionManifestPath) const versionManifestBuf = await readFile(versionManifestPath)
const versionManifest = JSON.parse(versionManifestBuf.toString()) as VersionManifest113 const versionManifest = JSON.parse(versionManifestBuf.toString()) as VersionManifestFG3
const versionManifestModule: Module = { const versionManifestModule: Module = {
id: this.artifactVersion, id: this.artifactVersion,

View File

@@ -3,6 +3,7 @@ import { Stats } from 'fs-extra'
import { Artifact } from 'helios-distribution-types' import { Artifact } from 'helios-distribution-types'
import { RepoStructure } from '../../model/struct/repo/repo.struct' import { RepoStructure } from '../../model/struct/repo/repo.struct'
import { BaseResolver } from '../baseresolver' import { BaseResolver } from '../baseresolver'
import { MinecraftVersion } from '../../util/MinecraftVersion'
export abstract class ForgeResolver extends BaseResolver { export abstract class ForgeResolver extends BaseResolver {
@@ -15,7 +16,7 @@ export abstract class ForgeResolver extends BaseResolver {
absoluteRoot: string, absoluteRoot: string,
relativeRoot: string, relativeRoot: string,
baseUrl: string, baseUrl: string,
protected minecraftVersion: string, protected minecraftVersion: MinecraftVersion,
protected forgeVersion: string protected forgeVersion: string
) { ) {
super(absoluteRoot, relativeRoot, baseUrl) super(absoluteRoot, relativeRoot, baseUrl)

View 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}`}
}

View File

@@ -1,5 +1,7 @@
import { MinecraftVersion } from './MinecraftVersion'
export interface VersionSegmented { export interface VersionSegmented {
isForVersion(version: string): boolean isForVersion(version: MinecraftVersion): boolean
} }

View File

@@ -1,15 +1,16 @@
import { ForgeModStructure113 } from '../model/struct/model/module/forgemod/forgemod113.struct' import { ForgeModStructure113 } from '../model/struct/model/module/forgemod/forgemod113.struct'
import { ForgeModStructure17 } from '../model/struct/model/module/forgemod/forgemod17.struct' import { ForgeModStructure17 } from '../model/struct/model/module/forgemod/forgemod17.struct'
import { Forge113Adapter } from '../resolver/forge/adapter/forge113.resolver' import { ForgeGradle3Adapter } from '../resolver/forge/adapter/ForgeGradle3.resolver'
import { Forge17Adapter } from '../resolver/forge/adapter/forge17.resolver' import { ForgeGradle2Adapter } from '../resolver/forge/adapter/ForgeGradle2.resolver'
import { ForgeResolver } from '../resolver/forge/forge.resolver' import { ForgeResolver } from '../resolver/forge/forge.resolver'
import { BaseForgeModStructure } from '../model/struct/model/module/forgemod.struct' import { BaseForgeModStructure } from '../model/struct/model/module/forgemod.struct'
import { MinecraftVersion } from './MinecraftVersion'
export class VersionSegmentedRegistry { export class VersionSegmentedRegistry {
public static readonly FORGE_ADAPTER_IMPL = [ public static readonly FORGE_ADAPTER_IMPL = [
Forge17Adapter, ForgeGradle2Adapter,
Forge113Adapter ForgeGradle3Adapter
] ]
public static readonly FORGEMOD_STRUCT_IML = [ public static readonly FORGEMOD_STRUCT_IML = [
@@ -18,7 +19,7 @@ export class VersionSegmentedRegistry {
] ]
public static getForgeResolver( public static getForgeResolver(
minecraftVersion: string, minecraftVersion: MinecraftVersion,
forgeVersion: string, forgeVersion: string,
absoluteRoot: string, absoluteRoot: string,
relativeRoot: string, relativeRoot: string,
@@ -33,7 +34,7 @@ export class VersionSegmentedRegistry {
} }
public static getForgeModStruct( public static getForgeModStruct(
minecraftVersion: string, minecraftVersion: MinecraftVersion,
absoluteRoot: string, absoluteRoot: string,
relativeRoot: string, relativeRoot: string,
baseUrl: string baseUrl: string

View File

@@ -1,5 +1,6 @@
import Axios from 'axios' import Axios from 'axios'
import { PromotionsSlim } from '../model/forge/promotionsslim' import { PromotionsSlim } from '../model/forge/promotionsslim'
import { MinecraftVersion } from './MinecraftVersion'
export class VersionUtil { export class VersionUtil {
@@ -10,28 +11,9 @@ export class VersionUtil {
public static readonly MINECRAFT_VERSION_REGEX = /(\d+).(\d+).(\d+)/ public static readonly MINECRAFT_VERSION_REGEX = /(\d+).(\d+).(\d+)/
public static isMinecraftVersion(version: string): boolean { public static isVersionAcceptable(version: MinecraftVersion, acceptable: number[]): boolean {
return VersionUtil.MINECRAFT_VERSION_REGEX.test(version) if (version.getMajor() === 1) {
} return acceptable.find((element) => version.getMinor() === element) != null
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
} }
return false return false
} }
@@ -49,12 +31,12 @@ export class VersionUtil {
return response.data as PromotionsSlim 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() const workingPromotion = promotion.toLowerCase()
return index.promos[`${minecraftVersion}-${workingPromotion}`] 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 workingPromotion = promotion.toLowerCase()
const res = await VersionUtil.getPromotionIndex() const res = await VersionUtil.getPromotionIndex()
let version = res.promos[`${minecraftVersion}-${workingPromotion}`] let version = res.promos[`${minecraftVersion}-${workingPromotion}`]