class TemplateProcessor

Template processing and file generation using Vento.

Handles template compilation and rendering with enhanced data preparation. Supports built-in templates (TypeScript, JSON, YAML) and custom templates.

Examples

Creating a processor with custom configuration

const config = {
  versionFile: {
    template: TemplateFormat.TYPESCRIPT,
    additionalExports: [
      { name: "BUILD_DATE", value: "buildDate" }
    ]
  },
  security: {
    templateSandbox: "strict"
  }
};
const processor = new TemplateProcessor(config);

Constructors

TemplateProcessor(config: NagareConfig)

Initialize template processor with Vento environment.

Methods

generateVersionFile(data: TemplateData): Promise<string>

Generate version file content using built-in templates

Uses the configured template format to generate version file content. Supports extending templates with additional exports and custom content.

processTemplate(
template: string,
): Promise<string>

Process a template string with data using Vento

Compiles and renders a template with enhanced data preparation. Throws descriptive errors for template compilation or rendering failures.

validateTemplate(template: string): Promise<{ valid: boolean; error?: string; }>

Test template compilation (useful for validation)

Validates template syntax without rendering data. Useful for configuration validation and debugging.