BililiveRecorder/config_gen/generators/doc.ts

27 lines
730 B
TypeScript
Raw Normal View History

2021-08-13 21:03:21 +08:00
import { ConfigEntry } from "../types"
2022-06-10 16:34:25 +08:00
import { statSync, writeFileSync } from "fs";
2021-08-13 21:03:21 +08:00
import { resolve } from "path"
import { data } from "../data";
import { trimEnd } from "../utils";
export default function doc(path: string): void {
2022-06-10 16:34:25 +08:00
if (!statSync(resolve(path, 'mkdocs.yml'))) {
2021-08-13 21:03:21 +08:00
console.error('Check your path');
return;
}
2022-06-10 16:34:25 +08:00
if (!statSync(resolve(path, 'docs/user/settings.md'))) {
2021-08-13 21:03:21 +08:00
console.error('Check your path');
return;
}
2022-06-10 16:34:25 +08:00
const targetPath = resolve(path, 'data/brec_settings.json')
2021-08-13 21:03:21 +08:00
2022-06-10 16:34:25 +08:00
const text = buildJson(data)
2021-08-13 21:03:21 +08:00
2022-06-10 16:34:25 +08:00
writeFileSync(targetPath, text, { encoding: 'utf8' });
2021-08-13 21:03:21 +08:00
}
2022-06-10 16:34:25 +08:00
function buildJson(data: ConfigEntry[]): string {
return JSON.stringify(data, null, 2);
2021-08-13 21:03:21 +08:00
}