Create Model plugin

Creates framework-specific models based on Magnolia YAML dialogs.

Package name

@magnolia/cli-create-model-plugin

Repository link

Latest version

Magnolia CLI create model plugin - latest version tag

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 (--) in quotes:

npm run mgnl "--" ...

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

Manually

  1. Run the following command in the project folder.

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

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

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

-lm [name]

--light-module [name]

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

-s [path…​]

--source [path…​]

Provide one or more paths to YAML files for specific components or pages to generate the models from.

-v

--version

Displays the version.

-h

--help

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 (--) in quotes:

npm run mgnl "--" ...

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 (--) in quotes:

npm run mgnl "--" ...

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 (--) in quotes:

npm run mgnl "--" ...

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 (--) in quotes:

npm run mgnl "--" ...

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

lightModulesPath

The path to a directory containing all light modules.

lightModule

The name of the light module containing the dialogs (dialogs/components or dialogs/pages) to generate the models from.

Alternative forms: -lm [name], --light-module [name]

type

The file type or extension used in the project’s framework (for example tsx, jsx, or vue). It determines which version of the prototype files is used and the file extensions for the generated code.

componentsSpaPath

The path to the folder containing the front-end components.

pagesSpaPath

The path to the folder containing the front-end pages.

customTypes

Allows you to override the default Magnolia types with your own type mappings.

Example: customTypes: { textField: "number" }

Plugin properties

Property name Description

lightModule

The name of the light module containing the dialogs (dialogs/components or dialogs/pages) to generate the models from.

Alternative forms: -lm [name], --light-module [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