From b1371373c87e6d1916c591423db47a36f929c17b Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Fri, 19 Nov 2021 17:26:15 +0100 Subject: [PATCH] docs: improve schema generation (#2035) --- docs/package.json | 2 +- docs/scripts/gen-docs.ts | 19 +++++++++++++------ docs/scripts/make-schema.sh | 8 ++++++++ packages/kit/src/config/schema/index.ts | 7 ++++++- 4 files changed, 28 insertions(+), 8 deletions(-) create mode 100755 docs/scripts/make-schema.sh diff --git a/docs/package.json b/docs/package.json index 6182830fbc..12c77c3786 100644 --- a/docs/package.json +++ b/docs/package.json @@ -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": { diff --git a/docs/scripts/gen-docs.ts b/docs/scripts/gen-docs.ts index 22bc47cb0d..e54ad4182e 100644 --- a/docs/scripts/gen-docs.ts +++ b/docs/scripts/gen-docs.ts @@ -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 = '' diff --git a/docs/scripts/make-schema.sh b/docs/scripts/make-schema.sh new file mode 100755 index 0000000000..30c1736094 --- /dev/null +++ b/docs/scripts/make-schema.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +cd .. +yarn="node `pwd`/.yarn/releases/yarn-*.cjs" +$yarn install +cd packages/kit +$yarn prepack --stub diff --git a/packages/kit/src/config/schema/index.ts b/packages/kit/src/config/schema/index.ts index f08999097c..a2dde046ff 100644 --- a/packages/kit/src/config/schema/index.ts +++ b/packages/kit/src/config/schema/index.ts @@ -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, }