Skip to content

Commit

Permalink
feat(tasks,bin): add fail option to watch task and command
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 7, 2021
1 parent 8463a82 commit a329ad5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/cli/commands/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export async function watch(params: CLI.Extension.Params): Promise<Task> {
Options:
-g, --glob Parse globs in paths
-p, --prime Runs the task once when ready to wait for changes
-f, --fail Finalizes the watch effort if a given task fails
-c, --clear Clear stdout before tasks execution
-i, --include <value> Paths to include
-e, --exclude <value> Paths to exclude
Expand All @@ -47,9 +48,10 @@ export async function watch(params: CLI.Extension.Params): Promise<Task> {
const types = {
'--glob': Boolean,
'--prime': Boolean,
'--fail': Boolean,
'--clear': Boolean,
'--include': [String] as [StringConstructor],
'--exclude': [String] as [StringConstructor],
'--clear': Boolean,
'--parallel': Boolean,
'--symlinks': Boolean,
'--debounce': Number,
Expand Down Expand Up @@ -90,6 +92,7 @@ export async function watch(params: CLI.Extension.Params): Promise<Task> {
{
glob: cmd['--glob'],
prime: cmd['--prime'],
fail: cmd['--fail'],
clear: cmd['--clear'],
include: cmd['--include'],
exclude: cmd['--exclude'],
Expand Down
13 changes: 12 additions & 1 deletion src/tasks/filesystem/watch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Task, Context } from '../../definitions';
import { stringifyError } from '../../helpers/stringify';
import { run } from '../../utils/run';
import { log } from '../stdio/log';
import { clear } from '../stdio/clear';
Expand All @@ -14,6 +15,8 @@ export interface WatchOptions {
glob?: boolean;
/** Runs the task once when ready to wait for changes */
prime?: boolean;
/** Finalizes the watch effort if a given task fails */
fail?: boolean;
/** Clear stdout before tasks execution */
clear?: boolean;
/** Paths to include */
Expand Down Expand Up @@ -43,6 +46,7 @@ export function watch(options: WatchOptions | Empty, task: Task): Task.Async {
{
glob: false,
prime: false,
fail: false,
clear: false,
include: ['./'],
exclude: ['node_modules'],
Expand Down Expand Up @@ -107,7 +111,14 @@ export function watch(options: WatchOptions | Empty, task: Task): Task.Async {
})
});
})
.catch(onError);
.catch((err) => {
return opts.fail
? onError(err)
: run(
series(log('trace', err), log('warn', stringifyError(err))),
ctx
);
});
},
opts.debounce >= 0 ? opts.debounce : 0
);
Expand Down

0 comments on commit a329ad5

Please sign in to comment.