# Maker Console
# Introduction
Maker is the command line interface for ExpressWebJs. Maker exists at the root of your application as the maker script and provides a number of helpful commands that can assist you while building your application. To view a list of all available Maker commands, you may use the help command:
# Writing Commands
To create a new command, you may use the make-command .This command will create a new command class in the App/Console/Commands directory. Don't worry if this directory does not exist in your application, it will be created the first time you run the make-command
Let's take a look at an example command:
import Command from "maker-console-ts"; class SendEmails extends Command { signature: string; arguments: object[]; description: string; constructor() { super(); //The name or signature of the console command. this.signature = ""; /** * The name and mode of the console command argument. * name is the name of the argument while mode can be REQUIRED or OPTIONAL * Example [{name: "Debug", mode: "REQUIRED"},{name: "Task", mode: "REQUIRED"}] */ this.arguments = []; /** * The console command description. * @var string */ this.description = ""; super.checkCommandName(this.signature); } /** * Execute the console command. * * @return mixed */ fire() { // } } export default SendEmails;
Copied!
# Command Structure
After Generating your maker command, you should define appropriate values for the signature,arguments and description properties of the class. These properties will be used when adding your command to the maker command.
The arguments property allows you to define your commands arguments which can be REQUIRED or OPTIONAL.
To define an argument of emailAddress in the SendEmails command, we can do so:
this.arguments = [{name:”emailAddress”,mode:”REQUIRED”}].
Copied!
You can add multiple arguments.
# fire method
The fire method will be called when your command is executed. You may place your command logic in this method.
# Retrieving Input
While your command is executing, you will likely need to access the values for the arguments and options accepted by your command. To do so, you may add the argument name as a parameter to the fire method. If the argument does not exist, undefined will be returned.
/** * Execute the console command. * * @return mixed */ fire(userDetails:{name:string,email:string}) { console.log(`My name is ${userDetails.name}, and my email is ${userDetails.email}`); }
Copied!
# Registering Your Command
All of your console commands are registered within your application's App\Console\Kernel class, which is your application's console kernel. You may register commands by adding the command to the commands method of your App\Console\Kernel class. When Maker boots, all the commands listed in commands method will be resolved and registered with Maker:
import SendEmails from "./Commands/SendEmails_command"; class Kernel { /** * The Maker commands provided by your application. * @var array */ static commands() { return [SendEmails]; } } export default Kernel;
Copied!