mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-01 18:07:22 +00:00
docs: improve schema generation (#2035)
This commit is contained in:
parent
d3fb5129d7
commit
b1371373c8
@ -4,7 +4,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "yarn gendocs && nuxt dev",
|
"dev": "yarn gendocs && nuxt dev",
|
||||||
"build": "yarn gendocs && nuxt generate --force-build",
|
"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"
|
"gendocs": "jiti ./scripts/gen-docs.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -34,11 +34,16 @@ function generateMarkdown (schema: Schema, title: string, level: string, parentV
|
|||||||
// Render meta info
|
// Render meta info
|
||||||
if (schema.type !== 'object' || !schema.properties) {
|
if (schema.type !== 'object' || !schema.properties) {
|
||||||
// Type and default
|
// Type and default
|
||||||
|
if (schema.type !== 'any') {
|
||||||
lines.push(`- **Type**: \`${schema.type}\``)
|
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('')
|
lines.push('')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +91,9 @@ const InternalTypes = new Set([
|
|||||||
])
|
])
|
||||||
|
|
||||||
function formatValue (val) {
|
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) {
|
function renderTag (tag: string) {
|
||||||
@ -110,7 +117,7 @@ async function generateDocs ({ configFile, configTemplate }) {
|
|||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
console.log(`Updating docs on ${configFile}`)
|
console.log(`Updating docs on ${configFile}`)
|
||||||
const template = await readFile(configTemplate, 'utf8')
|
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()
|
const keys = Object.keys(rootSchema.properties).sort()
|
||||||
let generatedDocs = ''
|
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,
|
cli,
|
||||||
generate,
|
generate,
|
||||||
typescript,
|
typescript,
|
||||||
// TODO: split out into separate file
|
|
||||||
/**
|
/**
|
||||||
* Configuration that will be passed directly to Vite.
|
* 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}
|
* @type {boolean | typeof import('vite').InlineConfig}
|
||||||
|
* @version 3
|
||||||
*/
|
*/
|
||||||
vite: undefined,
|
vite: undefined,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user