-
-
Notifications
You must be signed in to change notification settings - Fork 252
/
.huskyrc.js
50 lines (43 loc) · 1.1 KB
/
.huskyrc.js
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
40
41
42
43
44
45
46
47
48
49
50
const tasks = (tasks) => {
return tasks
.map((task) => {
return `cd ${__dirname}/${task.path} && ${task.command}`
})
.join(`&& cd ${__dirname} && `)
}
// Run eslint on the files inside path for the last commit
// It will try to amend the latest commit if possible to fix.
const eslint = (path) => {
return {
command: `git diff --name-only --diff-filter=d $(git merge-base origin/master HEAD) | grep "^${path}.*js$" | sed 's/${path}\\///' | xargs eslint --fix`,
path: path,
}
}
// lintStaged actually just runs formatting rules on staged files
const lintStaged = (path) => {
return { command: `echo ${path} && lint-staged`, path: path }
}
const subDirs = [
'locksmith',
'paywall',
'smart-contracts',
'governance',
'tests',
'unlock-app',
'paywall',
'unlock-js',
'unlock-protocol.com',
]
const prePushTasks = subDirs.map((dir) => {
return eslint(dir)
})
const preCommitTasks = subDirs.map((dir) => {
return lintStaged(dir)
})
const config = {
hooks: {
'pre-push': tasks(prePushTasks),
'pre-commit': tasks(preCommitTasks),
},
}
module.exports = config