gitignore-utils helps tools keep generated files, local secrets, deployment folders, and other project-specific artifacts out of git.
It adds ignore rules that are not already listed in a .gitignore file, which makes it useful for CLIs, project scaffolds, deployment tooling, and setup scripts that need to protect users from accidentally committing hidden files or folders.
Full documentation, synced from the package README:
Utilities for working with .gitignore files
const path = require('path')
const { addRules } = require('gitignore-utils')
async function ensureGitIgnore() {
const gitIgnorePath = path.resolve(__dirname, '.gitignore')
const gitIgnoreDetails = await addRules(gitIgnorePath, [
{
comment: '# Super secret stuff',
patterns: ['.env', '.env.prod']
},
{
comment: '# Project stuff',
patterns: ['.netlify', '.serverless']
},
{
comment: '# Other things',
patterns: ['.shhhh', '/folder']
}
])
console.log('gitIgnoreDetails', gitIgnoreDetails)
}
ensureGitIgnore()
/*
.gitignore file now has these lines added
# Super secret stuff
.env
.env.prod
# Project stuff
.netlify
.serverless
# Other things
.shhhh
/folder
*/