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:
composer --version
To install the Leaf CLI, you can run the following command:
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:
_ __ ___ _ ___
| | ___ __ _ / _| / __| | |_ 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:
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:
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
source ~/.bashrc
Or if you're using Zsh:
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
.
cd my-app
leaf serve
You can also specify a port to run your app on by passing the --port
or -p
flag:
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:
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:
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:
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.
leaf install leafs/auth
If you are installing a leaf module or package, you can leave out the leafs/
part.
leaf install auth
You can also pass in a bunch of packages to install at once.
leaf install auth db illuminate/support
Versioning
Leaf CLI also allows you to install a particular version of any package using @
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.
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.
leaf view:build