SitecoreDXG Documention
  • SitecoreDXG: The Documentation Experience Generator
  • Overview
    • SitecoreDXG: The Documentation Experience Generator
    • Comparison with SitecoreUML
    • CI/CD Integration
    • Helix Dependency Validation
  • Getting Started
    • Compatibility and System Requirements
    • Installing SitecoreDXG
      • General Installation
        • 1. Install the SitecoreDXG Generation Service
        • 2. Install RabbitMQ
        • 3. Install the SitecoreUML Service for Sitecore
        • 4. (Optional) Configure the Documentation Configuration Item for your Solution
        • 5. Install the Default RabbitMQ Middleman in a Custom Location
        • 6. (Optional) Integrate SitecoreDXG into your CI/CD Pipeline
      • Developer Installation
        • 1. Install the SitecoreDXG Generation Service for Developers
        • 2. Install RabbitMQ for Developers
        • 3. Install the SitecoreUML Service for Sitecore for Developers
        • 4. (Optional) Configure the Documentation Configuration Item for your Solution
        • 5. (Optional) Install the Default RabbitMQ Middleman for Developers
        • 6. (Optional) Integrate SitecoreDXG into your CI/CD Pipeline for Developers
    • Upgrading and Downgrading
    • Downloads
    • Using SitecoreDXG
      • Using the Default RabbitMQ Middleman and Trigger
        • Using the DocumentationConfiguration Object
      • Using the Provided AWS S3 Deploy Completion Handler
      • Using the Provided Azure Blob Storage Deploy Completion Handler
  • Architecture
    • Architecture Overview
    • Roles
      • Role Combinations
    • Components
    • Plugins
      • Trigger Plugins
      • Completion Handler Plugins
    • Middlemen
    • Understanding the Default RabbitMQ Middleman and Trigger
  • How To
    • CI/CD Integration
      • Integrating SitecoreDXG into your CI/CD Pipeline
      • Integrating the Default TeamCity RabbitMQ Meta-Runner
    • Creating a Custom Trigger
      • Executing Documentation Generation
      • Executing Meta-Data JSON Generation
    • Slack and Microsoft Teams Integration
      • Integrating with Slack via Webhooks
      • Integrating with Microsoft Teams via Webhooks
    • Creating a Custom Completion Handler
    • Creating a Custom Middleman
    • Viewing Helix Validation Errors
  • About the Generated Documentation
    • Overview
    • Models
      • Template Model
      • Template Field Model
      • Template Folder Model
      • Parent-Child Relationships of Models
      • Inheritance Relationship Model
      • Dependency Relationship Model
    • Views
      • Template View
      • Template Field View
      • Template Folder View
      • Parent-Child Relationship View
      • Inheritance Relationship View
      • Dependency Relationship View
    • Diagrams
      • SitecoreUML Syntax
      • Templates Diagram
      • Template Folders Diagram
      • Layer Diagrams
      • Module Diagrams
      • Module Templates Diagrams
    • Samples
Powered by GitBook
On this page
  1. How To

Creating a Custom Trigger

Writing a custom trigger for your SitecoreDXG Generation Service is meant to be as low-effort and straightforward a task as possible, to enable you to kick off your documentation generation in whatever way you see fit.

Triggers can be self-contained modules, in that they can have their own package.json files and their own local dependencies without having to modify the SitecoreDXG Generation Service's package.json file in any way. If a package.json file is detected for a trigger, the trigger module and its dependencies are automatically installed immediately before the SitecoreDXG Generation Service when calling npm install in the SitecoreDXG Generation Service's installation directory.

To create a custom trigger, all you need to do is create a node module (.JS file) that looks similar to the below template:

#!/usr/local/env node

/**
 * DEPENDENCIES
 */


/**
 * CONSTANTS
 */

const TRIGGER_ID = "MyTrigger";

/**
 * FUNCTIONS
 */

var _registrationCallback = function (configurationLoader, generation, logger) {
  ...your logic for listening and calling the generation function here...
};

/**
 * Registers the trigger for the given triggerManager - this function is required on all trigger modules
 * @param {object} triggerManager the trigger manager to register the trigger for
 */
var registerTrigger = function (triggerManager) {
  triggerManager.registerTrigger(TRIGGER_ID, _registrationCallback);
};

exports.TRIGGER_ID = TRIGGER_ID;
exports.registerTrigger = registerTrigger;

The first thing that you should take note of in the above template is the registerTrigger function. This function is required, and has the job of performing the registration logic that binds the ID of the trigger to the function that should be called in order to start listening and executing the generation, which in this case is the _registrationCallback function.

Strictly speaking, the TRIGGER_ID property does not actually need to be made public via exports, but it is a good practice to do so anyway.

Adding a Custom Trigger to the SitecoreDXG Generation Service

In order to add a custom trigger to the SitecoreDXG Generation Service, you need to perform the following steps:

  1. Navigate to the [SitecoreDXG-Generation-Service-Installation-Directory]/plugins/triggers folder and copy in your custom trigger file. SitecoreDXG will dynamically load all files in this folder as triggers. Note that it is recommended that you add your trigger file into a sub-directory of the triggers folder, e.g. triggers/MyTrigger, for better organization.

  2. (Optional) If your custom trigger uses third-party modules then it is recommended that you create a package.json file for it either manually or by calling npm init and then add the third-party modules to the package's dependencies. This will help keep your custom trigger more self-contained and modular, while avoiding the need to make changes to the SitecoreDXG Generation Service's native package.json

  3. Open the [SitecoreDXG-Generation-Service-Installation-Directory]/settings.js file and in the configuration object update the value of the Trigger property to the ID of your custom trigger. This will tell SitecoreDXG that your custom trigger is the one that should be registered and used.

  4. If your trigger uses third-party modules and has its own package.json file then be sure to run npm install in either the SitecoreDXG Generation Service root or in the trigger's root to install the dependencies

  5. If you are running the SitecoreDXG Generation Service as a Windows service then you need to restart the service

PreviousIntegrating the Default TeamCity RabbitMQ Meta-RunnerNextExecuting Documentation Generation

Last updated 6 years ago