4.0.0 • Published 10 months ago
@4o/engineer v4.0.0
🚀 Engineer: Automated Code Generation Toolkit
Overview
Engineer is a powerful, flexible code generation toolkit designed to streamline the process of creating boilerplate code, configuration files, and project structures using liquid templates and a declarative configuration approach.
🌟 Features
- Dynamic Template Generation: Create code from liquid templates with context-aware rendering
- Flexible Configuration: Define complex entity relationships and generation strategies
- Multi-Template Support: Generate multiple file types in a single run
- Extensible Actions: Easily add custom generation actions
- Type-Safe Configuration: Built-in configuration validation with Superstruct
📦 Installation
Install Engineer using npm:
npm install @4o/engineer
🔧 Configuration
Create an engineer.config.js
file in your project root:
const config = () => {
const context = {
// Define your project's context and entities
entities: [
// Entity definitions
]
};
return {
context,
templates: [
// Template generation instructions
]
};
};
export default config;
Configuration Options
context
: An object containing your project's data modeltemplates
: An array of template generation instructionstype
: Generation type ("once"
or"loop"
)name
: Template identifiertemplate
: Path to the liquid templatepath
: Output file path (supports dynamic paths with liquid syntax)iterator
: (Optional) Used for loop-based generation
🚀 Usage
Create a simple script to run Engineer:
import engineer from "@4o/engineer";
const main = async () => {
console.time('engineer');
await engineer();
console.timeEnd('engineer');
};
main();
📝 Liquid Template Example
{% for entity in entities %}
model {{entity.name}} {
// Model definition using entity metadata
}
{% endfor %}
🔍 Generation Strategies
One-Time Generation
Use type: "once"
to generate a single file:
{
type: "once",
name: "prisma-schema",
template: "./prisma.liquid",
path: "./out/prisma/schema.prisma"
}
Loop-Based Generation
Use type: "loop"
to generate multiple files:
{
type: "loop",
name: "module",
template: "./module.liquid",
path: "./out/modules/{{name}}.js",
iterator: "entities"
}
🛠️ Supported Actions
compile
: Render liquid templateswriteTextToFile
: Write generated content to filesreadTextFromFile
: Read template filesparseState
: Extract nested object propertieslog
: Console logging
🚨 Error Handling
Engineer provides detailed configuration and runtime error messages to help diagnose issues quickly.
🤝 Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
📄 License
Add your project's license information
🔗 Dependencies
- Liquid.js: Template rendering
- Superstruct: Configuration validation
- Node.js File System APIs