From e3a02c4894ad711f1e5c3f5a343b2c125bf1bd45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Tue, 20 Aug 2024 11:17:59 +0200 Subject: [PATCH] chore: add docgen script (#7387) * chore: add docgen script * fixup! chore: add docgen script * fixup! chore: add docgen script --- dev/test-studio/schema/debug/validation.tsx | 2 +- dev/test-studio/schema/species.ts | 1 + package.json | 1 + scripts/generate-documents/cli.ts | 123 ++++++++++++++++++ scripts/generate-documents/run.ts | 59 +++++++++ scripts/generate-documents/templates/book.ts | 6 + .../generate-documents/templates/species.ts | 11 ++ .../templates/validation.ts | 49 +++++++ scripts/generate-documents/types.ts | 8 ++ scripts/generate-documents/utils/lorem.ts | 26 ++++ 10 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 scripts/generate-documents/cli.ts create mode 100644 scripts/generate-documents/run.ts create mode 100644 scripts/generate-documents/templates/book.ts create mode 100644 scripts/generate-documents/templates/species.ts create mode 100644 scripts/generate-documents/templates/validation.ts create mode 100644 scripts/generate-documents/types.ts create mode 100644 scripts/generate-documents/utils/lorem.ts diff --git a/dev/test-studio/schema/debug/validation.tsx b/dev/test-studio/schema/debug/validation.tsx index dea4568c621..365315ff50d 100644 --- a/dev/test-studio/schema/debug/validation.tsx +++ b/dev/test-studio/schema/debug/validation.tsx @@ -368,7 +368,7 @@ export default defineType({ title: 'A geopoint', description: 'Required, must be in Norway somewhere', validation: (Rule) => - Rule.required().custom((geoPoint) => { + Rule.custom((geoPoint) => { if (!geoPoint) { return true } diff --git a/dev/test-studio/schema/species.ts b/dev/test-studio/schema/species.ts index ad17c9c867f..ffb32cf4f13 100644 --- a/dev/test-studio/schema/species.ts +++ b/dev/test-studio/schema/species.ts @@ -18,6 +18,7 @@ export default { title: 'Species', type: 'string', }, + {name: 'description', type: 'text', title: 'Description'}, { name: 'image', title: 'Image', diff --git a/package.json b/package.json index d29d9ebd606..d9dd7feb037 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "deploy:movies": "pnpm build && cd examples/movies-studio && sanity deploy", "deploy:test": "pnpm build && cd dev/test-studio && sanity deploy", "dev": "pnpm dev:test-studio", + "generate:docs": "tsx --env-file=.env.local ./scripts/generate-documents/cli.ts", "dev:cli": "pnpm watch", "dev:design-studio": "pnpm --filter design-studio dev", "dev:embedded-studio": "pnpm --filter embedded-studio dev", diff --git a/scripts/generate-documents/cli.ts b/scripts/generate-documents/cli.ts new file mode 100644 index 00000000000..45d70f32966 --- /dev/null +++ b/scripts/generate-documents/cli.ts @@ -0,0 +1,123 @@ +import path from 'node:path' +import {parseArgs} from 'node:util' + +import {createClient} from '@sanity/client' +import {tap} from 'rxjs' + +import {readEnv} from '../utils/envVars' +import {run} from './run' +import {book} from './templates/book' +import {species} from './templates/species' +import {validation} from './templates/validation' + +const {values: args} = parseArgs({ + args: process.argv.slice(2), + options: { + number: { + type: 'string', + short: 'n', + default: '1', + }, + dataset: { + type: 'string', + }, + bundle: { + type: 'string', + }, + draft: { + type: 'boolean', + }, + published: { + type: 'boolean', + }, + size: { + type: 'string', + }, + concurrency: { + type: 'string', + short: 'c', + }, + template: { + type: 'string', + short: 't', + }, + help: { + type: 'boolean', + short: 'h', + }, + }, +}) + +const templates = { + validation: validation, + book: book, + species: species, +} + +const HELP_TEXT = `Usage: tsx --env-file=.env.local ./${path.relative(process.cwd(), process.argv[1])} --template