Propagate baseURL to resolved forge modules.

This commit is contained in:
Daniel Scalzi
2020-01-12 06:20:23 -05:00
parent 21d80fef82
commit 9e420db907
8 changed files with 107 additions and 46 deletions

View File

@@ -17,12 +17,20 @@ Generate a distribution.json for Helios.
Example
```properties
JAVA_EXECUTABLE=C:\Program Files\AdoptOpenJDK\jdk-8.0.222.10-hotspot\bin\java.exe
ROOT=D:\TestRoot2
BASE_URL=http://localhost:8080/
```
## Usage
Nebula is not complete. The following usage is tentative.
#### Notes
Rather than updating the entire usage with minor changes, please read these notes.
* Root and BaseUrl options are currently disabled. This information is being pulled from the `.env` for now.
## Commands
Commands will be documented here. You can run any command with the `--help` option to view more information.

View File

@@ -10,40 +10,57 @@ import { ResolverRegistry } from './resolver/ResolverRegistry'
dotenv.config()
function rootOption(yargs: yargs.Argv) {
return yargs.option('root', {
describe: 'File structure root.',
type: 'string',
demandOption: true,
global: true
})
.coerce({
root: resolvePath
})
function getRoot() {
return resolvePath(process.env.ROOT as string)
}
function baseUrlOption(yargs: yargs.Argv) {
return yargs.option('baseUrl', {
describe: 'Base url of your file host.',
type: 'string',
demandOption: true,
global: true
})
.coerce({
baseUrl: (arg: string) => {
function getBaseURL() {
let baseUrl = process.env.BASE_URL as string
// Users must provide protocol in all other instances.
if (arg.indexOf('//') === -1) {
if (arg.toLowerCase().startsWith('localhost')) {
arg = 'http://' + arg
if (baseUrl.indexOf('//') === -1) {
if (baseUrl.toLowerCase().startsWith('localhost')) {
baseUrl = 'http://' + baseUrl
} else {
throw new TypeError('Please provide a URL protocol (ex. http:// or https://)')
}
}
return (new URL(arg)).toString()
}
})
return (new URL(baseUrl)).toString()
}
// function rootOption(yargs: yargs.Argv) {
// return yargs.option('root', {
// describe: 'File structure root.',
// type: 'string',
// demandOption: true,
// global: true
// })
// .coerce({
// root: resolvePath
// })
// }
// function baseUrlOption(yargs: yargs.Argv) {
// return yargs.option('baseUrl', {
// describe: 'Base url of your file host.',
// type: 'string',
// demandOption: true,
// global: true
// })
// .coerce({
// baseUrl: (arg: string) => {
// // Users must provide protocol in all other instances.
// if (arg.indexOf('//') === -1) {
// if (arg.toLowerCase().startsWith('localhost')) {
// arg = 'http://' + arg
// } else {
// throw new TypeError('Please provide a URL protocol (ex. http:// or https://)')
// }
// }
// return (new URL(arg)).toString()
// }
// })
// }
function namePositional(yargs: yargs.Argv) {
return yargs.option('name', {
describe: 'Distribution index file name.',
@@ -59,10 +76,12 @@ const initRootCommand: yargs.CommandModule = {
command: 'root',
describe: 'Generate an empty standard file structure.',
builder: (yargs) => {
yargs = rootOption(yargs)
// yargs = rootOption(yargs)
return yargs
},
handler: async (argv) => {
argv.root = getRoot()
console.debug(`Root set to ${argv.root}`)
console.debug('Invoked init root.')
try {
@@ -94,7 +113,7 @@ const generateServerCommand: yargs.CommandModule = {
command: 'server <id> <version>',
describe: 'Generate a new server configuration.',
builder: (yargs) => {
yargs = rootOption(yargs)
// yargs = rootOption(yargs)
return yargs
.positional('id', {
describe: 'Server id.',
@@ -116,6 +135,8 @@ const generateServerCommand: yargs.CommandModule = {
})
},
handler: (argv) => {
argv.root = getRoot()
console.debug(`Root set to ${argv.root}`)
console.debug(`Generating server ${argv.id} for Minecraft ${argv.version}.`,
`\n\t├ Include forge: ${argv.forge}`,
@@ -127,12 +148,15 @@ const generateDistroCommand: yargs.CommandModule = {
command: 'distro [name]',
describe: 'Generate a distribution index from the root file structure.',
builder: (yargs) => {
yargs = rootOption(yargs)
yargs = baseUrlOption(yargs)
// yargs = rootOption(yargs)
// yargs = baseUrlOption(yargs)
yargs = namePositional(yargs)
return yargs
},
handler: async (argv) => {
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.`)
@@ -181,7 +205,7 @@ const testCommand: yargs.CommandModule = {
handler: async (argv) => {
console.debug(`Invoked test with mcVer ${argv.mcVer} forgeVer ${argv.forgeVer}`)
console.log(process.cwd())
const resolver = ResolverRegistry.getForgeResolver('1.12.2', '14.23.5.2847', 'D:/TestRoot2', 'D:/TestRoot2')
const resolver = ResolverRegistry.getForgeResolver('1.12.2', '14.23.5.2847', getRoot(), '', getBaseURL())
if (resolver != null) {
const mdl = await resolver.getModule()
console.log(inspect(mdl, false, null, true))

View File

@@ -1,6 +1,6 @@
import axios from 'axios'
import { createWriteStream, mkdirs, pathExists } from 'fs-extra'
import { dirname, resolve } from 'path'
import { dirname, join, resolve } from 'path'
import { resolve as resolveURL } from 'url'
import { MavenUtil } from '../../../util/maven'
import { BaseFileStructure } from '../BaseFileStructure'
@@ -26,6 +26,12 @@ export abstract class BaseMavenRepo extends BaseFileStructure {
MavenUtil.mavenComponentsToString(group, artifact, version, classifier, extension))
}
public getArtifactUrlByComponents(baseURL: string, group: string, artifact: string, version: string,
classifier?: string, extension = 'jar'): string {
return resolveURL(baseURL, join(this.relativeRoot,
MavenUtil.mavenComponentsToString(group, artifact, version, classifier, extension)))
}
public async artifactExists(path: string) {
return pathExists(path)
}

View File

@@ -12,10 +12,12 @@ export class ResolverRegistry {
public static getForgeResolver(
minecraftVersion: string,
forgeVersion: string,
absoluteRoot: string, relativeRoot: string): ForgeResolver | undefined {
absoluteRoot: string,
relativeRoot: string,
baseURL: string): ForgeResolver | undefined {
for (const impl of ResolverRegistry.FORGE_ADAPTER_IMPL) {
if (impl.isForVersion(minecraftVersion)) {
return new impl(absoluteRoot, relativeRoot, minecraftVersion, forgeVersion)
return new impl(absoluteRoot, relativeRoot, baseURL, minecraftVersion, forgeVersion)
}
}
}

View File

@@ -14,7 +14,8 @@ export abstract class BaseResolver implements Resolver {
constructor(
protected absoluteRoot: string,
protected relativeRoot: string
protected relativeRoot: string,
protected baseUrl: string
) {}
public abstract getModule(): Promise<Module>

View File

@@ -10,10 +10,11 @@ export class Forge113Adapter extends ForgeResolver {
constructor(
absoluteRoot: string,
relativeRoot: string,
baseUrl: string,
minecraftVersion: string,
forgeVersion: string
) {
super(absoluteRoot, relativeRoot, minecraftVersion, forgeVersion)
super(absoluteRoot, relativeRoot, baseUrl, minecraftVersion, forgeVersion)
}
public async getModule(): Promise<Module> {

View File

@@ -20,10 +20,11 @@ export class Forge18Adapter extends ForgeResolver {
constructor(
absoluteRoot: string,
relativeRoot: string,
baseUrl: string,
minecraftVersion: string,
forgeVersion: string
) {
super(absoluteRoot, relativeRoot, minecraftVersion, forgeVersion)
super(absoluteRoot, relativeRoot, baseUrl, minecraftVersion, forgeVersion)
}
public async getModule(): Promise<Module> {
@@ -78,7 +79,16 @@ export class Forge18Adapter extends ForgeResolver {
),
name: 'Minecraft Forge',
type: Type.ForgeHosted,
artifact: this.generateArtifact(forgeUniversalBuffer, await lstat(targetLocalPath)),
artifact: this.generateArtifact(
forgeUniversalBuffer,
await lstat(targetLocalPath),
forgeRepo.getArtifactUrlByComponents(
this.baseUrl,
ForgeRepoStructure.FORGE_GROUP,
ForgeRepoStructure.FORGE_ARTIFACT,
artifactVersion, 'universal'
)
),
subModules: []
}
@@ -136,7 +146,15 @@ export class Forge18Adapter extends ForgeResolver {
id: properId,
name: `Minecraft Forge (${mavenComponents?.artifact})`,
type: Type.Library,
artifact: this.generateArtifact(libBuf as Buffer, stats)
artifact: this.generateArtifact(
libBuf as Buffer,
stats,
libRepo.getArtifactUrlByComponents(
this.baseUrl,
mavenComponents.group, mavenComponents.artifact,
mavenComponents.version, mavenComponents.classifier, extension
)
)
})
if (postProcess) {
@@ -160,11 +178,11 @@ export class Forge18Adapter extends ForgeResolver {
return forgeModule
}
private generateArtifact(buf: Buffer, stats: Stats): Artifact {
private generateArtifact(buf: Buffer, stats: Stats, url: string): Artifact {
return {
size: stats.size,
MD5: createHash('md5').update(buf).digest('hex'),
url: 'TODO'
url
}
}
@@ -194,7 +212,7 @@ export class Forge18Adapter extends ForgeResolver {
console.debug('Spawning PackXZExtract.')
await PackXZExtractWrapper.extractUnpack(files)
console.debug('All filex extracted, calculating hashes..')
console.debug('All files extracted, calculating hashes..')
for (const entry of processingQueue) {
const tmpFileName = basename(entry.localPath)

View File

@@ -10,10 +10,11 @@ export abstract class ForgeResolver extends BaseResolver {
constructor(
absoluteRoot: string,
relativeRoot: string,
baseUrl: string,
protected minecraftVersion: string,
protected forgeVersion: string
) {
super(absoluteRoot, relativeRoot)
super(absoluteRoot, relativeRoot, baseUrl)
this.repoStructure = new RepoStructure(absoluteRoot, relativeRoot)
}