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 🙏

© 2024 – Pkg Stats / Ryan Hefner

t3gen

v0.3.6

Published

Code generation tool for NextJS / create-t3-app projects powered by Plop

Downloads

30

Readme

t3gen

Code generation tool for NextJS / create-t3-app projects powered by Plop

If you find this project useful, please consider giving it a star ⭐️ on GitHub!

Table of Contents

Motivation

create-t3-app is a great tool for creating NextJS projects, but it is a little repetitive to add things like environment variables, tRPC routers, and feature directories. t3gen aims to simplify the process of creating new components, pages, and actions by providing a set of generators that can be easily customized to fit your project's needs.

Everyone can be lazy and just want to do things quickly, so t3gen is designed to be as easy to use as possible. See Usage without Installation for an example of how t3gen will literally just save you time. It's that simple!

Installation (Optional)

# npm
npm install -g t3gen

# yarn
yarn global add t3gen

# pnpm (recommended)
pnpm install -g t3gen

Usage without Installation

You can also use t3gen without installation by running the following command:

npx t3gen <generator-name> [options]

So, for example, if you want to create a new environment variable, you can run the following command:

npx t3gen env FOO='bar'

This will update the .env file in your project and add the environment variable to the src/env.js file in your project.

The generator will infer the type of the environment variable based on the value you provide. For example, if you provide:

  • a url, it will be inferred as a url type, and the zod schema will be z.string().url().
  • a number, it will be inferred as a number type, and the zod schema will be z.number().
  • a boolean, it will be inferred as a boolean type, and the zod schema will be z.boolean().
  • anything else, it will be inferred as a string type, and the zod schema will be z.string().

Usage

t3gen <generator-name> [options]

See the list of generators below for more details.

Features

  • 🧠 Smart Insertion: t3gen will figure out where to insert the new code based on the current project structure, that means you can run t3gen from any directory and it will work.
  • 🪛Generators: t3gen comes with a set of generators that can help you get started quickly. See the list below for more details.
  • 🌟Custom Generators: t3gen is built on top of Plop, so you can create your own generators by extending the Plop API.

Generators

| Generator | Status | Description | Example Command | |----------------|--------|-----------------------------------------------------------------------------------------------------|---------------------------| | env | ✔️ | Creates an environment variable in .env, and adds the appropriate definition and zod schema in src/env.js | t3gen env FOO='bar' | | router | ⏳ | Creates a tRPC router in src/server/api/ and adds it to the appRouter in src/server/api/root.ts | t3gen router posts | | feature | ⏳ | Creates a directory in src for a client feature, or in src/server for a server feature | t3gen feature posts | | page | ⏳ | Creates a page.tsx in src/<feature>/<name>/ | t3gen page contact | | component | ⏳ | Creates a client/server component tsx file as src/feature/_components/.tsx or src/server/feature/_components/.tsx | t3gen component button or t3gen component button --client or t3gen component posts/button | | action | ⏳ | Creates server actions files: src/feature/action.ts and/or src/feature/validation.ts | t3gen action posts/create | | procedure | ⏳ | Creates a tRPC procedure in src/server/api/routers/<router>.ts | t3gen procedure posts/getPost | | store | ⏳ | Creates a Zustand store in src/<feature>/store.ts | t3gen store posts |

Configuration using .t3gen.json (Optional) {#configuration}

t3gen should work out of the box, but if you want to customize the behavior of t3gen, you can create a .t3gen.json file in the root of your project. This file should be a JSON object with the following properties:

{
  "srcPath": "custom/path/to/src" // defaults to "src"
}

Contribution

This project is still in its early stages, so contributions are welcome. If you have any ideas or suggestions, please open an issue or submit a pull request.

License

Apache-2.0

Credits

  • Plop: The tool that powers t3gen
  • create-t3-app: The template that t3gen is based on
  • Zod: The library that t3gen uses to generate Zod schemas for environment variables