Externalize spec typings, use eslint.

Tslint is deprecated, as such we have moved to eslint. Linted the project with more
stringent rules. The configuration will be changed as we figure out which rules we
should keep.
This commit is contained in:
Daniel Scalzi
2020-01-24 19:27:20 -05:00
parent 8911f54039
commit 064a664687
40 changed files with 2121 additions and 493 deletions

View File

@@ -1,4 +1,4 @@
import { Module } from '../model/spec/module'
import { Module } from 'helios-distribution-types'
import { VersionSegmented } from '../util/VersionSegmented'
import { Resolver } from './resolver'

View File

@@ -1,9 +1,8 @@
import { spawn } from 'child_process'
import { copy, lstat, mkdirs, move, pathExists, readFile, remove, writeFile } from 'fs-extra'
import { Module, Type } from 'helios-distribution-types'
import { basename, dirname, join } from 'path'
import { VersionManifest113 } from '../../../model/forge/versionmanifest113'
import { Module } from '../../../model/spec/module'
import { Type } from '../../../model/spec/type'
import { LibRepoStructure } from '../../../model/struct/repo/librepo.struct'
import { JavaUtil } from '../../../util/javautil'
import { MavenUtil } from '../../../util/maven'
@@ -12,7 +11,7 @@ import { ForgeResolver } from '../forge.resolver'
export class Forge113Adapter extends ForgeResolver {
public static isForVersion(version: string) {
public static isForVersion(version: string): boolean {
return VersionUtil.isVersionAcceptable(version, [13, 14, 15])
}
@@ -34,12 +33,12 @@ export class Forge113Adapter extends ForgeResolver {
return Forge113Adapter.isForVersion(version)
}
private async process() {
private async process(): Promise<Module> {
const libRepo = this.repoStructure.getLibRepoStruct()
const installerPath = libRepo.getLocalForge(this.artifactVersion, 'installer')
console.debug(`Checking for forge installer at ${installerPath}..`)
if (!await libRepo.artifactExists(installerPath)) {
console.debug(`Forge installer not found locally, initializing download..`)
console.debug('Forge installer not found locally, initializing download..')
await libRepo.downloadArtifactByComponents(
this.REMOTE_REPOSITORY,
LibRepoStructure.FORGE_GROUP,
@@ -65,7 +64,7 @@ export class Forge113Adapter extends ForgeResolver {
// Required for the installer to function.
await writeFile(join(workDir, 'launcher_profiles.json'), JSON.stringify({}))
console.debug(`Spawning forge installer`)
console.debug('Spawning forge installer')
console.log('============== [ IMPORTANT ] ==============')
console.log('When the installer opens please set the client installation directory to:')
@@ -96,7 +95,7 @@ export class Forge113Adapter extends ForgeResolver {
return forgeModule
}
private async processLibraries(manifest: VersionManifest113) {
private async processLibraries(manifest: VersionManifest113): Promise<Module[]> {
const libDir = join(this.repoStructure.getWorkDirectory(), 'libraries')
const libRepo = this.repoStructure.getLibRepoStruct()
@@ -150,7 +149,7 @@ export class Forge113Adapter extends ForgeResolver {
}
private async processForgeModule(versionManifest: VersionManifest113) {
private async processForgeModule(versionManifest: VersionManifest113): Promise<Module> {
const libDir = join(this.repoStructure.getWorkDirectory(), 'libraries')
const mcpVersion = this.getMCPVersion(versionManifest.arguments.game)
@@ -267,7 +266,7 @@ export class Forge113Adapter extends ForgeResolver {
return forgeModule
}
private async processVersionManifest() {
private async processVersionManifest(): Promise<[VersionManifest113, Module]> {
const workDir = this.repoStructure.getWorkDirectory()
const versionRepo = this.repoStructure.getVersionRepoStruct()
const versionName = versionRepo.getFileName(this.minecraftVersion, this.forgeVersion)
@@ -297,8 +296,8 @@ export class Forge113Adapter extends ForgeResolver {
return [versionManifest, versionManifestModule]
}
private executeInstaller(installerExec: string) {
return new Promise((resolve, reject) => {
private executeInstaller(installerExec: string): Promise<void> {
return new Promise(resolve => {
const child = spawn(JavaUtil.getJavaExecutable(), [
'-jar',
installerExec
@@ -307,14 +306,14 @@ export class Forge113Adapter extends ForgeResolver {
})
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.on('close', (code, signal) => {
child.on('close', code => {
console.log('[Forge Installer]', 'Exited with code', code)
resolve()
})
})
}
private getMCPVersion(args: string[]) {
private getMCPVersion(args: string[]): string | null {
for (let i = 0; i < args.length; i++) {
if (args[i] === '--fml.mcpVersion') {
return args[i + 1]

View File

@@ -1,10 +1,9 @@
import AdmZip from 'adm-zip'
import { createHash } from 'crypto'
import { copy, lstat, mkdirs, pathExists, readFile, remove } from 'fs-extra'
import { Module, Type } from 'helios-distribution-types'
import { basename, join } from 'path'
import { VersionManifest17 } from '../../../model/forge/versionmanifest17'
import { Module } from '../../../model/spec/module'
import { Type } from '../../../model/spec/type'
import { LibRepoStructure } from '../../../model/struct/repo/librepo.struct'
import { MavenUtil } from '../../../util/maven'
import { PackXZExtractWrapper } from '../../../util/PackXZExtractWrapper'
@@ -13,7 +12,7 @@ import { ForgeResolver } from '../forge.resolver'
export class Forge17Adapter extends ForgeResolver {
public static isForVersion(version: string) {
public static isForVersion(version: string): boolean {
return VersionUtil.isVersionAcceptable(version, [7, 8, 9, 10, 11, 12])
}
@@ -31,16 +30,16 @@ export class Forge17Adapter extends ForgeResolver {
return this.getForgeByVersion()
}
public isForVersion(version: string) {
public isForVersion(version: string): boolean {
return Forge17Adapter.isForVersion(version)
}
public async getForgeByVersion() {
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}..`)
if (!await libRepo.artifactExists(targetLocalPath)) {
console.debug(`Forge not found locally, initializing download..`)
console.debug('Forge not found locally, initializing download..')
await libRepo.downloadArtifactByComponents(
this.REMOTE_REPOSITORY,
LibRepoStructure.FORGE_GROUP,
@@ -121,7 +120,7 @@ export class Forge17Adapter extends ForgeResolver {
}
}
} else {
console.debug(`Not found locally, downloading..`)
console.debug('Not found locally, downloading..')
queueDownload = true
}
@@ -176,12 +175,13 @@ export class Forge17Adapter extends ForgeResolver {
return forgeModule
}
private determineExtension(checksums: string[] | undefined) {
private determineExtension(checksums: string[] | undefined): string {
return checksums != null && checksums.length > 1 ? 'jar.pack.xz' : 'jar'
}
private async processPackXZFiles(
processingQueue: Array<{id: string, localPath: string}>): Promise<Array<{id: string, MD5: string}>> {
processingQueue: Array<{id: string, localPath: string}>
): Promise<Array<{id: string, MD5: string}>> {
const accumulator = []

View File

@@ -1,6 +1,6 @@
import { createHash } from 'crypto'
import { Stats } from 'fs-extra'
import { Artifact } from '../../model/spec/artifact'
import { Artifact } from 'helios-distribution-types'
import { RepoStructure } from '../../model/struct/repo/repo.struct'
import { BaseResolver } from '../baseresolver'
@@ -25,7 +25,7 @@ export abstract class ForgeResolver extends BaseResolver {
// Coverage is not 100% but that doesnt matter.
// It's enough and you should always use the latest version anyway.
public inferArtifactVersion() {
public inferArtifactVersion(): string {
const version = `${this.minecraftVersion}-${this.forgeVersion}`
const ver = this.forgeVersion.split('.')

View File

@@ -1,4 +1,4 @@
import { Module } from '../model/spec/module'
import { Module } from 'helios-distribution-types'
export interface Resolver {