Path: blob/master/webpage/src/components/Configuration/generate.js
1007 views
/* This script reads a help.txt file and generates a help.json file with the configuration options. */1const fs = require('fs');23const parseConfigOptions = (text) => {4const lines = text.split('\n');5return lines.map(line => {6const match = line.match(/--([\w.]+)(?:\s(\w+))?\s+(.*?)(?:\s+\(default\s+"?([^"]+)"?\))?$/);7if (match) {8let [, key, type, description, defaultValue] = match;9// if the type is not specified, it is a boolean10if (!type) {11type = 'boolean';12// if the default value is not specified, it is false13if (!defaultValue) {14defaultValue = 'false';15} else if (defaultValue !== 'false') {16defaultValue = 'true';17}18}19// this is an opaque object20if (type === 'string' && defaultValue === '{}') {21type = 'object';22defaultValue = {};23}24// this is an opaque array25if (type === 'string' && defaultValue === '[]') {26type = 'array';27defaultValue = [];28}29return { key: key.split('.'), type, defaultValue: defaultValue || undefined, description };30}31return null;32}).filter(option => option !== null);33};3435const [,, inputFilePath, outputFilePath] = process.argv;3637if (!inputFilePath || !outputFilePath) {38console.error('Usage: node generate.js <inputFilePath> <outputFilePath>');39process.exit(1);40}4142fs.readFile(inputFilePath, 'utf8', (err, data) => {43if (err) {44console.error('Error reading input file:', err);45return;46}47const configOptions = parseConfigOptions(data);48fs.writeFile(outputFilePath, JSON.stringify(configOptions, null, 2), (err) => {49if (err) {50console.error('Error writing output file:', err);51} else {52console.log('Output file generated successfully.');53}54});55});565758