Create Component plugin
A plugin to create a new component in a light module.
Package name |
|
Repository link |
|
Latest version |
|
Changelog link |
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. |
Usage
Options
Form (short and long) | Description |
---|---|
|
Specifies the page to make the component available to. The default values for
Example: |
|
Defines the light module for the component template.
By default, uses the directory specified in the |
|
Selects a prototype for component creation. |
|
Displays the version. |
|
Displays help information. |
Examples
In the following examples, assume that the mgnl.config.js
file looks like this:
import CreateComponentPlugin from "@magnolia/cli-create-component-plugin";
export default {
plugins: [
new CreateComponentPlugin()
]
};
For more information, see Configuring plugins.
Create a new component
npm run mgnl -- create-component "my-component"
This command creates a new component called my-component
.
The plugin will prompt you to choose a:
-
Directory containing all light modules.
-
Specific light module where the
my-component
component will be created. -
Framework containing prototypes.
-
Prototype available in the framework.
-
Directory with all components in the frontend project directory.
-
File containing the
componentMapping
object. -
Filetype of the newly generated component.
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
componentMappingFilePath
-
type
-
-
Plugin
-
lightModule
-
framework
-
prototype
-
componentsSpaPath
-
Create a new component and add it to an existing page
npm run mgnl -- create-component "my-component" --available "basic"
This command creates a new component called my-component
.
The plugin will prompt you to choose a:
-
Directory containing all light modules.
-
Specific light module.
-
Framework containing prototypes.
-
Prototype available in the framework.
-
Directory with all components in the frontend project directory.
-
File containing the
componentMapping
object. -
Filetype of the newly generated component.
After creating the component, the plugin adds it to basic
page template.
Make sure that the basic
page exists in the light module directory.
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
componentMappingFilePath
-
type
-
-
Plugin
-
lightModule
-
framework
-
prototype
-
componentsSpaPath
-
Create a new component in a light module
npm run mgnl -- create-component "my-component" --light-module "my-lm"
This command creates a new component called my-component
in the my-lm
light module.
The plugin will prompt you to choose a:
-
Directory containing all light modules.
-
Framework containing prototypes.
-
Prototype available in the framework.
-
Directory with all components in the frontend project directory.
-
File containing the
componentMapping
object. -
Filetype of the newly generated component.
If the my-lm
light module doesn’t exist in the light module directory, the plugin will prompt you to select another one.
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
componentMappingFilePath
-
type
-
-
Plugin
-
lightModule
-
framework
-
prototype
-
componentsSpaPath
-
Create a new component based on a specific prototype
npm run mgnl -- create-component "my-component" --prototype "card"
This command creates a new component called my-component
.
The plugin will prompt you to choose a:
-
Directory containing all light modules.
-
specific light module where the
my-component
component will be created. -
Framework containing prototypes.
-
Prototype available in the framework.
-
Directory with all components in the frontend project directory.
-
File containing the
componentMapping
object. -
Filetype of the newly generated component.
In case the card
prototype is not available in the framework selected, you’ll be prompted to choose a different prototype.
Prototype availability in the Create Component plugin depends on the |
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
componentMappingFilePath
-
type
-
-
Plugin
-
lightModule
-
framework
-
prototype
-
componentsSpaPath
-
Configuration
You can set the following properties in mgnl.config.js
to predefine the plugin’s behavior.
Global properties
Property name | Description |
---|---|
|
The path to a directory containing all light modules. |
|
The name of a light module where the component will be created. Alternative forms: |
|
The path to the file containing the |
|
The type for the selected prototype, for example |
Plugin properties
Property name | Description | ||
---|---|---|---|
|
The name of a light module where the component will be created. Alternative forms: |
||
|
The path to the folder containing the front-end components. |
||
|
The framework prototype to use for component creation, for example |
||
|
Bypass the confirmation prompt when downloading the framework.
|
||
|
The name of a prototype. Alternative forms: |
||
|
A key-value object used by Handlebars for template rendering. |
||
|
A key-value object that modifies how the prototype behaves. |
For more information, see Configuring plugins.