1.1.1 • Published 10 months ago

@asaidimu/blueprint v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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/blueprint

Core 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 structure
  • addComponent(config): Register a component type
  • create(type, options): Create a top-level component

Component Methods

  • create(options): Create the component
  • update(options): Update component files
  • remove(): Delete the component
  • add(type, options): Create a nested sub-component

Template File Configuration

  • source: Path to the Handlebars template
  • target: 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/promises support
  • Template paths must be resolvable

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push and submit a Pull Request

License

MIT License

Contact

For questions, issues, or support, please open a GitHub issue.

1.1.1

10 months ago

1.1.0

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago