docs: improve schema generation (#2035)

This commit is contained in:
pooya parsa 2021-11-19 17:26:15 +01:00 committed by GitHub
parent d3fb5129d7
commit b1371373c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 8 deletions

View File

@ -4,7 +4,7 @@
"scripts": {
"dev": "yarn gendocs && nuxt dev",
"build": "yarn gendocs && nuxt generate --force-build",
"build:ci": "yarn add @nuxt/kit@npm:@nuxt/kit-edge && yarn build",
"build:ci": "./scripts/make-schema.sh && yarn build",
"gendocs": "jiti ./scripts/gen-docs.ts"
},
"devDependencies": {

View File

@ -34,11 +34,16 @@ function generateMarkdown (schema: Schema, title: string, level: string, parentV
// Render meta info
if (schema.type !== 'object' || !schema.properties) {
// Type and default
lines.push(`- **Type**: \`${schema.type}\``)
lines.push(`- **Version**: ${versions.join(', ')}`)
if ('default' in schema) {
lines.push('- **Default**', ...formatValue(schema.default))
if (schema.type !== 'any') {
lines.push(`- **Type**: \`${schema.type}\``)
}
const defaultValue = formatValue(schema.default)
if (defaultValue) {
lines.push('- **Default**', ...defaultValue)
}
lines.push(`- **Version**: ${versions.join(', ')}`)
lines.push('')
}
@ -86,7 +91,9 @@ const InternalTypes = new Set([
])
function formatValue (val) {
return ['```json', JSON.stringify(val, null, 2), '```']
const stringified = JSON.stringify(val, null, 2)
if (stringified === '{}' || stringified === '[]') { return null }
return ['```json', stringified, '```']
}
function renderTag (tag: string) {
@ -110,7 +117,7 @@ async function generateDocs ({ configFile, configTemplate }) {
const start = Date.now()
console.log(`Updating docs on ${configFile}`)
const template = await readFile(configTemplate, 'utf8')
const rootSchema = require('@nuxt/kit/schema/config.schema.json') as Schema
const rootSchema = require('../../packages/kit/schema/config.schema.json') as Schema
const keys = Object.keys(rootSchema.properties).sort()
let generatedDocs = ''

8
docs/scripts/make-schema.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
set -e
cd ..
yarn="node `pwd`/.yarn/releases/yarn-*.cjs"
$yarn install
cd packages/kit
$yarn prepack --stub

View File

@ -43,10 +43,15 @@ export default {
cli,
generate,
typescript,
// TODO: split out into separate file
/**
* Configuration that will be passed directly to Vite.
*
* See https://vitejs.dev/config for more information.
* Please note that not all vite options are supported in Nuxt.
*
* @type {boolean | typeof import('vite').InlineConfig}
* @version 3
*/
vite: undefined,
}