On this page

@remix-breeze/cli

The scaffold-crud command

The 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.

Description

This tool helps to automatically generate routes, Prisma models, services, and necessary pages for a specified resource, streamlining the development process.

Usage

@remix-breeze/cli scaffold-crud -r <ressource> -f <folder> -m <model> [-pr <parentRoute>]

Example

@remix-breeze/cli scaffold-crud -r posts -m "title:string content:text isPublished:boolean"
After successful command execution, you may run the following commands to update your database with the new ressource:

Commands for Next Steps

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.

Command Options

  • -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"

Simple Command Example

npx @remix-breeze/cli scaffold-crud -r posts -m "title:string content:text isPublished:boolean"

That will do the following change in the project:

  1. Create the Post model with the specified fields in the prisma/schema.prisma file.

  2. Create the post.service.ts file inside the services folder

  3. 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
  1. Create a posts folder inside the app/pages directory with the corresponding component, loader anc action to display the UI for each route.

Advanced Command Example

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:

  1. Create the User model with the specified fields in the prisma/schema.prisma file.

  2. Create the user.service.ts file inside the services folder

  3. 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
  1. Create a 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.

What the Command Does Internally

Here is a break down of what the scaffold-crud (or g-crud) command does internally:

  1. Validate Input Options:

    • Checks if the required options --ressource and --model are provided.
    • Validates the types of provided options.
    • Validates ressource not yet exists in the project.
  2. Generate Model Fields Object:

    • Parses the model input string to create an object representing model fields and their types.
  3. Scaffold CRUD Function:

    • Calls the internal scripts to:
      • Create routes.
      • Create Prisma model.
      • Create service.
  4. Informational Output:

    • Informs the user of the successful scaffolding, displaying the created routes, model, and service locations.
    • Provides next steps to update the database schema using Prisma and restart the Remix server.

Example Command 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
Docs and examples licensed under MIT