Magnolia CLI is an npm package providing a command line interface (CLI) tool to set up and facilitate light development with Magnolia. You can use Magnolia CLI to quickly create a  light module skeleton: the folders and files that form a Magnolia light module.

Light module minimal folder structure

Some Magnolia CLI commands may require that a minimal light module skeleton exists. For example, to run the create-app command, at least the following folder structure is expected to have been created:

<module-name>/
└── templates
├── components
└── pages

We currently have two versions of the CLI that are maintained. The main difference is how prototypes are handled. If you are a new user, use v3. If you are an existing user and want to continue with the same prototype structure as before, use v2.

This page provides instructions on how to install Magnolia CLI and tracks the changes in Magnolia CLI releases.

If you want to jump straight in, try out our Magnolia CLI walkthrough that provides step-by-step instructions to get everything set up and create a working light module.

Installing

Prerequisites: Node.js and Java

Node.js

The Magnolia CLI tool runs on Node.js. To check the version of your node.js installation, run the following command in a shell:

node -v
Node.js provides two branches:

  • LTS - recommended for long-term support
  • Current - providing the latest features 

Make sure you are running the latest version of the LTS branch. You can get it from https://nodejs.org/en/download. It may also be installed via package managers.

Java

Having Java installed is a prerequisite if you want to use the mgnl start CLI command to start Magnolia.

Magnolia needs a Java Runtime Environment (JRE) in at least version 8. See the Certified stack page to confirm the latest supported Java version. Type java -version in a terminal or command prompt. If the system reports a version number, Java is installed on your computer. If you don't have Java, install it:

Java is not pre-installed on Mac OS X 10.7 and later. Download the latest Java from Oracle.

On Windows you need a Java SE Development Kit (JDK). The Java Runtime Environment (JRE) is not enough because the Tomcat application server does not recognize it.

What is the difference?

  • JRE is for users who run Java programs on their computer.
  • JDK is for developers who write Java-based applications.

Download and install JDK. By default JDK is installed in C:\Program Files\Java\. You can choose another location.

Check JAVA_HOME environment variable

  1. Open the command prompt.
  2. Type set and press ENTER.
  3. Find JAVA_HOME in the command output and verify that the path points to your JDK installation directory.
  4. If JAVA_HOME is missing or it points to the wrong directory, see Set JAVA_HOME environment variable below.

Set JAVA_HOME environment variable

  1. Right-click My Computer and select Properties.
  2. Go to the Advanced tab. 
    (In Windows 7+, right-click Computer and select Advanced System Settings, then Environment variables.)
  3. If the JAVA_HOME environment variable does not exist in User variables or System variables, create it:
    • User variables apply to the currently signed-in user only. Create JAVA_HOME here if you want it to apply only to the currently logged in user. These variables take precedence over system variables.
    • System variables apply to all users. Create JAVA_HOME here if you want it to apply to all users. You must be an administrator to modify a system environment variable. 
  4. Set the value of JAVA_HOME to the path of your JDK installation directory, for example C:\Program Files\Java\jdk1.8.0_131.
  5. Optional step: Add the Magnolia bin directory to the PATH variable, for example C:\Program Files\magnolia\apache-tomcat-x.y\bin. Setting the PATH allows you to issue the Magnolia start and stop commands from anywhere without navigating to the installation directory first. Separate the path from existing paths with a semicolon ( ; ). If you do this, you also need to add CATALINA_HOME to environment variables. Set the value of CATALINA_HOME to the Tomcat installation directory, for example C:\Program Files\magnolia\apache-tomcat-x.y
  6. Click OK.
  7. Go back to Check JAVA_HOME environment variable above and test that the variable is found and has the correct value. You need to open a new command prompt since environment variables are session specific.

Alternatively you can set JAVA_HOME with a batch file, by adding a line like the one below to /apache-tomcat/bin/magnolia_control.bat:

set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_131

The set command creates the JAVA_HOME environment variable and sets its value to the JDK directory. The command is executed when Magnolia starts.

Download the latest Java from Oracle. The installation directory varies from one Linux system to another. For example, on Ubuntu 18.04 the OpenJDK is installed in /usr/lib/jvm/java-11-openjdk-amd64/bin/java by default.

Download the latest Java from Oracle. You can install it in any directory such as /usr/java.

Installing Magnolia CLI

Best practice

Install Magnolia CLI globally.

  • The configuration is stored globally.
  • The commands are available in the shell on all directories.
  • The global configuration can be overridden on a project level using the customize-local-config command.
The instructions that follow are based on the global npm package installation.

Which versions are available?

To display a list of released versions of Magnolia CLI, enter the following command in a shell:

npm view @magnolia/cli versions

Besides a version list, the following command shows additional information about the Magnolia CLI package:

npm view @magnolia/cli

Installing the latest version

To install the latest version (globally), run the following command in a shell:

npm install @magnolia/cli -g

Depending on your permissions and the Node.js installation location, you may have to execute the above command with root permissions. On Linux or OS-X, to run this command as root, use:

sudo npm install @magnolia/cli -g

Installing a specific version

To install a specific version (globally), for example, 2.1.0, run the following command in a shell:

npm install @magnolia/cli@2.1.0 -g

Depending on your permissions and the Node.js installation location, you may have to execute the above command with root permissions. On Linux or OS-X, to run this command as root, use:

sudo npm install @magnolia/cli@2.1.0 -g

Installing the latest development version

The master branch on https://git.magnolia-cms.com/scm/build/npm-cli.git typically contains the version with the latest code. You may alternatively check out the latest code and simply install it from source. (warning) Please be aware that the official documentation does not cover the functionalities and changes of development versions.

To install the latest version from the master, do the following after checking out the latest code:

npm pack
sudo npm install ~/dev/cli3/npm-cli/magnolia-cli-<version>.tgz -g

Updating Magnolia CLI

If you have already installed the CLI and want to update to the latest version, use:

npm update @magnolia/cli -g

Testing the installation

To test the installation, run the following command in the shell:

mgnl help

Shell autocompletion

The Magnolia CLI package provides autocompletion for bash, C-shell and Windows PowerShell

To install/enable autocompletion, use:

mgnl tab-completion install

To uninstall it, use:

mgnl tab-completion uninstall

A successful installation of autocompletion displays a list of files to which the tab-completion script has been appended.

To test the autocompletion installation, type mgnl and then successively hit the Tab key to scroll through the available commands.

On Windows, autocompletion is only available in PowerShell. If it does not work as expected after installation, you may have to change your execution policy. To do this, in PowerShell, run as Administrator:

Set-ExecutionPolicy RemoteSigned

Uninstalling old autocompletion source

If you have already used autocompletion with Magnolia CLI version below 2.0, you may want to uninstall the "old" autocompletion manually. To do so, remove the following line in your bash settings (in ~/.profile or ~/.bashrc):

source /usr/local/lib/node_modules/@magnolia/cli/extra/mgnl-autocompletion.sh

Release history

3.1.0

Released on June 26, 2019.

  • This release comes with full support for Magnolia 6.1 and content types. It also seamlessly handles both the new DX Core artifacts introduced with the release of Magnolia 6.1 and the old ones.
    If you install Magnolia using the CLI jumpstart command and set the -m switch to 6.1 or higher, the CLI offers the new dx-core webapps for installation.

    $ mgnl jumpstart -m 6.1
    
    ? What Magnolia would you like to install? 
      1) magnolia-empty-webapp
      2) magnolia-community-webapp
      3) magnolia-community-demo-webapp
      4) magnolia-dx-core-webapp
      5) magnolia-dx-core-demo-webapp

    If you set -m to below 6.1, the CLI offers the former Enterprise and Cloud webapps.

    $ mgnl jumpstart -m 5.7.3
    
    ? What Magnolia would you like to install?
      1) magnolia-empty-webapp
      2) magnolia-community-webapp
      3) magnolia-community-demo-webapp
      4) magnolia-enterprise-standard-webapp
      5) magnolia-enterprise-standard-demo-webapp
      6) magnolia-enterprise-pro-webapp
      7) magnolia-enterprise-pro-demo-webapp
      8) magnolia-cloud-dev-webapp
  • Two new commands have been added: create-app, which creates a content type and an app based on it, and create-content-type, which creates a content type. NPMCLI-149
  • This release also fixes an issue with the jumpstart command when running it behind a proxy and updates third-party dependencies due to some vulnerabilities. NPMCLI-206,  NPMCLI-223

3.0.7

Released on March 12, 2019.

This release fixes a security vulnerability found in the adm-zip package by removing the dependency to this package. The unzipping process during the CLI installation is now handled by the decompress-zip library. NPMCLI-198

3.0.6

Released on February 11, 2019.

This release brings an additional fix to the jumpstart  command, which was failing when issued from behind a proxy server. The issue, again, originated in the Axios client. CLI is now using axios-https-proxy-fix instead of the axios-proxy-fix. NPMCLI-207

3.0.5

Released on December 17, 2018.

This release fixes an issue with the jumpstart command, which was failing when issued from behind a proxy server. The issue concerns Axios, a promise-based HTTP client. Until the issue is solved by Axios, you can work around it by including the axios-proxy-fix package. NPMCLI-176

3.0.4

Released on September 24, 2018.

When executing the jumpstart command with the snapshot flag, Magnolia CLI will download not only the latest snapshot development version of the specified webapp but also the latest snapshot version of the Magnolia  tomcat-barebone bundle. NPMCLI-194

3.0.3

Released on August 28, 2018.

Fixed an issue with the create-page command on Windows where the dialog and templateScript properties were incorrectly set to undefined. NPMCLI-189

3.0.2

Version 3.0.2 was not published due to an issue with npm.

3.0.1

Released on June 8, 2018.

Fixed an issue with the jumpstart command that was caused by a regression in the adm-zip dependency. NPMCLI-182

3.0.0

Released on March 12, 2018.

  • New command create-blocks to create blocksNPMCLI-132
  • New command create-virtual-uri to create a virtual URI mappingNPMCLI-135
  • Prototypes:
    • New prototype structure with an expanded choice of prototype options. NPMCLI-119
    • Prototypes allow the creation of additional custom files in any directory of the light module. NPMCLI-86
    • Prototype variants to create component or page templates with a JavaScript modelNPMCLI-137
    • Prototype variants to create a light module. NPMCLI-148
    • Prototypes to create blocks with the new command create-block
    • Prototypes to create a virtual URI mapping with the new command create-virtual-uri.
  • Based on user feedback, Magnolia no longer checks for the nearest Tomcat folder when you create a light-modules folder and so the -f (force) option has been removed from the create-light-module command. NPMCLI-159
  • jumpstart:
    • You can use the new -w option to choose which Magnolia webapp you want to install when using the jumpstart command. With this, the options -e and -c are no longer available. NPMCLI-120
    • You can choose the latest SNAPSHOT of the selected webapp. NPMCLI-144
    • Jumpstart does not set the wrong light-modules directory on Windows anymore. NPMCLI-156
    • Jumpstart stores downloaded artifacts in a separate folder to reuse them later. This also fixes a bug where -e and -c options were ignored due to an already existing artifact with a generic filename. NPMCLI-100
  • mgnl-cli.json:
    • No longer contains the lightDevFoldersInModule property. The folder structure of a light module created with the CLI is defined in the prototypes.
    • The webapps property is used to define the list of possible webapps you can choose from from when running the jumpstart command.
  • The -V option, which used to display the version information of the installed Magnolia CLI, has been replaced with a lower-case option (-v). The output now also displays the version of Node.js installed. NPMCLI-133

Key Summary T Created Status
Loading...
Refresh

2.2.0

Released on January 18, 2018.

  • Node v 6.10+ is required to run the CLI.
  • A new option -c (--cloud) has been added to the jumpstart command. mgnl jumpstart -c downloads and sets up a Magnolia Cloud bundle. It requires Enterprise credentials to access the Magnolia Nexus repositoryNPMCLI-138
  • If no -p option is set when executing the jumpstart command, the  magnolia.resources.dir property in the magnolia.properties file is set to a relative path by default:  magnolia.resources.dir=${magnolia.home}/../../../light-modules NPMCLI-129
  • When creating a light module with the mgnl create-light-module command, if you specify a path to a light modules folder that does not match the light modules root folder at the nearest Tomcat installation, you get an error. The error warns you that Magnolia cannot observe your module in the location specified. You can use the -f option if you want to force the path to an unobserved folder. NPMCLI-103

  • To help us help you in case you run into an issue, the mgnl -h command now also prints out your node.js version, OS and Magnolia CLI version. NPMCLI-128
  • The mgnl create-component command now generates a component dialog definition YAML file containing label options (instead of the previously used name) for i18n compliance. NPMCLI-105

Key Summary T Created Status
Loading...
Refresh

2.1.0

Released on March 17, 2017.

  • Two new commands have been added:
    • search - helps find light modules on npm. NPMCLI-99
    • install - installs a light module from the registry into your light modules folder. NPMCLI-98
  • In the prototype dialog template, the image alt attribute uses the caption property. NPMCLI-31
  • The placeholder __lightDevModuleFolder__ for the name of the corresponding light module can be used in all prototypes files for page and component templates (in mgnl-cli-prototypes/page/* and mgnl-cli-prototypes/component). NPMCLI-84
  • The tab-completion install command, if completed successfully, also displays the files (together with their paths) to which the autocompletion script has been appended. NPMCLI-107
  • All CLI i18n messages are served from a single location ( lib/locales/ ). The messages in English are located in the en subfolder. NPMCLI-91
  • This release also fixes a few bugs. A complete list of the issues that have been resolved in version 2.1.0 is available via the following link:

Key Summary T Created Status
Loading...
Refresh

2.0.0

Released on February 27, 2017.

This version contains many improvements and bug fixes. Here is an incomplete list of the new or changed features:

  • New command start for easy start, stop and logging of Magnolia. NPMCLI-58
  • Improved autocompletion: (NPMCLI-69)
    • Can be enabled and disabled with the new command mgnl tab-completion.
    • Is now available not only for bash, but also for C-shell and Windows PowerShell
    • Knows more things to autocomplete.
    • (warning) If you were using autocompletion in a Magnolia CLI version below 2.0, you may want to uninstall autocomplete version 1.
  • User experience enhanced by:
    • Improved error and crash handling.
    • Instructions on how to continue when a command is successfully executed.
  • setup command is renamed to customize-local-config command. NPMCLI-101 
  • add-availability command defaults to main area when no area is specified. NPMCLI-48
  • create-light-module command generates README files. NPMCLI-62
  • Node v 6.0+ is required to run the CLI.

Key Summary T Created Status
Loading...
Refresh

Video: Magnolia CLI Tool makes web developers' lives easier

Please note that this video is based on Magnolia CLI 2.0.0 and Magnolia 5.5.1 Community Edition. (The latest release of Magnolia is

Error rendering macro 'artifact-resource-macro'

com.sun.jersey.api.client.ClientHandlerException: java.net.NoRouteToHostException: No route to host (Host unreachable)

.)

Pre-2.0.0 versions

All pre-2.0.0 versions of Magnolia CLI are considered beta and no official documentation is available for them.

See also

#trackbackRdf ($trackbackUtils.getContentIdentifier($page) $page.title $trackbackUtils.getPingUrl($page))