Skip to content

Commit

Permalink
feat(tasks): add name option for announce
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 8, 2021
1 parent ffbd42c commit 6b32f6b
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/tasks/stdio/announce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import { series } from '../aggregate/series';
import { create } from '../creation/create';
import { log } from '../stdio/log';
import { shallow } from 'merge-strategies';
import { TypeGuard } from 'type-core';

export interface AnnounceOptions {
info: boolean;
success: boolean;
/** Use instead of the task route */
name?: string;
/** Print route before execution */
info?: boolean;
/** Print route after successful execution */
success?: boolean;
}

/**
Expand All @@ -18,23 +23,14 @@ export interface AnnounceOptions {
export function announce(task: Task, options?: AnnounceOptions): Task.Async {
return create((ctx) => {
const opts = shallow({ info: true, success: true }, options || undefined);
const name = TypeGuard.isString(opts.name)
? opts.name
: stringifyPrintRoute(ctx.route);

return series(
opts.info
? log(
'info',
style('task', { bold: true }),
stringifyPrintRoute(ctx.route)
)
: null,
opts.info ? log('info', style('task', { bold: true }), name) : null,
task,
opts.success
? log(
'success',
style('task', { bold: true }),
stringifyPrintRoute(ctx.route)
)
: null
opts.success ? log('success', style('task', { bold: true }), name) : null
);
});
}

0 comments on commit 6b32f6b

Please sign in to comment.