Created
April 29, 2016 17:53
-
-
Save zoffixznet/66411b043894cb9e276c8d8f193dde04 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
zoffix@zoffix-VirtualBox:~/CPANPRC/party$ perl6 bin/bailer.p6 bin/app.p6 | |
DIRS: [lib|bin] | |
CMON Instant:1461952414.362061 | |
Attempting to boot up the app | |
ZOMFG! Instant:1461952414.406619 | |
["/home/zoffix/CPANPRC/party/lib".IO "/home/zoffix/CPANPRC/party/bin".IO] | |
Starting watch on `lib` main | |
Starting watch on `bin` main | |
ZOMFG! Instant:1461952414.430843 | |
["/home/zoffix/CPANPRC/party/lib".IO "/home/zoffix/CPANPRC/party/bin".IO] | |
Starting watch on `lib` main | |
Starting watch on `bin` main | |
Entering the development dance floor: http://0.0.0.0:3000 | |
[2016-04-29T17:52:59Z] Started HTTP server. | |
^C | |
zoffix@zoffix-VirtualBox:~/CPANPRC/party$ |
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("|")}]"; | |
say "CMON {now}"; | |
supply { | |
say "ZOMFG! {now}"; | |
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); | |
} | |
} | |
my @d = |@dirs.map: { find-dirs $_ }; | |
say @d; | |
watch-it(~$_) for @d; | |
} | |
} | |
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