Skip to content

Commit

Permalink
refactor: reuse Listr stuff better
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Jun 8, 2022
1 parent f27f1d4 commit 4384114
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions lib/runAll.js
Expand Up @@ -206,14 +206,12 @@ export const runAll = async (
title: `${task.pattern}${dim(
` — ${fileCount} ${fileCount === 1 ? 'file' : 'files'}`
)}`,
task: async () =>
new Listr(subTasks, {
// In sub-tasks we don't want to run concurrently
// and we want to abort on errors
...listrOptions,
concurrent: false,
exitOnError: true,
}),
task: async (ctx, task) =>
task.newListr(
subTasks,
// Subtasks should not run in parallel, and should exit on error
{ concurrent: false, exitOnError: true }
),
skip: () => {
// Skip task when no files matched
if (fileCount === 0) {
Expand All @@ -230,7 +228,7 @@ export const runAll = async (
title:
`${configName}${dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
(chunkCount > 1 ? dim(` (chunk ${index + 1}/${chunkCount})...`) : ''),
task: () => new Listr(chunkListrTasks, { ...listrOptions, concurrent, exitOnError: true }),
task: (ctx, task) => task.newListr(chunkListrTasks, { concurrent, exitOnError: true }),
skip: () => {
// Skip if the first step (backup) failed
if (ctx.errors.has(GitError)) return SKIPPED_GIT_ERROR
Expand Down Expand Up @@ -279,7 +277,7 @@ export const runAll = async (
},
{
title: `Running tasks for staged files...`,
task: () => new Listr(listrTasks, { ...listrOptions, concurrent }),
task: (ctx, task) => task.newListr(listrTasks, { concurrent }),
skip: () => listrTasks.every((task) => task.skip()),
},
{
Expand Down
4 changes: 2 additions & 2 deletions test/runAll.spec.js
Expand Up @@ -234,7 +234,7 @@ describe('runAll', () => {
LOG [STARTED] echo \\"sample\\"
ERROR [FAILED] echo \\"sample\\" [1]
ERROR [FAILED] echo \\"sample\\" [1]
LOG [SUCCESS] Running tasks for staged files...
ERROR [FAILED] echo \\"sample\\" [1]
LOG [STARTED] Applying modifications from tasks...
INFO [SKIPPED] Skipped because of errors from tasks.
LOG [STARTED] Reverting to original state because of errors...
Expand Down Expand Up @@ -273,7 +273,7 @@ describe('runAll', () => {
LOG [STARTED] echo \\"sample\\"
ERROR [FAILED] echo \\"sample\\" [KILLED]
ERROR [FAILED] echo \\"sample\\" [KILLED]
LOG [SUCCESS] Running tasks for staged files...
ERROR [FAILED] echo \\"sample\\" [KILLED]
LOG [STARTED] Applying modifications from tasks...
INFO [SKIPPED] Skipped because of errors from tasks.
LOG [STARTED] Reverting to original state because of errors...
Expand Down

0 comments on commit 4384114

Please sign in to comment.