/
bin.ts
39 lines (33 loc) 路 1009 Bytes
/
bin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import isCI from 'is-ci'
import path from 'path'
import debug from '../debug'
import { install, uninstall } from './'
import gitRevParse from './gitRevParse'
// Debug
debug(`cwd: ${process.cwd()}`)
debug(`INIT_CWD: ${process.env.INIT_CWD}`)
// Action can be "install" or "uninstall"
// huskyDir is ONLY used in dev, don't use this arguments
const [, , action, huskyDir = path.join(__dirname, '../..')] = process.argv
// Find Git dir
try {
// Show un/install message
console.log(
'husky > %s git hooks',
action === 'install' ? 'Setting up' : 'Uninstalling'
)
// Get top level and git dir
const { topLevel, absoluteGitDir } = gitRevParse()
// Debug
debug(`topLevel: ${topLevel}`)
debug(`gitDir: ${absoluteGitDir}`)
// Install or uninstall
if (action === 'install') {
install(topLevel, absoluteGitDir, huskyDir, isCI)
} else {
uninstall(absoluteGitDir, huskyDir)
}
} catch (error) {
console.log(error.message.trim())
console.log(`husky > Failed to ${action}`)
}