mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 17:07:22 +00:00
docs: improve schema generation (#2035)
This commit is contained in:
parent
d3fb5129d7
commit
b1371373c8
@ -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": {
|
||||
|
@ -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
|
||||
if (schema.type !== 'any') {
|
||||
lines.push(`- **Type**: \`${schema.type}\``)
|
||||
lines.push(`- **Version**: ${versions.join(', ')}`)
|
||||
if ('default' in schema) {
|
||||
lines.push('- **Default**', ...formatValue(schema.default))
|
||||
}
|
||||
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
8
docs/scripts/make-schema.sh
Executable 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
|
@ -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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user