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,9 +10,12 @@ import { ServerStructure } from './model/struct/model/server.struct'
import { VersionSegmentedRegistry } from './util/VersionSegmentedRegistry'
import { VersionUtil } from './util/versionutil'
import { MinecraftVersion } from './util/MinecraftVersion'
import { LoggerUtil } from './util/LoggerUtil'
dotenv.config()
const logger = LoggerUtil.getLogger('Index')
function getRoot(): string {
return resolvePath(process.env.ROOT as string)
}
@@ -86,13 +89,13 @@ const initRootCommand: yargs.CommandModule = {
handler: async (argv) => {
argv.root = getRoot()
console.debug(`Root set to ${argv.root}`)
console.debug('Invoked init root.')
logger.debug(`Root set to ${argv.root}`)
logger.debug('Invoked init root.')
try {
await new DistributionStructure(argv.root as string, '').init()
console.log(`Successfully created new root at ${argv.root}`)
logger.info(`Successfully created new root at ${argv.root}`)
} catch (error) {
console.error(`Failed to init new root at ${argv.root}`, error)
logger.error(`Failed to init new root at ${argv.root}`, error)
}
}
}
@@ -141,8 +144,8 @@ const generateServerCommand: yargs.CommandModule = {
handler: async (argv) => {
argv.root = getRoot()
console.debug(`Root set to ${argv.root}`)
console.debug(`Generating server ${argv.id} for Minecraft ${argv.version}.`,
logger.debug(`Root set to ${argv.root}`)
logger.debug(`Generating server ${argv.id} for Minecraft ${argv.version}.`,
`\n\t├ Forge version: ${argv.forge}`,
`\n\t└ LiteLoader version: ${argv.liteloader}`)
@@ -150,9 +153,9 @@ const generateServerCommand: yargs.CommandModule = {
if(argv.forge != null) {
if (VersionUtil.isPromotionVersion(argv.forge as string)) {
console.debug(`Resolving ${argv.forge} Forge Version..`)
logger.debug(`Resolving ${argv.forge} Forge Version..`)
const version = await VersionUtil.getPromotedForgeVersion(minecraftVersion, argv.forge as string)
console.debug(`Forge version set to ${version}`)
logger.debug(`Forge version set to ${version}`)
argv.forge = version
}
}
@@ -183,16 +186,19 @@ const generateDistroCommand: yargs.CommandModule = {
argv.root = getRoot()
argv.baseUrl = getBaseURL()
console.debug(`Root set to ${argv.root}`)
console.debug(`Base Url set to ${argv.baseUrl}`)
console.debug(`Invoked generate distro name ${argv.name}.json.`)
logger.debug(`Root set to ${argv.root}`)
logger.debug(`Base Url set to ${argv.baseUrl}`)
logger.debug(`Invoked generate distro name ${argv.name}.json.`)
try {
const distributionStruct = new DistributionStructure(argv.root as string, argv.baseUrl as string)
const distro = await distributionStruct.getSpecModel()
writeFile(resolvePath(argv.root as string, `${argv.name}.json`), JSON.stringify(distro, null, 2))
console.log(distro)
const distroPath = resolvePath(argv.root as string, `${argv.name}.json`)
writeFile(distroPath, JSON.stringify(distro, null, 2))
logger.info(`Successfully generated ${argv.name}.json`)
logger.info(`Saved to ${distroPath}`)
logger.debug('Preview:\n', distro)
} catch (error) {
console.error(`Failed to generate distribution with root ${argv.root}.`, error)
logger.error(`Failed to generate distribution with root ${argv.root}.`, error)
}
}
}
@@ -218,7 +224,7 @@ const validateCommand: yargs.CommandModule = {
return namePositional(yargs)
},
handler: (argv) => {
console.debug(`Invoked validate with name ${argv.name}.json`)
logger.debug(`Invoked validate with name ${argv.name}.json`)
}
}
@@ -226,11 +232,11 @@ const latestForgeCommand: yargs.CommandModule = {
command: 'latest-forge <version>',
describe: 'Get the latest version of forge.',
handler: async (argv) => {
console.debug(`Invoked latest-forge with version ${argv.version}.`)
logger.debug(`Invoked latest-forge with version ${argv.version}.`)
const minecraftVersion = new MinecraftVersion(argv.version as string)
const forgeVer = await VersionUtil.getPromotedForgeVersion(minecraftVersion, 'latest')
console.log(`Latest version: Forge ${forgeVer} (${argv.version})`)
logger.info(`Latest version: Forge ${forgeVer} (${argv.version})`)
}
}
@@ -238,21 +244,21 @@ const recommendedForgeCommand: yargs.CommandModule = {
command: 'recommended-forge <version>',
describe: 'Get the recommended version of forge. Returns latest if there is no recommended build.',
handler: async (argv) => {
console.debug(`Invoked recommended-forge with version ${argv.version}.`)
logger.debug(`Invoked recommended-forge with version ${argv.version}.`)
const index = await VersionUtil.getPromotionIndex()
const minecraftVersion = new MinecraftVersion(argv.version as string)
let forgeVer = VersionUtil.getPromotedVersionStrict(index, minecraftVersion, 'recommended')
if (forgeVer != null) {
console.log(`Recommended version: Forge ${forgeVer} (${minecraftVersion})`)
logger.info(`Recommended version: Forge ${forgeVer} (${minecraftVersion})`)
} else {
console.log(`No recommended build for ${minecraftVersion}. Checking for latest version..`)
logger.info(`No recommended build for ${minecraftVersion}. Checking for latest version..`)
forgeVer = VersionUtil.getPromotedVersionStrict(index, minecraftVersion, 'latest')
if (forgeVer != null) {
console.log(`Latest version: Forge ${forgeVer} (${minecraftVersion})`)
logger.info(`Latest version: Forge ${forgeVer} (${minecraftVersion})`)
} else {
console.log(`No build available for ${minecraftVersion}.`)
logger.info(`No build available for ${minecraftVersion}.`)
}
}
@@ -266,14 +272,14 @@ const testCommand: yargs.CommandModule = {
return namePositional(yargs)
},
handler: async (argv) => {
console.debug(`Invoked test with mcVer ${argv.mcVer} forgeVer ${argv.forgeVer}`)
console.log(process.cwd())
logger.debug(`Invoked test with mcVer ${argv.mcVer} forgeVer ${argv.forgeVer}`)
logger.info(process.cwd())
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()
console.log(inspect(mdl, false, null, true))
logger.info(inspect(mdl, false, null, true))
}
}
}

View File

@@ -6,9 +6,12 @@ import { VersionUtil } from '../../../../../util/versionutil'
import { ModsToml } from '../../../../forge/modstoml'
import { BaseForgeModStructure } from '../forgemod.struct'
import { MinecraftVersion } from '../../../../../util/MinecraftVersion'
import { LoggerUtil } from '../../../../../util/LoggerUtil'
export class ForgeModStructure113 extends BaseForgeModStructure {
private static readonly logger = LoggerUtil.getLogger('ForgeModStructure (1.13)')
public static readonly IMPLEMENTATION_VERSION_REGEX = /^Implementation-Version: (.+)[\r\n]/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -83,25 +86,25 @@ export class ForgeModStructure113 extends BaseForgeModStructure {
let version = '0.0.0'
const manifest = zip.readAsText('META-INF/MANIFEST.MF')
const keys = manifest.split('\n')
console.log(keys)
ForgeModStructure113.logger.debug(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}`)
ForgeModStructure113.logger.debug(`ForgeMod ${name} contains a version wildcard, inferring ${version}`)
parsed.mods[0].version = version
}
this.forgeModMetadata[name] = parsed
} catch (err) {
console.error(`ForgeMod ${name} contains an invalid mods.toml file.`)
ForgeModStructure113.logger.error(`ForgeMod ${name} contains an invalid mods.toml file.`)
createDefault = true
}
} else {
console.error(`ForgeMod ${name} does not contain mods.toml file.`)
ForgeModStructure113.logger.error(`ForgeMod ${name} does not contain mods.toml file.`)
createDefault = true
}

View File

@@ -6,9 +6,12 @@ import { McModInfo } from '../../../../forge/mcmodinfo'
import { McModInfoList } from '../../../../forge/mcmodinfolist'
import { BaseForgeModStructure } from '../forgemod.struct'
import { MinecraftVersion } from '../../../../../util/MinecraftVersion'
import { LoggerUtil } from '../../../../../util/LoggerUtil'
export class ForgeModStructure17 extends BaseForgeModStructure {
private static readonly logger = LoggerUtil.getLogger('ForgeModStructure (1.7)')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public static isForVersion(version: MinecraftVersion, libraryVersion: string): boolean {
return VersionUtil.isVersionAcceptable(version, [7, 8, 9, 10, 11, 12])
@@ -92,11 +95,11 @@ export class ForgeModStructure17 extends BaseForgeModStructure {
this.forgeModMetadata[name]!.version = '0.0.0'
}
} catch (err) {
console.error(`ForgeMod ${name} contains an invalid mcmod.info file.`)
ForgeModStructure17.logger.error(`ForgeMod ${name} contains an invalid mcmod.info file.`)
createDefault = true
}
} else {
console.error(`ForgeMod ${name} does not contain mcmod.info file.`)
ForgeModStructure17.logger.error(`ForgeMod ${name} does not contain mcmod.info file.`)
createDefault = true
}

View File

@@ -9,9 +9,12 @@ import { MiscFileStructure } from './module/file.struct'
import { LiteModStructure } from './module/litemod.struct'
import { LibraryStructure } from './module/library.struct'
import { MinecraftVersion } from '../../../util/MinecraftVersion'
import { LoggerUtil } from '../../../util/LoggerUtil'
export class ServerStructure extends BaseModelStructure<Server> {
private static readonly logger = LoggerUtil.getLogger('ServerStructure')
private readonly ID_REGEX = /(.+-(.+)$)/
constructor(
@@ -41,7 +44,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
const relativeServerRoot = join(this.relativeRoot, effectiveId)
if (await pathExists(absoluteServerRoot)) {
console.error('Server already exists! Aborting.')
ServerStructure.logger.error('Server already exists! Aborting.')
return
}
@@ -86,8 +89,8 @@ export class ServerStructure extends BaseModelStructure<Server> {
const match = this.ID_REGEX.exec(file)
if (match == null) {
console.warn(`Server directory ${file} does not match the defined standard.`)
console.warn('All server ids must end with -<minecraft version> (ex. -1.12.2)')
ServerStructure.logger.warn(`Server directory ${file} does not match the defined standard.`)
ServerStructure.logger.warn('All server ids must end with -<minecraft version> (ex. -1.12.2)')
continue
}
@@ -103,7 +106,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
}
if (!iconUrl) {
console.warn(`No icon file found for server ${file}.`)
ServerStructure.logger.warn(`No icon file found for server ${file}.`)
iconUrl = '<FILL IN MANUALLY>'
}
@@ -167,7 +170,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
})
} else {
console.warn(`Path ${file} in server directory is not a directory!`)
ServerStructure.logger.warn(`Path ${file} in server directory is not a directory!`)
}
}
return accumulator

View File

@@ -4,9 +4,12 @@ import { dirname, join, resolve } from 'path'
import { resolve as resolveURL } from 'url'
import { MavenUtil } from '../../../util/maven'
import { BaseFileStructure } from '../BaseFileStructure'
import { LoggerUtil } from '../../../util/LoggerUtil'
export abstract class BaseMavenRepo extends BaseFileStructure {
private static readonly logger = LoggerUtil.getLogger('BaseMavenRepo')
constructor(
absoluteRoot: string,
relativeRoot: string,
@@ -54,7 +57,7 @@ export abstract class BaseMavenRepo extends BaseFileStructure {
}
public async downloadArtifactDirect(url: string, path: string): Promise<void> {
console.debug(`Downloading ${url}..`)
BaseMavenRepo.logger.debug(`Downloading ${url}..`)
const response = await axios({
method: 'get',
url,
@@ -67,7 +70,7 @@ export abstract class BaseMavenRepo extends BaseFileStructure {
// tslint:disable-next-line: no-shadowed-variable
return new Promise((resolve, reject) => {
writer.on('finish', () => {
console.debug(`Completed download of ${url}.`)
BaseMavenRepo.logger.debug(`Completed download of ${url}.`)
resolve()
})
writer.on('error', reject)

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)

44
src/util/LoggerUtil.ts Normal file
View File

@@ -0,0 +1,44 @@
import { createLogger, format, transports, Logger } from 'winston'
import { SPLAT } from 'triple-beam'
import moment from 'moment'
import { inspect } from 'util'
export class LoggerUtil {
public static getLogger(label: string): Logger {
return createLogger({
format: format.combine(
format.label(),
format.colorize(),
format.label({ label }),
format.printf(info => {
if(info[SPLAT]) {
if(info[SPLAT].length === 1 && info[SPLAT][0] instanceof Error) {
const err = info[SPLAT][0] as Error
if(info.message.length > err.message.length && info.message.endsWith(err.message)) {
info.message = info.message.substring(0, info.message.length-err.message.length)
}
} else if(info[SPLAT].length > 0) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
info.message += ' ' + info[SPLAT].map((it: any) => {
if(typeof it === 'object' && it != null) {
return inspect(it, false, 4, true)
}
return it
}).join(' ')
}
}
if(typeof info.message === 'object') {
info.message = inspect(info.message, false, 4, true)
}
return `[${moment().format('YYYY-MM-DD hh:mm:ss').trim()}] [${info.level}] [${info.label}]: ${info.message}${info.stack ? `\n${info.stack}` : ''}`
})
),
level: 'debug',
transports: [
new transports.Console()
]
})
}
}

View File

@@ -1,9 +1,12 @@
import { spawn } from 'child_process'
import { join } from 'path'
import { JavaUtil } from './javautil'
import { LoggerUtil } from './LoggerUtil'
export class PackXZExtractWrapper {
private static readonly logger = LoggerUtil.getLogger('PackXZExtract')
public static getPackXZExtract(): string {
return join(process.cwd(), 'libraries', 'java', 'PackXZExtract.jar')
}
@@ -28,14 +31,14 @@ export class PackXZExtractWrapper {
command,
paths.join(',')
])
child.stdout.on('data', (data) => console.log('[PackXZExtract]', data.toString('utf8').trim()))
child.stderr.on('data', (data) => console.error('[PackXZExtract]', data.toString('utf8').trim()))
child.stdout.on('data', (data) => PackXZExtractWrapper.logger.info(data.toString('utf8').trim()))
child.stderr.on('data', (data) => PackXZExtractWrapper.logger.error(data.toString('utf8').trim()))
child.on('close', code => {
console.log('[PackXZExtract]', 'Exited with code', code)
PackXZExtractWrapper.logger.info('Exited with code', code)
resolve()
})
child.on('error', (err) => {
console.log('[PackXZExtract]', 'Error during process execution', err)
PackXZExtractWrapper.logger.info('Error during process execution', err)
reject(err)
})
})

View File

@@ -1,9 +1,12 @@
import Axios from 'axios'
import { PromotionsSlim } from '../model/forge/promotionsslim'
import { MinecraftVersion } from './MinecraftVersion'
import { LoggerUtil } from './LoggerUtil'
export class VersionUtil {
private static readonly logger = LoggerUtil.getLogger('VersionUtil')
public static readonly PROMOTION_TYPE = [
'recommended',
'latest'
@@ -54,8 +57,8 @@ export class VersionUtil {
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.')
VersionUtil.logger.warn(`No ${workingPromotion} version found for Forge ${minecraftVersion}.`)
VersionUtil.logger.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}.`)