-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·109 lines (84 loc) · 2.68 KB
/
build.sh
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# Constants ############################################################################################################
read -d USAGE <<-END
USAGE: $0 <clean|compile|help|watch> (--view)
END
FSWATCH="fswatch"
LILYPOND_APP="/Applications/LilyPond.app"
LILYPOND="$LILYPOND_APP/Contents/Resources/bin/lilypond"
# Helper Functions #####################################################################################################
function cancel {
echo "$USAGE"; echo; echo $@
exit 1
}
function check-dependencies {
if ! which -s "$FSWATCH"; then
echo "Could not find \"fswatch\"! Try installing using: brew install fswatch"
echo
exit 1
fi
if [[ ! -d "$LILYPOND_APP" ]]; then
echo "Could not find LilyPond! Please install it from http://lilypond.org/download.html."
echo
exit 1
fi
}
function compile-ly {
BASE_NAME=$(basename -s .ly $1)
DIR_NAME=$(dirname $1 | sed "s@./src/scores/@@")
mkdir -p "dist/$DIR_NAME"
$LILYPOND -I "$PWD/src/includes" -I "$PWD/src/pieces" -o "dist/$DIR_NAME/$BASE_NAME" $1
if [[ "$VIEW" == "YES" ]]; then
open -a "/Applications/Safari.app" -g "dist/$DIR_NAME/$BASE_NAME.pdf"
fi
}
function usage {
echo "$USAGE"
exit 0
}
# Command Functions ####################################################################################################
function command-clean {
rm -rf dist 2>/dev/null
}
function command-compile {
[[ ${#PATTERNS[*]} == 0 ]] && PATTERNS=(".*")
while true; do
PATTERN=${PATTERNS[0]}
[[ "$PATTERN" == "" ]] && break
PATTERNS=(${PATTERNS[@]:1})
find src/scores -name "*.ly" | grep -v includes | grep "\.ly$" | grep "$PATTERN" | while read FILE; do
compile-ly "./$FILE"
done
done
}
function command-watch {
CURRENT_DIR=$(dirname $0)
$FSWATCH -r src/scores | egrep '\.ly$' --line-buffered | grep -v 'includes' --line-buffered | while read FILE; do
FILE=$(echo $FILE | sed 's@.*/src/scores/\(.*\)$@./src/scores/\1@')
compile-ly $FILE
done
}
# Initialization #######################################################################################################
check-dependencies
COMMAND="$1"
shift
[[ "$COMMAND" == "" ]] && COMMAND="help"
PATTERNS=()
HELP="NO"
VIEW="NO"
while [[ "$1" != "" ]]; do
case "$1" in
-h|-?|--help) HELP="YES";;
-v|--view) VIEW="YES";;
*) PATTERNS+=($1);;
esac
shift
done
[[ "$HELP" == "YES" ]] && usage
case "$COMMAND" in
clean) command-clean;;
compile) command-compile;;
help|-h|-?|--help) usage;;
watch) command-watch;;
*) cancel "Unrecognized command: $COMMAND"
esac