Create App plugin

A plugin to create an app in a light module.

Package name

@magnolia/cli-create-app-plugin

Repository link

Latest version

Magnolia CLI create app 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-app-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-app-plugin
  2. Modify the mgnl.config.js file accordingly.

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

Usage

Command

create-app <name> [options]

Options

Form (short and long) Description

-ct <name>

--content-type <name>

Configures the content type by creating a new type or choosing an existing one.

We recommended using singular form for the name.

-lm [name]

--light-module [name]

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

-pd <path>

--prototype-dir <path>

The path to the custom prototype templates directory as the prototype source for app creation.

-p [name]

--prototype [name]

Selects a prototype for app 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 CreateAppPlugin from "@magnolia/cli-create-app-plugin";

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

For more information, see Configuring plugins.

Create a new app

npm run mgnl -- create-app "my-app"

This command creates a new app called my-app 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 app will be created.

  • Choose an existing content type, or create a new one.

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

  • Global

    • lightModulesPath

  • Plugin

    • lightModule

Create a new app with a specific content type

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

This command creates a new app called my-app 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 app will be created.

If the my-ct content type 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 app in a specific light module

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

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

The plugin will prompt you to:

  • Choose a directory containing all light modules.

  • Choose an existing content type, or create a new one.

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

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

  • Global

    • lightModulesPath

  • Plugin

    • lightModule

Create a new app based on a prototype from a custom prototypes directory

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

This command creates a new app called my-app 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 app will be created.

  • Choose an existing content type, or create a new one.

If the _default prototype is not present in the custom prototypes directory, it prompts 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 be:

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-app "my-app" --prototype-dir "/path/to/custom-prototypes-dir/app-content-type" --prototype "my-second-prototype"

Create a new app based on a specific prototype

npm run mgnl -- create-app "my-app" --prototype "custom-prototype-name"

This command creates a new app called my-app 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 app will be created.

  • Choose an existing content type, or create a new one.

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

The Create App plugin only contains the _default prototype.

To choose a custom prototype from a custom prototypes directory, use --prototype with the --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 app will be created.

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

Plugin properties

Property name Description

lightModule

The name of a light module where the app 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