morphus/scripts/generate_markdown_tables.mjs

36 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-11-28 16:48:50 +00:00
import { config, StorageType } from '../dist/src/config.js'
const schema = config._def
2022-05-29 09:31:18 +00:00
const asInlineCode = (s) => '`' + s + '`'
const formatInline = (s, empty = '') => (s === undefined ? empty : asInlineCode(s))
const formatEnv = (s) => formatInline(s, 'not supported')
const formatDefault = (s) => formatInline(s, '')
2021-11-28 16:48:50 +00:00
for (const storage of Object.values(StorageType)) {
const storageType = schema[storage]
let table = `
| Config | Environment | Default | Description |
| ---------------- | ------------------ | ------- | ------------------------ |
`
for (const [key, value] of Object.entries(storageType)) {
2022-05-29 09:31:18 +00:00
table += `| \`${storage}.${key}\` | ${formatEnv(value.env)} | ${formatDefault(value.default)} | ${value.doc} |\n`
}
console.log(table)
}
{
let table = `
| Config | Environment | Default | Description |
| ------- | ----------- | ------- | ------------ |
`
for (const [key, value] of Object.entries(schema)) {
if (Object.values(StorageType).includes(key)) continue
table += `| ${asInlineCode(key)} | ${formatEnv(value.env)} | ${formatDefault(value.default)} | ${value.doc} |\n`
2021-11-28 16:48:50 +00:00
}
console.log(table)
}