CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-moonrepo--core-macos-x64

macOS x64 binary distribution package for the moon repository management tool

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

generation.mddocs/

Code Generation

Commands for generating code from templates and managing template libraries to accelerate development and maintain consistency across projects.

Capabilities

Generate from Template

Generate and scaffold files from a pre-defined template into the workspace.

moon generate <name> [dest] [--defaults] [--dry-run] [--force] [--template]

Alias: moon g

Arguments:

  • name (required) - Name of the template to generate from
  • dest (optional) - Destination path relative to workspace root or working directory

Options:

  • --defaults - Use default values for all template variables instead of prompting
  • --dry-run - Run the entire generation process without writing any files
  • --force - Force overwrite any existing files at the destination
  • --template - Create a new template instead of generating from an existing one

Usage Examples:

# Generate using interactive prompts
moon generate react-component

# Generate to specific destination
moon generate react-component ./src/components/NewComponent

# Use short alias
moon g nodejs-app ./apps/my-new-app

# Use defaults without prompting
moon generate typescript-library --defaults

# Preview generation without creating files
moon generate react-component --dry-run

# Force overwrite existing files
moon generate api-endpoint ./src/api/users --force

# Create a new template
moon generate my-template --template

List Available Templates

Display all templates available for code generation in the workspace.

moon templates [--filter <PATTERN>] [--json]

Options:

  • --filter <PATTERN> - Filter templates based on name or description pattern
  • --json - Output template information in JSON format

Usage Examples:

# List all available templates
moon templates

# Filter templates by pattern
moon templates --filter react

# Get template info as JSON
moon templates --json

# Filter with wildcard pattern
moon templates --filter "*-component"

Sample Output:

Templates:
  react-component     Generate a React functional component with TypeScript
  nodejs-api          Generate a Node.js API server with Express
  typescript-library  Generate a TypeScript library package
  nextjs-app          Generate a Next.js application
  documentation       Generate documentation files and structure

Template Structure

Moon templates are organized in the .moon/templates/ directory:

.moon/templates/
├── react-component/
│   ├── template.yml           # Template configuration
│   ├── {{name}}.tsx          # Component file template  
│   ├── {{name}}.test.tsx     # Test file template
│   └── index.ts              # Export file template
├── nodejs-api/
│   ├── template.yml
│   ├── src/
│   │   ├── app.ts
│   │   └── routes/
│   ├── package.json
│   └── README.md
└── shared/                   # Shared template partials
    ├── license.txt
    └── gitignore.txt

Template Configuration

Templates are configured using template.yml:

# Example template.yml
name: "React Component"
description: "Generate a React functional component with TypeScript"
destination: "src/components"

variables:
  - name: "name"
    description: "Component name"
    type: "string"
    required: true
    
  - name: "withTests"
    description: "Include test files"
    type: "boolean"
    default: true
    
  - name: "styling"
    description: "Styling approach"
    type: "enum"
    options: ["css-modules", "styled-components", "tailwind"]
    default: "css-modules"

files:
  - source: "{{name}}.tsx"
    destination: "{{name}}/{{name}}.tsx"
    
  - source: "{{name}}.test.tsx"
    destination: "{{name}}/{{name}}.test.tsx"
    condition: "{{withTests}}"
    
  - source: "index.ts"
    destination: "{{name}}/index.ts"

Template Variables

Templates support various variable types:

  • String - Text input from user
  • Boolean - Yes/no questions
  • Enum - Select from predefined options
  • Number - Numeric input
  • Array - Multiple values

Variables can be used in:

  • File names (e.g., {{name}}.tsx)
  • File contents (e.g., export const {{name}} = () => {})
  • Directory names (e.g., {{name}}/)
  • Conditional file inclusion

Template Syntax

Moon uses Handlebars-style templating:

// In template file: {{name}}.tsx
import React from 'react';
{{#if withTests}}
import { render } from '@testing-library/react';
{{/if}}

interface {{name}}Props {
  {{#each props}}
  {{name}}: {{type}};
  {{/each}}
}

export const {{name}}: React.FC<{{name}}Props> = ({
  {{#each props}}{{name}},{{/each}}
}) => {
  return (
    <div className="{{kebabCase name}}">
      {/* {{description}} */}
    </div>
  );
};

{{#if withTests}}
// Test file content
describe('{{name}}', () => {
  it('renders correctly', () => {
    render(<{{name}} />);
  });
});
{{/if}}

Helper Functions

Templates include built-in helper functions:

  • {{camelCase text}} - Convert to camelCase
  • {{pascalCase text}} - Convert to PascalCase
  • {{kebabCase text}} - Convert to kebab-case
  • {{snakeCase text}} - Convert to snake_case
  • {{upperCase text}} - Convert to UPPER_CASE
  • {{lowerCase text}} - Convert to lower case

Creating Custom Templates

# Create a new template interactively
moon generate my-template --template

# Manual template creation
mkdir .moon/templates/my-template
touch .moon/templates/my-template/template.yml

# Edit template.yml with configuration
# Add template files with variable placeholders

Template Sharing

Templates can be shared across projects:

# Export template
moon templates export react-component > react-component.tar.gz

# Import template
moon templates import react-component.tar.gz

# Sync templates from remote repository
moon templates sync --from https://github.com/company/moon-templates

Best Practices

Template Organization

  • Group related templates in logical categories
  • Use descriptive names and documentation
  • Include example usage in template descriptions
  • Version control templates with the workspace

Variable Design

  • Use clear, descriptive variable names
  • Provide sensible defaults where possible
  • Include help text for complex options
  • Validate user input when necessary

File Structure

  • Follow consistent naming conventions
  • Include necessary configuration files
  • Provide complete, working examples
  • Include appropriate documentation and comments

docs

environment.md

execution.md

extensions.md

generation.md

graphs.md

index.md

maintenance.md

project-task.md

query.md

toolchain.md

tile.json