aboutsummaryrefslogtreecommitdiff
path: root/bin/sass
blob: 8e3fc10e854b1b3673708e140f42270f25d4d770 (plain)
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
#!/bin/sh
# Copyright (C) 2014-2016 Miquel Sabaté Solà <mikisabate@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Launch a background job that deals with SASS/SCSS.
#
# If no arguments were given, then it will try to kill a previous instance
# of the background job and launch another one. You can prevent the
# re-launching by passing the "stop" argument. This way, this script will
# efectively kill the currently running process and quit. Any other argument
# will be ignored.
#
# Therefore, the usage of this script is as follows:
#
#   $ sass [stop]
#


##
# Config values.
#
# NOTE: path values should *not* start and/or end with a slash.

# The base directory.
dir="$( cd "$( dirname "$0" )" && pwd )/.."

# The absolute path to the directory where we can store temporary files. You
# don't really want to use this default since it can easily clash with other
# projects ;)
tmp="/tmp"

# The absolute path to the file that will store the PID of the currently
# running background job.
pidfile="$tmp/assets.pid"

# The absolute path to the SASS log.
csslog="$tmp/sass.log"

# The absolute path of the directory containing the SASS files.
cssdir="$dir/public/stylesheets"


##
# And here starts the script itself.


# Get pidfile.
mkdir -p $tmp
touch $pidfile

# Kill off old processes
while read pid; do
  kill $pid > /dev/null 2>&1;
done < $pidfile

# Truncate the PID file
> $pidfile

# If the user just wanted to stop all old processes, then exit here.
if [[ $1 == "stop" ]]; then
  exit 1
fi

# SASS
sass --watch "$cssdir" > $csslog 2>&1 &
echo $! >> $pidfile