npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@oddlaceguy49/typebox-codegen-cli

v0.1.5

Published

A CLI for generating Zod, Yup, and other schemas from TypeScript types using typebox-codegen.

Readme

Typebox Codegen CLI

npm version License: MIT

A powerful CLI wrapper for typebox-codegen to automatically generate validation schemas from your TypeScript types.

This tool streamlines your workflow by taking your TypeScript interfaces as the single source of truth and generating schemas for various validation libraries. It goes beyond the standard codegen by applying automated post-processing fixes to ensure compatibility with modern library versions and coding standards.

Key Features

  • Multi-Library Support: Generate schemas for Zod, Yup, Valibot, Effect, and more from a single command.
  • Automated Code Fixes: Applies patches to generated code, such as updating Zod v3 syntax to be compatible with v4 records.
  • AST-Powered Transformations: Intelligently flattens nested TypeScript interface properties into separate, named types for cleaner and more reusable schemas.
  • Automatic Barrel Files: Creates index.ts and details.ts barrel files for easy and organized importing of your generated schemas.
  • ESM-Ready: Automatically fixes relative import paths by appending the .js extension, making the output compatible with modern Node.js modules.
  • Simple CLI Interface: A clean and easy-to-use command-line interface with sensible defaults.

Installation

Install the tool as a development dependency in your project:

npm install --save-dev typebox-codegen-cli

Usage

The most common way to use this tool is by adding scripts to your package.json file.

In package.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"
    }
}

Then you can run the commands in your terminal:

# Generate Zod schemas using default paths
npm run schema:zod

# Generate Yup schemas with custom input/output paths
npm run schema:yup

Configuration File

For more complex projects, you can define all your generation tasks in a single configuration file. Create a codegen.config.js or codegen.config.ts file in your project's root directory.

When this file exists, you can simply run the command without any arguments:

npx typebox-codegen-cli

Example codegen.config.ts

// 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",
        },
    ],
});

Command-Line Options

| Option | Alias | Description | Default | | :-------------- | :---- | :------------------------------------------------------ | :-------------- | | target | | (Required) The target schema format. | | | --input | -i | Input directory containing TypeScript type definitions. | src/types | | --output | -o | Base output directory for all generated files. | src/generated | | --clean | | Clean the output directory before generating. | true | | --fix-imports | | Append .js to relative imports for ESM compatibility. | true | | --help | -h | Show the help message. | |

Supported Targets

  • [ ] ArkType
  • [x] Effect
  • [ ] io-ts
  • [ ] Javascript Transform
  • [x] JSON Schema
  • [x] TypeBox
  • [ ] Typescript Transform
  • [x] Valibot
  • [ ] Value Transform
  • [x] Yup
  • [ ] Yrel
  • [x] Zod

License

This project is licensed under the MIT License. See the LICENSE file for details.