Skip to main content

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.

  1. Create an Account: Go to forgecli.dev and sign up for a new account.
  2. 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 πŸΎβ€‹

  1. Create the Feature: Start by creating the feature using the make command:
  forge_cli make post
  1. 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);
}
  1. 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