Skip to content

Instantly share code, notes, and snippets.

@dotku
Last active September 15, 2024 05:52
Show Gist options
  • Save dotku/8ec4ac7c02b1a615e30d7c2d66e7c3e6 to your computer and use it in GitHub Desktop.
Save dotku/8ec4ac7c02b1a615e30d7c2d66e7c3e6 to your computer and use it in GitHub Desktop.
scripts/merge-gitignore
const fs = require("fs");
const path = require("path");
const gitignoreFiles = [
".gitignore", // Main .gitignore file
"next-app-template/.gitignore", // Add paths to other .gitignore files here
];
const outputGitignore = ".gitignore";
// Function to read and merge .gitignore files
function mergeGitignoreFiles(gitignoreFiles) {
const ignoreSet = new Set();
gitignoreFiles.forEach((file) => {
if (fs.existsSync(file)) {
const content = fs.readFileSync(file, "utf-8");
const lines = content
.split(/\r?\n/)
.filter((line) => line.trim() && !line.startsWith("#"));
lines.forEach((line) => ignoreSet.add(line.trim()));
} else {
console.error(`File not found: ${file}`);
}
});
const mergedContent = Array.from(ignoreSet).sort().join("\n");
fs.writeFileSync(outputGitignore, mergedContent, "utf-8");
console.log(`Merged .gitignore file created at: ${outputGitignore}`);
}
// Merge the .gitignore files
mergeGitignoreFiles(gitignoreFiles);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment