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

84
package-lock.json generated
View File

@@ -94,9 +94,9 @@
"dev": true "dev": true
}, },
"@types/node": { "@types/node": {
"version": "12.12.43", "version": "12.12.47",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.43.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.47.tgz",
"integrity": "sha512-KUyZdkGCnVPuXfsKmDUu2XLui65LZIJ2s0M57noy5e+ixUT2oK33ep7zlvgzI8LElcWqbf8AR+o/3GqAPac2zA==", "integrity": "sha512-yzBInQFhdY8kaZmqoL2+3U5dSTMrKaYcb561VU+lDzAYvqt+2lojvBEy+hmpSNuXnPTx7m9+04CzWYOUqWME2A==",
"dev": true "dev": true
}, },
"@types/triple-beam": { "@types/triple-beam": {
@@ -121,12 +121,12 @@
"dev": true "dev": true
}, },
"@typescript-eslint/eslint-plugin": { "@typescript-eslint/eslint-plugin": {
"version": "3.1.0", "version": "3.2.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.1.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.2.0.tgz",
"integrity": "sha512-D52KwdgkjYc+fmTZKW7CZpH5ZBJREJKZXRrveMiRCmlzZ+Rw9wRVJ1JAmHQ9b/+Ehy1ZeaylofDB9wwXUt83wg==", "integrity": "sha512-t9RTk/GyYilIXt6BmZurhBzuMT9kLKw3fQoJtK9ayv0tXTlznXEAnx07sCLXdkN3/tZDep1s1CEV95CWuARYWA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@typescript-eslint/experimental-utils": "3.1.0", "@typescript-eslint/experimental-utils": "3.2.0",
"functional-red-black-tree": "^1.0.1", "functional-red-black-tree": "^1.0.1",
"regexpp": "^3.0.0", "regexpp": "^3.0.0",
"semver": "^7.3.2", "semver": "^7.3.2",
@@ -134,33 +134,33 @@
} }
}, },
"@typescript-eslint/experimental-utils": { "@typescript-eslint/experimental-utils": {
"version": "3.1.0", "version": "3.2.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-3.1.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-3.2.0.tgz",
"integrity": "sha512-Zf8JVC2K1svqPIk1CB/ehCiWPaERJBBokbMfNTNRczCbQSlQXaXtO/7OfYz9wZaecNvdSvVADt6/XQuIxhC79w==", "integrity": "sha512-UbJBsk+xO9dIFKtj16+m42EvUvsjZbbgQ2O5xSTSfVT1Z3yGkL90DVu0Hd3029FZ5/uBgl+F3Vo8FAcEcqc6aQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/json-schema": "^7.0.3", "@types/json-schema": "^7.0.3",
"@typescript-eslint/typescript-estree": "3.1.0", "@typescript-eslint/typescript-estree": "3.2.0",
"eslint-scope": "^5.0.0", "eslint-scope": "^5.0.0",
"eslint-utils": "^2.0.0" "eslint-utils": "^2.0.0"
} }
}, },
"@typescript-eslint/parser": { "@typescript-eslint/parser": {
"version": "3.1.0", "version": "3.2.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-3.1.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-3.2.0.tgz",
"integrity": "sha512-NcDSJK8qTA2tPfyGiPes9HtVKLbksmuYjlgGAUs7Ld2K0swdWibnCq9IJx9kJN8JJdgUJSorFiGaPHBgH81F/Q==", "integrity": "sha512-Vhu+wwdevDLVDjK1lIcoD6ZbuOa93fzqszkaO3iCnmrScmKwyW/AGkzc2UvfE5TCoCXqq7Jyt6SOXjsIlpqF4A==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/eslint-visitor-keys": "^1.0.0", "@types/eslint-visitor-keys": "^1.0.0",
"@typescript-eslint/experimental-utils": "3.1.0", "@typescript-eslint/experimental-utils": "3.2.0",
"@typescript-eslint/typescript-estree": "3.1.0", "@typescript-eslint/typescript-estree": "3.2.0",
"eslint-visitor-keys": "^1.1.0" "eslint-visitor-keys": "^1.1.0"
} }
}, },
"@typescript-eslint/typescript-estree": { "@typescript-eslint/typescript-estree": {
"version": "3.1.0", "version": "3.2.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-3.1.0.tgz", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-3.2.0.tgz",
"integrity": "sha512-+4nfYauqeQvK55PgFrmBWFVYb6IskLyOosYEmhH3mSVhfBp9AIJnjExdgDmKWoOBHRcPM8Ihfm2BFpZf0euUZQ==", "integrity": "sha512-uh+Y2QO7dxNrdLw7mVnjUqkwO/InxEqwN0wF+Za6eo3coxls9aH9kQ/5rSvW2GcNanebRTmsT5w1/92lAOb1bA==",
"dev": true, "dev": true,
"requires": { "requires": {
"debug": "^4.1.1", "debug": "^4.1.1",
@@ -520,9 +520,9 @@
"dev": true "dev": true
}, },
"eslint": { "eslint": {
"version": "7.1.0", "version": "7.2.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-7.1.0.tgz", "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.2.0.tgz",
"integrity": "sha512-DfS3b8iHMK5z/YLSme8K5cge168I8j8o1uiVmFCgnnjxZQbCGyraF8bMl7Ju4yfBmCuxD7shOF7eqGkcuIHfsA==", "integrity": "sha512-B3BtEyaDKC5MlfDa2Ha8/D6DsS4fju95zs0hjS3HdGazw+LNayai38A25qMppK37wWGWNYSPOR6oYzlz5MHsRQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/code-frame": "^7.0.0", "@babel/code-frame": "^7.0.0",
@@ -531,10 +531,10 @@
"cross-spawn": "^7.0.2", "cross-spawn": "^7.0.2",
"debug": "^4.0.1", "debug": "^4.0.1",
"doctrine": "^3.0.0", "doctrine": "^3.0.0",
"eslint-scope": "^5.0.0", "eslint-scope": "^5.1.0",
"eslint-utils": "^2.0.0", "eslint-utils": "^2.0.0",
"eslint-visitor-keys": "^1.1.0", "eslint-visitor-keys": "^1.2.0",
"espree": "^7.0.0", "espree": "^7.1.0",
"esquery": "^1.2.0", "esquery": "^1.2.0",
"esutils": "^2.0.2", "esutils": "^2.0.2",
"file-entry-cache": "^5.0.1", "file-entry-cache": "^5.0.1",
@@ -581,9 +581,9 @@
} }
}, },
"eslint-scope": { "eslint-scope": {
"version": "5.0.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.0.0.tgz", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.0.tgz",
"integrity": "sha512-oYrhJW7S0bxAFDvWqzvMPRm6pcgcnWc4QnofCAqRTRfQC0JcwenzGglTtsLyIuuWFfkqDG9vz67cnttSd53djw==", "integrity": "sha512-iiGRvtxWqgtx5m8EyQUJihBloE4EnYeGE/bz1wSPwJE6tZuJUtHlhqDM4Xj2ukE8Dyy1+HCZ4hE0fzIVMzb58w==",
"dev": true, "dev": true,
"requires": { "requires": {
"esrecurse": "^4.1.0", "esrecurse": "^4.1.0",
@@ -600,20 +600,20 @@
} }
}, },
"eslint-visitor-keys": { "eslint-visitor-keys": {
"version": "1.1.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.2.0.tgz",
"integrity": "sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==", "integrity": "sha512-WFb4ihckKil6hu3Dp798xdzSfddwKKU3+nGniKF6HfeW6OLd2OUDEPP7TcHtB5+QXOKg2s6B2DaMPE1Nn/kxKQ==",
"dev": true "dev": true
}, },
"espree": { "espree": {
"version": "7.0.0", "version": "7.1.0",
"resolved": "https://registry.npmjs.org/espree/-/espree-7.0.0.tgz", "resolved": "https://registry.npmjs.org/espree/-/espree-7.1.0.tgz",
"integrity": "sha512-/r2XEx5Mw4pgKdyb7GNLQNsu++asx/dltf/CI8RFi9oGHxmQFgvLbc5Op4U6i8Oaj+kdslhJtVlEZeAqH5qOTw==", "integrity": "sha512-dcorZSyfmm4WTuTnE5Y7MEN1DyoPYy1ZR783QW1FJoenn7RailyWFsq/UL6ZAAA7uXurN9FIpYyUs3OfiIW+Qw==",
"dev": true, "dev": true,
"requires": { "requires": {
"acorn": "^7.1.1", "acorn": "^7.2.0",
"acorn-jsx": "^5.2.0", "acorn-jsx": "^5.2.0",
"eslint-visitor-keys": "^1.1.0" "eslint-visitor-keys": "^1.2.0"
} }
}, },
"esprima": { "esprima": {
@@ -672,9 +672,9 @@
} }
}, },
"fast-deep-equal": { "fast-deep-equal": {
"version": "3.1.1", "version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
"integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
"dev": true "dev": true
}, },
"fast-json-stable-stringify": { "fast-json-stable-stringify": {
@@ -1586,9 +1586,9 @@
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
}, },
"v8-compile-cache": { "v8-compile-cache": {
"version": "2.1.0", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.1.1.tgz",
"integrity": "sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g==", "integrity": "sha512-8OQ9CL+VWyt3JStj7HX7/ciTL2V3Rl1Wf5OL+SNTm0yK1KvtReVulksyeRnCANHHuUxHlQig+JJDlUhBt1NQDQ==",
"dev": true "dev": true
}, },
"which": { "which": {

View File

@@ -27,12 +27,12 @@
"homepage": "https://github.com/dscalzi/Nebula#readme", "homepage": "https://github.com/dscalzi/Nebula#readme",
"devDependencies": { "devDependencies": {
"@types/fs-extra": "^9.0.1", "@types/fs-extra": "^9.0.1",
"@types/node": "^12.12.43", "@types/node": "^12.12.47",
"@types/triple-beam": "^1.3.1", "@types/triple-beam": "^1.3.1",
"@types/yargs": "^15.0.5", "@types/yargs": "^15.0.5",
"@typescript-eslint/eslint-plugin": "^3.1.0", "@typescript-eslint/eslint-plugin": "^3.2.0",
"@typescript-eslint/parser": "^3.1.0", "@typescript-eslint/parser": "^3.2.0",
"eslint": "^7.1.0", "eslint": "^7.2.0",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"typescript": "^3.9.5" "typescript": "^3.9.5"
}, },

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 { Distribution } from 'helios-distribution-types'
import { ModelStructure } from './ModelStructure' import { ModelStructure } from './ModelStructure'
import { ServerStructure } from './server.struct' import { ServerStructure } from './server.struct'
import { join, resolve } from 'path'
import { DistroMeta, getDefaultDistroMeta } from '../../nebula/distrometa'
export class DistributionStructure implements ModelStructure<Distribution> { export class DistributionStructure implements ModelStructure<Distribution> {
private readonly DISTRO_META_FILE = 'distrometa.json'
private serverStruct: ServerStructure private serverStruct: ServerStructure
private metaPath: string
constructor( constructor(
private absoluteRoot: string, private absoluteRoot: string,
private baseUrl: string private baseUrl: string
) { ) {
this.serverStruct = new ServerStructure(this.absoluteRoot, this.baseUrl) this.serverStruct = new ServerStructure(this.absoluteRoot, this.baseUrl)
this.metaPath = join(this.absoluteRoot, 'meta')
} }
public async init(): Promise<void> { public async init(): Promise<void> {
await mkdirs(this.absoluteRoot) 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() await this.serverStruct.init()
} }
public async getSpecModel(): Promise<Distribution> { public async getSpecModel(): Promise<Distribution> {
const distroMeta: DistroMeta = JSON.parse(await readFile(resolve(this.metaPath, this.DISTRO_META_FILE), 'utf-8'))
return { return {
version: '1.0.0', version: '1.0.0',
rss: '<FILL IN MANUALLY>', rss: distroMeta.meta.rss,
...(distroMeta.meta.discord ? {discord: distroMeta.meta.discord} : {}),
servers: await this.serverStruct.getSpecModel() 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 static readonly logger = LoggerUtil.getLogger('ServerStructure')
private readonly ID_REGEX = /(.+-(.+)$)/ private readonly ID_REGEX = /(.+-(.+)$)/
private readonly SERVER_META_FILE = 'servermeta.json'
constructor( constructor(
absoluteRoot: string, absoluteRoot: string,
@@ -71,7 +72,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
} }
const serverMeta: ServerMeta = getDefaultServerMeta(id, minecraftVersion.toString(), serverMetaOpts) 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) const libS = new LibraryStructure(absoluteServerRoot, relativeServerRoot, this.baseUrl)
await libS.init() await libS.init()
@@ -113,7 +114,7 @@ export class ServerStructure extends BaseModelStructure<Server> {
} }
// Read server meta // 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 minecraftVersion = new MinecraftVersion(match[2])
const modules: Module[] = [] const modules: Module[] = []