Created
April 29, 2016 17:46
-
-
Save zoffixznet/50e0a7a14a8115fae14865a521ed4f0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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