-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-config-docs.js
42 lines (31 loc) · 1.14 KB
/
generate-config-docs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const {getConfigDocs} = require('./src/config');
const {writeFile} = require('fs/promises');
// eslint-disable-next-line require-jsdoc
function formatJson(data) {
return `\`${data.replace(/\n/g, '')}\``;
}
let data = `# Configuration
The configuration properties are applied in the following order (from higher to
lower precedence):
- arguments passed to the executable in kebab case (e.g. \`url-query\`);
- environment variables in uppercase snake format (e.g. \`URL_QUERY\`);
- \`config.json\` configuration file;
- default values.
| Name | Description | Format | Default value |
| :--- | :---------- | :----- | :------------ |
`;
const configDocs = getConfigDocs();
Object.entries(configDocs).forEach((entry) => {
const [name, value] = entry;
// eslint-disable-next-line max-len
data += `| ${name} | ${value.doc} | ${formatJson(value.format)} | \`${formatJson(value.default)}\` |\n`;
});
data += `
---
*Document generated with:* \`yarn generate-config-docs\`
`;
writeFile('CONFIG.md', data).then(() => {
console.log('done'); // eslint-disable-line
}, (err) => {
console.error(`Error writing file: ${err.message}`); // eslint-disable-line
});