mirror of
https://github.com/supabase/supabase.git
synced 2026-12-05 16:09:06 +00:00
- zod schema for clispec 001/002 and strict sections/spec id check in codegen - CLI versions v3 (latest) and v2 with version switcher keeping the same command - one statically generated page per command under /reference/cli/<path>, overview by category, global flags and migrating-from-v2 pages - breaking-change callouts, flag table with choices and defaults, titled examples with tabular output, collapsible CLI sidebar and single-active TOC - 301 redirects from the old single-page slugs; static redirects point at final paths - Markdown twin per page, CLI llms index and search indexing of the new URLs - crawler script checking links and anchors across every CLI page Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import * as fs from 'fs'
|
|
import * as ejs from 'ejs'
|
|
import * as yaml from 'js-yaml'
|
|
|
|
import { writeToDisk } from './helpers'
|
|
import template from './templates/CliTemplate'
|
|
import { parseCliSpec, type CliSpec } from './types/CliSpec'
|
|
|
|
export default async function gen(inputFileName: string, outputDir: string) {
|
|
const spec = parseCliSpec(yaml.load(fs.readFileSync(inputFileName, 'utf8')), inputFileName)
|
|
|
|
switch (spec.clispec) {
|
|
case '001':
|
|
case '002':
|
|
await gen_v001(spec, outputDir)
|
|
break
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Versioned Generator
|
|
*/
|
|
async function gen_v001(spec: CliSpec, dest: string) {
|
|
let commandMap = new Map(spec.commands.map((item) => [item.id, item] as const))
|
|
|
|
const commands = spec.commands.map((x) => {
|
|
const isChild = x.subcommands.length < 1
|
|
const heading = isChild ? `### ${x.summary} [#${x.id}]` : `## ${x.summary} [#${x.id}]`
|
|
|
|
return {
|
|
...x,
|
|
heading,
|
|
subcommandList: x.subcommands.map((c) => commandMap.get(c)),
|
|
}
|
|
})
|
|
|
|
const content = ejs.render(template, {
|
|
info: spec.info,
|
|
commands,
|
|
})
|
|
// console.log(content)
|
|
// Write to disk
|
|
await writeToDisk(dest, content)
|
|
console.log('Saved: ', dest)
|
|
}
|