Skip to content

Proposal: Migrate templating engine from Mustache to EJSΒ #141

@fabiomartino

Description

@fabiomartino

πŸš€ Context

Currently, create-capacitor-plugin utilizes Mustache for templating. While Mustache is excellent for simple substitutions, its "logic-less" philosophy becomes a limitation when the scaffolding requirements grow in complexity.

❓ The Problem

As we look to add more advanced features to the generator (e.g., selecting between different Package Managers, handling complex conditional file generation for Android/iOS, or managing dynamic license text), Mustache forces us to pre-calculate heavily in TypeScript to create simple boolean flags. It lacks:

  • Native if/else logic (only existence checks).
  • String comparison (if variable == 'value').
  • Helper functions inside templates.

πŸ’‘ The Solution

I propose migrating to EJS (Embedded JavaScript templating).
EJS allows us to use standard JavaScript logic directly within the templates, making the codebase more maintainable and the generator significantly more powerful.

βš–οΈ Pros & Cons

Pros (Why EJS?):

  • Conditionals: We can handle complex logic like <% if (locals.packageManager === 'npm') { %> directly in the templates, removing the need for boolean clutter in src/template.ts.
  • Flexibility: It simplifies future additions like supporting multiple languages (Java/Kotlin) or optional features (Logging helpers) without rewriting the core extractor logic.
  • Familiarity: It uses standard JavaScript syntax, reducing the learning curve for contributors compared to learning Mustache-specific patterns.

Cons:

  • Syntax: It is slightly more verbose (<% %> vs {{ }}).
  • Discipline: Because it allows arbitrary JS execution, we must ensure we don't put business logic inside the views (though for a CLI generator, this risk is minimal).

πŸ›  Implementation Plan

I have already prepared a refactor that:

  1. Replaces mustache dependency with ejs.
  2. Renames all templates from .mustache to .ejs.
  3. Updates src/template.ts to use ejs.render().

Is the team open to this change? I can submit the PR immediately mustache2ejs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions