/
moon-watch
executable file
·57 lines (45 loc) · 1.4 KB
/
moon-watch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
if [ -z "$1" ]
then
echo "Moon-Watch v 0.2"
echo "better -watch for moonscript(moonc)"
echo "Usage: moon-watch path/to/moonscript [path/to/output/lua]"
exit 0
fi
SRC_DIR=$1
#if [ -z "$SRC_DIR" ]; then SRC_DIR="`dirname "$0"`"; fi
SRC_DIR=$(cd "$SRC_DIR" && pwd)
TARGET_DIR=$2
if [ -z "$TARGET_DIR" ]; then TARGET_DIR="`dirname "$1"`"; fi
TARGET_DIR=$(cd "$TARGET_DIR" && pwd)
echo "moon-watch start: $SRC_DIR ==> $TARGET_DIR"
callmoonc(){
PART=$(echo $1 | sed "s|$SRC_DIR|$EMPTY|g")
DEST="`dirname $TARGET_DIR$PART`"
RESULT_FILENAME=$(echo "`basename $i`" | sed "s/\.moon/\.lua/g")
cd "`dirname $1`"
moonc -t $DEST "`basename $1`" && echo "=> $DEST/$RESULT_FILENAME (`date`)"
if [ $? != 0 ]; then tput bel; fi # beep when compile failed
}
find $SRC_DIR -name "*.moon" | tr \\n \\0 | while read -d "" i
do
echo $i
callmoonc $i
done
fsw -0 $SRC_DIR | while read -d "" i
do
if echo $i | grep -q "^.*moon$" > /dev/null ; then
callmoonc $i
fi
done
#fsw -0 $SRC_DIR | while read -d "" i
#do
#if echo $i | grep -q "^.*moon$" > /dev/null ; then
#PART=$(echo $i | sed "s|$SRC_DIR|$EMPTY|g")
#DEST="`dirname $TARGET_DIR$PART`"
#RESULT_FILENAME=$(echo "`basename $i`" | sed "s/\.moon/\.lua/g")
#cd "`dirname $i`"
#moonc -t $DEST "`basename $i`" && echo "=> $DEST/$RESULT_FILENAME (`date`)"
#if [ $? != 0 ]; then tput bel; fi # beep when compile failed
#fi
#done