Skip to main content

InitTemplateBase class

Base class for xpm init templates.

Signature

export declare abstract class InitTemplateBase

Remarks

This abstract class provides the foundation for template-based project initialisation. It handles the complete workflow: property validation, interactive user prompts for missing mandatory values, variable substitution, and file generation using the Liquid templating engine.

Template workflow:

  1. Properties are validated against their definitions
  2. Missing mandatory properties trigger interactive prompts (if TTY)
  3. Substitution variables are prepared from properties
  4. The InitTemplateBase.generate() method creates project files

Derived classes must implement InitTemplateBase.generate() to define the specific files and folder structure to create.

Constructors

Constructor

Modifiers

Description

(constructor)({ context, __dirname, templatesPath, propertiesDefinitions, process: _process, options, policies, }, input)

Constructs an xpm init template instance.

Properties

Property

Modifiers

Type

Description

__dirname

readonly

string

The absolute path to the module folder.

context

readonly

Context

The xpm context containing configuration and logging utilities.

engine

readonly

Liquid

The Liquid templating engine instance.

isInteractive

boolean

Flag indicating whether the template is running in interactive mode.

log

readonly

Logger

The logger instance for output and diagnostics.

policies

Policies

The policy flags instance that governs template behaviour.

process

readonly

NodeJS.Process

The Node.js process object for accessing runtime environment information.

propertiesDefinitions

readonly

InitTemplatePropertiesDefinitions

Definitions of all properties supported by this template.

substitutionsVariables?

InitTemplateSubstitutionsVariables

(Optional) The variables to be used for template substitutions.

templatesPath

readonly

string

The absolute path to the templates folder.

Methods

Method

Modifiers

Description

_askForMoreValues()

protected

Prompts the user interactively for missing property values.

_copyFolderRecursively({ sourceFolderPath, destinationFolderPath, }, input)

protected

Recursively copies all contents of a source folder to a destination folder.

_validatePropertiesDefinitions()

protected

Validates the structure and content of property definitions.

copyFile({ sourceFileRelativePath, destinationFilePath, }, input)

Copies a single file from the templates folder to the destination.

copyFolder({ sourceFolderRelativePath, destinationFolderPath, }, input)

Copies an entire folder from the templates folder to the destination.

generate()

abstract

Generates the project files from the template.

isPlatformSupported(platforms)

Determines whether the current platform is supported.

render({ sourceFilePath, destinationFilePath, substitutionsVariables, }, input)

Renders a template file using Liquid and writes the output.

run()

Executes the template initialisation process.

validatePropertyValue(name, value)

Validates a property value against its definition.


Generated via tsdoc2docusaurus 1.3.2 by API Extractor/Documenter 7.57.2.