Usage examples
The same command line you already know, extended with fork-native features: glob batch actions, content transforms, conditional skip: and the interactive picker.
Glob batch — one action, a whole directory
# _templates/module/new/spec.ejs.t
---
glob: module/**/*
to: src/<%= name %>/
base: module
stripExtensions: ['.t']
---
# The glob template itself writes nothing; every match becomes its own file.
hygen module new billing
# added: src/billing/service.ts
# added: src/billing/index.ts
Content transforms — post-process before writing
// .hygen.js
const prettier = require('prettier');
module.exports = {
transforms: {
prettier: (content, locals) => prettier.format(content, { parser: 'typescript' }),
},
};
---
to: src/gen/<%= name %>.ts
transform: trim | prettier
---
export const <%= name %> = <%- value %>;
Conditional skip — decide at render time
---
to: tests/<%= name %>.spec.ts
skip: <%= wantTests ? 'false' : 'no tests requested' %>
---
describe('<%= name %>', () => { /* ... */ });
Interactive picker — no arguments, pick it live
hygen
# ? Select a generator (Use arrow keys)
# 1) mailer
# 2) module
# ? Select an action
# 1) new
# runs exactly as if you had typed: hygen <generator> <action>
Fork features
Glob batch actions
Scaffold a whole directory tree from a single template with a `glob:` pattern, `base:`/`stripExtensions:` path shaping and per-match `skipIfExists`.
Content transforms
Post-process the rendered output before it is written or injected with a named `transforms:` namespace in the config file — prettier is the canonical use.
Conditional skip
A template can decide at render time whether it runs: `skip:` (EJS-rendered) skips the action when truthy, reported as a skipped status, not a failure.
Interactive picker
Run `hygen` with no arguments and pick a generator then an action from a two-level terminal picker; forced off in non-TTY environments.
Differences from upstream
@biorate/hygen is a fork of jondot/hygen (v6.2.11, MIT). Here is how it differs from upstream.
- Identity escaping — `<%= %>` does not HTML-escape (the EJS `escape` option is the identity), because the tool generates code, not HTML.
- `--version` flag — `hygen --version` / `hygen -v` prints `Hygen v<version>` and exits.
- Anchor-not-found error — a missing `inject` anchor fails with `InjectionAnchorNotFoundError` instead of silently no-oping.
- New inject options — `create_if_missing: true`, `replace: true`, and `skip_if_not: true`.
- Composition — action and name positionals accept comma lists; `mirror: true` writes to the path mirroring its template location.
- `--name` flag removed (breaking) — use the positional name; two legacy escapes (`HYGEN_LEGACY_NAME`, `legacyNameFlag`) restore the old behavior.
- Glob batch actions, named content transforms, conditional action skipping and an interactive generator/action picker.
- Error classes — `BaseError`-derived classes (`src/errors.ts`) instead of raw `Error`.
- Strict TypeScript / Vitest — authored in strict TypeScript, tests migrated to Vitest.
Ecosystem & tools
Share generators as packages, turn existing code into a generator, ship a standalone binary — and edit .t templates in IntelliJ IDEA.
Packages
Publish compiled generators as versioned npm packages and consume them with hygen-add.
IntelliJ IDEA plugin
The biorate/idea-hygen-plugin provides file type recognition for .t templates, syntax highlighting of frontmatter and EJS tags, host-language injection, completion of frontmatter keys / h helpers / context variables and more. Requires IDEA 2024.3+ (Community vs Ultimate capabilities differ).
Create & standalone
Wrap existing code with hygen-create, or ship a self-contained binary with the standalone distribution.
Support
If @biorate/hygen is useful to you, consider supporting the fork's maintainers. Picking a platform below is the quickest way to help the project keep moving.
Donation platform URLs are configured in src/data/donations.ts. Donations are voluntary and do not constitute consideration for any goods or services; they grant no rights to the code or priority in decision-making, and the project is provided AS IS under its license.
