Code Generation and Templates

Code Generation and Templates

Teaches a coding agent to generate code from templates: scaffolding, boilerplate, AST-based generation, template engines, OpenAPI clients and database models.

Skill files10 files

references/

scripts/

templates/

SKILL.md103 lines
1
---
2
name: code-generation-template
3
description: >
4
Generate code from templates and patterns including scaffolding, boilerplate
5
generation, AST-based code generation, and template engines. Use when
6
generating code, scaffolding projects, creating boilerplate, or using
7
templates.
8
---
9
10
# Code Generation & Templates
11
12
## Table of Contents
13
14
- [Overview](#overview)
15
- [When to Use](#when-to-use)
16
- [Quick Start](#quick-start)
17
- [Reference Guides](#reference-guides)
18
- [Best Practices](#best-practices)
19
20
## Overview
21
22
Comprehensive guide to code generation techniques including template engines, AST manipulation, code scaffolding, and automated boilerplate generation for increased productivity and consistency.
23
24
## When to Use
25
26
- Scaffolding new projects or components
27
- Generating repetitive boilerplate code
28
- Creating CRUD operations automatically
29
- Generating API clients from OpenAPI specs
30
- Building code from templates
31
- Creating database models from schemas
32
- Generating TypeScript types from JSON Schema
33
- Building custom CLI generators
34
35
## Quick Start
36
37
Minimal working example:
38
39
```typescript
40
// templates/component.hbs
41
import React from 'react';
42
43
export interface {{pascalCase name}}Props {
44
{{#each props}}
45
{{this.name}}{{#if this.optional}}?{{/if}}: {{this.type}};
46
{{/each}}
47
}
48
49
export const {{pascalCase name}}: React.FC<{{pascalCase name}}Props> = ({
50
{{#each props}}{{this.name}},{{/each}}
51
}) => {
52
return (
53
<div className="{{kebabCase name}}">
54
{/* Component implementation */}
55
</div>
56
);
57
};
58
```
59
60
## Reference Guides
61
62
Detailed implementations in the `references/` directory:
63
64
| Guide | Contents |
65
|---|---|
66
| [Template Engines](references/template-engines.md) | Template Engines |
67
| [AST-Based Code Generation](references/ast-based-code-generation.md) | AST-Based Code Generation |
68
| [Project Scaffolding](references/project-scaffolding.md) | Project Scaffolding |
69
| [OpenAPI Client Generation](references/openapi-client-generation.md) | OpenAPI Client Generation |
70
| [Database Model Generation](references/database-model-generation.md) | Database Model Generation |
71
| [GraphQL Code Generation](references/graphql-code-generation.md) | GraphQL Code Generation |
72
| [Plop.js Generator](references/plopjs-generator.md) | Plop.js Generator |
73
74
## Best Practices
75
76
### ✅ DO
77
78
- Use templates for repetitive code patterns
79
- Generate TypeScript types from schemas
80
- Include tests in generated code
81
- Follow project conventions in templates
82
- Add comments to explain generated code
83
- Version control your templates
84
- Make templates configurable
85
- Generate documentation alongside code
86
- Validate inputs before generating
87
- Use consistent naming conventions
88
- Keep templates simple and maintainable
89
- Provide CLI for easy generation
90
91
### ❌ DON'T
92
93
- Over-generate (avoid unnecessary complexity)
94
- Generate code that's hard to maintain
95
- Forget to validate generated code
96
- Hardcode values in templates
97
- Generate code without documentation
98
- Create generators for one-off use cases
99
- Mix business logic in templates
100
- Generate code without formatting
101
- Skip error handling in generators
102
- Create overly complex templates
103

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,330 prompts

More by @OpenSourceBuffGuy

See all
Valentine's newspaper editorial portrait from your photo prompt image

Valentine's newspaper editorial portrait from your photo

Turns an uploaded face photo into a top-down Valentine's fashion editorial: red blazer, roses, heart balloons and a newspaper headline.

image-prompt, nano-banana, reference-image, face-reference, photo-editing, portrait, woman, fashion-shoot, editorial, valentines-day, photorealistic, studio-lighting, close-up, high-angle, film-grain, vibrant-colors, flowers, text-rendering, placeholders, fashion, holiday, soft-lighting, bokeh, vertical-format

Woman leaps into leaf pile revealing pool prompt image

Woman leaps into leaf pile revealing pool

Generates a one-shot autumn gag where someone announces the first day of fall and leaps into a leaf pile that hides a tiny blue kiddie pool.

video-prompt, comedy, autumn, single-take, wide-shot, golden-hour, vibrant-colors, humorous, timed-beats, lip-sync, natural-light, short-form-video, quick, cinematic, action, transformation

Seaside morning vlog from bedroom to terrace prompt image

Seaside morning vlog from bedroom to terrace

Generates a 15-second vertical seaside vlog of a woman waking up, stepping onto a terrace and speaking to camera, with a beat for every second and written dialogue.

video-prompt, vlog, timed-beats, multi-shot, lip-sync, short-form-video, vertical-format, selfie, ocean, travel, natural-light, golden-hour, character-consistency, handheld, camera-movement, cinematic, photorealistic, woman, hailuo, for-content-creators, long-form, structured-output, bokeh, summer, text-to-video

Reviews

Loading reviews…

Discussion

Loading comments…