-
Notifications
You must be signed in to change notification settings - Fork 205
/
pre-commit.js
36 lines (26 loc) · 832 Bytes
/
pre-commit.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
const path = require('path')
const spawn = require('cross-spawn')
const {hasPkgProp, hasFile, resolveBin} = require('../utils')
const here = p => path.join(__dirname, p)
const hereRelative = p => here(p).replace(process.cwd(), '.')
const args = process.argv.slice(2)
const useBuiltInConfig =
!args.includes('--config') &&
!hasFile('.lintstagedrc') &&
!hasFile('lint-staged.config.js') &&
!hasPkgProp('lint-staged')
const config = useBuiltInConfig
? ['--config', hereRelative('../config/lintstagedrc.js')]
: []
function go() {
let result
result = spawn.sync(resolveBin('lint-staged'), [...config, ...args], {
stdio: 'inherit',
})
if (result.status !== 0) return result.status
result = spawn.sync('npm', ['run', 'validate'], {
stdio: 'inherit',
})
return result.status
}
process.exit(go())