New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@netlify/git-utils

Package Overview
Dependencies
Maintainers
17
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@netlify/git-utils

Utility for dealing with modified, created, deleted files since a git commit

  • 5.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
138K
increased by9.32%
Maintainers
17
Weekly downloads
 
Created
Source

Coverage Status Build

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

Keywords

FAQs

Package last updated on 11 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc