Gen is your go-to tool for creating, managing, and using code templates across various programming languages and projects. Say goodbye to repetitive coding!
curl -sSL https://raw.githubusercontent.com/samuelgja/gen/main/install.sh | sh
Or you can download the repo and build binary directly.
- 📚 Easy to Use: Create and use your own template in matter of seconds.
- 🛠 Efficient Template Management: Tackle repetitive code across different projects with ease.
- 📁 Versatile Templates: From UI components to data models and boilerplate code.
Unlike standard IDE templates that are limited to single files, Gen allows for a comprehensive template comprising multiple files.
- Template Directory: The
.gen
folder in your project root contains templates and a config JSON file. - Template Structure: Templates consist of a path and content, both supporting variable inclusion.
- Types of Variables: Use
__var__
for text inputs and__select__
for dropdown selections.
- 📂 Path: Where to place the template.
- ✍️ Content: The template itself.
- 🖊️ Variables: Dynamic placeholders in the template.
- 🆕
gen new
: Create a new template. - 📝
gen edit
: Edit an existing template. - 🗑️
gen delete
: Delete a template. - 🔍
gen fetch
: Fetch templates from GitHub or other URLs. - ❓
gen help
: Get help with commands. - 🔄
gen refresh
: Refresh all templates. - 🎯
gen use
: Use a specific template. - 🔎
gen variables
: List all template variables. - 🔗
--global
(-g
): Use global scope.
In Gen, templates are key to automating code generation. They consist of:
- Template Path: Where your template files will reside in your project.
- Template Content: The actual code or structure within these files.
Template variables are dynamic elements in both your template path and content. There are two types:
-
var: A standard variable for text input.
- Custom Naming: You can name it like
__var__myname__
. - Casing Support: You can specify the case format, such as
__var__kebab__
,__var__camel__
,__var__snake__
, or__var__pascal__
. - Example:
const __var__pascal__ = __var__kebab__;
- Custom Naming: You can name it like
-
select: A variable for predefined options.
- Same rule as
__var__
for naming and casing and usage. - When creating a template, the CLI wizard prompts you to set options for these selects.
- These options are stored in the template or config file
_.json
- Same rule as
- In Paths:
src/something/__select__/__var__.cpp
- In Content:
const __var__pascal__ = __var__kebab__;
Imagine a UI component template in .gen/my-template
:
- UI Main Component:
- Path:
src/components/__var__/__var__.tsx
- Content:
import React from 'react'; import { __var__pascal__Props } from './__var__'; const __var__pascal__: React.FC<__var__pascal__Props> = ({}) => { return <div></div>; }; export default __var__pascal__;
- Path:
- UI Component Test:
- Path:
src/components/__var__/__var__.test.tsx
- Content:
import React from 'react'; import { render } from '@testing-library/react'; import __var__pascal__ from './__var__kebab__'; describe('<__var__pascal__ />', () => { it('should render successfully', () => { const { baseElement } = render(<__var__pascal__ />); expect(baseElement).toBeTruthy(); }); });
- Path:
- Index File Update:
- Path:
src/components/index.ts
- Content:
export * from './__var__kebab/__var__kebab';
- Path:
For detailed instructions and updates, visit: Gen GitHub Page
I was frustrated how many times and in how many languages I had to create same files again and again and again. So I created this tool to help me with that :)
- Currently
fetch
is in BETA, and it's plan to fetch any template from any URL for easy manage. - Store templates in cloud, and share with others.
- Cleanup cli prints