generate_readme_template
Create standardized README templates for various project types with best practices, including libraries, applications, CLI tools, APIs, and documentation.
Instructions
Generate standardized README templates for different project types with best practices
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectName | Yes | Name of the project | |
| description | Yes | Brief description of what the project does | |
| templateType | Yes | Type of project template to generate | |
| author | No | Project author/organization name | |
| license | No | Project license | MIT |
| includeScreenshots | No | Include screenshot placeholders for applications | |
| includeBadges | No | Include status badges | |
| includeContributing | No | Include contributing section | |
| outputPath | No | Path to write the generated README.md file |
Implementation Reference
- Main handler function that validates the input schema, instantiates the template generator, generates the README content, handles optional file output, and returns the result with metadata.export async function generateReadmeTemplate( input: GenerateReadmeTemplateInput, ): Promise<{ content: string; metadata: { templateType: TemplateType; estimatedLength: number; sectionsIncluded: number; }; }> { const validatedInput = GenerateReadmeTemplateSchema.parse(input); const generator = new ReadmeTemplateGenerator(); const content = generator.generateTemplate(validatedInput); const templateInfo = generator.getTemplateInfo(validatedInput.templateType); if (!templateInfo) { throw new Error(`Template type "${validatedInput.templateType}" not found`); } // Write to file if output path specified if (validatedInput.outputPath) { const fs = await import("fs/promises"); await fs.writeFile(validatedInput.outputPath, content, "utf-8"); } return { content, metadata: { templateType: validatedInput.templateType, estimatedLength: templateInfo.estimatedLength, sectionsIncluded: content.split("##").length - 1, }, }; }
- Zod input schema defining parameters for the tool including project details, template type, and optional flags.export const GenerateReadmeTemplateSchema = z.object({ projectName: z.string().min(1, "Project name is required"), description: z.string().min(1, "Project description is required"), templateType: TemplateType, author: z.string().optional(), license: z.string().default("MIT"), includeScreenshots: z.boolean().default(false), includeBadges: z.boolean().default(true), includeContributing: z.boolean().default(true), outputPath: z.string().optional(), });
- Zod enum schema for supported README template types used in the main input schema.export const TemplateType = z.enum([ "library", "application", "cli-tool", "api", "documentation", ]);
- Core helper method in ReadmeTemplateGenerator class that processes the template sections, handles conditional inclusion of badges, screenshots, and contributing sections, and assembles the final README string.generateTemplate(input: GenerateReadmeTemplateInput): string { const template = this.templates.get(input.templateType); if (!template) { throw new Error(`Template type "${input.templateType}" not supported`); } let readme = ""; const camelCaseName = this.toCamelCase(input.projectName); // Process each section for (const section of template.sections) { if (section.title === "Badges" && input.includeBadges) { readme += this.processBadges(template.badges, input) + "\n\n"; } else if (section.title === "Screenshot" && input.includeScreenshots) { readme += this.processScreenshot(input) + "\n\n"; } else if ( section.title === "Contributing" && !input.includeContributing ) { continue; } else { readme += this.processSection(section.content, input, camelCaseName) + "\n\n"; } } return readme.trim(); }