CodeGenerator.js is a core module in the project that handles various code generation tasks using the Anthropic AI model. It provides functionality for generating and updating code files, optimizing and refactoring existing code, splitting large files, generating dependency files, creating AI agent code, and more.
Generates or updates a code file based on the provided information.
Parameters:
readme(string): Content of the README.md filecurrentCode(string): Current content of the file (if it exists)fileName(string): Name of the file to generate or updateprojectStructure(object): Structure of the projectallFileContents(object): Contents of all other files in the project
Returns: Promise - The generated code
Updates the README.md file with new design ideas and considerations.
Parameters:
readme(string): Current content of the README.md fileprojectStructure(object): Structure of the project
Returns: Promise - The updated README content
Splits a large file into smaller, more manageable parts.
Parameters:
filePath(string): Path of the file to splitcontent(string): Content of the fileprojectStructure(object): Structure of the project
Optimizes and refactors a given file.
Parameters:
filePath(string): Path of the file to optimize and refactorprojectStructure(object): Structure of the project
Generates a dependency file (e.g., package.json, requirements.txt) for the specified language.
Parameters:
language(string): Programming language of the projectprojectStructure(object): Structure of the projectreadme(string): Content of the README.md file
Generates code for an AI agent based on the provided information.
Parameters:
agentType(string): Type of the AI agentagentDescription(string): Description of the AI agentprojectStructure(object): Structure of the projectreadme(string): Content of the README.md file
Generates an HTML landing page for the project.
Parameters:
projectStructure(object): Structure of the projectreadme(string): Content of the README.md file
Generates a full project structure based on the provided information.
Parameters:
projectStructure(object): Structure of the projectreadme(string): Content of the README.md file
Updates the CHANGELOG.md file with new changes.
Parameters:
changes(array): Array of change descriptions
Creates app description and metadata files for app store submissions.
Parameters:
projectStructure(object): Structure of the projectreadme(string): Content of the README.md file
cleanGeneratedCode(code): Cleans the generated code by removing markdown formatting.getLanguageFromExtension(fileExtension): Determines the programming language based on the file extension.calculateTokenStats(inputTokens, outputTokens): Calculates and displays token usage statistics.parseGeneratedFiles(content): Parses generated file content into separate files.
import CodeGenerator from "./codeGenerator.js";
// Generate a new file
const readme = "# My Project\n\nThis is a sample project.";
const fileName = "app.js";
const projectStructure = { "app.js": null, "README.md": null };
const generatedCode = await CodeGenerator.generate(readme, "", fileName, projectStructure, {});
// Optimize and refactor an existing file
await CodeGenerator.optimizeAndRefactorFile("app.js", projectStructure);
// Generate a full project
await CodeGenerator.generateFullProject(projectStructure, readme);This module is central to the project's code generation and management capabilities, interacting with various other modules like FileManager, CodeAnalyzer, DocumentationGenerator, and UserInterface to provide a comprehensive code generation solution.