mirror of
https://github.com/github/awesome-copilot.git
synced 2026-02-22 19:35:13 +00:00
Update development instructions and guidelines (#29)
* Delete outdated development instructions for Next.js + Tailwind and Python; add comprehensive guidelines for PostgreSQL DBA, Angular, ASP.NET REST APIs, Azure Functions with TypeScript, Bicep, Blazor, CMake with vcpkg, C#, .NET MAUI, GenAIScript, Terraform for Azure, localization, and markdown standards. * Update documentation and prompts for consistency and clarity - Standardized description formatting in various markdown files to use single quotes. - Added error handling utility in update-readme.js for safer file operations. - Improved title extraction logic in update-readme.js to handle frontmatter more robustly. - Updated chat modes section in README to reflect new emoji and sorted chat mode links. - Cleaned up various instruction files for better readability and consistency. - Ensured all markdown files end with a newline for better compatibility with version control. * Remove standardize-frontmatter.js script * Add usage instructions for creating and switching chat modes in README.md * Update README.md generation script to enhance instructions and usage details for custom chat modes * Update README.md and update-readme.js for improved instruction clarity and consistency * Refactor README.md links and update readme script for improved clarity and consistency in instructions * Update README.md and update-readme.js for improved instruction clarity and consistency * Changing from a patch to regen approach for the readme * Bit more cleanup for how to show things in the readme * Adding missing description * Another missing description --------- Co-authored-by: Aaron Powell <me@aaron-powell.com>
This commit is contained in:
682
update-readme.js
682
update-readme.js
@@ -3,191 +3,260 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
function extractTitle(filePath) {
|
||||
// Template sections for the README
|
||||
const TEMPLATES = {
|
||||
header: `# 🤖 Awesome GitHub Copilot Customizations
|
||||
|
||||
Enhance your GitHub Copilot experience with community-contributed instructions, prompts, and configurations. Get consistent AI assistance that follows your team's coding standards and project requirements.
|
||||
|
||||
## 🎯 GitHub Copilot Customization Features
|
||||
|
||||
GitHub Copilot provides three main ways to customize AI responses and tailor assistance to your specific workflows, team guidelines, and project requirements:
|
||||
|
||||
| **🔧 Custom Instructions** | **📝 Reusable Prompts** | **🧩 Custom Chat Modes** |
|
||||
| --- | --- | --- |
|
||||
| Define common guidelines for tasks like code generation, reviews, and commit messages. Describe *how* tasks should be performed<br><br>**Benefits:**<br>• Automatic inclusion in every chat request<br>• Repository-wide consistency<br>• Multiple implementation options | Create reusable, standalone prompts for specific tasks. Describe *what* should be done with optional task-specific guidelines<br><br>**Benefits:**<br>• Eliminate repetitive prompt writing<br>• Shareable across teams<br>• Support for variables and dependencies | Define chat behavior, available tools, and codebase interaction patterns within specific boundaries for each request<br><br>**Benefits:**<br>• Context-aware assistance<br>• Tool configuration<br>• Role-specific workflows |
|
||||
|
||||
> **💡 Pro Tip:** Custom instructions only affect Copilot Chat (not inline code completions). You can combine all three customization types - use custom instructions for general guidelines, prompt files for specific tasks, and chat modes to control the interaction context.
|
||||
|
||||
|
||||
## 📝 Contributing
|
||||
|
||||
We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details on how to submit new instructions and prompts.`,
|
||||
|
||||
instructionsSection: `## 📋 Custom Instructions
|
||||
|
||||
Team and project-specific instructions to enhance GitHub Copilot's behavior for specific technologies and coding practices:`,
|
||||
|
||||
instructionsUsage: `> 💡 **Usage**: Copy these instructions to your \`.github/copilot-instructions.md\` file or create task-specific \`.github/.instructions.md\` files in your workspace's \`.github/instructions\` folder.`,
|
||||
|
||||
promptsSection: `## 🎯 Reusable Prompts
|
||||
|
||||
Ready-to-use prompt templates for specific development scenarios and tasks, defining prompt text with a specific mode, model, and available set of tools.`,
|
||||
|
||||
promptsUsage: `> 💡 **Usage**: Use \`/prompt-name\` in VS Code chat, run \`Chat: Run Prompt\` command, or hit the run button while you have a prompt open.`,
|
||||
|
||||
chatmodesSection: `## 🧩 Custom Chat Modes
|
||||
|
||||
Custom chat modes define specific behaviors and tools for GitHub Copilot Chat, enabling enhanced context-aware assistance for particular tasks or workflows.`,
|
||||
|
||||
chatmodesUsage: `> 💡 **Usage**: Create new chat modes using the command \`Chat: Configure Chat Modes...\`, then switch your chat mode in the Chat input from _Agent_ or _Ask_ to your own mode.`,
|
||||
|
||||
footer: `## 📚 Additional Resources
|
||||
|
||||
- [VS Code Copilot Customization Documentation](https://code.visualstudio.com/docs/copilot/copilot-customization) - Official Microsoft documentation
|
||||
- [GitHub Copilot Chat Documentation](https://code.visualstudio.com/docs/copilot/chat/copilot-chat) - Complete chat feature guide
|
||||
- [Custom Chat Modes](https://code.visualstudio.com/docs/copilot/chat/chat-modes) - Advanced chat configuration
|
||||
- [VS Code Settings](https://code.visualstudio.com/docs/getstarted/settings) - General VS Code configuration guide
|
||||
|
||||
|
||||
## 📄 License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
|
||||
## 🤝 Code of Conduct
|
||||
|
||||
Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.
|
||||
|
||||
## ™️ Trademarks
|
||||
|
||||
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
|
||||
trademarks or logos is subject to and must follow
|
||||
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
|
||||
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
|
||||
Any use of third-party trademarks or logos are subject to those third-party's policies.`,
|
||||
};
|
||||
|
||||
// Add error handling utility
|
||||
function safeFileOperation(operation, filePath, defaultValue = null) {
|
||||
try {
|
||||
const content = fs.readFileSync(filePath, "utf8");
|
||||
const lines = content.split("\n");
|
||||
return operation();
|
||||
} catch (error) {
|
||||
console.error(`Error processing file ${filePath}: ${error.message}`);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 1: Look for title in frontmatter for all file types
|
||||
let inFrontmatter = false;
|
||||
let frontmatterEnded = false;
|
||||
function extractTitle(filePath) {
|
||||
return safeFileOperation(
|
||||
() => {
|
||||
const content = fs.readFileSync(filePath, "utf8");
|
||||
const lines = content.split("\n");
|
||||
|
||||
for (const line of lines) {
|
||||
if (line.trim() === "---") {
|
||||
if (!inFrontmatter) {
|
||||
inFrontmatter = true;
|
||||
} else if (!frontmatterEnded) {
|
||||
frontmatterEnded = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Step 1: Look for title in frontmatter for all file types
|
||||
let inFrontmatter = false;
|
||||
let frontmatterEnded = false;
|
||||
|
||||
if (inFrontmatter && !frontmatterEnded) {
|
||||
// Look for title field in frontmatter
|
||||
const titleMatch = line.match(/^title:\s*['"]?(.+?)['"]?$/);
|
||||
if (titleMatch) {
|
||||
return titleMatch[1].trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset for second pass
|
||||
inFrontmatter = false;
|
||||
frontmatterEnded = false;
|
||||
|
||||
// Step 2: For prompt/chatmode files, look for heading after frontmatter
|
||||
if (filePath.includes(".prompt.md") || filePath.includes(".chatmode.md")) {
|
||||
for (const line of lines) {
|
||||
if (line.trim() === "---") {
|
||||
if (!inFrontmatter) {
|
||||
inFrontmatter = true;
|
||||
} else if (inFrontmatter && !frontmatterEnded) {
|
||||
} else if (!frontmatterEnded) {
|
||||
frontmatterEnded = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (frontmatterEnded && line.startsWith("# ")) {
|
||||
if (inFrontmatter && !frontmatterEnded) {
|
||||
// Look for title field in frontmatter
|
||||
if (line.includes("title:")) {
|
||||
// Extract everything after 'title:'
|
||||
const afterTitle = line
|
||||
.substring(line.indexOf("title:") + 6)
|
||||
.trim();
|
||||
// Remove quotes if present
|
||||
const cleanTitle = afterTitle.replace(/^['"]|['"]$/g, "");
|
||||
return cleanTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset for second pass
|
||||
inFrontmatter = false;
|
||||
frontmatterEnded = false;
|
||||
|
||||
// Step 2: For prompt/chatmode/instructions files, look for heading after frontmatter
|
||||
if (
|
||||
filePath.includes(".prompt.md") ||
|
||||
filePath.includes(".chatmode.md") ||
|
||||
filePath.includes(".instructions.md")
|
||||
) {
|
||||
for (const line of lines) {
|
||||
if (line.trim() === "---") {
|
||||
if (!inFrontmatter) {
|
||||
inFrontmatter = true;
|
||||
} else if (inFrontmatter && !frontmatterEnded) {
|
||||
frontmatterEnded = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (frontmatterEnded && line.startsWith("# ")) {
|
||||
return line.substring(2).trim();
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Format filename for prompt/chatmode/instructions files if no heading found
|
||||
const basename = path.basename(
|
||||
filePath,
|
||||
filePath.includes(".prompt.md")
|
||||
? ".prompt.md"
|
||||
: filePath.includes(".chatmode.md")
|
||||
? ".chatmode.md"
|
||||
: ".instructions.md"
|
||||
);
|
||||
return basename
|
||||
.replace(/[-_]/g, " ")
|
||||
.replace(/\b\w/g, (l) => l.toUpperCase());
|
||||
}
|
||||
|
||||
// Step 4: For instruction files, look for the first heading
|
||||
for (const line of lines) {
|
||||
if (line.startsWith("# ")) {
|
||||
return line.substring(2).trim();
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Format filename for prompt/chatmode files if no heading found
|
||||
const basename = path.basename(
|
||||
filePath,
|
||||
filePath.includes(".prompt.md") ? ".prompt.md" : ".chatmode.md"
|
||||
);
|
||||
// Step 5: Fallback to filename
|
||||
const basename = path.basename(filePath, path.extname(filePath));
|
||||
return basename
|
||||
.replace(/[-_]/g, " ")
|
||||
.replace(/\b\w/g, (l) => l.toUpperCase());
|
||||
}
|
||||
|
||||
// Step 4: For instruction files, look for the first heading
|
||||
for (const line of lines) {
|
||||
if (line.startsWith("# ")) {
|
||||
return line.substring(2).trim();
|
||||
}
|
||||
}
|
||||
|
||||
// Step 5: Fallback to filename
|
||||
const basename = path.basename(filePath, path.extname(filePath));
|
||||
return basename
|
||||
},
|
||||
filePath,
|
||||
path
|
||||
.basename(filePath, path.extname(filePath))
|
||||
.replace(/[-_]/g, " ")
|
||||
.replace(/\b\w/g, (l) => l.toUpperCase());
|
||||
} catch (error) {
|
||||
// Fallback to filename
|
||||
const basename = path.basename(filePath, path.extname(filePath));
|
||||
return basename
|
||||
.replace(/[-_]/g, " ")
|
||||
.replace(/\b\w/g, (l) => l.toUpperCase());
|
||||
}
|
||||
.replace(/\b\w/g, (l) => l.toUpperCase())
|
||||
);
|
||||
}
|
||||
|
||||
function extractDescription(filePath) {
|
||||
try {
|
||||
const content = fs.readFileSync(filePath, "utf8");
|
||||
return safeFileOperation(
|
||||
() => {
|
||||
const content = fs.readFileSync(filePath, "utf8");
|
||||
|
||||
// Parse frontmatter for description (for both prompts and instructions)
|
||||
const lines = content.split("\n");
|
||||
let inFrontmatter = false;
|
||||
let frontmatterEnded = false;
|
||||
// Parse frontmatter for description (for both prompts and instructions)
|
||||
const lines = content.split("\n");
|
||||
let inFrontmatter = false;
|
||||
let frontmatterEnded = false;
|
||||
|
||||
// For multi-line descriptions
|
||||
let isMultilineDescription = false;
|
||||
let multilineDescription = [];
|
||||
// For multi-line descriptions
|
||||
let isMultilineDescription = false;
|
||||
let multilineDescription = [];
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
|
||||
if (line.trim() === "---") {
|
||||
if (!inFrontmatter) {
|
||||
inFrontmatter = true;
|
||||
} else if (inFrontmatter && !frontmatterEnded) {
|
||||
frontmatterEnded = true;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (inFrontmatter && !frontmatterEnded) {
|
||||
// Check for multi-line description with pipe syntax (|)
|
||||
const multilineMatch = line.match(/^description:\s*\|(\s*)$/);
|
||||
if (multilineMatch) {
|
||||
isMultilineDescription = true;
|
||||
// Continue to next line to start collecting the multi-line content
|
||||
if (line.trim() === "---") {
|
||||
if (!inFrontmatter) {
|
||||
inFrontmatter = true;
|
||||
} else if (inFrontmatter && !frontmatterEnded) {
|
||||
frontmatterEnded = true;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we're collecting a multi-line description
|
||||
if (isMultilineDescription) {
|
||||
// If the line has no indentation or has another frontmatter key, stop collecting
|
||||
if (!line.startsWith(" ") || line.match(/^[a-zA-Z0-9_-]+:/)) {
|
||||
isMultilineDescription = false;
|
||||
// Join the collected lines and return
|
||||
return multilineDescription.join(" ").trim();
|
||||
if (inFrontmatter && !frontmatterEnded) {
|
||||
// Check for multi-line description with pipe syntax (|)
|
||||
const multilineMatch = line.match(/^description:\s*\|(\s*)$/);
|
||||
if (multilineMatch) {
|
||||
isMultilineDescription = true;
|
||||
// Continue to next line to start collecting the multi-line content
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add the line to our multi-line collection (removing the 2-space indentation)
|
||||
multilineDescription.push(line.substring(2));
|
||||
} else {
|
||||
// Look for single-line description field in frontmatter
|
||||
const descriptionMatch = line.match(
|
||||
/^description:\s*['"]?(.+?)['"]?$/
|
||||
);
|
||||
if (descriptionMatch) {
|
||||
return descriptionMatch[1];
|
||||
// If we're collecting a multi-line description
|
||||
if (isMultilineDescription) {
|
||||
// If the line has no indentation or has another frontmatter key, stop collecting
|
||||
if (!line.startsWith(" ") || line.match(/^[a-zA-Z0-9_-]+:/)) {
|
||||
isMultilineDescription = false;
|
||||
// Join the collected lines and return
|
||||
return multilineDescription.join(" ").trim();
|
||||
}
|
||||
|
||||
// Add the line to our multi-line collection (removing the 2-space indentation)
|
||||
multilineDescription.push(line.substring(2));
|
||||
} else {
|
||||
// Look for single-line description field in frontmatter
|
||||
const descriptionMatch = line.match(
|
||||
/^description:\s*['"]?(.+?)['"]?$/
|
||||
);
|
||||
if (descriptionMatch) {
|
||||
return descriptionMatch[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we've collected multi-line description but the frontmatter ended
|
||||
if (multilineDescription.length > 0) {
|
||||
return multilineDescription.join(" ").trim();
|
||||
}
|
||||
// If we've collected multi-line description but the frontmatter ended
|
||||
if (multilineDescription.length > 0) {
|
||||
return multilineDescription.join(" ").trim();
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
filePath,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
function updateInstructionsSection(
|
||||
currentReadme,
|
||||
instructionFiles,
|
||||
instructionsDir
|
||||
) {
|
||||
const instructionsSection = currentReadme.match(
|
||||
/## 📋 Custom Instructions\n\nTeam and project-specific instructions.+?(?=\n\n>)/s
|
||||
);
|
||||
/**
|
||||
* Generate the instructions section with an alphabetical list of all instructions
|
||||
*/
|
||||
function generateInstructionsSection(instructionsDir) {
|
||||
// Get all instruction files
|
||||
const instructionFiles = fs
|
||||
.readdirSync(instructionsDir)
|
||||
.filter((file) => file.endsWith(".md"))
|
||||
.sort();
|
||||
|
||||
if (!instructionsSection) {
|
||||
return currentReadme;
|
||||
}
|
||||
console.log(`Found ${instructionFiles.length} instruction files`);
|
||||
|
||||
// Extract existing instruction links from README
|
||||
const existingInstructionLinks = [];
|
||||
const instructionLinkRegex = /\[.*?\]\(instructions\/(.+?)\)/g;
|
||||
let match;
|
||||
let instructionsContent = "";
|
||||
|
||||
while ((match = instructionLinkRegex.exec(currentReadme)) !== null) {
|
||||
existingInstructionLinks.push(match[1]);
|
||||
}
|
||||
|
||||
// Find new instructions that aren't already in the README
|
||||
const newInstructionFiles = instructionFiles.filter(
|
||||
(file) => !existingInstructionLinks.includes(file)
|
||||
);
|
||||
|
||||
if (newInstructionFiles.length === 0) {
|
||||
console.log("No new instructions to add.");
|
||||
} else {
|
||||
console.log(`Found ${newInstructionFiles.length} new instructions to add.`);
|
||||
}
|
||||
|
||||
let instructionsListContent = "\n\n";
|
||||
|
||||
// Generate alphabetically sorted list of instruction links
|
||||
// Generate list items for each instruction file
|
||||
for (const file of instructionFiles) {
|
||||
const filePath = path.join(instructionsDir, file);
|
||||
const title = extractTitle(filePath);
|
||||
@@ -196,210 +265,100 @@ function updateInstructionsSection(
|
||||
// Check if there's a description in the frontmatter
|
||||
const customDescription = extractDescription(filePath);
|
||||
|
||||
if (customDescription) {
|
||||
if (customDescription && customDescription !== "null") {
|
||||
// Use the description from frontmatter
|
||||
instructionsListContent += `- [${title}](${link}) - ${customDescription}\n`;
|
||||
instructionsContent += `- [${title}](${link}) - ${customDescription}\n`;
|
||||
} else {
|
||||
// Fallback to the default approach - use last word of title for description, removing trailing 's' if present
|
||||
const topic = title.split(" ").pop().replace(/s$/, "");
|
||||
instructionsListContent += `- [${title}](${link}) - ${topic} specific coding standards and best practices\n`;
|
||||
instructionsContent += `- [${title}](${link}) - ${topic} specific coding standards and best practices\n`;
|
||||
}
|
||||
}
|
||||
|
||||
// Replace the current instructions section with the updated one
|
||||
const newInstructionsSection =
|
||||
"## 📋 Custom Instructions\n\nTeam and project-specific instructions to enhance GitHub Copilot's behavior for specific technologies and coding practices:" +
|
||||
instructionsListContent;
|
||||
|
||||
return currentReadme.replace(instructionsSection[0], newInstructionsSection);
|
||||
return `${TEMPLATES.instructionsSection}\n\n${instructionsContent}\n${TEMPLATES.instructionsUsage}`;
|
||||
}
|
||||
|
||||
function updatePromptsSection(currentReadme, promptFiles, promptsDir) {
|
||||
// Extract existing prompt links from README
|
||||
const existingPromptLinks = [];
|
||||
const promptLinkRegex = /\[.*?\]\(prompts\/(.+?)\)/g;
|
||||
let match;
|
||||
/**
|
||||
* Generate the prompts section with an alphabetical list of all prompts
|
||||
*/
|
||||
function generatePromptsSection(promptsDir) {
|
||||
// Get all prompt files
|
||||
const promptFiles = fs
|
||||
.readdirSync(promptsDir)
|
||||
.filter((file) => file.endsWith(".prompt.md"))
|
||||
.sort();
|
||||
|
||||
while ((match = promptLinkRegex.exec(currentReadme)) !== null) {
|
||||
existingPromptLinks.push(match[1]);
|
||||
}
|
||||
console.log(`Found ${promptFiles.length} prompt files`);
|
||||
|
||||
// Find new prompts that aren't already in the README
|
||||
const newPromptFiles = promptFiles.filter(
|
||||
(file) => !existingPromptLinks.includes(file)
|
||||
);
|
||||
let promptsContent = "";
|
||||
|
||||
if (newPromptFiles.length === 0) {
|
||||
console.log("No new prompts to add.");
|
||||
return currentReadme;
|
||||
}
|
||||
|
||||
console.log(`Found ${newPromptFiles.length} new prompts to add.`);
|
||||
|
||||
// Create content for new prompts (in Uncategorised section)
|
||||
let newPromptsContent = "";
|
||||
|
||||
// Check if we already have an Uncategorised section
|
||||
const uncategorisedSectionRegex = /### Uncategorised\n/;
|
||||
const hasUncategorisedSection = uncategorisedSectionRegex.test(currentReadme);
|
||||
|
||||
// If we need to add the section header
|
||||
if (!hasUncategorisedSection) {
|
||||
newPromptsContent += "### Uncategorised\n";
|
||||
}
|
||||
|
||||
// Add each new prompt
|
||||
for (const file of newPromptFiles) {
|
||||
// Generate list items for each prompt file
|
||||
for (const file of promptFiles) {
|
||||
const filePath = path.join(promptsDir, file);
|
||||
const title = extractTitle(filePath);
|
||||
const description = extractDescription(filePath);
|
||||
const link = encodeURI(`prompts/${file}`);
|
||||
|
||||
if (description) {
|
||||
newPromptsContent += `- [${title}](${link}) - ${description}\n`;
|
||||
// Check if there's a description in the frontmatter
|
||||
const customDescription = extractDescription(filePath);
|
||||
|
||||
if (customDescription && customDescription !== "null") {
|
||||
promptsContent += `- [${title}](${link}) - ${customDescription}\n`;
|
||||
} else {
|
||||
newPromptsContent += `- [${title}](${link})\n`;
|
||||
promptsContent += `- [${title}](${link})\n`;
|
||||
}
|
||||
}
|
||||
|
||||
// Add a newline if we created a new section
|
||||
if (!hasUncategorisedSection) {
|
||||
newPromptsContent += "\n";
|
||||
}
|
||||
|
||||
// Update the README content - insert new content in the right place
|
||||
if (hasUncategorisedSection) {
|
||||
// Add to existing Uncategorised section
|
||||
const uncategorisedSectionPos = currentReadme.match(
|
||||
uncategorisedSectionRegex
|
||||
).index;
|
||||
const sectionEndRegex = /\n\n/;
|
||||
let sectionEndMatch = sectionEndRegex.exec(
|
||||
currentReadme.slice(uncategorisedSectionPos + 16)
|
||||
); // 16 is length of "### Uncategorised\n"
|
||||
|
||||
let insertPos;
|
||||
if (sectionEndMatch) {
|
||||
insertPos = uncategorisedSectionPos + 16 + sectionEndMatch.index;
|
||||
} else {
|
||||
// If we can't find the end of the section, just insert at the end of the section header
|
||||
insertPos = uncategorisedSectionPos + 16;
|
||||
}
|
||||
|
||||
return (
|
||||
currentReadme.slice(0, insertPos) +
|
||||
newPromptsContent +
|
||||
currentReadme.slice(insertPos)
|
||||
);
|
||||
} else {
|
||||
// No Uncategorised section exists yet - find where to add it
|
||||
return addNewUncategorisedSection(currentReadme, newPromptsContent);
|
||||
}
|
||||
return `${TEMPLATES.promptsSection}\n\n${promptsContent}\n${TEMPLATES.promptsUsage}`;
|
||||
}
|
||||
|
||||
function addNewUncategorisedSection(currentReadme, newPromptsContent) {
|
||||
// Look for the "Ready-to-use prompt templates" section and the next section after it
|
||||
const promptSectionRegex =
|
||||
/## 🎯 Reusable Prompts\n\nReady-to-use prompt templates/;
|
||||
const promptSectionMatch = currentReadme.match(promptSectionRegex);
|
||||
|
||||
if (!promptSectionMatch) {
|
||||
console.error("Could not find the Reusable Prompts section in the README.");
|
||||
return currentReadme;
|
||||
/**
|
||||
* Generate the chat modes section with an alphabetical list of all chat modes
|
||||
*/
|
||||
function generateChatModesSection(chatmodesDir) {
|
||||
// Check if chatmodes directory exists
|
||||
if (!fs.existsSync(chatmodesDir)) {
|
||||
console.log("Chat modes directory does not exist");
|
||||
return "";
|
||||
}
|
||||
|
||||
// Find where to insert the new section - after any existing categories
|
||||
let insertPos;
|
||||
// First check if there are any existing categories
|
||||
const existingCategoriesRegex = /### [^\n]+\n/g;
|
||||
let lastCategoryMatch = null;
|
||||
let match;
|
||||
// Get all chat mode files
|
||||
const chatmodeFiles = fs
|
||||
.readdirSync(chatmodesDir)
|
||||
.filter((file) => file.endsWith(".chatmode.md"))
|
||||
.sort();
|
||||
|
||||
while ((match = existingCategoriesRegex.exec(currentReadme)) !== null) {
|
||||
lastCategoryMatch = match;
|
||||
}
|
||||
console.log(`Found ${chatmodeFiles.length} chat mode files`);
|
||||
|
||||
if (lastCategoryMatch) {
|
||||
// Find the end of the last category section
|
||||
const afterLastCategory = currentReadme.slice(
|
||||
lastCategoryMatch.index + lastCategoryMatch[0].length
|
||||
);
|
||||
const nextSectionRegex = /\n\n>/;
|
||||
const nextSectionMatch = afterLastCategory.match(nextSectionRegex);
|
||||
|
||||
if (nextSectionMatch) {
|
||||
insertPos =
|
||||
lastCategoryMatch.index +
|
||||
lastCategoryMatch[0].length +
|
||||
nextSectionMatch.index;
|
||||
} else {
|
||||
// If we can't find the next section, add at the end of the prompt section
|
||||
insertPos = currentReadme.indexOf("> 💡 **Usage**: Use `/prompt-name`");
|
||||
if (insertPos === -1) {
|
||||
// Fallback position - before Additional Resources
|
||||
insertPos = currentReadme.indexOf("## 📚 Additional Resources");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No categories yet, add right after the intro text
|
||||
const afterIntroRegex = /prompt\` command\.\n\n/;
|
||||
const afterIntroMatch = currentReadme.match(afterIntroRegex);
|
||||
|
||||
if (afterIntroMatch) {
|
||||
insertPos = afterIntroMatch.index + afterIntroMatch[0].length;
|
||||
} else {
|
||||
// Fallback position - before Additional Resources
|
||||
insertPos = currentReadme.indexOf("## 📚 Additional Resources");
|
||||
}
|
||||
}
|
||||
|
||||
if (insertPos !== -1) {
|
||||
return (
|
||||
currentReadme.slice(0, insertPos) +
|
||||
newPromptsContent +
|
||||
currentReadme.slice(insertPos)
|
||||
);
|
||||
} else {
|
||||
console.error("Could not find a suitable place to insert new prompts.");
|
||||
return currentReadme;
|
||||
}
|
||||
}
|
||||
|
||||
function updateChatModesSection(currentReadme, chatmodeFiles, chatmodesDir) {
|
||||
// No chat mode files, nothing to do
|
||||
// If no chat modes, return empty string
|
||||
if (chatmodeFiles.length === 0) {
|
||||
return currentReadme;
|
||||
return "";
|
||||
}
|
||||
|
||||
// Extract existing chat mode links from README
|
||||
const existingChatModeLinks = [];
|
||||
const chatModeLinkRegex = /\[.*?\]\(chatmodes\/(.+?)\)/g;
|
||||
let match;
|
||||
let chatmodesContent = "";
|
||||
|
||||
while ((match = chatModeLinkRegex.exec(currentReadme)) !== null) {
|
||||
existingChatModeLinks.push(match[1]);
|
||||
// Generate list items for each chat mode file
|
||||
for (const file of chatmodeFiles) {
|
||||
const filePath = path.join(chatmodesDir, file);
|
||||
const title = extractTitle(filePath);
|
||||
const link = encodeURI(`chatmodes/${file}`);
|
||||
|
||||
// Check if there's a description in the frontmatter
|
||||
const customDescription = extractDescription(filePath);
|
||||
|
||||
if (customDescription && customDescription !== "null") {
|
||||
chatmodesContent += `- [${title}](${link}) - ${customDescription}\n`;
|
||||
} else {
|
||||
chatmodesContent += `- [${title}](${link})\n`;
|
||||
}
|
||||
}
|
||||
|
||||
// Find new chat modes that aren't already in the README
|
||||
const newChatModeFiles = chatmodeFiles.filter(
|
||||
(file) => !existingChatModeLinks.includes(file)
|
||||
);
|
||||
|
||||
if (newChatModeFiles.length === 0) {
|
||||
console.log("No new chat modes to add.");
|
||||
} else {
|
||||
console.log(`Found ${newChatModeFiles.length} new chat modes to add.`);
|
||||
}
|
||||
|
||||
const chatmodesSection = currentReadme.match(
|
||||
/## 🧩 Custom Chat Modes\n\nCustom chat modes define.+?(?=\n\n>)/s
|
||||
);
|
||||
return `${TEMPLATES.chatmodesSection}\n\n${chatmodesContent}\n${TEMPLATES.chatmodesUsage}`;
|
||||
|
||||
if (chatmodesSection) {
|
||||
let chatmodesListContent = "\n\n";
|
||||
|
||||
// Generate list of chat mode links
|
||||
for (const file of chatmodeFiles) {
|
||||
// Always regenerate the entire list to ensure descriptions are included
|
||||
for (const file of chatmodeFiles.sort()) {
|
||||
const filePath = path.join(chatmodesDir, file);
|
||||
const title = extractTitle(filePath);
|
||||
const link = encodeURI(`chatmodes/${file}`);
|
||||
@@ -407,7 +366,7 @@ function updateChatModesSection(currentReadme, chatmodeFiles, chatmodesDir) {
|
||||
// Check if there's a description in the frontmatter
|
||||
const customDescription = extractDescription(filePath);
|
||||
|
||||
if (customDescription) {
|
||||
if (customDescription && customDescription !== "null") {
|
||||
// Use the description from frontmatter
|
||||
chatmodesListContent += `- [${title}](${link}) - ${customDescription}\n`;
|
||||
} else {
|
||||
@@ -419,7 +378,8 @@ function updateChatModesSection(currentReadme, chatmodeFiles, chatmodesDir) {
|
||||
// Replace the current chat modes section with the updated one
|
||||
const newChatmodesSection =
|
||||
"## 🧩 Custom Chat Modes\n\nCustom chat modes define specific behaviors and tools for GitHub Copilot Chat, enabling enhanced context-aware assistance for particular tasks or workflows." +
|
||||
chatmodesListContent;
|
||||
chatmodesListContent +
|
||||
"\n> 💡 **Usage**: Create new chat modes using the command `Chat: Configure Chat Modes...`, then switch your chat mode in the Chat input from _Agent_ or _Ask_ to your own mode.";
|
||||
|
||||
return currentReadme.replace(chatmodesSection[0], newChatmodesSection);
|
||||
} else {
|
||||
@@ -429,6 +389,7 @@ function updateChatModesSection(currentReadme, chatmodeFiles, chatmodesDir) {
|
||||
);
|
||||
|
||||
const chatmodesListContent = chatmodeFiles
|
||||
.sort()
|
||||
.map((file) => {
|
||||
const filePath = path.join(chatmodesDir, file);
|
||||
const title = extractTitle(filePath);
|
||||
@@ -444,7 +405,7 @@ function updateChatModesSection(currentReadme, chatmodeFiles, chatmodesDir) {
|
||||
.join("\n");
|
||||
|
||||
const newChatmodesSection =
|
||||
"## 🎭 Custom Chat Modes\n\n" +
|
||||
"## 🧩 Custom Chat Modes\n\n" +
|
||||
"Custom chat modes define specific behaviors and tools for GitHub Copilot Chat, enabling enhanced context-aware assistance for particular tasks or workflows.\n\n" +
|
||||
chatmodesListContent +
|
||||
"\n\n> 💡 **Usage**: Create new chat modes using the command `Chat: Configure Chat Modes...`, then switch your chat mode in the Chat input from _Agent_ or _Ask_ to your own mode.\n";
|
||||
@@ -466,68 +427,57 @@ function updateChatModesSection(currentReadme, chatmodeFiles, chatmodesDir) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the complete README.md content from scratch
|
||||
*/
|
||||
function generateReadme() {
|
||||
const instructionsDir = path.join(__dirname, "instructions");
|
||||
const promptsDir = path.join(__dirname, "prompts");
|
||||
const chatmodesDir = path.join(__dirname, "chatmodes");
|
||||
const readmePath = path.join(__dirname, "README.md");
|
||||
|
||||
// Check if README file exists
|
||||
if (!fs.existsSync(readmePath)) {
|
||||
console.error(
|
||||
"README.md not found! Please create a base README.md file first."
|
||||
);
|
||||
process.exit(1);
|
||||
// Generate each section
|
||||
const instructionsSection = generateInstructionsSection(instructionsDir);
|
||||
const promptsSection = generatePromptsSection(promptsDir);
|
||||
const chatmodesSection = generateChatModesSection(chatmodesDir);
|
||||
|
||||
// Build the complete README content with template sections
|
||||
let readmeContent = [TEMPLATES.header, instructionsSection, promptsSection];
|
||||
|
||||
// Only include chat modes section if we have any chat modes
|
||||
if (chatmodesSection) {
|
||||
readmeContent.push(chatmodesSection);
|
||||
}
|
||||
|
||||
// Read the current README content
|
||||
let currentReadme = fs.readFileSync(readmePath, "utf8");
|
||||
// Add footer
|
||||
readmeContent.push(TEMPLATES.footer);
|
||||
|
||||
// Get all instruction files
|
||||
const instructionFiles = fs
|
||||
.readdirSync(instructionsDir)
|
||||
.filter((file) => file.endsWith(".md"))
|
||||
.sort();
|
||||
|
||||
// Get all prompt files - we'll use this to find new prompts
|
||||
const promptFiles = fs
|
||||
.readdirSync(promptsDir)
|
||||
.filter((file) => file.endsWith(".prompt.md"))
|
||||
.sort();
|
||||
|
||||
// Get all chat mode files - we'll use this to update the chat modes section
|
||||
const chatmodeFiles = fs.existsSync(chatmodesDir)
|
||||
? fs
|
||||
.readdirSync(chatmodesDir)
|
||||
.filter((file) => file.endsWith(".chatmode.md"))
|
||||
.sort()
|
||||
: [];
|
||||
|
||||
// Update instructions section
|
||||
currentReadme = updateInstructionsSection(
|
||||
currentReadme,
|
||||
instructionFiles,
|
||||
instructionsDir
|
||||
);
|
||||
|
||||
// Update prompts section
|
||||
currentReadme = updatePromptsSection(currentReadme, promptFiles, promptsDir);
|
||||
|
||||
// Update chat modes section
|
||||
currentReadme = updateChatModesSection(
|
||||
currentReadme,
|
||||
chatmodeFiles,
|
||||
chatmodesDir
|
||||
);
|
||||
|
||||
return currentReadme;
|
||||
return readmeContent.join("\n\n");
|
||||
}
|
||||
|
||||
// Generate and write the README
|
||||
const updatedReadme = generateReadme();
|
||||
// Main execution
|
||||
try {
|
||||
console.log("Generating README.md from scratch...");
|
||||
|
||||
// Only write file if we have content to write
|
||||
if (updatedReadme) {
|
||||
fs.writeFileSync(path.join(__dirname, "README.md"), updatedReadme);
|
||||
console.log("README.md updated successfully!");
|
||||
const readmePath = path.join(__dirname, "README.md");
|
||||
const newReadmeContent = generateReadme();
|
||||
|
||||
// Check if the README file already exists
|
||||
if (fs.existsSync(readmePath)) {
|
||||
const originalContent = fs.readFileSync(readmePath, "utf8");
|
||||
const hasChanges = originalContent !== newReadmeContent;
|
||||
|
||||
if (hasChanges) {
|
||||
fs.writeFileSync(readmePath, newReadmeContent);
|
||||
console.log("README.md updated successfully!");
|
||||
} else {
|
||||
console.log("README.md is already up to date. No changes needed.");
|
||||
}
|
||||
} else {
|
||||
// Create the README file if it doesn't exist
|
||||
fs.writeFileSync(readmePath, newReadmeContent);
|
||||
console.log("README.md created successfully!");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error generating README.md: ${error.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user