@sargonpiraev/env-docs
v0.0.0
Published
Generate .env.example (and optional README env docs) from Zod env schema maps with .describe()
Maintainers
Readme
@sargonpiraev/env-docs
Generate .env.example (and optional README env docs) from Zod env schema maps that use .describe().
SSOT pattern: export raw serverSchema / clientSchema / sharedSchema objects from one env.ts, then:
- runtime:
@t3-oss/env-nextjs/@t3-oss/env-corecreateEnv({ server, client, … }) - docs: this package walks those maps →
KEY=lines +# descriptioncomments
Install
npm install -D @sargonpiraev/env-docs zodEnv module shape
import { createEnv } from '@t3-oss/env-nextjs'
import { z } from 'zod'
export const serverSchema = {
DATABASE_URL: z.string().min(1).describe('Postgres connection URL'),
}
export const clientSchema = {
NEXT_PUBLIC_SITE_URL: z.string().url().describe('Public site origin'),
}
export const env = createEnv({
server: serverSchema,
client: clientSchema,
experimental__runtimeEnv: {
NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL,
},
emptyStringAsUndefined: true,
// Allow codegen to import this file without real env values
skipValidation: process.env.ENV_DOCS_CODEGEN === '1',
})TODO: howToGet / docsUrl via Zod .meta() — not implemented yet.
CLI
npx env-docs generate --module ./src/env.ts --out .env.example
npx env-docs generate --module ./src/env.ts --out .env.example --readme README.mdREADME injection uses markers:
<!-- env-docs -->
…
<!-- /env-docs -->Library
import { renderEnvExample, generateEnvDocs } from '@sargonpiraev/env-docs'