5.1.1 • Published 2 years ago
@netlify/git-utils v5.1.1
Git Utility
Utility for dealing with modified, created, deleted files since a git commit.
Usage
/* Export the Netlify Plugin */
export const onPreBuild = function ({ utils }) {
const { git } = utils
/* Do stuff if files modified */
if (git.modifiedFiles.length !== 0) {
console.log('Modified files:', git.modifiedFiles)
}
/* Do stuff only if html code edited */
const htmlFiles = git.fileMatch('**/*.html')
console.log('html files git info:', htmlFiles)
if (htmlFiles.edited.length !== 0) {
console.log('>> Run thing because HTML has changed\n')
}
//
/* Do stuff only if markdown files edited */
const markdownFiles = git.fileMatch('**/*.md')
console.log('markdown files git info:', markdownFiles)
if (markdownFiles.modified.length !== 0) {
console.log('>> Run thing because Markdown files have been created/changed/deleted\n')
}
/* Do stuff only if css files edited */
const cssFiles = git.fileMatch('**/*.css')
if (cssFiles.deleted.length !== 0) {
console.log('>> Run thing because css files have been deleted\n')
console.log(cssFiles)
}
}
API
The git
util includes the following signature.
export const onPreBuild = function ({ utils }) {
console.log(utils.git)
// {
// fileMatch: [Function], <-- Lookup function. See below
// modifiedFiles: [ Array of all modified files ],
// createdFiles: [ Array of all created files ],
// deletedFiles: [ Array of all deleted files ],
// commits: [ Array of commits with details ],
// linesOfCode: [AsyncFunction: linesOfCode] <-- how many lines of code have changed
// }
//
}
git.fileMatch()
is a glob matcher function to detect the git status of a pattern of files.
export const onPreBuild = function ({ utils }) {
const cssFiles = utils.git.fileMatch('**/*.css')
console.log('cssFiles', cssFiles)
// {
// modified: [ 'just-changed.css', 'just-changed-two.css' ],
// created: [ 'just-added.css' ],
// deleted: [ 'just-deleted.css' ],
// edited: [ 'just-changed.css', 'just-changed-two.css', 'just-added.css', 'just-deleted.css' ]
// }
//
}
Prior art
This was originally found in danger.js and extracted into this utility
5.1.1
2 years ago
5.1.0
2 years ago
5.0.2
2 years ago
5.0.1
2 years ago
5.0.0
2 years ago
4.1.4
2 years ago
4.1.3
2 years ago
4.1.3-rc
2 years ago
4.1.2-rc
2 years ago
4.1.2
2 years ago
4.1.0
3 years ago
4.1.1
3 years ago
3.0.0
3 years ago
4.0.0
3 years ago
2.0.2
4 years ago
2.0.1
4 years ago
2.0.0
4 years ago
1.0.9
4 years ago
1.0.11
4 years ago
1.0.10
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago
0.2.2
5 years ago
0.2.1
5 years ago
0.2.0
5 years ago
0.1.0
5 years ago
0.0.2
5 years ago
0.0.1
5 years ago