Working with Templates

Using and creating templates for structured README generation

Templates provide a structured way to generate README files with consistent formatting and sections. They allow you to define the structure of your README while letting Amazon Q generate the content.

Using Templates

To generate a README using a template:

qmims generate --mode template:templateName

For example, to use the "detailed" template:

qmims generate --mode template:detailed

To list all available templates:

qmims templates list

Built-in Templates

qmims includes five built-in templates:

Basic Template

Simple README with essential sections:

  • Project title and description
  • Installation
  • Usage
  • License
# {{projectName}}

<!-- qmims:generate: Write a concise description of the project based on its structure and purpose -->

## Installation

<!-- qmims:generate: Provide installation instructions based on the detected package manager -->

## Usage

<!-- qmims:generate: Create usage examples based on the project's main functionality -->

## License

<!-- qmims:generate: Add license information based on the detected license file or package.json -->

Creating Custom Templates

You can create your own custom templates to match your project's specific needs. Templates are Markdown files with special comments that serve as placeholders for generated content.

Template Syntax

Templates can include:

  • Placeholders: Variables like {{projectName}} that are replaced with actual values
  • Generation Instructions: HTML comments that tell Amazon Q what content to generate
  • Static Content: Regular Markdown content that remains unchanged

Steps to Create a Custom Template

  1. Create a Markdown file with your desired structure
  2. Add placeholders and generation instructions:
    # {{projectName}}
    
    <!-- qmims:generate: Write a description based on the project's purpose -->
    
    ## Features
    
    <!-- qmims:generate: List the main features based on the code structure -->
  3. Add the template to qmims:
    qmims templates add my-template path/to/template.md
  4. Use your custom template:
    qmims generate --mode template:my-template

Template Best Practices

  • Be Specific in Instructions: Provide clear instructions to Amazon Q about what content to generate
  • Include Essential Sections: Make sure your template includes all the sections that are important for your project type
  • Use Consistent Formatting: Maintain consistent heading levels and formatting throughout the template
  • Keep It Modular: Organize your template into logical sections that can be easily maintained
  • Test Your Template: Generate READMEs with your template for different projects to ensure it works well in various contexts