36 lines
978 B
TypeScript
36 lines
978 B
TypeScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import yaml from 'js-yaml'
|
|
|
|
export interface ServerPack {
|
|
name: string
|
|
category: string
|
|
mods: string[]
|
|
plugins: string[]
|
|
core: string
|
|
javaVersion: string
|
|
minecraftVersion: string
|
|
dockerImage: string
|
|
imageVersion: string
|
|
description: string
|
|
}
|
|
|
|
export function parseServerPacks(): { packs: ServerPack[], categories: string[], versions: string[] } {
|
|
const dataDirectory = path.join(process.cwd(), 'data')
|
|
const files = fs.readdirSync(dataDirectory)
|
|
|
|
const packs = files
|
|
.filter(file => path.extname(file) === '.yaml')
|
|
.map(file => {
|
|
const filePath = path.join(dataDirectory, file)
|
|
const fileContents = fs.readFileSync(filePath, 'utf8')
|
|
return yaml.load(fileContents) as ServerPack
|
|
})
|
|
|
|
const categories = ['All', ...new Set(packs.map(pack => pack.category))]
|
|
const versions = [...new Set(packs.map(pack => pack.minecraftVersion))]
|
|
|
|
return { packs, categories, versions }
|
|
}
|
|
|