
Git Utility
Utility for dealing with modified, created, deleted files since a git commit.
Usage
export const onPreBuild = function ({ utils }) {
const { git } = utils
if (git.modifiedFiles.length !== 0) {
console.log('Modified files:', git.modifiedFiles)
}
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')
}
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')
}
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)
}
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)
}
Prior art
This was originally found in danger.js and extracted into this utility