1.0.0-preview.1 • Published 1 month ago

@magnolia/cli-create-content-type v1.0.0-preview.1

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
-
Last release
1 month ago

Create Content Type

The CreateContentTypePlugin is a CLI plugin designed for the Magnolia CLI Plugin System. It facilitates the creation of contentTypes in a Magnolia light module.

Installation

To install the plugin, run the following command in your terminal:

npm install @magnolia/create-content-type-plugin

Configuration

After installation, integrate the plugin with the Magnolia CLI by adding it to your mgnl.config.js configuration file:

// other imports
import CreateContentTypePlugin  from "@magnolia/cli-create-content";

export default {
  commands: [
    // other commands
    new CreateContentTypePlugin()
  ]
};

Adding the plugin to the configuration file enables the Magnolia CLI to recognize and execute the plugin's commands.

Usage

Create new content types by executing the following command with the appropriate options:

npm run mgnl create-content-type -- <ContentTypeName> [options]

Command-line Options

Customize the actions of the plugin using the following command-line options:

  • -a, --app <pluralName>: Specifies the plural name for creating the content app and workspace.
  • -lmp, --light-module-path <path>: The path to the Magnolia light module. Defaults to the current directory if omitted.
  • -pd, --prototypeDir <path>, Sets the path to a custom prototype directory. This overrides the use of the default prototype directory. When specified, available prototypes are looked up in this directory.
  • -P, --prototype <prototype>, Prototype that will be used for contentType creation.

    • If neither --prototype nor --prototypeDir is specified, the '_default' prototype from the default prototype directory is automatically used.
    • If --prototype is specified without --prototypeDir, the chosen prototype must be one of the prototypes in the default prototype directory.
    • If --prototypeDir is specified without --prototype, the plugin searches for a '_default' prototype within the specified custom prototype directory.
    • If both --prototypeDir and --prototype are specified, the chosen prototype must be located within the custom prototype directory specified by --prototypeDir.

Examples

  • To create a content type named event without associating it with a workspace:
npm run mgnl create-content-type -- event
  • To create a content type named event with an app named events in a specific path:
npm run mgnl create-content-type -- event --app events -lmp ./light-modules/spa-lm
  • To create a content type named event in the current directory, where you will be prompted to select or create a workspace:
npm run mgnl create-content-type -- event --app

Directory Structure

The resulting directory structure after executing the commands will be as follows:

my-light-module/
├── contentTypes
│   └── MyContentType.yaml
├── apps
│   └── MyApp.yaml

Overriding the Default Prototypes Directory

  • Custom prototype directory structure:

    /myCustomTemplates
    |-- /contentType
    |   |-- /myTemplate
    |   |-- |-- /__name__.yaml
    |-- /app
    |   |-- /myTemplate
    |   |-- |-- /__name__.yaml

    Note: Ensure that when using prototypeDir with --app option, the custom directory's structure for app templates matches that of the contentType templates. This means having corresponding directories files with equivalent naming conventions. Inconsistencies in this structure will result in command failure.

1) Using command line option - Use --prototypeDir <path> to specify a custom directory - Example:

  ```bash
  npm run mgnl create-content-type -- event --prototypeDir '/Path/to/myCustomTemplates'
  ```

2) Using constructor argument - If custom prototypes are frequently used, pass the directory path directly to the constructor. - Example:

  ```js
  import CreateContentTypePlugin from "@magnolia/cli-create-content-type";
  
  export default {
    commands: [
      new CreateContentTypePlugin({prototypeDir: '/Path/to/myCustomTemplates'})
    ]
  };
  ```
  • Note: The --prototypeDir option takes the highest priority.