explaingit

jondot/hygen

5,933JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A code generator that lives inside your project, define a template once, then run one command to create any boilerplate file automatically instead of copying and editing by hand every time.

Mindmap

mindmap
  root((hygen))
    What it does
      Code generation
      File creation
      File injection
      Prompt inputs
    Tech stack
      JavaScript
      npm
      EJS templates
    Use cases
      Component scaffolding
      API endpoint generation
      Team-shared generators
    Audience
      Frontend developers
      Full-stack developers
      Engineering teams
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Create a new React component with all its files in one command instead of copying boilerplate from an existing file

USE CASE 2

Inject a new route or Redux reducer into an existing file at a specific insertion point automatically

USE CASE 3

Share code generators with your whole team by checking the _templates folder into your Git repository

USE CASE 4

Scaffold an API endpoint with test file and types in one command whenever you add a new feature

Tech stack

JavaScriptNode.jsnpmEJS

Getting it running

Difficulty · easy Time to first run · 5min
License type was not specified in the explanation.

In plain English

Hygen is a command-line code generator that lives inside your project folder. Instead of writing the same boilerplate files by hand each time you add a component, a route, or another repeated structure, you define a template once and then run a short command to generate new files from it. The generated files appear in your project automatically, ready to edit. The tool stores templates in a folder called _templates within your project, which you check into version control alongside your code. This means the whole team shares the same generators, and they evolve with the project rather than living in a separate tool that gets out of sync. Templates use a format called EJS, which is a simple way to embed variables and logic inside otherwise ordinary text files. Hygen can do more than create new files. It can inject content into existing files at a specific point, run shell commands as part of a generation step, and prompt the user for input before generating anything. This covers a wide range of repetitive tasks: adding a new Redux reducer, scaffolding a new API endpoint, or creating a test file whenever a new module is added. Installing it takes one command via npm, Homebrew, or npx. Once installed, you run hygen init self in your project to set it up, then hygen generator new to create your first template. The quickstart in the README walks through this in a few minutes. The project also supports initializing from a GitHub repository template with a single command. Hygen is used by companies including Airbnb, Accenture, and Wix according to the README's credits section. It is available on npm and licensed as open source. Full documentation is available at hygen.io.

Copy-paste prompts

Prompt 1
Create a Hygen template that generates a new React component, it should create a .tsx file, a .test.tsx file, and a CSS module file, all named after the component I pass as an argument.
Prompt 2
I want a Hygen generator that injects a new route into my existing routes/index.js file. Show me the template that uses the inject action to add the line in the right place.
Prompt 3
Walk me through initializing Hygen in a brand new project: the commands to run, what the _templates folder structure looks like, and how to create and run my first generator.
Prompt 4
Set up a Hygen generator that prompts me for a name and description before generating files, using the front-matter prompt syntax.
Prompt 5
Show me how to create a Hygen generator that initializes from a GitHub template repository, so my team can share a standard project starter.
Open on GitHub → Explain another repo

← jondot on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.