1.1.1 • Published 10 months ago
@asaidimu/blueprint v1.1.1
BluePrint: A Component Generation Library
Overview
This library provides a flexible, extensible system for generating and managing project components with support for templating, hooks, and nested component structures.
Features
- Dynamic Component Generation: Create components with customizable templates
- Nested Component Support: Build complex project structures with hierarchical components
- Lifecycle Hooks: Execute custom logic before and after component operations
- Template Rendering: Use Handlebars for dynamic template generation
- Flexible Configuration: Supports various project and component configurations
Installation
npm install @asaidimu/blueprintCore Concepts
Project
The Project class represents the root of your project structure. It manages top-level components and provides initialization capabilities.
const project = new Project('/path/to/project');
await project.initialize({
components: {
// Define your component types
},
hooks: {
// Optional project-level hooks
}
});Component
Component represents individual project elements that can:
- Generate files from templates
- Create sub-components
- Apply lifecycle hooks
- Update and remove themselves
Basic Usage
Creating a Project
const project = new Project('/my-project');
await project.initialize({
components: {
'service': {
name: 'service',
path: 'src/services',
templates: [
{
source: 'service.ts.hbs',
target: '{{name}}.ts'
}
]
}
}
});Creating a Component
// Create a top-level component
const userService = await project.create('service', {
name: 'UserService'
});
// Add a sub-component to an existing component
const helperMethod = await userService.add('method', {
name: 'validateUser'
});Advanced Features
Hooks
Define lifecycle hooks for granular control:
const serviceConfig = {
name: 'service',
path: 'src/services',
templates: [...],
hooks: {
beforeCreate: async (context) => {
// Validate options
// Perform pre-creation logic
},
afterCreate: async (context) => {
// Log creation
// Trigger additional processes
}
}
};Validation
Component options can be validated using Zod schemas:
- Define validation rules when adding components
- Prevent invalid component creation
- Transform and normalize input data
- Provides detailed error messages
component.addComponent({
schema: z.object({
name: z.string().min(3),
type: z.enum(['service', 'model'])
})
})Template Rendering
Use Handlebars for dynamic template generation:
// service.ts.hbs
export class {{pascalCase name}} {
constructor(private config: {{configType}}) {}
async {{methodName}}() {
// Generated method
}
}API Reference
Project Methods
initialize(config?): Set up project structureaddComponent(config): Register a component typecreate(type, options): Create a top-level component
Component Methods
create(options): Create the componentupdate(options): Update component filesremove(): Delete the componentadd(type, options): Create a nested sub-component
Template File Configuration
source: Path to the Handlebars templatetarget: Output file path (supports Handlebars interpolation)required: Whether the file must always be generated
Error Handling
The library throws descriptive errors for:
- Unknown component types
- Invalid configurations
- File system issues
Performance Considerations
- Uses async/await for non-blocking file operations
- Supports recursive directory creation
- Minimal overhead for template rendering
Limitations
- Requires Node.js with native
fs/promisessupport - Template paths must be resolvable
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push and submit a Pull Request
License
MIT License
Contact
For questions, issues, or support, please open a GitHub issue.