Create Content Type plugin

A plugin to create a content type in a light module.

Package name

@magnolia/cli-create-content-type-plugin

Repository link

Latest version

Magnolia CLI create content type plugin - latest version tag

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.

With add-plugin

Run the following command in the project folder.

npm run mgnl -- add-plugin @magnolia/cli-create-content-type-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-content-type-plugin
  2. Modify the mgnl.config.js file accordingly.

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

Usage

Command

create-content-type <name> [options]

Options

Form (short and long) Description

-a [name]

--app [name]

Configure a content app and an associated workspace by creating a new app or choosing an existing one.

We recommended using plural form for the name.

-lm [name]

--light-module [name]

Sets a light module for the content type. By default, the name is the directory specified in the mgnl.config.js file.

-pd <path>

--prototype-dir <path>

Use the specified path to the custom prototype templates directory as the prototype source for content type creation.

-p [name]

--prototype [name]

Selects a prototype for content type creation.

-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 CreateContentTypePlugin from "@magnolia/cli-create-content-type-plugin";

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

For more information, see Configuring plugins.

Create a new content type

npm run mgnl -- create-content-type "my-ct"

This command creates a new content type called my-ct based on the _default prototype.

The plugin will prompt you to:

  • Choose a directory containing all light modules.

  • Choose a light module directory where the new content type will be created.

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

  • Global

    • lightModulesPath

  • Plugin

    • lightModule

Create a new content type with a specific app

npm run mgnl -- create-content-type "my-ct" --app "my-app"

This command creates a new content type called my-ct based on the _default prototype with the my-ct content type.

The plugin will prompt you to:

  • Choose a directory containing all light modules.

  • Choose a light module directory where the new content type will be created.

If the my-app app doesn’t exist in the light module directory, it is created automatically.

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

  • Global

    • lightModulesPath

  • Plugin

    • lightModule

Create a new content type in a specific light module

npm run mgnl -- create-content-type "my-ct" --light-module "my-lm"

This command creates a new content type called my-ct based on the _default prototype in the my-lm light module.

The plugin will prompt you to choose a directory containing all light modules.

If the my-lm light module doesn’t exist in the light modules directory, the plugin will prompt you to select another one.

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

  • Global

    • lightModulesPath

  • Plugin

    • lightModule

Create a new content type based on a prototype from a custom prototypes directory

npm run mgnl -- create-content-type "my-ct" --prototype-dir "/path/to/custom-prototypes-dir/app-content-type"

This command creates a new content type called my-ct based on the _default prototype from /path/to/custom-prototypes-dir/app-content-type.

The plugin will prompt you to:

  • Choose a directory containing all light modules.

  • Choose a light module directory where the new content type 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

  • Plugin

    • lightModule

    • prototypeDir

    • prototype

The structure of the custom-prototypes directory can look like this:

custom-prototypes-dir/
  └── app-content-type/
    └── _default/
      └── {{app-name}}.yaml
      └── {{content-type-name}}.yaml
    └── my-first-prototype/
      └── {{app-name}}.yaml
      └── {{content-type-name}}.yaml
    └── my-second-prototype/
      └── {{app-name}}.yaml
      └── {{content-type-name}}.yaml

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

npm run mgnl -- create-content-type "my-ct" --prototype-dir "/path/to/custom-prototypes-dir/app-content-type" --prototype "my-second-prototype"

Create a new content type based on a specific prototype

npm run mgnl -- create-content-type "my-ct" --prototype "custom-prototype-name"

This command creates a new content type called my-ct based on the custom-prototype-name prototype.

The plugin will prompt you to:

  • Choose a directory containing all light modules.

  • Choose a light module directory where the new content type will be created.

If the custom-prototype-name prototype is not present, it will prompt you to choose another prototype.

The Create Content Type plugin only contains the _default prototype.

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

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

  • Global

    • lightModulesPath

  • Plugin

    • lightModule

    • prototype

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 a directory containing all light modules.

lightModule

The name of a light module where the content type will be created.

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

Plugin properties

Property name Description

lightModule

The name of a light module where the content type will be created.

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

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