Infer version from MANIFEST.MF if mod uses version wildcard.

This commit is contained in:
Daniel Scalzi
2020-01-19 14:23:44 -05:00
parent ec30886cbb
commit f7173c4f5c

View File

@@ -8,6 +8,8 @@ import { BaseForgeModStructure } from '../forgemod.struct'
export class ForgeModStructure113 extends BaseForgeModStructure { export class ForgeModStructure113 extends BaseForgeModStructure {
public static readonly IMPLEMENTATION_VERSION_REGEX = /^Implementation-Version: (.+)[\r\n]/
public static isForVersion(version: string) { public static isForVersion(version: string) {
return VersionUtil.isVersionAcceptable(version, [13, 14, 15]) return VersionUtil.isVersionAcceptable(version, [13, 14, 15])
} }
@@ -73,7 +75,26 @@ export class ForgeModStructure113 extends BaseForgeModStructure {
if (raw) { if (raw) {
// Assuming the main mod will be the first entry in this file. // Assuming the main mod will be the first entry in this file.
try { try {
this.forgeModMetadata[name] = toml.parse(raw) as ModsToml const parsed = toml.parse(raw) as ModsToml
// tslint:disable-next-line: no-invalid-template-strings
if (parsed.mods[0].version === '${file.jarVersion}') {
let version = '0.0.0'
const manifest = zip.readAsText('META-INF/MANIFEST.MF')
const keys = manifest.split('\n')
console.log(keys)
for (const key of keys) {
const match = ForgeModStructure113.IMPLEMENTATION_VERSION_REGEX.exec(key)
if (match != null) {
version = match[1]
}
}
console.debug(`ForgeMod ${name} contains a version wildcard, inferring ${version}`)
parsed.mods[0].version = version
}
this.forgeModMetadata[name] = parsed
} catch (err) { } catch (err) {
console.error(`ForgeMod ${name} contains an invalid mods.toml file.`) console.error(`ForgeMod ${name} contains an invalid mods.toml file.`)
createDefault = true createDefault = true