Add distrometa.json for storing distribution wide metadata.

The distrometa.json file is stored at {ROOT}/meta/distrometa.json.
You can generate it by rereunning the init root command.
It behaves exactly the same as the servermeta.json file.
This commit is contained in:
Daniel Scalzi
2020-06-10 11:09:49 -04:00
parent 97ffb9c44b
commit a6b6ed9db3
5 changed files with 93 additions and 50 deletions

View File

@@ -0,0 +1,27 @@
import { Distribution } from 'helios-distribution-types'
export interface DistroMeta {
meta: {
rss: Distribution['rss']
discord?: Distribution['discord']
}
}
export function getDefaultDistroMeta(): DistroMeta {
return {
meta: {
rss: '<LINK TO RSS FEED>',
discord: {
clientId: '<FILL IN OR REMOVE DISCORD OBJECT>',
smallImageText: '<FILL IN OR REMOVE DISCORD OBJECT>',
smallImageKey: '<FILL IN OR REMOVE DISCORD OBJECT>'
}
}
}
}

View File

@@ -1,28 +1,43 @@
import { mkdirs } from 'fs-extra'
import { mkdirs, writeFile, readFile } from 'fs-extra'
import { Distribution } from 'helios-distribution-types'
import { ModelStructure } from './ModelStructure'
import { ServerStructure } from './server.struct'
import { join, resolve } from 'path'
import { DistroMeta, getDefaultDistroMeta } from '../../nebula/distrometa'
export class DistributionStructure implements ModelStructure<Distribution> {
private readonly DISTRO_META_FILE = 'distrometa.json'
private serverStruct: ServerStructure
private metaPath: string
constructor(
private absoluteRoot: string,
private baseUrl: string
) {
this.serverStruct = new ServerStructure(this.absoluteRoot, this.baseUrl)
this.metaPath = join(this.absoluteRoot, 'meta')
}
public async init(): Promise<void> {
await mkdirs(this.absoluteRoot)
await mkdirs(this.metaPath)
const distroMeta: DistroMeta = getDefaultDistroMeta()
await writeFile(resolve(this.metaPath, this.DISTRO_META_FILE), JSON.stringify(distroMeta, null, 2))
await this.serverStruct.init()
}
public async getSpecModel(): Promise<Distribution> {
const distroMeta: DistroMeta = JSON.parse(await readFile(resolve(this.metaPath, this.DISTRO_META_FILE), 'utf-8'))
return {
version: '1.0.0',
rss: '<FILL IN MANUALLY>',
rss: distroMeta.meta.rss,
...(distroMeta.meta.discord ? {discord: distroMeta.meta.discord} : {}),
servers: await this.serverStruct.getSpecModel()
}
}

View File

@@ -16,6 +16,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
private static readonly logger = LoggerUtil.getLogger('ServerStructure')
private readonly ID_REGEX = /(.+-(.+)$)/
private readonly SERVER_META_FILE = 'servermeta.json'
constructor(
absoluteRoot: string,
@@ -71,7 +72,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
}
const serverMeta: ServerMeta = getDefaultServerMeta(id, minecraftVersion.toString(), serverMetaOpts)
await writeFile(resolvePath(absoluteServerRoot, 'servermeta.json'), JSON.stringify(serverMeta, null, 2))
await writeFile(resolvePath(absoluteServerRoot, this.SERVER_META_FILE), JSON.stringify(serverMeta, null, 2))
const libS = new LibraryStructure(absoluteServerRoot, relativeServerRoot, this.baseUrl)
await libS.init()
@@ -113,7 +114,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
}
// Read server meta
const serverMeta: ServerMeta = JSON.parse(await readFile(resolvePath(absoluteServerRoot, 'servermeta.json'), 'utf-8'))
const serverMeta: ServerMeta = JSON.parse(await readFile(resolvePath(absoluteServerRoot, this.SERVER_META_FILE), 'utf-8'))
const minecraftVersion = new MinecraftVersion(match[2])
const modules: Module[] = []