Giter Site home page Giter Site logo

tomherman11 / npm-install-or-yarn-after-git-merge-checkout-rebase Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 6.45 MB

An example of a Node.js project that utilizes the npm package Husky and git hooks for automatic execution of npm install (or yarn) after git merge, git checkout or git rebase, if needed โ›‘๏ธ๐Ÿ› ๏ธ

Shell 100.00%
npm-install git-merge git-checkout yarn git-rebase githooks husky

npm-install-or-yarn-after-git-merge-checkout-rebase's Introduction

npm-install-or-yarn-after-git-merge-checkout-rebase

An example of a Node.js project that utilizes the npm package Husky and git hooks for automatic execution of npm install (or yarn) after git merge, git checkout or git rebase, if needed.

Demo

Example video

How to Use

  1. Install husky: npm install --save-dev husky

  2. Copy and use the relevant scripts from this repository for npm (./githooks/npm/) or yarn (./githooks/yarn/).

  3. In package.json, add the git hooks using husky:

    {
        ...
        "husky": {
            "hooks": {
                "post-checkout": "./githooks/npm/post-checkout.sh $HUSKY_GIT_PARAMS",
                "post-merge": "./githooks/npm/post-merge.sh"
            }
        }
    }

How It Works

Both scripts (post-checkout.sh & post-merge.sh) use git diff in order to find which files have been updated by comparing two commits. Then, by using grep, the scripts check if package-lock.json (for npm) or yarn.lock (for yarn) are among the updated files.

  • For merge: git diff HEAD^ HEAD - compare the previous commit (HEAD^) with the current commit (HEAD). We compare these commits because git merge creates a new commit of the merge itself.

  • For checkout: We use the enivronment variable provided by husky $HUSKY_GIT_PARAMS in the post-checkout.sh script in order to provide git diff the source & target commits (of the source & target branches, respectively).

  • For rebase: git checkout is executed as part of git rebase, so post-checkout.sh is executed in this scenario.

Flags used:

  • git diff --name-only
    • --name-only - Show only the names of the changed files.
  • grep -x -q
    • -x - Select only matches that exactly match the whole line.
    • -q - Do not write anything to standard output, but only return the exit status code.

npm-install-or-yarn-after-git-merge-checkout-rebase's People

Contributors

tomherman11 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.