Added basic library discovery.
Put all libraries into the libraries folder at the root of your server directory. These will be added to the distribution as Library modules. Recall, Library modules are added to the client's classpath at runtime.
This commit is contained in:
56
src/model/struct/model/module/library.struct.ts
Normal file
56
src/model/struct/model/module/library.struct.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { ModuleStructure } from './module.struct'
|
||||
import { Type } from 'helios-distribution-types'
|
||||
import { Stats } from 'fs-extra'
|
||||
import { join } from 'path'
|
||||
import { resolve } from 'url'
|
||||
|
||||
export class LibraryStructure extends ModuleStructure {
|
||||
|
||||
private readonly crudeRegex = /(.+)-([\d.]+).[jJ][aA][rR]/
|
||||
private readonly libraryExt = '.jar'
|
||||
|
||||
constructor(
|
||||
absoluteRoot: string,
|
||||
relativeRoot: string,
|
||||
baseUrl: string
|
||||
) {
|
||||
super(absoluteRoot, relativeRoot, 'libraries', baseUrl, Type.Library, (name: string) => {
|
||||
return name.toLowerCase().endsWith(this.libraryExt)
|
||||
})
|
||||
}
|
||||
|
||||
private attemptCrudeInference(name: string): { name: string, version: string } {
|
||||
const result = this.crudeRegex.exec(name)
|
||||
if(result != null) {
|
||||
return {
|
||||
name: result[1],
|
||||
version: result[2]
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
name: name.substring(0, name.toLowerCase().indexOf(this.libraryExt)),
|
||||
version: '0.0.0'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
protected async getModuleId(name: string, path: string, stats: Stats, buf: Buffer): Promise<string> {
|
||||
const inference = this.attemptCrudeInference(name)
|
||||
return this.generateMavenIdentifier(inference.name, inference.version)
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
protected async getModuleName(name: string, path: string, stats: Stats, buf: Buffer): Promise<string> {
|
||||
const inference = this.attemptCrudeInference(name)
|
||||
return inference.name
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
protected async getModuleUrl(name: string, path: string, stats: Stats): Promise<string> {
|
||||
return resolve(this.baseUrl, join(this.relativeRoot, name))
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
protected async getModulePath(name: string, path: string, stats: Stats): Promise<string | null> {
|
||||
return null
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,8 @@ export abstract class ModuleStructure extends BaseModelStructure<Module> {
|
||||
relativeRoot: string,
|
||||
structRoot: string,
|
||||
baseUrl: string,
|
||||
protected type: Type
|
||||
protected type: Type,
|
||||
protected filter?: ((name: string, path: string, stats: Stats) => boolean)
|
||||
) {
|
||||
super(absoluteRoot, relativeRoot, structRoot, baseUrl)
|
||||
}
|
||||
@@ -66,7 +67,10 @@ export abstract class ModuleStructure extends BaseModelStructure<Module> {
|
||||
const filePath = resolve(this.containerDirectory, file)
|
||||
const stats = await lstat(filePath)
|
||||
if (stats.isFile()) {
|
||||
accumulator.push(await this.parseModule(file, filePath, stats))
|
||||
if(this.filter == null || this.filter(file, filePath, stats)) {
|
||||
accumulator.push(await this.parseModule(file, filePath, stats))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { ServerMeta } from '../../nebula/servermeta'
|
||||
import { BaseModelStructure } from './basemodel.struct'
|
||||
import { MiscFileStructure } from './module/file.struct'
|
||||
import { LiteModStructure } from './module/litemod.struct'
|
||||
import { LibraryStructure } from './module/library.struct'
|
||||
|
||||
export class ServerStructure extends BaseModelStructure<Server> {
|
||||
|
||||
@@ -64,6 +65,9 @@ export class ServerStructure extends BaseModelStructure<Server> {
|
||||
await lms.init()
|
||||
}
|
||||
|
||||
const libS = new LibraryStructure(absoluteServerRoot, relativeServerRoot, this.baseUrl)
|
||||
await libS.init()
|
||||
|
||||
const mfs = new MiscFileStructure(absoluteServerRoot, relativeServerRoot, this.baseUrl)
|
||||
await mfs.init()
|
||||
|
||||
@@ -130,8 +134,12 @@ export class ServerStructure extends BaseModelStructure<Server> {
|
||||
const fileStruct = new MiscFileStructure(absoluteServerRoot, relativeServerRoot, this.baseUrl)
|
||||
const fileModules = await fileStruct.getSpecModel()
|
||||
|
||||
const libraryStruct = new LibraryStructure(absoluteServerRoot, relativeServerRoot, this.baseUrl)
|
||||
const libraryModules = await libraryStruct.getSpecModel()
|
||||
|
||||
const modules = [
|
||||
forgeItselfModule,
|
||||
...libraryModules,
|
||||
...forgeModModules,
|
||||
...liteModModules,
|
||||
...fileModules
|
||||
|
||||
Reference in New Issue
Block a user