Skip to content

Commit

Permalink
refactor: simplify spreading of listrTasks into main runner tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Nov 19, 2019
1 parent e1c5220 commit 86b562f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/runAll.js
Expand Up @@ -60,7 +60,10 @@ module.exports = async function runAll(
debugLog('Loaded list of staged files in git:\n%O', files)

const chunkedFiles = chunkFiles({ files, gitDir, maxArgLength, relative })
debugLog('Chunked staged files into %s parts', chunkedFiles.length)
const chunkCount = chunkedFiles.length
if (chunkCount > 1) {
debugLog(`Chunked staged files into ${chunkCount} part`, chunkCount)
}

// lint-staged 10 will automatically add modifications to index
// Warn user when their command includes `git add`
Expand Down Expand Up @@ -107,7 +110,9 @@ module.exports = async function runAll(
})

listrTasks.push({
title: `Running tasks (${index}/${chunkedFiles.length})...`,
// No need to show number of task chunks when there's only one
title:
chunkCount > 1 ? `Running tasks (chunk ${index}/${chunkCount})...` : 'Running tasks...',
task: () =>
new Listr(chunkListrTasks, { ...listrOptions, concurrent: false, exitOnError: false }),
skip: () => {
Expand Down Expand Up @@ -141,14 +146,7 @@ module.exports = async function runAll(
title: 'Preparing...',
task: () => git.stashBackup()
},
...(listrTasks.length === 1
? [
{
...listrTasks[0],
title: 'Running tasks...'
}
]
: listrTasks),
...listrTasks,
{
title: 'Applying modifications...',
skip: ctx => ctx.hasErrors && 'Skipped because of errors from tasks',
Expand Down

0 comments on commit 86b562f

Please sign in to comment.