Skip to content

Commit

Permalink
feat(tasks): adds catches transform
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Feb 17, 2021
1 parent f3f0c5d commit c7bb182
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
7 changes: 2 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
},
"dependencies": {
"chalk": "^2.4.2",
"errorish": "^0.4.0",
"execa": "^3.4.0",
"objectpath": "^2.0.0",
"pipettes": "^0.1.3",
Expand Down
28 changes: 28 additions & 0 deletions src/tasks/transform/catches.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Task, Context, LogLevel } from '../../definitions';
import { log } from '../create/log';
import { into } from 'pipettes';
import { ensure } from 'errorish';

export interface CatchesOptions {
level?: LogLevel;
}

export function catches(
task: Task,
alternate?: Task | null,
options?: CatchesOptions
): Task.Async {
return async (ctx: Context): Promise<void> => {
const opts = Object.assign({ level: 'warn' }, options);
try {
await task(ctx);
} catch (err) {
if (opts.level !== 'silent') {
into(ctx, log(opts.level, ensure(err).message));
}
if (alternate) {
await alternate(ctx);
}
}
};
}
1 change: 1 addition & 0 deletions src/tasks/transform/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './catches';
export * from './context';
export * from './parallel';
export * from './select';
Expand Down

0 comments on commit c7bb182

Please sign in to comment.