@remix-breeze/cli
scaffold-crud
commandThe scaffold-crud
command (aliases: s-crud
, g-crud
) is a CLI tool designed to scaffold CRUD (Create, Read, Update, Delete) operations for a specified resource in your Remix-Breeze application.
This tool helps to automatically generate routes, Prisma models, services, and necessary pages for a specified resource, streamlining the development process.
@remix-breeze/cli scaffold-crud -r <ressource> -f <folder> -m <model> [-pr <parentRoute>]
@remix-breeze/cli scaffold-crud -r posts -m "title:string content:text isPublished:boolean"
npx prisma db push
npx prisma generate
You may also stop and restart your dev server with npm run dev
and navigate to the new resource routes to verify the generated CRUD operations.
-r, --ressource <ressource>
Description: The name of the resource for which CRUD operations will be scaffolded.
Required: Yes
-f, --folder [folder]
Description: The folder where the pages will be created.
Default: app/pages
Optional: Yes
-m, --model <model>
Description: Model fields in the format fieldName:type
.
Example: npx @remix-breeze/cli g-crud -r banners -m "title:string imageUrl:string?"
.
Required: Yes
-pr, --parent-route [parentRoute]
Description: The parent route path, to nest resource routes.
Default: /
Optional: Yes
Example: @remix-breeze/cli g-crud -r users -pr /admin -m "name:string email:string"
npx @remix-breeze/cli scaffold-crud -r posts -m "title:string content:text isPublished:boolean"
That will do the following change in the project:
Create the Post
model with the specified fields in the prisma/schema.prisma
file.
Create the post.service.ts
file inside the services
folder
Create the following routes and add the to the app/breeze.routes.config.js
file:
- /posts
- /posts/create
- /posts/:id
- /posts/:id/edit
- /posts/:id/delete
posts
folder inside the app/pages
directory with the corresponding component, loader anc action to display the UI for each route.npx @remix-breeze/cli scaffold-crud -r users -f app/pages/admin -pr /admin -m "name:string email:string"
That will do the following change in the project:
Create the User
model with the specified fields in the prisma/schema.prisma
file.
Create the user.service.ts
file inside the services
folder
Create the following routes and add the to the app/breeze.routes.config.js
file:
- /admin/users
- /admin/users/create
- /admin/users/:id
- /admin/users/:id/edit
- /admin/users/:id/delete
users
folder inside the app/pages/admin
directory with the corresponding component, loader anc action to display the UI for each route.Note: Make sure parent routes, in this case /admin
already exists in the breeze.routes.config.ts
file and the app/pages/admin
folder exists. Otherwise you'll get an error that the parent route is not found.
Here is a break down of what the scaffold-crud
(or g-crud
) command does internally:
Validate Input Options:
--ressource
and --model
are provided.Generate Model Fields Object:
model
input string to create an object representing model fields and their types.Scaffold CRUD Function:
Informational Output:
✅ CRUD scaffolded successfully!
---------------------------------------------------------------
👉Routes Created and Added to 'app/breeze.routes.config.js' :
---------------------------------------------------------------
✅ /posts
✅ /posts/create
✅ /posts/:id
✅ /posts/:id/edit
✅ /posts/:id/delete
---------------------------------------------------------------
👉Model 'Post' added to 'prisma/schema.prisma'
👉Service added to 'app/services' folder
👉Pages added to 'app/pages' folder
---------------------------------------------------------------
ℹ️ WHAT TO DO NEXT ?
-------------------
🖥️ Run the following command to update your database schema:
>👉 npx prisma db push
>👉 npx prisma generate
🚀 Restart your Remix server and navigate to '/posts' and see the magic happen