Skip to content

Commit

Permalink
feat(run/exec): run all on fail unless --fast-fail set
Browse files Browse the repository at this point in the history
Also, improve error output

Fixes #60
Fixes #59
Fixes #58
Fixes #57
  • Loading branch information
ianwremmel committed Apr 3, 2018
1 parent 8f24a71 commit f28e592
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 9 deletions.
19 changes: 14 additions & 5 deletions src/commands/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
},

Expand Down
23 changes: 22 additions & 1 deletion src/lib/handlers/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down
41 changes: 38 additions & 3 deletions src/lib/handlers/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
},
});
}

/**
Expand Down

0 comments on commit f28e592

Please sign in to comment.