Created
September 11, 2011 04:57
-
-
Save issm/1209188 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 5.12.0; | |
use warnings; | |
use Cocoa::Growl ':all'; | |
use File::Basename; | |
sub main { | |
my ($target) = @_; | |
growl_register( | |
app => 'CoffeeScript Compiler', | |
notifications => [qw/ notif_success notif_failure /], | |
); | |
my $cmd = sprintf 'coffee -c -o js %s 2> /dev/stdout', $target; | |
my $result = `$cmd`; | |
my $title; | |
my %params_notify; | |
# failure | |
if ( $result ) { | |
$title = sprintf '%s: compile failed', (basename $target); | |
%params_notify = ( | |
%params_notify, | |
name => 'notif_failure', | |
title => $title, | |
description => $result, | |
priority => 3, | |
sticky => 1, | |
); | |
} | |
# success | |
else { | |
$title = sprintf '%s: compiled', (basename $target); | |
%params_notify = ( | |
%params_notify, | |
name => 'notif_success', | |
title => $title, | |
description => 'ok.', | |
); | |
} | |
growl_notify(%params_notify); | |
} | |
main(@ARGV); | |
__END__ |
This file contains hidden or 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
#!/bin/sh | |
ROOT=$( cd $(dirname $0)/../ && pwd ) | |
PIDFILE=$ROOT/tmp/watch-coffee.pid | |
MODE=$1 | |
_main() | |
{ | |
case $MODE in | |
"start") | |
__start | |
;; | |
"stop") | |
__stop | |
;; | |
"restart") | |
__stop | |
__start | |
;; | |
* ) | |
__start | |
esac | |
exit 0 | |
} | |
__start() | |
{ | |
if [ ! -d $ROOT/tmp ]; then | |
echo "no such directory: $ROOT/tmp" | |
exit 1 | |
fi | |
exec watcher \ | |
--dir $ROOT/coffee \ | |
-- \ | |
perl $ROOT/script/compile_coffee.pl $ROOT/coffee/slidegeso.coffee \ | |
> /dev/null 2>&1 & | |
PID_WATCHER=$! | |
echo $PID_WATCHER > $PIDFILE | |
} | |
__stop() | |
{ | |
kill -TERM $(cat $PIDFILE) | |
if [ -f $PIDFILE ]; then | |
rm $PIDFILE | |
fi | |
} | |
__restart() | |
{ | |
__stop | |
sleep .5 | |
__start | |
} | |
_main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment