/
lint-staged
executable file
·76 lines (65 loc) · 1.89 KB
/
lint-staged
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
'use strict'
// Force colors for packages that depend on https://www.npmjs.com/package/supports-color
// but do this only in TTY mode
if (process.stdout.isTTY) {
// istanbul ignore next
process.env.FORCE_COLOR = '1'
}
// Do not terminate main Listr process on SIGINT
process.on('SIGINT', () => {})
const pkg = require('../package.json')
require('please-upgrade-node')(
Object.assign({}, pkg, {
engines: {
node: '>=8.12.0'
}
})
)
const cmdline = require('commander')
const debugLib = require('debug')
const lintStaged = require('../lib')
const debug = debugLib('lint-staged:bin')
cmdline
.version(pkg.version)
.option('-c, --config [path]', 'Path to configuration file')
.option('-r, --relative', 'Pass relative filepaths to tasks')
.option('-x, --shell', 'Skip parsing of tasks for better shell support')
.option('-q, --quiet', 'Disable lint-staged’s own console output')
.option('-d, --debug', 'Enable debug mode')
.parse(process.argv)
if (cmdline.debug) {
debugLib.enable('lint-staged*')
}
debug('Running `lint-staged@%s`', pkg.version)
/**
* Get the maximum length of a command-line argument string based on current platform
*
* https://serverfault.com/questions/69430/what-is-the-maximum-length-of-a-command-line-in-mac-os-x
* https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitation
* https://unix.stackexchange.com/a/120652
*/
const getMaxArgLength = () => {
switch (process.platform) {
case 'darwin':
return 262144
case 'win32':
return 8191
default:
return 131072
}
}
lintStaged({
configPath: cmdline.config,
maxArgLength: getMaxArgLength(),
relative: !!cmdline.relative,
shell: !!cmdline.shell,
quiet: !!cmdline.quiet,
debug: !!cmdline.debug
})
.then(passed => {
process.exitCode = passed ? 0 : 1
})
.catch(() => {
process.exitCode = 1
})