1.0.0-preview.1 • Published 1 month ago

@magnolia/cli-create-app v1.0.0-preview.1

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

Create App

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

Installation

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

npm install @magnolia/create-app-plugin

Configuration

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

// other imports
import CreateAppPlugin  from "@magnolia/cli-create-app";

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

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

Usage

Create new apps by executing the following command with the appropriate options:

npm run mgnl create-content-app -- <AppName> [options]

Command-line Options

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

  • -c, --content-type <singularName>: Specifies the singular name for creating the contentType.
  • -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 app 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 an app named events without associating it with a contentType:
npm run mgnl create-app -- events
  • To create an app named events with a content-type named event in a specific path:
npm run mgnl create-app -- events --content-type event -lmp ./light-modules/spa-lm
  • To create an app named events in the current directory, where you will be prompted to select or create a contentType:
npm run mgnl create-app -- events --content-type

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
    |-- /app
    |   |-- /myTemplate
    |   |-- |-- /__name__.yaml
    |-- /contentType
    |   |-- /myTemplate
    |   |-- |-- /__name__.yaml

    Note: Ensure that when using prototypeDir with --content-type option, the custom directory's structure for contentType templates matches that of the app 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-app -- events --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 CreateAppPlugin from "@magnolia/cli-create-app";
  
  export default {
    commands: [
      new CreateAppPlugin({prototypeDir: '/Path/to/myCustomTemplates'})
    ]
  };
  ```
  • Note: The --prototypeDir option takes the highest priority.