2022-09-29 01:59:28 +00:00
|
|
|
import fs from 'fs'
|
|
|
|
import path from 'path'
|
|
|
|
import yaml from 'js-yaml'
|
|
|
|
import { unified } from 'unified'
|
|
|
|
import remarkParse from 'remark-parse'
|
|
|
|
import remarkGfm from 'remark-gfm'
|
|
|
|
import remarkRehype from 'remark-rehype'
|
|
|
|
import rehypeStringify from 'rehype-stringify'
|
|
|
|
|
|
|
|
const DOC_PATH = path.join(process.cwd(), '..', 'doc')
|
|
|
|
|
2022-09-30 22:20:17 +00:00
|
|
|
export interface Documentation {
|
|
|
|
desc: string
|
|
|
|
values: DocItem[]
|
|
|
|
}
|
|
|
|
export interface DocItem {
|
2022-09-29 01:59:28 +00:00
|
|
|
name: string
|
|
|
|
desc: string
|
|
|
|
default: string | undefined
|
|
|
|
args: string[]
|
|
|
|
}
|
|
|
|
|
2022-09-30 22:20:17 +00:00
|
|
|
function getDocumentation(source: string): Documentation {
|
2022-09-29 01:59:28 +00:00
|
|
|
const configSettingsFile = fs.readFileSync(
|
2022-09-30 16:31:40 +00:00
|
|
|
path.join(DOC_PATH, source),
|
2022-09-29 01:59:28 +00:00
|
|
|
'utf-8'
|
|
|
|
)
|
2022-09-30 22:20:17 +00:00
|
|
|
const parsed = yaml.load(configSettingsFile.toString()) as Documentation
|
|
|
|
const docs = {
|
|
|
|
desc: processMarkdown(parsed.desc),
|
|
|
|
values: parsed.values.map((c) => ({ ...c, desc: processMarkdown(c.desc) })),
|
|
|
|
}
|
2022-09-29 01:59:28 +00:00
|
|
|
|
|
|
|
return docs
|
|
|
|
}
|
|
|
|
|
2022-09-30 22:20:17 +00:00
|
|
|
export function getConfigSettings(): Documentation {
|
2022-09-30 16:31:40 +00:00
|
|
|
return getDocumentation('config_settings.yaml')
|
2022-09-29 01:59:28 +00:00
|
|
|
}
|
|
|
|
|
2022-09-30 22:20:17 +00:00
|
|
|
export function getVariables(): Documentation {
|
2022-09-30 16:31:40 +00:00
|
|
|
return getDocumentation('variables.yaml')
|
2022-09-29 01:59:28 +00:00
|
|
|
}
|
2022-09-30 22:20:17 +00:00
|
|
|
export function getLua(): Documentation {
|
2022-09-30 16:31:40 +00:00
|
|
|
return getDocumentation('lua.yaml')
|
2022-09-29 01:59:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function processMarkdown(input: string): string {
|
|
|
|
return unified()
|
|
|
|
.use(remarkParse)
|
|
|
|
.use(remarkGfm)
|
|
|
|
.use(remarkRehype)
|
|
|
|
.use(rehypeStringify)
|
|
|
|
.processSync(input)
|
|
|
|
.toString()
|
|
|
|
}
|