### Install Typebox Codegen CLI Source: https://github.com/oddlaceguy49/typebox-codegen-cli/blob/main/README.md Install the tool as a development dependency using npm. ```bash npm install --save-dev typebox-codegen-cli ``` -------------------------------- ### Running NPM Schema Generation Scripts Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Examples of running individual or all schema generation tasks using npm scripts. ```bash # Run individual schema generation ``` ```bash npm run schema:zod # Run all schema generation tasks ``` ```bash npm run schema:all # Run from configuration file ``` ```bash npm run schema:config ``` -------------------------------- ### Run Generation Programmatically with Zod Example Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Demonstrates how to use the `runGeneration` function programmatically to generate Zod schemas. Specify input and output directories, and control cleaning and import fixing behavior. ```typescript import { runGeneration } from "typebox-codegen-cli"; // Generate Zod schemas programmatically await runGeneration({ target: "zod", inputDir: "/absolute/path/to/src/types", outputDir: "/absolute/path/to/src/generated", clean: true, // Remove output directory before generating fixImports: true, // Append .js to relative imports for ESM }); // Example output structure: // src/generated/ // └── zod/ // ├── types/ // │ └── User.ts # Generated schema file // ├── User/ // │ ├── index.ts # Barrel file with main exports // │ └── details.ts # Barrel file with nested property exports ``` -------------------------------- ### Example codegen.config.ts Configuration Source: https://github.com/oddlaceguy49/typebox-codegen-cli/blob/main/README.md Configure schema generation tasks using a dedicated config file for complex projects. This example sets global input/output paths and defines specific tasks for Zod, Yup, and JSON Schema. ```typescript // To get type-safety and autocompletion, you can optionally import the helper // Note: You may need to add "moduleResolution": "bundler" to your tsconfig.json // if you get an error importing this type. import { defineConfig } from "typebox-codegen-cli/config"; export default defineConfig({ // Global settings that apply to all tasks unless overridden input: "src/api-types", output: "src/generated", // An array of generation tasks to run tasks: [ { target: "zod", }, { target: "yup", }, { // This task overrides the global output directory target: "jsonschema", output: "public/schemas", }, ], }); ``` -------------------------------- ### Define Configuration with defineConfig Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Example of using the `defineConfig` helper function in a TypeScript configuration file for type-safe schema generation task definitions. It allows setting global input/output paths and defining multiple generation tasks. ```typescript // codegen.config.ts import { defineConfig } from "typebox-codegen-cli/config"; export default defineConfig({ // Global settings applied to all tasks unless overridden input: "src/api-types", output: "src/generated", // Array of generation tasks tasks: [ { target: "zod", // Uses global input/output }, { target: "yup", // Uses global input/output }, { target: "jsonschema", // Override output for this task only output: "public/schemas", }, { target: "effect", // Override both input and output input: "src/effect-types", output: "src/effect-schemas", }, ], }); ``` -------------------------------- ### Generate Zod Schemas with Default Paths Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Generates Zod schemas using default input and output directories. Run this command to quickly generate schemas for your project. ```bash npx typebox-codegen-cli zod ``` -------------------------------- ### Override Configuration File Settings Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Overrides global input and output directory settings specified in the configuration file. Use CLI flags to temporarily change settings for a specific run. ```bash npx typebox-codegen-cli --input ./custom-types --output ./custom-output ``` -------------------------------- ### Run All Configured Tasks Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Executes all generation tasks defined in a `codegen.config.js` or `codegen.config.ts` file. The CLI automatically searches for this file in the project root. ```bash npx typebox-codegen-cli ``` -------------------------------- ### NPM Scripts for Schema Generation Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Configure schema generation tasks as npm scripts for easy execution. Supports various schema types and options. ```json { "scripts": { "schema:zod": "typebox-codegen-cli zod", "schema:yup": "typebox-codegen-cli yup --input ./src/api-types --output ./src/schemas", "schema:valibot": "typebox-codegen-cli valibot", "schema:effect": "typebox-codegen-cli effect --fix-imports false", "schema:json": "typebox-codegen-cli jsonschema -o ./public/schemas", "schema:all": "npm run schema:zod && npm run schema:yup && npm run schema:valibot", "schema:config": "typebox-codegen-cli" } } ``` -------------------------------- ### Generate TypeBox Schemas Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Generates TypeBox schemas using default input and output directories. This is a straightforward command for TypeBox schema generation. ```bash npx typebox-codegen-cli typebox ``` -------------------------------- ### Generate JSON Schema with Custom Paths Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Generates JSON Schemas specifying custom input and output directories using shorthand flags. Use `-i` for input and `-o` for output. ```bash npx typebox-codegen-cli jsonschema -i ./types -o ./schemas ``` -------------------------------- ### Generate Yup Schemas with Custom Directories Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Generates Yup schemas by specifying custom input and output directories. Use this when your type definitions or desired output locations differ from the defaults. ```bash npx typebox-codegen-cli yup --input ./src/api-types --output ./src/generated-schemas ``` -------------------------------- ### Add Schema Generation Scripts to package.json Source: https://github.com/oddlaceguy49/typebox-codegen-cli/blob/main/README.md Define scripts in your package.json to generate schemas for different libraries and paths. ```json { "scripts": { "schema:zod": "typebox-codegen-cli zod", "schema:yup": "typebox-codegen-cli yup --input ./src/api-types --output ./src/generated-schemas", "schema:all": "npm run schema:zod && npm run schema:yup" } } ``` -------------------------------- ### Generate Valibot Schemas Without Cleaning Output Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Generates Valibot schemas without cleaning the output directory. Set `--clean false` to preserve existing files in the output directory. ```bash npx typebox-codegen-cli valibot --clean false ``` -------------------------------- ### Config Interface for Generation Tasks Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Defines the structure for a single generation task, specifying the target schema format, and optional overrides for input and output directories. This interface is part of the overall configuration object. ```typescript interface GenerationTask { target: string; // Required: "zod" | "yup" | "valibot" | "effect" | "jsonschema" | "typebox" input?: string; // Optional: Override global input directory output?: string; // Optional: Override global output directory } interface Config { input?: string; // Global input directory (default: "src/types") output?: string; // Global output directory (default: "src/generated") tasks: GenerationTask[]; // Array of generation tasks (required, min 1) } ``` -------------------------------- ### Generate Effect Schema Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Generates Effect Schema with backward-compatible Record syntax and fixed import paths. ```typescript // Output: src/generated/effect/types/User.ts // THIS FILE IS AUTO-GENERATED FOR EFFECT. DO NOT EDIT. import * as ES from 'effect'; // Fixed import path export const User = ES.Struct({ id: ES.String, name: ES.String, metadata: ES.Record({ key: ES.String, value: ES.String }), // Fixed syntax }); ``` -------------------------------- ### Generate Zod Schema Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Generates Zod v4-compatible validation schemas. Includes automatic record syntax fixes for Zod v4. ```typescript // Input: src/types/User.ts export interface User { id: string; name: string; metadata: Record; } // Output: src/generated/zod/types/User.ts // THIS FILE IS AUTO-GENERATED FOR ZOD. DO NOT EDIT. import z from 'zod'; export const User = z.object({ id: z.string(), name: z.string(), metadata: z.record(z.string(), z.string()), // Fixed for Zod v4 }); ``` -------------------------------- ### Generate Effect Schemas Without ESM Import Fixes Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Generates Effect schemas without applying ESM import fixes. Set `--fix-imports false` to disable the automatic appending of `.js` to relative imports. ```bash npx typebox-codegen-cli effect --fix-imports false ``` -------------------------------- ### Generate Yup Schema Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Generates Yup validation schemas with corrected import syntax. ```typescript // Output: src/generated/yup/types/User.ts // THIS FILE IS AUTO-GENERATED FOR YUP. DO NOT EDIT. import * as y from 'yup'; // Fixed import syntax export const User = y.object({ id: y.string().required(), name: y.string().required(), metadata: y.object(), }); ``` -------------------------------- ### Fix ESM Imports in Directory Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Use `fixEsmImports` to append `.js` extensions to relative imports for ESM compatibility. This is a post-processing utility. ```typescript import { fixEsmImports } from "typebox-codegen-cli"; // Fix all TypeScript files in a directory fixEsmImports("/path/to/src/generated/zod"); // Before: import { User } from "./types/User" // After: import { User } from "./types/User.js" ``` -------------------------------- ### Transform TypeScript Source Text Source: https://context7.com/oddlaceguy49/typebox-codegen-cli/llms.txt Use `transformSourceText` to flatten nested TypeScript interface properties into separate named types before code generation. This utility is AST-powered. ```typescript import { transformSourceText } from "typebox-codegen-cli"; const sourceCode = ` export interface User { id: string; profile: { name: string; avatar: string; }; } `; const transformed = await transformSourceText(sourceCode, "User.ts"); // Output: // export interface User_properties_profile { // name: string; // avatar: string; // } // // export interface User { // id: string; // profile: User_properties_profile; // } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.