lean_builder 0.1.0
lean_builder: ^0.1.0 copied to clipboard
A streamlined Dart build system that applies lean principles to minimize waste and maximize speed. Designed for developers who value efficiency and performance.
Lean Builder #
A streamlined Dart build system that applies lean principles to minimize waste and maximize speed.
Table of Contents #
- Disclaimer
- Overview
- Features
- Installation
- Usage
- Creating Builders
- Advanced Usage
- Performance Tips
- Contributing
- License
Disclaimer #
Some core concepts and code-abstractions are borrowed from the Dart build system. However, Lean Builder is designed as a more efficient and user-friendly alternative, not a direct replacement. It prioritizes performance and simplicity while offering a streamlined approach to code generation.
Overview #
Lean Builder is a code generation system designed to be fast, efficient, and easy to use. It provides a streamlined alternative to other build systems with a focus on performance and developer experience.
Features #
- β‘ Fast incremental builds
- π Native code compatibility (no mirrors dependency)
- π§΅ Parallel processing for maximum efficiency
- π Watch mode with hot reload support
- π Simple, declarative builder configuration using annotations
- π§© Comprehensive asset tracking and dependency management
- π Support for shared part builders, library builders, and standard builders
- π§ Customizable build pipelines
- π Build performance analytics
- π οΈ And much more!
Installation #
Add Lean Builder to your pubspec.yaml as a dependency:
dev_dependencies:
lean_builder: ^1.0.0
Usage #
One-time Build #
To generate code just once:
dart run lean_builder build
Options:
dart run lean_builder build [--release] [--verbose] [--dir=<directory>]
Watch Mode #
For continuous builds during development:
dart run lean_builder watch
Use the --dev flag for development mode with hot reload support:
dart run lean_builder watch --dev
Additional options:
dart run lean_builder watch [--dev] [--verbose] [--port=<number>]
Cleaning Build Cache #
To clean all generated files and cache:
dart run lean_builder clean
Creating Builders #
Lean Builder offers multiple ways to create code generators, from simple annotations to custom builders.
Using LeanGenerator #
Library Generator
Create a generator that outputs standalone library files:
@LeanGenerator({'.lib.dart'})
class MyGenerator extends GeneratorForAnnotatedClass<MyAnnotation> {
@override
Future<String> generateForClass(BuildStep buildStep, ClassElement element, MyAnnotation annotation) async {
return '// Generated code for ${element.name}';
}
}
Shared Part Generator
Create a generator that outputs part files that can be included in multiple libraries:
@LeanGenerator.shared()
class MySharedGenerator extends GeneratorForAnnotatedClass<MyAnnotation> {
@override
Future<String> generateForClass(BuildStep buildStep, ClassElement element, MyAnnotation annotation) async {
return '// Generated code for ${element.name}';
}
}
Custom Builders #
For more control, create a custom builder by extending the Builder class:
@LeanBuilder()
class MyBuilder extends Builder {
@override
Set<String> get outputExtensions => {'.lib.dart'};
@override
bool shouldBuildFor(BuildCandidate candidate) {
return candidate.isDartSource && candidate.hasTopLevelMetadata;
}
@override
FutureOr<void> build(BuildStep buildStep) async {
final resolver = buildStep.resolver;
final library = await resolver.resolveLibrary(buildStep.asset);
final elements = library.annotatedWith('<type-checker>');
// Your build logic here
await buildStep.writeAsString('// Generated code', extension: '.lib.dart');
}
}
Registering Runtime Types #
To use your runtime types with type checkers, register them with Lean Builder:
@LeanBuilder(registerTypes: {MyAnnotation})
// ...
final myAnnotationChecker = resolver.typeCheckerOf<MyAnnotation>();
}
**Note**: Generic types of `GeneratorForAnnotation<Type>` and its subclasses are automatically registered.
## Advanced Usage
### Build Configuration
Create a `build.yaml` file in your project root to customize build behavior:
```yaml
targets:
$default:
builders:
lean_builder:my_builder:
enabled: true
options:
option1: value1
option2: value2
Performance Optimization #
Configure build performance settings: @LeanBuilder( concurrency: 4, priority: BuildPriority.high, cacheResults: true ) class MyOptimizedBuilder extends Builder { // Implementation }
## Performance Tips
- Use incremental builds for faster development cycles
- Register only the types you need to minimize startup time
- Leverage shared builders when appropriate to reduce redundant code generation
- Consider setting appropriate concurrency levels based on your machine's capabilities
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## License
This project is licensed under the MIT License - see the LICENSE file for details.
constant.get('constKey'); // Constant?;
}
if (constant is ConstList) {
constant.value; // List<Constant>
constant.literalValue; // List<dynamic>, dart values
}
if (constant is ConstFunctionReference) {
constant.name; // the name of the function
constant.type; // the type of the function
constant.element; // the executable element of the function
}
}