Table of Contents
Intro
In this post we will see how to create a Cli for your abp application.
Why a CLI?
The CLI is a great way to automate repetitive tasks. I use it to import large amounts of data into the database, to create new entities, to seed dummy data, etc.
Create a new CLI
To create a new CLI, you need to install the cli dotnet new template.
dotnet new install Anto.Cli.Template
Then you can create a new CLI project.
dotnet new cli-template -o MyProject --api myabpproject.com
Note: The --api parameter is the url of your abp project.
How to use it
The CLI is a dotnet core console application. You can run it with the following command.
dotnet run -- --help
Features
- Login
- Logout
- Seed Tenant
- Seed User
Future plans
- Import data from csv
Setup
Once you have created the cli there are few things you need to do.
- Create a new OpenIdConnect client in your abp project for the cli.
- Update the ClientId and Scope in the
AuthService.cs
file.
Generating HttpClient?
The CLI uses the abp REST API to communicate with the abp project. But that means you need to generate the HttpClient before you can use it. To do that, I have used nswag
to generate the client. To generate the client, you need to run the following command.
yarn gen-api
Note: You need to have
nswag
installed globally.#
Check the package.json
file for more details.
Storing the token
The CLI stores the token in the access-token.bin
file. If you want to change the location of the file, you can change it in the CliPaths.cs
file. the token is not encrypted, keep that in mind.
Code generation
This cli uses plop
to generate code. You can find the templates in the plop-templates
folder. You can add your own templates there.
Right now, there is only 3 templates. you can just run the following command to generate the code.
yarn plop
Note: Make sure you have install npm packages before running the command.
Repo: https://github.com/antosubash/abp-cli-template
Conclusion
This is a very simple CLI, but it can be very useful. I hope you like it.
Related Posts
ABP-Powered Web App with Inertia.js, React, and Vite
Building a web application with ABP Framework, Inertia.js, React, and Vite.
Migrating Tye to Aspire
In this post we will see how to migrate the Tye to Aspire
ABP React Template V2
Version 2 of React Starter Template for ABP application with Next.js, Tailwind CSS, and shadcn-ui.