Create Model plugin
Creates framework-specific models based on Magnolia YAML dialogs.
Package name |
|
Repository link |
|
Latest version |
|
Changelog |
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-model-plugin
|
Windows users using PowerShell must enclose the two consecutive hyphens (
|
The command automatically downloads, installs, and registers the plugin in the mgnl.config.js file.
Usage
Command
create-model [name] [options]
If the name argument isn’t provided, models are created for all components and pages found in the selected light module. To generate a model for a specific component or page, provide its name as the name argument.
Options
| Form (short and long) | Description |
|---|---|
|
Sets a light module for the models.
By default, uses the directory specified in the |
|
Provide one or more paths to YAML files for specific components or pages to generate the models from. |
|
Displays the version. |
|
Displays help information. |
Examples
For the following examples, it’s assumed that the mgnl.config.js file looks like this:
import CreateModelPlugin from "@magnolia/cli-create-model-plugin";
export default {
plugins: [
new CreateModelPlugin()
]
};
For more information, see Configuring plugins.
Generate models for all components
npm run mgnl -- create-model
|
Windows users using PowerShell must enclose the two consecutive hyphens (
|
The command scans both dialogs/components and dialogs/pages in the selected light module, and generates models for all detected components and pages.
The plugin determines the model format automatically based on the project’s framework and file type.
The plugin prompt’s you to:
-
Choose a directory containing all light modules.
-
Choose a light module directory from where the dialogs are read.
-
Choose a directory with all pages in the frontend project directory.
-
Choose a directory with all components in the frontend project directory.
The plugin writes the following properties to the mgnl.config.js file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule -
componentsSpaPath -
pagesSpaPath
-
Generate model for a single component
npm run mgnl -- create-model "my-component"
|
Windows users using PowerShell must enclose the two consecutive hyphens (
|
The command creates a model for dialogs/components/my-component (or dialogs/pages/my-component) if it exists.
The plugin determines the model format automatically based on the project’s framework and file type.
The plugin prompts you to:
-
Choose a directory containing all light modules.
-
Choose a light module directory from where the dialogs are read.
-
Choose a directory with all components in the frontend project directory.
The plugin writes the following properties to the mgnl.config.js file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule -
componentsSpaPath
-
Generate models for all components from a specific light module
npm run mgnl -- create-model --light-module "my-lm"
|
Windows users using PowerShell must enclose the two consecutive hyphens (
|
The command scans both dialogs/components and dialogs/pages in the selected light module and creates corresponding models.
The plugin determines the model format automatically based on the project’s framework and file type.
The plugin prompts you to choose a directory containing all light modules.
If the my-lm light module doesn’t exist yet in the light modules directory, the plugin prompt’s you to select another one.
The plugin writes the following properties to the mgnl.config.js file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule -
componentsSpaPath -
pagesSpaPath
-
Generate model using a direct source path
npm run mgnl -- create-model --source light-modules/spa-lm/dialogs/components/my-component.yaml
|
Windows users using PowerShell must enclose the two consecutive hyphens (
|
Creates a model for dialogs/components/my-component.yaml using the exact YAML file specified.
You can provide multiple paths separated by the space character.
The plugin prompts you to:
-
Choose a directory containing all light modules.
-
Choose a light module directory from where the dialogs are read.
-
Choose a directory with all components in the frontend project directory.
The plugin writes the following properties to the mgnl.config.js file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule -
componentsSpaPath
-
Configuration
In mgnl.config.js, you can set the following properties to predefine the plugin’s behavior.
Global properties
| Property name | Description |
|---|---|
|
The path to a directory containing all light modules. |
|
The name of the light module containing the dialogs ( Alternative forms: |
|
The file type or extension used in the project’s framework (for example |
|
The path to the folder containing the front-end components. |
|
The path to the folder containing the front-end pages. |
|
Allows you to override the default Magnolia types with your own type mappings. Example: |
Plugin properties
| Property name | Description |
|---|---|
|
The name of the light module containing the dialogs ( Alternative forms: |
For more information, see Configuring plugins.