component_creator 0.0.1
component_creator: ^0.0.1 copied to clipboard
A powerful CLI tool for automatically generating Flutter components with integrated design system theming. Streamlines the process of creating new Flutter widgets by generating all necessary files inc [...]
Component Creator #
A powerful CLI tool for automatically generating Flutter components with integrated design system theming. This tool streamlines the process of creating new Flutter widgets by generating all necessary files including the component widget, theme files, and proper integration with your design system.
π Features #
- Automated Component Generation: Create complete Flutter components with a single command
- Design System Integration: Automatically generates theme files and integrates with your design system
- File Structure Management: Creates organized directory structures for components and themes
- Code Formatting: Automatically formats generated code using Dart formatter
- Smart Naming Conventions: Converts component names to proper naming conventions (PascalCase, snake_case, camelCase)
- Theme Extension Support: Generates theme extensions for easy theming integration
- Error Handling: Comprehensive error handling with informative messages
π Prerequisites #
- Dart SDK >= 3.7.2
- Flutter SDK
- A Flutter project with design system structure
π οΈ Installation #
From Source #
- Clone the repository:
git clone <repository-url>
cd component_creator
- Install dependencies:
dart pub get
- Make the tool executable:
dart pub global activate --source path .
Global Installation #
dart pub global activate component_creator
π― Usage #
Basic Usage #
# Interactive mode - tool will prompt for component name
component_creator
# Direct mode - provide component name as argument
component_creator Button
component_creator "Custom Card"
component_creator MyAwesomeWidget
What Gets Generated #
When you run the tool with a component name (e.g., Button), it creates:
- Component Widget:
lib/components/ds_button/ds_button.dart - Theme File:
lib/theme/components/ds_button/ds_button_theme.dart - Theme Extension:
lib/theme/components/ds_button/ds_button_theme.ext.dart - Theme Integration: Updates
lib/theme/ds_theme.dartwith part directives - App Theme Integration: Updates
lib/theme/base/app_theme/ds_app_theme.dartwith extensions
Generated File Structure #
lib/
βββ components/
β βββ ds_button/
β βββ ds_button.dart
βββ theme/
βββ ds_theme.dart (updated)
βββ base/
β βββ app_theme/
β βββ ds_app_theme.dart (updated)
βββ components/
βββ ds_button/
βββ ds_button_theme.dart
βββ ds_button_theme.ext.dart
ποΈ Architecture #
Core Components #
ComponentCreator: Main orchestrator class that coordinates the component generation processTemplates: Contains all template strings for generating different file typesFileUtils: Utility class for file and directory operationsStringUtils: Extension methods for string manipulation and case conversion
File Generation Process #
- Input Processing: Validates and processes the component name
- Directory Creation: Creates necessary directories if they don't exist
- File Generation: Generates component widget, theme files, and extensions
- Integration: Updates existing theme files to include new components
- Code Formatting: Formats all generated code using Dart formatter
Naming Conventions #
The tool automatically converts component names to appropriate naming conventions:
- Component Class:
DS{ComponentName}(e.g.,DSButton) - File Names:
ds_{component_name}(e.g.,ds_button.dart) - Theme Class:
{ComponentName}Theme(e.g.,ButtonTheme) - Theme Extension:
{ComponentName}ThemeExt(e.g.,ButtonThemeExt)
π Project Structure #
component_creator/
βββ bin/
β βββ component_creator.dart # CLI entry point
βββ lib/
β βββ tool/
β β βββ component_creator.dart # Main component creator logic
β β βββ templates.dart # Template definitions
β β βββ file_utils.dart # File utility functions
β βββ utils/
β βββ string_utils.dart # String manipulation utilities
βββ test/
β βββ component_creator_test.dart # Test files
βββ example/ # Example Flutter project
βββ pubspec.yaml # Package configuration
π§ Configuration #
Design System Structure #
The tool expects your Flutter project to have the following structure:
lib/
βββ components/ # Component widgets
βββ theme/
β βββ ds_theme.dart # Main theme file
β βββ base/
β β βββ app_theme/
β β βββ ds_app_theme.dart # App theme configuration
β βββ components/ # Component themes
βββ constants/
βββ constants.dart # Design system constants
Required Dependencies #
Your Flutter project should include these dependencies for the generated components:
dependencies:
flutter:
sdk: flutter
design_system_project: ^1.0.0 # Your design system package
π§ͺ Testing #
Run the test suite:
dart test
π Generated Code Examples #
Component Widget Template #
import '../../theme/ds_theme.dart';
import 'package:flutter/material.dart';
import 'package:design_system_project/base/ds_base.dart';
class DSButton extends StatefulWidget {
const DSButton({super.key});
@override
State<DSButton> createState() => _DSButtonState();
}
class _DSButtonState extends DSStateBase<DSButton> {
late DSButtonTheme componentTheme =
theme.extension<DSButtonThemeExt>()!.dSButtonTheme;
@override
Widget build(BuildContext context) {
return Container();
}
}
Theme File Template #
part of '../../ds_theme.dart';
class DSButtonTheme {
// TODO: Define theme properties for DSButton component
}
Theme Extension Template #
part of '../../ds_theme.dart';
class DSButtonThemeExt extends ThemeExtension<DSButtonThemeExt> {
final DSButtonTheme dSButtonTheme = DSButtonTheme();
@override
ThemeExtension<DSButtonThemeExt> copyWith() {
return DSButtonThemeExt();
}
@override
ThemeExtension<DSButtonThemeExt> lerp(
covariant ThemeExtension<DSButtonThemeExt>? other,
double t,
) {
return DSButtonThemeExt();
}
}
π€ Contributing #
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
π License #
This project is licensed under the MIT License - see the LICENSE file for details.
π Troubleshooting #
Common Issues #
-
"File ds_app_theme.dart khΓ΄ng tα»n tαΊ‘i"
- Ensure your project has the correct design system structure
- Create the missing file or adjust the path in the tool
-
"Lα»i khi format code"
- Make sure Dart SDK is properly installed
- Check that
dart formatcommand works in your terminal
-
"TΓͺn component khΓ΄ng Δược Δα» trα»ng"
- Provide a valid component name as an argument
- Or enter a name when prompted in interactive mode
Getting Help #
If you encounter any issues:
- Check the error messages for specific guidance
- Verify your project structure matches the expected design system layout
- Ensure all required dependencies are installed
- Open an issue on GitHub with detailed error information
π Version History #
- v0.0.1: Initial release with basic component generation functionality