Propagate baseURL to resolved forge modules.
This commit is contained in:
@@ -17,12 +17,20 @@ Generate a distribution.json for Helios.
|
|||||||
Example
|
Example
|
||||||
```properties
|
```properties
|
||||||
JAVA_EXECUTABLE=C:\Program Files\AdoptOpenJDK\jdk-8.0.222.10-hotspot\bin\java.exe
|
JAVA_EXECUTABLE=C:\Program Files\AdoptOpenJDK\jdk-8.0.222.10-hotspot\bin\java.exe
|
||||||
|
ROOT=D:\TestRoot2
|
||||||
|
BASE_URL=http://localhost:8080/
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Nebula is not complete. The following usage is tentative.
|
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
|
||||||
|
|
||||||
Commands will be documented here. You can run any command with the `--help` option to view more information.
|
Commands will be documented here. You can run any command with the `--help` option to view more information.
|
||||||
|
|||||||
92
src/index.ts
92
src/index.ts
@@ -10,40 +10,57 @@ import { ResolverRegistry } from './resolver/ResolverRegistry'
|
|||||||
|
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
function rootOption(yargs: yargs.Argv) {
|
function getRoot() {
|
||||||
return yargs.option('root', {
|
return resolvePath(process.env.ROOT as string)
|
||||||
describe: 'File structure root.',
|
|
||||||
type: 'string',
|
|
||||||
demandOption: true,
|
|
||||||
global: true
|
|
||||||
})
|
|
||||||
.coerce({
|
|
||||||
root: resolvePath
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function baseUrlOption(yargs: yargs.Argv) {
|
function getBaseURL() {
|
||||||
return yargs.option('baseUrl', {
|
let baseUrl = process.env.BASE_URL as string
|
||||||
describe: 'Base url of your file host.',
|
// Users must provide protocol in all other instances.
|
||||||
type: 'string',
|
if (baseUrl.indexOf('//') === -1) {
|
||||||
demandOption: true,
|
if (baseUrl.toLowerCase().startsWith('localhost')) {
|
||||||
global: true
|
baseUrl = 'http://' + baseUrl
|
||||||
})
|
} else {
|
||||||
.coerce({
|
throw new TypeError('Please provide a URL protocol (ex. http:// or https://)')
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
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) {
|
function namePositional(yargs: yargs.Argv) {
|
||||||
return yargs.option('name', {
|
return yargs.option('name', {
|
||||||
describe: 'Distribution index file name.',
|
describe: 'Distribution index file name.',
|
||||||
@@ -59,10 +76,12 @@ const initRootCommand: yargs.CommandModule = {
|
|||||||
command: 'root',
|
command: 'root',
|
||||||
describe: 'Generate an empty standard file structure.',
|
describe: 'Generate an empty standard file structure.',
|
||||||
builder: (yargs) => {
|
builder: (yargs) => {
|
||||||
yargs = rootOption(yargs)
|
// yargs = rootOption(yargs)
|
||||||
return yargs
|
return yargs
|
||||||
},
|
},
|
||||||
handler: async (argv) => {
|
handler: async (argv) => {
|
||||||
|
argv.root = getRoot()
|
||||||
|
|
||||||
console.debug(`Root set to ${argv.root}`)
|
console.debug(`Root set to ${argv.root}`)
|
||||||
console.debug('Invoked init root.')
|
console.debug('Invoked init root.')
|
||||||
try {
|
try {
|
||||||
@@ -94,7 +113,7 @@ const generateServerCommand: yargs.CommandModule = {
|
|||||||
command: 'server <id> <version>',
|
command: 'server <id> <version>',
|
||||||
describe: 'Generate a new server configuration.',
|
describe: 'Generate a new server configuration.',
|
||||||
builder: (yargs) => {
|
builder: (yargs) => {
|
||||||
yargs = rootOption(yargs)
|
// yargs = rootOption(yargs)
|
||||||
return yargs
|
return yargs
|
||||||
.positional('id', {
|
.positional('id', {
|
||||||
describe: 'Server id.',
|
describe: 'Server id.',
|
||||||
@@ -116,6 +135,8 @@ const generateServerCommand: yargs.CommandModule = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
handler: (argv) => {
|
handler: (argv) => {
|
||||||
|
argv.root = getRoot()
|
||||||
|
|
||||||
console.debug(`Root set to ${argv.root}`)
|
console.debug(`Root set to ${argv.root}`)
|
||||||
console.debug(`Generating server ${argv.id} for Minecraft ${argv.version}.`,
|
console.debug(`Generating server ${argv.id} for Minecraft ${argv.version}.`,
|
||||||
`\n\t├ Include forge: ${argv.forge}`,
|
`\n\t├ Include forge: ${argv.forge}`,
|
||||||
@@ -127,12 +148,15 @@ const generateDistroCommand: yargs.CommandModule = {
|
|||||||
command: 'distro [name]',
|
command: 'distro [name]',
|
||||||
describe: 'Generate a distribution index from the root file structure.',
|
describe: 'Generate a distribution index from the root file structure.',
|
||||||
builder: (yargs) => {
|
builder: (yargs) => {
|
||||||
yargs = rootOption(yargs)
|
// yargs = rootOption(yargs)
|
||||||
yargs = baseUrlOption(yargs)
|
// yargs = baseUrlOption(yargs)
|
||||||
yargs = namePositional(yargs)
|
yargs = namePositional(yargs)
|
||||||
return yargs
|
return yargs
|
||||||
},
|
},
|
||||||
handler: async (argv) => {
|
handler: async (argv) => {
|
||||||
|
argv.root = getRoot()
|
||||||
|
argv.baseUrl = getBaseURL()
|
||||||
|
|
||||||
console.debug(`Root set to ${argv.root}`)
|
console.debug(`Root set to ${argv.root}`)
|
||||||
console.debug(`Base Url set to ${argv.baseUrl}`)
|
console.debug(`Base Url set to ${argv.baseUrl}`)
|
||||||
console.debug(`Invoked generate distro name ${argv.name}.json.`)
|
console.debug(`Invoked generate distro name ${argv.name}.json.`)
|
||||||
@@ -181,7 +205,7 @@ const testCommand: yargs.CommandModule = {
|
|||||||
handler: async (argv) => {
|
handler: async (argv) => {
|
||||||
console.debug(`Invoked test with mcVer ${argv.mcVer} forgeVer ${argv.forgeVer}`)
|
console.debug(`Invoked test with mcVer ${argv.mcVer} forgeVer ${argv.forgeVer}`)
|
||||||
console.log(process.cwd())
|
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) {
|
if (resolver != null) {
|
||||||
const mdl = await resolver.getModule()
|
const mdl = await resolver.getModule()
|
||||||
console.log(inspect(mdl, false, null, true))
|
console.log(inspect(mdl, false, null, true))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { createWriteStream, mkdirs, pathExists } from 'fs-extra'
|
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 { resolve as resolveURL } from 'url'
|
||||||
import { MavenUtil } from '../../../util/maven'
|
import { MavenUtil } from '../../../util/maven'
|
||||||
import { BaseFileStructure } from '../BaseFileStructure'
|
import { BaseFileStructure } from '../BaseFileStructure'
|
||||||
@@ -26,6 +26,12 @@ export abstract class BaseMavenRepo extends BaseFileStructure {
|
|||||||
MavenUtil.mavenComponentsToString(group, artifact, version, classifier, extension))
|
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) {
|
public async artifactExists(path: string) {
|
||||||
return pathExists(path)
|
return pathExists(path)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,12 @@ export class ResolverRegistry {
|
|||||||
public static getForgeResolver(
|
public static getForgeResolver(
|
||||||
minecraftVersion: string,
|
minecraftVersion: string,
|
||||||
forgeVersion: 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) {
|
for (const impl of ResolverRegistry.FORGE_ADAPTER_IMPL) {
|
||||||
if (impl.isForVersion(minecraftVersion)) {
|
if (impl.isForVersion(minecraftVersion)) {
|
||||||
return new impl(absoluteRoot, relativeRoot, minecraftVersion, forgeVersion)
|
return new impl(absoluteRoot, relativeRoot, baseURL, minecraftVersion, forgeVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ export abstract class BaseResolver implements Resolver {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected absoluteRoot: string,
|
protected absoluteRoot: string,
|
||||||
protected relativeRoot: string
|
protected relativeRoot: string,
|
||||||
|
protected baseUrl: string
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public abstract getModule(): Promise<Module>
|
public abstract getModule(): Promise<Module>
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ export class Forge113Adapter extends ForgeResolver {
|
|||||||
constructor(
|
constructor(
|
||||||
absoluteRoot: string,
|
absoluteRoot: string,
|
||||||
relativeRoot: string,
|
relativeRoot: string,
|
||||||
|
baseUrl: string,
|
||||||
minecraftVersion: string,
|
minecraftVersion: string,
|
||||||
forgeVersion: string
|
forgeVersion: string
|
||||||
) {
|
) {
|
||||||
super(absoluteRoot, relativeRoot, minecraftVersion, forgeVersion)
|
super(absoluteRoot, relativeRoot, baseUrl, minecraftVersion, forgeVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getModule(): Promise<Module> {
|
public async getModule(): Promise<Module> {
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ export class Forge18Adapter extends ForgeResolver {
|
|||||||
constructor(
|
constructor(
|
||||||
absoluteRoot: string,
|
absoluteRoot: string,
|
||||||
relativeRoot: string,
|
relativeRoot: string,
|
||||||
|
baseUrl: string,
|
||||||
minecraftVersion: string,
|
minecraftVersion: string,
|
||||||
forgeVersion: string
|
forgeVersion: string
|
||||||
) {
|
) {
|
||||||
super(absoluteRoot, relativeRoot, minecraftVersion, forgeVersion)
|
super(absoluteRoot, relativeRoot, baseUrl, minecraftVersion, forgeVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getModule(): Promise<Module> {
|
public async getModule(): Promise<Module> {
|
||||||
@@ -78,7 +79,16 @@ export class Forge18Adapter extends ForgeResolver {
|
|||||||
),
|
),
|
||||||
name: 'Minecraft Forge',
|
name: 'Minecraft Forge',
|
||||||
type: Type.ForgeHosted,
|
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: []
|
subModules: []
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +146,15 @@ export class Forge18Adapter extends ForgeResolver {
|
|||||||
id: properId,
|
id: properId,
|
||||||
name: `Minecraft Forge (${mavenComponents?.artifact})`,
|
name: `Minecraft Forge (${mavenComponents?.artifact})`,
|
||||||
type: Type.Library,
|
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) {
|
if (postProcess) {
|
||||||
@@ -160,11 +178,11 @@ export class Forge18Adapter extends ForgeResolver {
|
|||||||
return forgeModule
|
return forgeModule
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateArtifact(buf: Buffer, stats: Stats): Artifact {
|
private generateArtifact(buf: Buffer, stats: Stats, url: string): Artifact {
|
||||||
return {
|
return {
|
||||||
size: stats.size,
|
size: stats.size,
|
||||||
MD5: createHash('md5').update(buf).digest('hex'),
|
MD5: createHash('md5').update(buf).digest('hex'),
|
||||||
url: 'TODO'
|
url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +212,7 @@ export class Forge18Adapter extends ForgeResolver {
|
|||||||
|
|
||||||
console.debug('Spawning PackXZExtract.')
|
console.debug('Spawning PackXZExtract.')
|
||||||
await PackXZExtractWrapper.extractUnpack(files)
|
await PackXZExtractWrapper.extractUnpack(files)
|
||||||
console.debug('All filex extracted, calculating hashes..')
|
console.debug('All files extracted, calculating hashes..')
|
||||||
|
|
||||||
for (const entry of processingQueue) {
|
for (const entry of processingQueue) {
|
||||||
const tmpFileName = basename(entry.localPath)
|
const tmpFileName = basename(entry.localPath)
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ export abstract class ForgeResolver extends BaseResolver {
|
|||||||
constructor(
|
constructor(
|
||||||
absoluteRoot: string,
|
absoluteRoot: string,
|
||||||
relativeRoot: string,
|
relativeRoot: string,
|
||||||
|
baseUrl: string,
|
||||||
protected minecraftVersion: string,
|
protected minecraftVersion: string,
|
||||||
protected forgeVersion: string
|
protected forgeVersion: string
|
||||||
) {
|
) {
|
||||||
super(absoluteRoot, relativeRoot)
|
super(absoluteRoot, relativeRoot, baseUrl)
|
||||||
this.repoStructure = new RepoStructure(absoluteRoot, relativeRoot)
|
this.repoStructure = new RepoStructure(absoluteRoot, relativeRoot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user