1 | 'use strict'
|
2 |
|
3 | const chalk = require('chalk')
|
4 | const dedent = require('dedent')
|
5 | const has = require('lodash/has')
|
6 |
|
7 | const warn = msg => {
|
8 | console.warn(chalk.yellowBright.bold(msg))
|
9 | }
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | module.exports = function checkPkgScripts(pkg, cmd, binName, args) {
|
22 | if (pkg && pkg.scripts) {
|
23 | const { scripts } = pkg
|
24 | let scriptName
|
25 | let script
|
26 | if (has(scripts, cmd)) {
|
27 | scriptName = cmd
|
28 | script = scripts[cmd]
|
29 | } else if (has(scripts, binName)) {
|
30 | scriptName = binName
|
31 | script = scripts[binName]
|
32 | } else {
|
33 | return
|
34 | }
|
35 |
|
36 | const argsStr = args && args.length ? args.join(' ') : ''
|
37 | warn(dedent`
|
38 | \`lint-staged\` no longer supports running scripts defined in package.json.
|
39 |
|
40 | The same behavior can be achieved by changing the command to any of the following:
|
41 | - \`npm run ${scriptName} -- ${argsStr}\`
|
42 | - \`${script} ${argsStr}\`
|
43 | `)
|
44 | throw new Error(`Could not resolve binary for \`${cmd}\``)
|
45 | }
|
46 | }
|