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:
@@ -4,24 +4,24 @@ import { JavaUtil } from './javautil'
|
||||
|
||||
export class PackXZExtractWrapper {
|
||||
|
||||
public static getPackXZExtract() {
|
||||
public static getPackXZExtract(): string {
|
||||
return join(process.cwd(), 'libraries', 'java', 'PackXZExtract.jar')
|
||||
}
|
||||
|
||||
public static extractUnpack(paths: string[]) {
|
||||
public static extractUnpack(paths: string[]): Promise<void> {
|
||||
return PackXZExtractWrapper.execute('-packxz', paths)
|
||||
}
|
||||
|
||||
public static extract(paths: string[]) {
|
||||
public static extract(paths: string[]): Promise<void> {
|
||||
return PackXZExtractWrapper.execute('-xz', paths)
|
||||
}
|
||||
|
||||
public static unpack(paths: string[]) {
|
||||
public static unpack(paths: string[]): Promise<void> {
|
||||
return PackXZExtractWrapper.execute('-pack', paths)
|
||||
}
|
||||
|
||||
private static execute(command: string, paths: string[]) {
|
||||
return new Promise((resolve, reject) => {
|
||||
private static execute(command: string, paths: string[]): Promise<void> {
|
||||
return new Promise(resolve => {
|
||||
const child = spawn(JavaUtil.getJavaExecutable(), [
|
||||
'-jar',
|
||||
PackXZExtractWrapper.getPackXZExtract(),
|
||||
@@ -30,7 +30,7 @@ export class PackXZExtractWrapper {
|
||||
])
|
||||
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.on('close', (code, signal) => {
|
||||
child.on('close', code => {
|
||||
console.log('[PackXZExtract]', 'Exited with code', code)
|
||||
resolve()
|
||||
})
|
||||
|
||||
@@ -2,6 +2,8 @@ import { ForgeModStructure113 } from '../model/struct/model/module/forgemod/forg
|
||||
import { ForgeModStructure17 } from '../model/struct/model/module/forgemod/forgemod17.struct'
|
||||
import { Forge113Adapter } from '../resolver/forge/adapter/forge113.resolver'
|
||||
import { Forge17Adapter } from '../resolver/forge/adapter/forge17.resolver'
|
||||
import { ForgeResolver } from '../resolver/forge/forge.resolver'
|
||||
import { BaseForgeModStructure } from '../model/struct/model/module/forgemod.struct'
|
||||
|
||||
export class VersionSegmentedRegistry {
|
||||
|
||||
@@ -20,7 +22,8 @@ export class VersionSegmentedRegistry {
|
||||
forgeVersion: string,
|
||||
absoluteRoot: string,
|
||||
relativeRoot: string,
|
||||
baseURL: string) {
|
||||
baseURL: string
|
||||
): ForgeResolver {
|
||||
for (const impl of VersionSegmentedRegistry.FORGE_ADAPTER_IMPL) {
|
||||
if (impl.isForVersion(minecraftVersion)) {
|
||||
return new impl(absoluteRoot, relativeRoot, baseURL, minecraftVersion, forgeVersion)
|
||||
@@ -34,7 +37,7 @@ export class VersionSegmentedRegistry {
|
||||
absoluteRoot: string,
|
||||
relativeRoot: string,
|
||||
baseUrl: string
|
||||
) {
|
||||
): BaseForgeModStructure {
|
||||
for (const impl of VersionSegmentedRegistry.FORGEMOD_STRUCT_IML) {
|
||||
if (impl.isForVersion(minecraftVersion)) {
|
||||
return new impl(absoluteRoot, relativeRoot, baseUrl)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export class JavaUtil {
|
||||
|
||||
public static getJavaExecutable() {
|
||||
public static getJavaExecutable(): string {
|
||||
return process.env.JAVA_EXECUTABLE as string
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,13 @@ export class MavenUtil {
|
||||
public static readonly ID_REGEX = /(.+):(.+):([^@]+)()(?:@{1}(.+)$)?/
|
||||
public static readonly ID_REGEX_WITH_CLASSIFIER = /(.+):(.+):(?:([^@]+)(?:-([a-zA-Z]+)))(?:@{1}(.+)$)?/
|
||||
|
||||
public static mavenComponentsToIdentifier(group: string, artifact: string, version: string,
|
||||
classifier?: string, extension?: string) {
|
||||
public static mavenComponentsToIdentifier(
|
||||
group: string,
|
||||
artifact: string,
|
||||
version: string,
|
||||
classifier?: string,
|
||||
extension?: string
|
||||
): string {
|
||||
return `${group}:${artifact}:${version}${classifier != null ? `:${classifier}` : ''}${extension != null ? `@${extension}` : ''}`
|
||||
}
|
||||
|
||||
@@ -15,7 +20,13 @@ export class MavenUtil {
|
||||
return MavenUtil.ID_REGEX.test(id) || MavenUtil.ID_REGEX_WITH_CLASSIFIER.test(id)
|
||||
}
|
||||
|
||||
public static getMavenComponents(id: string, extension = 'jar') {
|
||||
public static getMavenComponents(id: string, extension = 'jar'): {
|
||||
group: string
|
||||
artifact: string
|
||||
version: string
|
||||
classifier?: string
|
||||
extension: string
|
||||
} {
|
||||
if (!MavenUtil.isMavenIdentifier(id)) {
|
||||
throw new Error('Id is not a maven identifier.')
|
||||
}
|
||||
@@ -41,39 +52,37 @@ export class MavenUtil {
|
||||
throw new Error('Failed to process maven data.')
|
||||
}
|
||||
|
||||
public static mavenIdentifierToString(id: string, extension = 'jar') {
|
||||
public static mavenIdentifierToString(id: string, extension = 'jar'): string {
|
||||
const tmp = MavenUtil.getMavenComponents(id, extension)
|
||||
|
||||
if (tmp != null) {
|
||||
return MavenUtil.mavenComponentsToString(tmp.group, tmp.artifact, tmp.version,
|
||||
tmp.classifier, tmp.extension)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
return MavenUtil.mavenComponentsToString(
|
||||
tmp.group, tmp.artifact, tmp.version, tmp.classifier, tmp.extension
|
||||
)
|
||||
}
|
||||
|
||||
public static mavenComponentsToString(group: string, artifact: string, version: string,
|
||||
classifier?: string, extension = 'jar') {
|
||||
public static mavenComponentsToString(
|
||||
group: string, artifact: string, version: string, classifier?: string, extension = 'jar'
|
||||
): string {
|
||||
return `${group.replace(/\./g, '/')}/${artifact}/${version}/${artifact}-${version}${classifier != null ? `-${classifier}` : ''}.${extension}`
|
||||
}
|
||||
|
||||
public static mavenIdentifierToUrl(id: string, extension = 'jar') {
|
||||
const res = MavenUtil.mavenIdentifierToString(id, extension)
|
||||
return res == null ? null : new URL(res)
|
||||
public static mavenIdentifierToUrl(id: string, extension = 'jar'): URL {
|
||||
return new URL(MavenUtil.mavenIdentifierToString(id, extension))
|
||||
}
|
||||
|
||||
public static mavenComponentsToUrl(group: string, artifact: string, version: string,
|
||||
classifier?: string, extension = 'jar') {
|
||||
public static mavenComponentsToUrl(
|
||||
group: string, artifact: string, version: string, classifier?: string, extension = 'jar'
|
||||
): URL {
|
||||
return new URL(MavenUtil.mavenComponentsToString(group, artifact, version, classifier, extension))
|
||||
}
|
||||
|
||||
public static mavenIdentifierToPath(id: string, extension = 'jar') {
|
||||
const res = MavenUtil.mavenIdentifierToString(id, extension)
|
||||
return res == null ? null : normalize(res)
|
||||
public static mavenIdentifierToPath(id: string, extension = 'jar'): string {
|
||||
return normalize(MavenUtil.mavenIdentifierToString(id, extension))
|
||||
}
|
||||
|
||||
public static mavenComponentsToPath(group: string, artifact: string, version: string,
|
||||
classifier?: string, extension = 'jar') {
|
||||
public static mavenComponentsToPath(
|
||||
group: string, artifact: string, version: string, classifier?: string, extension = 'jar'
|
||||
): string {
|
||||
return normalize(MavenUtil.mavenComponentsToString(group, artifact, version, classifier, extension))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export function capitalize(str: string) {
|
||||
export function capitalize(str: string): string {
|
||||
if (!str) {
|
||||
return str
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ export class VersionUtil {
|
||||
|
||||
public static readonly MINECRAFT_VERSION_REGEX = /(\d+).(\d+).(\d+)/
|
||||
|
||||
public static isMinecraftVersion(version: string) {
|
||||
public static isMinecraftVersion(version: string): boolean {
|
||||
return VersionUtil.MINECRAFT_VERSION_REGEX.test(version)
|
||||
}
|
||||
|
||||
public static getMinecraftVersionComponents(version: string) {
|
||||
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) {
|
||||
@@ -36,11 +36,11 @@ export class VersionUtil {
|
||||
return false
|
||||
}
|
||||
|
||||
public static isPromotionVersion(version: string) {
|
||||
public static isPromotionVersion(version: string): boolean {
|
||||
return VersionUtil.PROMOTION_TYPE.indexOf(version.toLowerCase()) > -1
|
||||
}
|
||||
|
||||
public static async getPromotionIndex() {
|
||||
public static async getPromotionIndex(): Promise<PromotionsSlim> {
|
||||
const response = await Axios({
|
||||
method: 'get',
|
||||
url: 'https://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json',
|
||||
@@ -49,18 +49,18 @@ export class VersionUtil {
|
||||
return response.data as PromotionsSlim
|
||||
}
|
||||
|
||||
public static getPromotedVersionStrict(index: PromotionsSlim, minecraftVersion: string, promotion: string) {
|
||||
public static getPromotedVersionStrict(index: PromotionsSlim, minecraftVersion: string, promotion: string): string {
|
||||
const workingPromotion = promotion.toLowerCase()
|
||||
return index.promos[`${minecraftVersion}-${workingPromotion}`]
|
||||
}
|
||||
|
||||
public static async getPromotedForgeVersion(minecraftVersion: string, promotion: string) {
|
||||
public static async getPromotedForgeVersion(minecraftVersion: string, promotion: string): Promise<string> {
|
||||
const workingPromotion = promotion.toLowerCase()
|
||||
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.`)
|
||||
console.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}.`)
|
||||
|
||||
Reference in New Issue
Block a user