# Vibes Template System

This directory contains templates used by the Vibes CLI to generate projects and features.

## Directory Structure

```
templates/
├── base/                  # Base monorepo structure
├── features/              # Individual feature templates
├── apps/                  # Application templates
└── typescript/            # TypeScript-based templates (new)
```

## Template Engine

As of v0.8.0, Vibes is transitioning from Bash-based templates to a TypeScript template engine. This provides:

- **Type Safety**: Full TypeScript support with compile-time checks
- **Testability**: Unit tests for template generation logic
- **Better DX**: Actual template files instead of heredocs
- **Extensibility**: Easy to add new templates and transformations

## Creating Templates

### Legacy Bash Templates

Located in `base/tools/` and use heredocs:

```bash
cat > file.ts << 'EOF'
content
EOF
```

### New TypeScript Templates

Located in `typescript/` and use Handlebars:

1. Create a `template.config.json`:
```json
{
  "name": "feature",
  "type": "feature",
  "variables": [
    {
      "name": "featureName",
      "type": "string",
      "required": true
    }
  ],
  "files": [
    {
      "source": "index.ts.hbs",
      "destination": "index.ts"
    }
  ]
}
```

2. Create template files with `.hbs` extension:
```handlebars
// {{featureName}}/index.ts
export const {{pascalCase featureName}} = {
  // implementation
};
```

## Available Helpers

The template engine provides these Handlebars helpers:

- `{{camelCase str}}`: Convert to camelCase
- `{{pascalCase str}}`: Convert to PascalCase  
- `{{kebabCase str}}`: Convert to kebab-case
- `{{#if_eq a b}}`: Conditional equality check
- `{{#if_includes array value}}`: Check if array includes value

## Feature Flags

The new template system uses structured feature definitions:

```typescript
export const expoRouterFeature: Feature = {
  id: 'expo-router',
  name: 'Expo Router',
  dependencies: ['expo-router'],
  postInstall: async (context) => {
    // Post-install configuration
  }
};
```

## Migration Status

- ✅ Template engine core implemented
- ✅ Feature definitions created
- ✅ Tests added
- 🚧 Bash template migration in progress
- 🚧 CLI integration pending

## Contributing

When adding new templates:

1. Use TypeScript templates for new features
2. Follow the existing structure
3. Add tests for complex logic
4. Document any special requirements

For more details, see the [Template Engine Improvements Proposal](/docs/template-engine-improvements-proposal.md).