From f28e592f3c7f81f829291fb3dd7a7bd7c6a8586e Mon Sep 17 00:00:00 2001 From: "Ian W. Remmel" <1182361+ianwremmel@users.noreply.github.com> Date: Mon, 2 Apr 2018 21:09:20 -0700 Subject: [PATCH] feat(run/exec): run all on fail unless --fast-fail set Also, improve error output Fixes #60 Fixes #59 Fixes #58 Fixes #57 --- src/commands/exec.ts | 19 ++++++++++++++----- src/lib/handlers/exec.ts | 23 +++++++++++++++++++++- src/lib/handlers/run.ts | 41 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 74 insertions(+), 9 deletions(-) diff --git a/src/commands/exec.ts b/src/commands/exec.ts index 2322ca81..10a3999d 100644 --- a/src/commands/exec.ts +++ b/src/commands/exec.ts @@ -13,11 +13,20 @@ const ExecCommand: CommandModule = { describe: 'The command to execute.', type: 'string', }) - .option('package-name', { - alias: ['p', 'package'], - describe: - 'The package against which to run this command. May be specified more than once.', - type: 'string', + .options({ + 'fail-fast': { + alias: 'ff', + default: false, + describe: + 'Fail as soon as a command fails, rather than running all to completion', + type: 'boolean', + }, + 'package-name': { + alias: ['p', 'package'], + describe: + 'The package against which to run this command. May be specified more than once.', + type: 'string', + }, }); }, diff --git a/src/lib/handlers/exec.ts b/src/lib/handlers/exec.ts index 7a6e1f97..f4659ce1 100644 --- a/src/lib/handlers/exec.ts +++ b/src/lib/handlers/exec.ts @@ -20,12 +20,33 @@ export namespace Exec { debug, `Running "${command}" against ${packages.length} packages`, ); + const errors = []; + for (const packageName of packages) { log(options, debug, `Running ${command} against ${packageName}`); - await exec(command, packageName); + try { + await exec(command, packageName); + } catch (err) { + errors.push(err); + log( + options, + debug, + `${command} failed against ${packageName} packages`, + ); + } log(options, debug, `Ran ${command} against ${packageName}`); } log(options, debug, `Ran "${command}" against ${packages.length} packages`); + + if (errors.length) { + console.error( + `clark exec failed to execute the following command against ${ + errors.length + } packages\n> ${command}\n`, + ); + console.error(errors); + process.exit(1); + } } /** diff --git a/src/lib/handlers/run.ts b/src/lib/handlers/run.ts index 45dfde4a..315a1c22 100644 --- a/src/lib/handlers/run.ts +++ b/src/lib/handlers/run.ts @@ -38,13 +38,23 @@ export namespace Run { debug, `Running ${command} against ${packages.length} packages`, ); + const errors = []; for (const packageName of packages) { log( argv as log.Options, debug, `Running ${command} against ${packageName} packages`, ); - await execScript(command, packageName, script); + try { + await execScript(command, packageName, script); + } catch (err) { + log( + argv as log.Options, + debug, + `${command} failed against ${packageName} packages`, + ); + errors.push(err); + } log( argv as log.Options, debug, @@ -56,13 +66,38 @@ export namespace Run { debug, `Ran ${command} against ${packages.length} packages`, ); + + if (errors.length) { + console.error( + argv as log.Options, + debug, + `clark run failed to execute the following command against ${ + errors.length + } packages\n> ${command}\n`, + ); + console.error(argv as log.Options, debug, errors); + process.exit(1); + } }, ), yargs, ); } - - return yargs; + return yargs.options({ + 'fail-fast': { + alias: 'ff', + default: false, + describe: + 'Fail as soon as a command fails, rather than running all to completion', + type: 'boolean', + }, + 'package-name': { + alias: ['p', 'package'], + describe: + 'The package against which to run this command. May be specified more than once.', + type: 'string', + }, + }); } /**