• [Bash] Run `npm install` when package.json changes in githook


    Git hooks

    In root of project:

    mkdir -p hooks
    cd hooks
    touch post-merge
    

    post-merge:

    #! /bin/bash
    
    # all stdio in this script after this line will be sent to the log file
    # note that we're appending so that the log file is not overwritten every time this script is called
    exec >> log/hooks-out.log 2>&1
    
    if git diff-tree --name-only --no-commit-id ORIG_HEAD HEAD | grep --quiet 'package.json'; then
      echo "$(date): Running npm install because package.json changed"
      # redirecting stdout to dev/null trashes quiets the stdout, but it's stderr will go to our log file
      npm install > /dev/null
    else
      echo "$(date): No changes in package.json found"
    fi
    

    Give premission:

    chmod +x hooks/post-merge
    

    Link to .git:

    ln -fv hooks/post-merge .git/hooks/
    

    Later if co-worker upgrade some packages, when we pull the changes, it will trigger `npm install

  • 相关阅读:
    VMware Workstation安装CentOs7固定ip地址
    使用阿里云oss
    使用Yapi展示你的api接口
    .net core使用MQTT
    CentOS 7服务器安装brook和bbr加速
    博客主题
    自定义控件
    winform数据绑定
    is as 运算符
    反射
  • 原文地址:https://www.cnblogs.com/Answer1215/p/14398455.html
Copyright © 2020-2023  润新知