From 86b562fb56e5716bb764d34fafe7dafe7174c49d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20Ja=CC=88ppinen?= Date: Tue, 19 Nov 2019 11:42:35 +0200 Subject: [PATCH] refactor: simplify spreading of listrTasks into main runner tasks --- lib/runAll.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/runAll.js b/lib/runAll.js index f8a402539..cbc6adaae 100644 --- a/lib/runAll.js +++ b/lib/runAll.js @@ -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` @@ -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: () => { @@ -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',