Added winston for logging.

This commit is contained in:
Daniel Scalzi
2020-06-02 20:47:34 -04:00
parent 672424b973
commit 0b063e4bfc
12 changed files with 437 additions and 89 deletions

View File

@@ -10,11 +10,14 @@ import { PackXZExtractWrapper } from '../../../util/PackXZExtractWrapper'
import { VersionUtil } from '../../../util/versionutil'
import { ForgeResolver } from '../forge.resolver'
import { MinecraftVersion } from '../../../util/MinecraftVersion'
import { LoggerUtil } from '../../../util/LoggerUtil'
type ArrayElement<A> = A extends readonly (infer T)[] ? T : never
export class ForgeGradle2Adapter extends ForgeResolver {
private static readonly logger = LoggerUtil.getLogger('FG2 Adapter')
public static isForVersion(version: MinecraftVersion, libraryVersion: string): boolean {
if(version.getMinor() === 12 && !VersionUtil.isOneDotTwelveFG2(libraryVersion)) {
return false
@@ -43,18 +46,18 @@ export class ForgeGradle2Adapter extends ForgeResolver {
public async getForgeByVersion(): Promise<Module> {
const libRepo = this.repoStructure.getLibRepoStruct()
const targetLocalPath = libRepo.getLocalForge(this.artifactVersion, 'universal')
console.debug(`Checking for forge version at ${targetLocalPath}..`)
ForgeGradle2Adapter.logger.debug(`Checking for forge version at ${targetLocalPath}..`)
if (!await libRepo.artifactExists(targetLocalPath)) {
console.debug('Forge not found locally, initializing download..')
ForgeGradle2Adapter.logger.debug('Forge not found locally, initializing download..')
await libRepo.downloadArtifactByComponents(
this.REMOTE_REPOSITORY,
LibRepoStructure.FORGE_GROUP,
LibRepoStructure.FORGE_ARTIFACT,
this.artifactVersion, 'universal', 'jar')
} else {
console.debug('Using locally discovered forge.')
ForgeGradle2Adapter.logger.debug('Using locally discovered forge.')
}
console.debug(`Beginning processing of Forge v${this.forgeVersion} (Minecraft ${this.minecraftVersion})`)
ForgeGradle2Adapter.logger.debug(`Beginning processing of Forge v${this.forgeVersion} (Minecraft ${this.minecraftVersion})`)
const forgeUniversalBuffer = await readFile(targetLocalPath)
const zip = new AdmZip(forgeUniversalBuffer)
@@ -103,7 +106,7 @@ export class ForgeGradle2Adapter extends ForgeResolver {
// We've already processed forge.
continue
}
console.debug(`Processing ${lib.name}..`)
ForgeGradle2Adapter.logger.debug(`Processing ${lib.name}..`)
const extension = await this.determineExtension(lib, libRepo)
const localPath = libRepo.getArtifactById(lib.name, extension)
@@ -120,13 +123,13 @@ export class ForgeGradle2Adapter extends ForgeResolver {
if (lib.checksums != null && lib.checksums.length == 1) {
const sha1 = createHash('sha1').update(libBuf).digest('hex')
if (sha1 !== lib.checksums[0]) {
console.debug('Hashes do not match, redownloading..')
ForgeGradle2Adapter.logger.debug('Hashes do not match, redownloading..')
queueDownload = true
}
}
}
} else {
console.debug('Not found locally, downloading..')
ForgeGradle2Adapter.logger.debug('Not found locally, downloading..')
queueDownload = true
}
@@ -134,7 +137,7 @@ export class ForgeGradle2Adapter extends ForgeResolver {
await libRepo.downloadArtifactById(lib.url || this.MOJANG_REMOTE_REPOSITORY, lib.name, extension)
libBuf = await readFile(localPath)
} else {
console.debug('Using local copy.')
ForgeGradle2Adapter.logger.debug('Using local copy.')
}
const stats = await lstat(localPath)
@@ -174,7 +177,7 @@ export class ForgeGradle2Adapter extends ForgeResolver {
if (el != null) {
el.artifact.MD5 = entry.MD5
} else {
console.error(`Error during post processing, could not update ${entry.id}`)
ForgeGradle2Adapter.logger.error(`Error during post processing, could not update ${entry.id}`)
}
}
@@ -185,7 +188,7 @@ export class ForgeGradle2Adapter extends ForgeResolver {
if(lib.url == null) {
return 'jar'
}
console.log('Determing extension..')
ForgeGradle2Adapter.logger.debug('Determing extension..')
const possibleExt = [
'jar.pack.xz',
'jar'
@@ -234,9 +237,9 @@ export class ForgeGradle2Adapter extends ForgeResolver {
files.push(tmpFile)
}
console.debug('Spawning PackXZExtract.')
ForgeGradle2Adapter.logger.debug('Spawning PackXZExtract.')
await PackXZExtractWrapper.extractUnpack(files)
console.debug('All files extracted, calculating hashes..')
ForgeGradle2Adapter.logger.debug('All files extracted, calculating hashes..')
for (const entry of processingQueue) {
const tmpFileName = basename(entry.localPath)
@@ -248,7 +251,7 @@ export class ForgeGradle2Adapter extends ForgeResolver {
})
}
console.debug('Complete, removing temp directory..')
ForgeGradle2Adapter.logger.debug('Complete, removing temp directory..')
await remove(tempDir)

View File

@@ -1,6 +1,7 @@
import AdmZip from 'adm-zip'
import { ForgeResolver } from '../forge.resolver'
import { MinecraftVersion } from '../../../util/MinecraftVersion'
import { LoggerUtil } from '../../../util/LoggerUtil'
import { VersionUtil } from '../../../util/versionutil'
import { Module, Type } from 'helios-distribution-types'
import { LibRepoStructure } from '../../../model/struct/repo/librepo.struct'
@@ -23,6 +24,8 @@ interface GeneratedFile {
export class ForgeGradle3Adapter extends ForgeResolver {
private static readonly logger = LoggerUtil.getLogger('FG3 Adapter')
private static readonly WILDCARD_MCP_VERSION = '${mcpVersion}'
public static isForVersion(version: MinecraftVersion, libraryVersion: string): boolean {
@@ -133,9 +136,9 @@ export class ForgeGradle3Adapter extends ForgeResolver {
// Get Installer
const installerPath = libRepo.getLocalForge(this.artifactVersion, 'installer')
console.debug(`Checking for forge installer at ${installerPath}..`)
ForgeGradle3Adapter.logger.debug(`Checking for forge installer at ${installerPath}..`)
if (!await libRepo.artifactExists(installerPath)) {
console.debug('Forge installer not found locally, initializing download..')
ForgeGradle3Adapter.logger.debug('Forge installer not found locally, initializing download..')
await libRepo.downloadArtifactByComponents(
this.REMOTE_REPOSITORY,
LibRepoStructure.FORGE_GROUP,
@@ -143,9 +146,9 @@ export class ForgeGradle3Adapter extends ForgeResolver {
this.artifactVersion, 'installer', 'jar'
)
} else {
console.debug('Using locally discovered forge installer.')
ForgeGradle3Adapter.logger.debug('Using locally discovered forge installer.')
}
console.debug(`Beginning processing of Forge v${this.forgeVersion} (Minecraft ${this.minecraftVersion})`)
ForgeGradle3Adapter.logger.debug(`Beginning processing of Forge v${this.forgeVersion} (Minecraft ${this.minecraftVersion})`)
if(this.generatedFiles != null && this.generatedFiles.length > 0) {
// Run installer
@@ -173,28 +176,28 @@ export class ForgeGradle3Adapter extends ForgeResolver {
// Required for the installer to function.
await writeFile(join(workDir, 'launcher_profiles.json'), JSON.stringify({}))
console.debug('Spawning forge installer')
ForgeGradle3Adapter.logger.debug('Spawning forge installer')
console.log('============== [ IMPORTANT ] ==============')
console.log('When the installer opens please set the client installation directory to:')
console.log(workDir)
console.log('===========================================')
ForgeGradle3Adapter.logger.info('============== [ IMPORTANT ] ==============')
ForgeGradle3Adapter.logger.info('When the installer opens please set the client installation directory to:')
ForgeGradle3Adapter.logger.info(workDir)
ForgeGradle3Adapter.logger.info('===========================================')
await this.executeInstaller(workingInstaller)
console.debug('Installer finished, beginning processing..')
ForgeGradle3Adapter.logger.debug('Installer finished, beginning processing..')
console.debug('Processing Version Manifest')
ForgeGradle3Adapter.logger.debug('Processing Version Manifest')
const versionManifestTuple = await this.processVersionManifest()
const versionManifest = versionManifestTuple[0] as VersionManifestFG3
console.debug('Processing generated forge files.')
ForgeGradle3Adapter.logger.debug('Processing generated forge files.')
const forgeModule = await this.processForgeModule(versionManifest)
// Attach version.json module.
forgeModule.subModules?.unshift(versionManifestTuple[1] as Module)
console.debug('Processing Libraries')
ForgeGradle3Adapter.logger.debug('Processing Libraries')
const libs = await this.processLibraries(versionManifest)
forgeModule.subModules = forgeModule.subModules?.concat(libs)
@@ -388,16 +391,22 @@ export class ForgeGradle3Adapter extends ForgeResolver {
private executeInstaller(installerExec: string): Promise<void> {
return new Promise(resolve => {
const fiLogger = LoggerUtil.getLogger('Forge Installer')
const child = spawn(JavaUtil.getJavaExecutable(), [
'-jar',
installerExec
], {
cwd: dirname(installerExec)
})
child.stdout.on('data', (data) => console.log('[Forge Installer]', data.toString('utf8').trim()))
child.stderr.on('data', (data) => console.error('[Forge Installer]', data.toString('utf8').trim()))
child.stdout.on('data', (data) => fiLogger.info(data.toString('utf8').trim()))
child.stderr.on('data', (data) => fiLogger.error(data.toString('utf8').trim()))
child.on('close', code => {
console.log('[Forge Installer]', 'Exited with code', code)
if(code === 0) {
fiLogger.info('Exited with code', code)
} else {
fiLogger.error('Exited with code', code)
}
resolve()
})
})
@@ -445,7 +454,7 @@ export class ForgeGradle3Adapter extends ForgeResolver {
const libRepo = this.repoStructure.getLibRepoStruct()
const universalLocalPath = libRepo.getLocalForge(this.artifactVersion, 'universal')
console.debug(`Checking for Forge Universal jar at ${universalLocalPath}..`)
ForgeGradle3Adapter.logger.debug(`Checking for Forge Universal jar at ${universalLocalPath}..`)
const forgeMdl = versionManifest.libraries.find(val => val.name.startsWith('net.minecraftforge:forge:'))
@@ -460,14 +469,14 @@ export class ForgeGradle3Adapter extends ForgeResolver {
const localUniBuf = await readFile(universalLocalPath)
const sha1 = createHash('sha1').update(localUniBuf).digest('hex')
if(sha1 !== forgeMdl.downloads.artifact.sha1) {
console.debug('SHA-1 of local universal jar does not match version.json entry.')
console.debug('Redownloading Forge Universal jar..')
ForgeGradle3Adapter.logger.debug('SHA-1 of local universal jar does not match version.json entry.')
ForgeGradle3Adapter.logger.debug('Redownloading Forge Universal jar..')
} else {
console.debug('Using locally discovered forge.')
ForgeGradle3Adapter.logger.debug('Using locally discovered forge.')
forgeUniversalBuffer = localUniBuf
}
} else {
console.debug('Forge Universal jar not found locally, initializing download..')
ForgeGradle3Adapter.logger.debug('Forge Universal jar not found locally, initializing download..')
}
// Download if local is missing or corrupt
@@ -480,7 +489,7 @@ export class ForgeGradle3Adapter extends ForgeResolver {
forgeUniversalBuffer = await readFile(universalLocalPath)
}
console.debug(`Beginning processing of Forge v${this.forgeVersion} (Minecraft ${this.minecraftVersion})`)
ForgeGradle3Adapter.logger.debug(`Beginning processing of Forge v${this.forgeVersion} (Minecraft ${this.minecraftVersion})`)
const forgeModule: Module = {
id: MavenUtil.mavenComponentsToIdentifier(
@@ -521,7 +530,7 @@ export class ForgeGradle3Adapter extends ForgeResolver {
// We've already processed forge.
continue
}
console.debug(`Processing ${lib.name}..`)
ForgeGradle3Adapter.logger.debug(`Processing ${lib.name}..`)
const extension = 'jar'
const localPath = libRepo.getArtifactById(lib.name, extension)
@@ -533,11 +542,11 @@ export class ForgeGradle3Adapter extends ForgeResolver {
libBuf = await readFile(localPath)
const sha1 = createHash('sha1').update(libBuf).digest('hex')
if (sha1 !== lib.downloads.artifact.sha1) {
console.debug('Hashes do not match, redownloading..')
ForgeGradle3Adapter.logger.debug('Hashes do not match, redownloading..')
queueDownload = true
}
} else {
console.debug('Not found locally, downloading..')
ForgeGradle3Adapter.logger.debug('Not found locally, downloading..')
queueDownload = true
}
@@ -545,7 +554,7 @@ export class ForgeGradle3Adapter extends ForgeResolver {
await libRepo.downloadArtifactDirect(lib.downloads.artifact.url, lib.downloads.artifact.path)
libBuf = await readFile(localPath)
} else {
console.debug('Using local copy.')
ForgeGradle3Adapter.logger.debug('Using local copy.')
}
const stats = await lstat(localPath)