简体   繁体   中英

Run Husky hooks only for specific folder changes

Is it possible to run only git hooks for when only files in certain folder are changed??

I have monorepo with backend and frontend. I would like to run husky hook only when the files in frontend got changed. Otherwise it should not be triggered and not run linting tests etc... It's irritating backend developers

With combination on lint-staged I managed to run husky hooks checks on only desired folder changes.

module.exports = {
  '*': (files) => {
    const isAppFolderChanges = files.some((fileName) =>
      fileName.includes('/app/'),
    )
    const scripts = [
      'npm run lint-fix',
      './node_modules/.bin/pretty-quick --staged',
      'npm test',
    ]

    return isAppFolderChanges ? scripts : []
  },
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM