Add auto-generated README functionality
This commit is contained in:
72
main.js
72
main.js
@@ -1393,6 +1393,78 @@ function buildTrayMenu() {
|
||||
});
|
||||
|
||||
|
||||
ipcMain.handle('generate-readme', async (evt, folderPath) => {
|
||||
// Hole Author aus Settings oder Default
|
||||
const store = require('./yourStore'); // oder wie auch immer...
|
||||
const authorName = store.get('author') || 'Unknown';
|
||||
const licenseType = store.get('license') || 'MIT';
|
||||
const repoName = path.basename(folderPath);
|
||||
|
||||
// Finde alle Code/Textdateien
|
||||
const codeFiles = getRelevantFiles(folderPath);
|
||||
let prompt = `
|
||||
You are a tool that generates README.md files in markdown format.
|
||||
Do not review, suggest, or improve the code.
|
||||
Your only job is to create a clear and concise README in markdown, suitable for immediate use on GitHub.
|
||||
|
||||
The project source code is below.
|
||||
|
||||
Example README.md:
|
||||
---
|
||||
# Example Project Name
|
||||
|
||||
**Author:** Alice
|
||||
|
||||
A simple script for downloading and processing web pages.
|
||||
|
||||
## Features
|
||||
- Downloads pages from a list of URLs
|
||||
- Extracts and saves the text content
|
||||
- Generates a summary report
|
||||
|
||||
## Usage
|
||||
|
||||
\`\`\`bash
|
||||
python main.py input.txt
|
||||
\`\`\`
|
||||
---
|
||||
NEVER add Contact Details.
|
||||
IMPORTANT: The LICENSE is ${licenseType}!
|
||||
So, write something like:
|
||||
"## License
|
||||
This project is licensed under the ${licenseType} License."
|
||||
|
||||
Now write a similar README.md for the following project (think of a good name and use the provided author):
|
||||
|
||||
**Author:** ${authorName}
|
||||
|
||||
Source Code:
|
||||
`;
|
||||
for (const f of codeFiles) {
|
||||
let rel = path.relative(folderPath, f);
|
||||
prompt += `\n---\nFile: ${rel}\n${fs.readFileSync(f, 'utf-8')}\n`;
|
||||
}
|
||||
prompt += `\n---\nWrite ONLY the complete README.md in markdown format. Do NOT add extra explanations, commentary, or code reviews. And remember, the license is ${licenseType}!`;
|
||||
|
||||
// LLM call
|
||||
const win = evt.sender; // für Cat-Stream
|
||||
await ensureOllamaRunning();
|
||||
const selectedModel = store.get('readmeModel') || 'qwen2.5-coder:32b';
|
||||
let result = await streamLLMCommitMessages(prompt, null, win);
|
||||
|
||||
// Output fixen: Entferne eventuelle Codeblocks
|
||||
result = result.replace(/^```markdown|^```md|^```/gmi, '').replace(/```$/gmi, '').trim();
|
||||
|
||||
// Disclaimer einbauen
|
||||
const disclaimer = `> ⚠️ **This README.md has been automatically generated using AI and might contain hallucinations or inaccuracies. Please proceed with caution!**\n\n`;
|
||||
// Falls nötig, Name/Author oben einbauen
|
||||
let final = `# ${repoName}\n\n**Author:** ${authorName}\n\n${disclaimer}${result}`;
|
||||
// Schreibe/Überschreibe README.md (wenn du willst, oder Preview)
|
||||
fs.writeFileSync(path.join(folderPath, 'README.md'), final, 'utf-8');
|
||||
return final;
|
||||
});
|
||||
|
||||
|
||||
|
||||
// … Ende der IPC-Handler …
|
||||
|
||||
|
||||
Reference in New Issue
Block a user