1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict'
|
4 |
|
5 |
|
6 | const { supportsColor } = require('chalk')
|
7 | if (supportsColor) {
|
8 | process.env.FORCE_COLOR = supportsColor.level.toString()
|
9 | }
|
10 |
|
11 |
|
12 | process.on('SIGINT', () => {})
|
13 |
|
14 | const pkg = require('../package.json')
|
15 | require('please-upgrade-node')(
|
16 | Object.assign({}, pkg, {
|
17 | engines: {
|
18 | node: '>=10.13.0',
|
19 | },
|
20 | })
|
21 | )
|
22 |
|
23 | const cmdline = require('commander')
|
24 | const debugLib = require('debug')
|
25 | const lintStaged = require('../lib')
|
26 |
|
27 | const debug = debugLib('lint-staged:bin')
|
28 |
|
29 | cmdline
|
30 | .version(pkg.version)
|
31 | .option('--allow-empty', 'allow empty commits when tasks revert all staged changes', false)
|
32 | .option('-c, --config [path]', 'path to configuration file')
|
33 | .option('-d, --debug', 'print additional debug information', false)
|
34 | .option('--no-stash', 'disable the backup stash, and do not revert in case of errors', false)
|
35 | .option(
|
36 | '-p, --concurrent <parallel tasks>',
|
37 | 'the number of tasks to run concurrently, or false to run tasks serially',
|
38 | true
|
39 | )
|
40 | .option('-q, --quiet', 'disable lint-staged’s own console output', false)
|
41 | .option('-r, --relative', 'pass relative filepaths to tasks', false)
|
42 | .option('-x, --shell', 'skip parsing of tasks for better shell support', false)
|
43 | .option(
|
44 | '-v, --verbose',
|
45 | 'show task output even when tasks succeed; by default only failed output is shown',
|
46 | false
|
47 | )
|
48 | .parse(process.argv)
|
49 |
|
50 | if (cmdline.debug) {
|
51 | debugLib.enable('lint-staged*')
|
52 | }
|
53 |
|
54 | debug('Running `lint-staged@%s`', pkg.version)
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | const getMaxArgLength = () => {
|
64 | switch (process.platform) {
|
65 | case 'darwin':
|
66 | return 262144
|
67 | case 'win32':
|
68 | return 8191
|
69 | default:
|
70 | return 131072
|
71 | }
|
72 | }
|
73 |
|
74 | const options = {
|
75 | allowEmpty: !!cmdline.allowEmpty,
|
76 | concurrent: cmdline.concurrent,
|
77 | configPath: cmdline.config,
|
78 | debug: !!cmdline.debug,
|
79 | maxArgLength: getMaxArgLength() / 2,
|
80 | stash: !!cmdline.stash,
|
81 | quiet: !!cmdline.quiet,
|
82 | relative: !!cmdline.relative,
|
83 | shell: !!cmdline.shell,
|
84 | verbose: !!cmdline.verbose,
|
85 | }
|
86 |
|
87 | debug('Options parsed from command-line:', options)
|
88 |
|
89 | lintStaged(options)
|
90 | .then((passed) => {
|
91 | process.exitCode = passed ? 0 : 1
|
92 | })
|
93 | .catch(() => {
|
94 | process.exitCode = 1
|
95 | })
|