neko/webpage/docs/getting-started/configuration/help.js
Miroslav Šedivý b23ca1af04 WIP new docs.
2025-02-08 20:30:40 +01:00

33 lines
1.1 KiB
JavaScript

/* This script reads the help.txt file and generates a help.json file with the configuration options. */
const fs = require('fs');
const path = require('path');
const parseConfigOptions = (text) => {
const lines = text.split('\n');
return lines.map(line => {
const match = line.match(/--([\w.]+)(?:\s(\w+))?\s+(.*?)(?:\s+\(default\s+"?([\w\/.@]+)"?\))?$/);
if (match) {
const [, key, type, description, defaultValue] = match;
return { key: key.split('.'), type, defaultValue: defaultValue || undefined, description };
}
return null;
}).filter(option => option !== null);
};
const filePath = path.resolve(__dirname, 'help.txt');
const outputFilePath = path.resolve(__dirname, 'help.json');
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading help file:', err);
return;
}
const configOptions = parseConfigOptions(data);
fs.writeFile(outputFilePath, JSON.stringify(configOptions, null, 2), (err) => {
if (err) {
console.error('Error writing help file:', err);
} else {
console.log('Help file generated successfully.');
}
});
});