Skip to content

Commands

Laratype provides a number of utility commands to help you manage and develop your application. These commands can be run from the command line (CLI) and are typically used to create new components, run the development server, and perform other tasks. You can learn more here.

However, you can create your own custom commands to serve the specific needs of your application. Below is a basic guide on how to create and use commands in Laratype.

INFO

Commands are organized in the console/commands directory.

INFO

Laratype uses the commander library to manage CLI commands.

Creating a New Command

Generate Command

sh
$ npx sauf make:command SendMail
sh
$ pnpx sauf make:command SendMail
sh
$ bunx sauf make:command SendMail

Laratype will create a new command file in the src/console/commands/ directory with the name SendMail.ts.

TIP

You can create multiple commands at once by passing multiple names.

See more
sh
$ npx sauf make:command SendMail AnotherCommand
sh
$ pnpx sauf make:command SendMail AnotherCommand
sh
$ bunx sauf make:command SendMail AnotherCommand

Writing Command

ts
import { Command } from "@laratype/console";

export default class SendMail extends Command {

  static signature = "send:mail";

  static description = "Send a test email";

  public async handle() {
    console.log("Sending a test email...");
  }

}

Each command inherits from the Command class available in the @laratype/console package. You need to define the signature and description properties to describe the command, and the handle() method to contain the command's execution logic.

Options

You can define options for your command using static options in the command class.

ts
import { Command } from "@laratype/console";

export default class SendMail extends Command {

  static signature = "send:mail";

  static description = "Send a test email";

  static options = [
    ['-d, --date <date>', 'Date to send the email', '2025-11-29'],
    ['-l, --logs <logs>', 'Logs to display', 'info'],
  ]

  public async handle() {
    const options = this.opts();
    console.log(`Sending email on date: ${options.date}`);
    console.log(`Logging level: ${options.logs}`);
    console.log("Sending a test email...");
  }

}

Arguments

You can define arguments for your command using static arguments in the command class.

ts
import { Command } from "@laratype/console";

export default class SendMail extends Command {

  static signature = "send:mail";

  static description = "Send a test email";

  static arguments = [
    {
      name: "<ids...>",
      description: "The IDs of users to send email to",
    }
  ]

  public async handle(userIds: string[]) {

    for (const id of userIds) {
      console.log(`Sending email to user ID: ${id}`);
    }
  }

}

Running Commands

After creating a command, you can run it from the command line using the sauf or saufx (for production environment) command. For example, to run the SendMail command, you would use:

Development
sh
$ npx sauf send:mail
sh
$ pnpx sauf send:mail
sh
$ yarn sauf send:mail
sh
$ bunx sauf send:mail
Production
sh
$ npm saufx send:mail
sh
$ pnpm saufx send:mail
sh
$ yarn saufx send:mail
sh
$ bun saufx send:mail

You can get a list of all available commands by running:

Development
sh
$ npx sauf -h
sh
$ pnpx sauf -h
sh
$ yarn sauf -h
sh
$ bun sauf -h
Production
sh
$ npm saufx -h
sh
$ pnpm saufx -h
sh
$ yarn saufx -h
sh
$ bun saufx -h