genie-snippet
v1.0.3
Published
A genie micro-generator for file creation
Maintainers
Readme
Genie-Snippet
A lightweight, TypeScript-based micro-generator for automating file creation, inspired by Plop.js. genie-snippet allows you to define templates and prompts to dynamically generate files using a simple and extensible CLI interface.
✨ Features
- 🧙 CLI-Driven – Use the
geniecommand to interactively generate files. - 🔧 Handlebars Templating – Use Handlebars for dynamic, readable templates.
- 🔐 TypeScript Native – Built in TypeScript for type safety and maintainability.
- 🛠️ Customizable – Easily configure prompts and generation actions with a config file.
- 📦 Lightweight – Minimal footprint; easy to integrate into any project.
🚀 Installation
Install genie-snippet either globally or locally in your project:
Global
npm install -g genie-snippet
### Local (Recommended)
```bash
npm install --save-dev genie-snippet
```⚙️ Getting Started
1. Create a Configuration File
In your project root, add a genie.config.js file:
// genie.config.js
module.exports = {
prompts: [
{
type: "input",
name: "name",
message: "What is the name of the component?",
validate: (input) => !!input || "Component name is required",
},
],
actions: [
{
type: "add",
path: "src/{{name}}.ts",
templateFile: "templates/component.hbs",
},
],
};2. Create a Template
In the templates folder, create a component.hbs file:
//
{{name}}.ts export function
{{name}}(): void { console.log('Hello from
{{name}}!'); }3. Run the Generator
Run the generator using the CLI:
genieYou'll be prompted for a component name, and a new file will be created in src/{{name}}.ts.
📁 Example Folder Structure
your-project/
├── genie.config.js
├── templates/
│ └── component.hbs
└── src/
└── [generated files]🧩 Use Cases
- React component generators
- Utility function templates
- Service or API layer stubs
- Reusable code scaffolding
- Project bootstrapping
💡 Tips
- You can define multiple generators with different prompt sets.
- Add conditional logic and custom helpers using Handlebars.
- Works well with mono-repos and larger codebases.
📄 License
MIT
