Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created April 29, 2016 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/50e0a7a14a8115fae14865a521ed4f0a to your computer and use it in GitHub Desktop.
Save zoffixznet/50e0a7a14a8115fae14865a521ed4f0a to your computer and use it in GitHub Desktop.
$ perl6 bin/bailer.p6 bin/app.p6
DIRS: [lib|bin]
Attempting to boot up the app
Starting watch on `lib` main
Starting watch on `bin` main
Starting watch on `lib` main
Starting watch on `bin` main
Entering the development dance floor: http://0.0.0.0:3000
use File::Find;
sub MAIN ( Str $app, Str :$w = 'lib,bin,templates,public') {
my @watchlist = $w.split: /<!after \\> \,/;
s/\\\,/,/ for @watchlist;
given watch-recursive @watchlist.grep: *.IO.e {
say "Attempting to boot up the app";
my $p = bootup-app $app;
.act: -> $e {
say "Change detected [$e.path(), $e.event()]. app";
$p.kill;
$p = bootup-app $app;
};
await .Promise;
}
}
########
my sub bootup-app ($app) {
my Proc::Async $p .= new: 'perl6', $app;
$p.stdout.tap: -> $v { say $v };
$p.stderr.tap: -> $v { $*ERR.print: $v };
$p.start;
return $p;
}
########
my sub watch-recursive(@dirs) {
say "DIRS: [{|@dirs.map({ find-dirs $_ }).join("|")}]";
supply {
my sub watch-it($p, $m = 'main') {
say "Starting watch on `$p` $m";
whenever IO::Notification.watch-path($p) -> $e {
if $e.event ~~ FileRenamed && $e.path.IO ~~ :d {
#watch-it($_, 'nope') for find-dirs $e.path;
}
emit($e);
}
}
watch-it(~$_) for |@dirs.map: { find-dirs $_ };
}
}
my sub find-dirs (Str:D $p) {
return slip $p.IO, slip find :dir($p), :type<dir>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment