Create Light Module plugin

A plugin to create a new light module. It creates the light module as a set of folders (mostly empty) and the following two files:

  • README.md, in the root folder of the module.

  • <moduleName>-messages_en.properties, in the i18n folder.

Package name

@magnolia/cli-create-light-module-plugin

Repository link

Latest version

Magnolia CLI create light module plugin - latest version tag

Changelog link

Prototypes available

  • _default: Contains frequently used light-module folders

  • comprehensive: Contains folders to create the most complete light-module structure

Installing

The plugin doesn’t come pre-installed with Magnolia CLI. You must add it to the mgnl.config.js project file.

The plugin is installed automatically by the Jumpstart plugin if it is defined in a project template.

With add-plugin

Run the following command in the project folder.

npm run mgnl -- add-plugin @magnolia/cli-create-light-module-plugin

The command automatically downloads, installs, and registers the plugin in mgnl.config.js.

Manually

  1. Run the following command in the project folder.

    npm install @magnolia/cli-create-light-module-plugin
  2. Modify the mgnl.config.js file accordingly.

    import CreateLightModulePlugin from "@magnolia/cli-create-light-module-plugin";
    
    export default {
      plugins: [
        new CreateLightModulePlugin()
      ]
    };

Usage

Command

create-light-module <name> [options]

Options

Form (short and long) Description

-d [directories…​]

--directories [directories…​]

Create specific directories within the light module.

Example: -d A D creates the apps and decorations directories.

Mappings available:

  • A - apps

  • B - blocks

  • C - contentTypes

  • D - decorations

  • DIA - dialogs

  • I - i18n

  • INC - includes

  • M - messageViews

  • R - restEndpoints

  • T - templates

  • THM - themes

  • V - virtualUriMappings

  • W - webresources

Conflicts:

  • -p, --prototype

  • -pd, --prototypeDir

-lmp <path>

--light-modules-path <path>

Sets the directory path for the new light module. By default, uses the directory specified in the mgnl.config.js file.

-pd <path>

--prototype-dir <path>

Allows you to use the path to the custom prototype templates directory as the prototype source for light module creation.

Conflicts:

  • -d, --directories

-p [name]

--prototype [name]

Selects a light module prototype.

Conflicts:

  • -d, --directories

-v

--version

Displays the version.

-h

--help

Displays help information.

Examples

In the following examples, assume that the mgnl.config.js file looks like this:

import CreateLightModulePlugin from "@magnolia/cli-create-light-module-plugin";

export default {
  plugins: [
    new CreateLightModulePlugin()
  ]
};

For more information, see Configuring plugins.

Create light module

npm run mgnl -- create-light-module "my-lm"

This command creates a new light module directory called my-lm based on the _default prototype.

The plugin will prompt you to choose a directory where the new light module will be created.

The plugin writes the following properties to the mgnl.config.js file:

  • Global

    • lightModulesPath

    • lightModule

Create a light module in a specific light modules directory

npm run mgnl -- create-light-module "my-lm" --light-modules-path "./magnolia/light-modules"

This command creates a new light module directory called my-lm based on the _default prototype.

If the ./magnolia/light-modules doesn’t exist, the plugin will prompt you to choose another directory where the new light module will be created.

The plugin writes the following properties to the mgnl.config.js file:

  • Global

    • lightModulesPath

    • lightModule

Create a light module with specific directories

npm run mgnl -- create-light-module "my-lm" --directories A D

This command creates a new light module directory called my-lm with the apps and decorations directories.

The plugin will prompt you to choose a directory where the new light module will be created.

The plugin writes the following properties to the mgnl.config.js file:

  • Global

    • lightModulesPath

    • lightModule

If the my-lm light module already exists, it will add the apps and decorations directories there (if not present yet).

Create a light module based on a prototype from a custom prototypes directory

npm run mgnl -- create-light-module "my-lm" --prototype-dir "/path/to/custom-prototypes-dir/light-module"

This command creates a new light module directory called my-lm based on the _default prototype from /path/to/custom-prototypes-dir/light-module.

The plugin will prompt you to choose a directory where the new light module will be created.

If the _default prototype is not present in the custom prototypes directory, it will prompt you to choose another prototype.

The plugin writes the following properties to the mgnl.config.js file:

  • Global

    • lightModulesPath

    • lightModule

  • Plugin

    • prototypeDir

    • prototype

Example structure of the custom prototypes directory:

custom-prototypes-dir/
  └── light-module/
    └── _default/
      └── apps/
      └── contentTypes/
      └── ...
    └── my-first-prototype/
      └── dialogs/
      └── templates/
      └── ...
    └── my-second-prototype/
      └── decorations/
      └── ...

To use the custom my-second-prototype, run:

npm run mgnl -- create-light-module "my-lm" --prototype-dir "/path/to/custom-prototypes-dir/light-module"

Create a light module based on a specific prototype

npm run mgnl -- create-light-module "my-lm" --prototype "comprehensive"

This command creates a new light module directory called my-lm based on the comprehensive prototype.

The plugin will prompt you to choose a directory where the new light module will be created.

The Create Light Module Plugin contains the _default and comprehensive prototypes.

To choose a custom prototype from a custom prototypes directory, use --prototype with the --prototype-dir option.

It can’t be used with the --directories option.

The plugin writes the following properties to the mgnl.config.js file:

  • Global

    • lightModulesPath

    • lightModule

Configuration

You can set the following properties in mgnl.config.js to predefine the plugin’s behavior.

Global properties

Property name Description

lightModulesPath

The path to the directory containing all light modules.

Alternative forms: -lmp [path], --light-modules-path [path]

Plugin properties

Property name Description

prototypeDir

The path to a custom prototypes directory.

Alternative forms: -pd <path>, --prototype-dir <path>

prototype

The name of a prototype.

Alternative forms: -p [name], --prototype [name]

For more information, see Configuring plugins.

Feedback

DX Core

×

Location

This widget lets you know where you are on the docs site.

You are currently perusing through the Magnolia CLI docs.

Main doc sections

DX Core Headless PaaS Legacy Cloud Incubator modules