This page describes the Magnolia CLI v5, its core components, and how to install it.
Plugin-based CLI
Magnolia CLI in version v5 is a plugin-based system.
The purpose of this architecture is to offer developers enhanced flexibility, control, customization of commands by creating a plugin, and definition of their own project templates.
The CLI itself provides the core functionality and oversees the operation of the plugins.
It uses a configuration file called mgnl.config.js, where you can configure the logger and the plugins.
The plugins specified in this file are loaded by the CLI.
To meet the requirements of your project, you can modify the file to use it with your own plugin collection.
We recommend you use the Jumpstart plugin or install the Magnolia CLI locally at project level.
This approach allows each project to:
maintain its unique configuration within the mgnl.config.js file,
have separate plugins per project, and
to manage different versions of the CLI and the plugins more effectively.
Through the jumpstart plugin
This following command prompts you to choose a project template, automatically installs the CLI locally at the project level, and sets up the required files (package.json and mgnl.config.js) for you.
npx @magnolia/cli@latest jumpstartCopy
Locally
To install the latest production version locally at the project level, do the following:
Initialize the project if it’s not already set up:
Windows users using PowerShell must enclose the two consecutive hyphens (--) in quotes:
npm run mgnl "--" ...Copy
Version
npm run mgnl -- -VCopy
Windows users using PowerShell must enclose the two consecutive hyphens (--) in quotes:
npm run mgnl "--" ...Copy
Globally
Help
mgnl -hCopy
Version
mgnl -VCopy
Updating
Locally
To update the CLI installed locally, run the following npm command in your project directory.
npm update @magnolia/cliCopy
Globally
To update the CLI installed globally, run the following npm command:
sudo npm update @magnolia/cli -g (1)Copy
1
The sudo part of the command may be required on Linux or macOS, depending on your permissions and the Node.js installation location.
Migrating from v4 to v5
This section describes how to migrate an existing project from Magnolia CLI v4 to CLI v5.
The procedure applies to all v4 projects, regardless of their rendering type.
A key change is that CLI v5 is installed at the project level instead of being installed globally.
This makes the CLI more modular.
Each project can have its own specific CLI version and configuration.
Migration steps
Initializing package.json in the project root.
Navigate to the project root and create the package.json file if it doesn’t exist there yet.
Use the following command to initialize the file and automatically set "type": "module":
The command initializes the project with default values, adds "type": "module" to the package.json file, and ensures compatibility with the ES module syntax in NodeJS.
You may need to add "type": "module" to the package.json file manually if the npm init -y command doesn’t work as expected.
Installing CLI v5 locally.
Install Magnolia CLI v5 at the project level:
npm install @magnolia/cliCopy
This installs CLI v5 into the project’s node_modules directory.
Adding a start script.
To simplify running the CLI, add the mgnl script to package.json.
The script allows you to execute the CLI with just npm run mgnl: