BililiveRecorder/config_gen/generators/doc.ts

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-08-13 21:03:21 +08:00
import { ConfigEntry } from "../types"
import fs from "fs"
import { resolve } from "path"
import { data } from "../data";
import { trimEnd } from "../utils";
export default function doc(path: string): void {
if (!fs.statSync(resolve(path, '_config.yml'))) {
console.error('Check your path');
return;
}
if (!fs.statSync(resolve(path, 'index.html'))) {
console.error('Check your path');
return;
}
const targetPath = resolve(path, '_includes/generated_settings_list.md')
const text = buildMarkdown(data)
fs.writeFileSync(targetPath, text, { encoding: 'utf8' });
}
function buildMarkdown(data: ConfigEntry[]): string {
let result = '';
// 目录
result += "## 目录\n\n"
result += data.filter(x => !x.advancedConfig).map(x => `- [${x.description}](#${x.description})`).join('\n')
result += '\n\n'
// 一般设置项目列表
result += data.filter(x => !x.advancedConfig).map(x =>
`### ${x.description}
: \`${x.name}\`
: \`${trimEnd(x.type, '?')}\`
: \`${x.defaultValueDescription ?? x.defaultValue}\`
${x.markdown}
`).join('\n')
result += '\n\n'
return result;
}