Configs2026年9月11日·1 分钟阅读

Hygen — The Scalable Code Generator for Your Team

A fast, convention-based code scaffolding tool that generates files from EJS templates, helping teams standardize component creation and boilerplate.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Hygen Overview
直接安装命令
npx -y tokrepo@latest install dbbc7e4d-ae2e-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Hygen is a code generator that lives inside your project repository. It uses simple EJS templates and a convention-over-configuration approach to let developers scaffold files, components, and modules with a single command, keeping boilerplate consistent across the team.

What Hygen Does

  • Generates files and directories from EJS templates stored in your repo
  • Injects code into existing files at marked positions using regex or string anchors
  • Supports interactive prompts for collecting input like names and options
  • Runs as a CLI tool with a generate-action-name convention
  • Stores all templates in a _templates directory under version control

Architecture Overview

Hygen scans the _templates directory for generators organized by name and action. Each generator contains a prompt file for interactive input and one or more EJS template files with frontmatter headers specifying the output path and injection targets. At runtime, Hygen resolves the template, evaluates EJS expressions against the collected variables, and writes or injects the result into the project tree.

Self-Hosting & Configuration

  • Install globally via npm or add as a devDependency
  • Run hygen init self to create the _templates directory
  • Organize templates as _templates/GENERATOR/ACTION/files.ejs.t
  • Use frontmatter to set output paths with to: and injection with inject: true
  • Add prompt.js files for interactive CLI prompts using Enquirer

Key Features

  • Templates live in the repo so the team shares and versions them together
  • Frontmatter-driven output with to, inject, after, and before directives
  • Shell command execution via sh: for post-generation setup steps
  • Fast startup with lazy loading and no heavy framework overhead
  • Works with any language or framework since it generates plain text files

Comparison with Similar Tools

  • Plop — similar template-based generator with Handlebars instead of EJS
  • Yeoman — full scaffolding framework with a plugin ecosystem, heavier setup
  • Angular CLI schematics — powerful but tightly coupled to Angular
  • Nx generators — monorepo-aware generation, requires the Nx toolchain
  • cookiecutter — Python-based project templating, oriented toward full project setup

FAQ

Q: Can Hygen inject into existing files? A: Yes. Set inject: true in the template frontmatter and use after or before with a regex to specify the insertion point.

Q: Does it work with TypeScript projects? A: Yes. Hygen generates any text file. Templates can produce .ts, .tsx, .py, or any other file type.

Q: How do I share templates across multiple repositories? A: Point the HYGEN_TMPLS environment variable to a shared directory, or publish templates as an npm package and symlink.

Q: Is it framework-specific? A: No. Hygen is language-agnostic and framework-agnostic. It generates files from templates regardless of your stack.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产