Skip to content

Instantly share code, notes, and snippets.

@condorheroblog
Created June 14, 2022 05:56
Show Gist options
  • Save condorheroblog/97f3a8cefcd1615b9da2c5f72142c60f to your computer and use it in GitHub Desktop.
Save condorheroblog/97f3a8cefcd1615b9da2c5f72142c60f to your computer and use it in GitHub Desktop.
/**
 * @see https://typicode.github.io/husky/#/?id=with-a-custom-script
 */

const { spawn } = require('child_process')
const { join } = require('path')
const husky = require('husky')

const dotHuskyPath = join(__dirname, '../.husky')
const huskyDirPath = join(__dirname, '../../')
const preCommit = join(dotHuskyPath, 'pre-commit')

const isCi = process.env.CI !== undefined

if (!isCi) {
  spawn('rm', ['-rf', dotHuskyPath])
  process.chdir(huskyDirPath)
  console.log(!isCi, huskyDirPath)
  husky.install(join(huskyDirPath, './vite-react/.husky'))
  husky.add(preCommit, 'cd ./vite-react \nnpx lint-staged')
  spawn('git', ['add', preCommit])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment