Skip to content

Leaf CLI

Leaf CLI is a command line tool that helps you create, manage and deploy Leaf applications. It's a powerful tool that helps you get started with Leaf quickly and easily. You can do things like creating apps, running your projects, installing dependencies, and more.

Installation

This guide will assume that your system meets all the technical requirements.

You can verify that composer is installed by running:

bash
composer --version

To install the Leaf CLI, you can run the following command:

bash
composer global require leafs/cli -W

This tells Composer to install the Leaf CLI globally on your system. You can verify that the CLI is installed correctly by typing leaf in your terminal:

bash

 _              __    ___ _    ___ 
| |   ___ __ _ / _|  / __| |  |_ v4.x-dev
| |__/ -_) _` |  _| | (__| |__ | | 
|____\___\__,_|_|    \___|____|___|                       
     

Usage:
  command [options] [arguments]

Options:
  -h, --help  -  Display help for the given command.
  -V, --version  -  Display this application version

Available commands:
  list — List commands
  create — Create a new Leaf project
  update — Update leaf cli to the latest version
  install — Install a new package
  uninstall — Uninstall a package
  serve — Run a server to serve your Leaf app
  interact — Interact with your application
  run — Run a script in your composer.json
  view:build — Build your frontend assets
  view:install — Set up a new view engine
[Error] command not found: leaf

If you get an error saying leaf: command not found, you need to add Composer's global bin directory to your system's PATH. This directory contains every package installed through composer global require. Let's fix this by adding the directory to your PATH.

Depending on your operating system, the composer bin directory will be located in different places. You can find the location by running:

bash
composer global config bin-dir --absolute

If this command does not work, you can try these common locations:

  • Windows: %USERPROFILE%\AppData\Roaming\Composer\vendor\bin
  • macOS: $HOME/.composer/vendor/bin
  • GNU / Linux Distributions: $HOME/.config/composer/vendor/bin or $HOME/.composer/vendor/bin

Adding to PATH:

Once you have the location, you can add it to your PATH. On Mac and Linux, you can do this by running these in your terminal:

bash
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
source ~/.bashrc

Or if you're using Zsh:

bash
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.zshrc
source ~/.zshrc

Besides creating apps, Leaf CLI also helps you manage your apps. This includes things like running your app, dependency management, running commands, and more. This guide covers all such features.

Running your app

You can run your app by navigating into your app's directory and running the leaf serve command. This will start a development server and serve your app on localhost:5500.

bash
cd my-app
leaf serve

You can also specify a port to run your app on by passing the --port or -p flag:

bash
leaf serve --port=8080

The serve command also has a --watch flag that watches your app for changes and automatically reloads your app when changes are detected:

bash
leaf serve --watch

Note: The --watch flag is only available when running your app in development mode and uses nodejs to watch your app for changes.

If you want to run your application from a different directory, you can pass the path to the directory as an argument:

bash
leaf serve /path/to/your/app

Automatic dependency installation

When running your app, Leaf will automatically try to install missing dependencies if no vendor directory is found in your app's directory.

Running commands

Leaf CLI also allows you to run commands in your app's directory. If you have a command in your composer.json file, you can run it using the leaf run command:

bash
leaf run my-command

Dependency management

Leaf CLI also has commands built on top of Composer to help you manage your app's dependencies. Leaf has a whole ecosystem of packages that are treated as first-class citizens in the Leaf ecosystem, and are given special treatment by the CLI. This makes working with Leaf packages a breeze, but also allows you to work with any Composer package.

Are you a visual learner?

This video will help you understand how to work with packages on the Leaf CLI.

Installing packages

This cli tool also adds a feature to install leaf packages from composer.

bash
leaf install leafs/auth

If you are installing a leaf module or package, you can leave out the leafs/ part.

bash
leaf install auth

You can also pass in a bunch of packages to install at once.

bash
leaf install auth db illuminate/support

Versioning

Leaf CLI also allows you to install a particular version of any package using @

bash
leaf install auth@4.0 illuminate/support@9.0.2

Uninstalling packages

This works the same way as installing packages, but you use the uninstall command instead.

bash
leaf uninstall auth
leaf uninstall auth db illuminate/support

Building frontend setups

You can also use the view:build command to build your frontend setup for production.

bash
leaf view:build

Released under the MIT License.