Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 0 additions & 65 deletions .vitepress/data/commands.data.ts

This file was deleted.

56 changes: 0 additions & 56 deletions .vitepress/theme/components/CommandSection.vue

This file was deleted.

2 changes: 0 additions & 2 deletions .vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { h, Fragment } from 'vue'
import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme-without-fonts'
import CommandSection from './components/CommandSection.vue'
import DockerIcon from './components/DockerIcon.vue'
import EnvVar from './components/EnvVar.vue'
import EnvVarSection from './components/EnvVarSection.vue'
Expand Down Expand Up @@ -32,7 +31,6 @@ export default {
})
},
enhanceApp({ app, router, siteData }) {
app.component('CommandSection', CommandSection)
app.component('EnvVar', EnvVar)
app.component('EnvVarSection', EnvVarSection)
}
Expand Down
64 changes: 63 additions & 1 deletion scripts/generate-commands.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,72 @@ const root = load(
fs.readFileSync(resolve('.vitepress/data/commands.yaml'), 'utf8')
)

const escape = value =>
(value ?? '')
.replaceAll('&', '&')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')

const cell = value => escape(value).replaceAll('|', '\\|')

const flag = ({ name, shorthand }) =>
shorthand ? `--${name}, -${shorthand}` : `--${name}`

const blockquote = description =>
escape(description)
.split('\n')
.map(line => (line === '' ? '>' : `> ${line}`))
.join('\n')

const optionsTable = options => {
const rows = ['| Flag | Description | Default |', '| --- | --- | --- |']

for (const option of options) {
const value = option.default ? `\`${option.default}\`` : ''

rows.push(`| \`${flag(option)}\` | ${cell(option.usage)} | ${value} |`)
}

return rows.join('\n')
}

const section = command => {
const badges = []

if (command.aliases?.length) {
badges.push(`<Badge type="info" text="alias: ${command.aliases.join(', ')}" />`)
}

if (command.since) {
badges.push(`<Badge type="tip" text="v${command.since}" />`)
}

if (command.deprecated) {
badges.push(`<Badge type="warning" text="deprecated v${command.deprecated}" />`)
}

const title = [`\`${command.name}\``, ...badges].join(' ')
const lines = [`### ${title}`, '']

if (command.description) {
lines.push(blockquote(command.description), '')
}

if (command.usage) {
lines.push(`\`${command.usage}\``, '')
}

if (command.options?.length) {
lines.push(optionsTable(command.options), '')
}

return lines.join('\n').trimEnd()
}

const sections = []

const walk = command => {
sections.push(`<CommandSection path="${command.name}" />`, '---', '')
sections.push(section(command), '', '---', '')

for (const child of command.commands ?? []) {
walk(child)
Expand Down
Loading