Build ποΈ
The build
command in Forge cli is used to generate the necessary backend integration and BLoC state management code for a specified feature. This command automates the creation of repositories, data sources, and BLoC components based on annotations in the repository interface.
Usageβ
forge_cli build <feature_name>
Replace <feature_name>
with the name of the feature you want to build.
Exampleβ
To build the post
feature, you would run:
forge_cli build post
Prerequisitesβ
Before using the build
command, you should have already created the feature using the make
command. Refer to the Make Command Documentation for more details.
Subscription Requirementβ
The build
command requires a subscription. You need to log in to our website and get your API key
.
- Create an Account: Go to forgecli.dev and sign up for a new account.
- Obtain Your API Key: After creating your account, log in and obtain your API key
Configure Forge cliβ
To use the build
command, you must configure Forge cli with your API key:
forge_cli token <your_api_key>
Replace <your_api_key>
with the API key you obtained from your account on the Forge cli website.
Steps to Follow πΎβ
- Create the Feature: Start by creating the feature using the make command:
forge_cli make post
- Define Repository Interface: Navigate to
lib/features/post/domain/repositories/post_repository.dart
and define the functions you need in the repository interface. You must specify annotations for each function so the CLI knows which HTTP method to use. You can also create entities and models as needed.
Here is an example of how your post_repository.dart
should look:
import 'package:dartz/dartz.dart';
import 'package:your_project_name/core/error/failures.dart';
import 'package:your_project_name/features/post/domain/entities/post_entity.dart';
import 'package:your_project_name/features/post/data/models/post_model.dart';
abstract class PostRepository {
(endPoint: 'api/posts')
Future<Either<Failure, List<PostModel>>> getPosts();
(endPoint: 'api/posts/{id}')
Future<Either<Failure, PostModel>> getPostById();
(endPoint: 'api/posts')
Future<Either<Failure, Unit>> createPost(PostEntity p);
(endPoint: 'api/posts')
Future<Either<Failure, Unit>> updatePost(PostEntity p);
(endPoint: 'api/posts')
Future<Either<Failure, Unit>> deletePost(PostEntity p);
}
- Run the Build Command: Once the repository interface is defined, run the build command:
forge_cli build post
Generated Folder Structureβ
When you run the build
command, Forge cli generates the necessary backend integration and BLoC state management code. Hereβs an example of the folder structure created for the post
feature:
βββ data
β βββ datasources
β β βββ post_data_source.dart
β βββ models
β β βββ post_model.dart
β β βββ post_models_export.dart
β βββ repositories
β βββ post_repository_impl.dart
βββ domain
β βββ entities
β β βββ post_entities_export.dart
β β βββ post_entity.dart
β βββ repositories
β β βββ post_repository.dart
β βββ usecases
β βββ create_post_usecase.dart
β βββ delete_post_usecase.dart
β βββ get_post_by_id_usecase.dart
β βββ get_posts_usecase.dart
β βββ update_post_usecase.dart
βββ presentation
βββ blocs
β βββ create_post
β β βββ create_post_bloc.dart
β β βββ create_post_bloc.freezed.dart
β β βββ create_post_event.dart
β β βββ create_post_state.dart
β βββ delete_post
β β βββ delete_post_bloc.dart
β β βββ delete_post_bloc.freezed.dart
β β βββ delete_post_event.dart
β β βββ delete_post_state.dart
β βββ get_post_by_id
β β βββ get_post_by_id_bloc.dart
β β βββ get_post_by_id_bloc.freezed.dart
β β βββ get_post_by_id_event.dart
β β βββ get_post_by_id_state.dart
β βββ get_posts
β β βββ get_posts_bloc.dart
β β βββ get_posts_bloc.freezed.dart
β β βββ get_posts_event.dart
β β βββ get_posts_state.dart
β βββ update_post
β βββ update_post_bloc.dart
β βββ update_post_bloc.freezed.dart
β βββ update_post_event.dart
β βββ update_post_state.dart
βββ views
β βββ post_screen.dart
βββ widgets
βββ example_widget.dart