1 | 'use strict'
|
2 |
|
3 | const resolveTaskFn = require('./resolveTaskFn')
|
4 |
|
5 | const debug = require('debug')('lint-staged:make-cmd-tasks')
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | module.exports = async function makeCmdTasks(commands, shell, gitDir, pathsToLint) {
|
15 | debug('Creating listr tasks for commands %o', commands)
|
16 | const commandsArray = Array.isArray(commands) ? commands : [commands]
|
17 |
|
18 | return commandsArray.reduce((tasks, command) => {
|
19 |
|
20 | const isFn = typeof command === 'function'
|
21 | const resolved = isFn ? command(pathsToLint) : command
|
22 | const linters = Array.isArray(resolved) ? resolved : [resolved]
|
23 |
|
24 | linters.forEach(linter => {
|
25 | const task = {
|
26 | title: linter,
|
27 | task: resolveTaskFn({ gitDir, isFn, linter, pathsToLint, shell })
|
28 | }
|
29 |
|
30 | tasks.push(task)
|
31 | })
|
32 |
|
33 | return tasks
|
34 | }, [])
|
35 | }
|