Skip to content

Commit

Permalink
fix: fix stdout clear for watch task and command
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 3, 2021
1 parent 90c1527 commit a1cc544
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
25 changes: 23 additions & 2 deletions src/bin/watch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { Task } from '../definitions';
import { series, raises, print, log, combine, watch, context } from '../tasks';
import {
series,
raises,
print,
log,
combine,
watch,
context,
bundle
} from '../tasks';
import { stripIndent as indent } from 'common-tags';
import { flags, safePairs, splitBy } from 'cli-belt';
import chalk from 'chalk';
Expand Down Expand Up @@ -67,6 +76,7 @@ export default async function bin(

if (cmd['--help']) return print(help + '\n');

let first = true;
const [names, args] = splitBy(cmd._, '--');
return names.length
? context(
Expand All @@ -93,7 +103,18 @@ export default async function bin(
poll: cmd['--poll'],
symlinks: cmd['--symlinks']
},
combine(params.record, names)
series(
bundle(() => {
if (first) return (first = false) || null;
return log(
'info',
chalk.bold(opts.bin),
chalk.bold.blue(':watch'),
names.join(' ')
);
}),
combine(params.record, names)
)
)
)
)
Expand Down
7 changes: 4 additions & 3 deletions src/tasks/filesystem/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function watch(options: WatchOptions | Empty, task: Task): Task.Async {
cancel();
}

let i = 0;
let i = -1;
let current: Promise<void> = Promise.resolve();
const onEvent = debounce(
(onError: UnaryFn<Error>): void => {
Expand All @@ -98,9 +98,10 @@ export function watch(options: WatchOptions | Empty, task: Task): Task.Async {

current = after
.then(() => {
return run(series(i === 0 ? null : clear(), task), {
i += 1;
return run(series(i > 0 && opts.clear ? clear() : null, task), {
...ctx,
route: opts.parallel ? ctx.route.concat(String(i++)) : ctx.route,
route: opts.parallel ? ctx.route.concat(String(i)) : ctx.route,
cancellation: new Promise((resolve) => {
cbs.push(resolve);
})
Expand Down

0 comments on commit a1cc544

Please sign in to comment.