-
Notifications
You must be signed in to change notification settings - Fork 15
Description
π 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/elselogic (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 insrc/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:
- Replaces
mustachedependency withejs. - Renames all templates from
.mustacheto.ejs. - Updates
src/template.tsto useejs.render().
Is the team open to this change? I can submit the PR immediately mustache2ejs.