/
build
executable file
·170 lines (146 loc) · 4.18 KB
/
build
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# set -x
error() {
echo " ! $*" >&2
exit 1
}
warning() {
echo " ! $*"
}
status() {
echo "-----> $*"
}
# sed -l basically makes sed replace and buffer through stdin to stdout
# so you get updates while the command runs and dont wait for the end
# e.g. npm install | indent
indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries
*) sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data
esac
}
message() {
echo " $*"
}
log() {
echo " ~ $*"
}
if [[ -d "/app" ]]; then
cd "/app"
else
error 'Error: No app found'
exit 1
fi
# default build variables
# Basic
BUILD_BOWER=0
BUILD_COMPASS=0
BUILD_GRUNT=0
BUILD_GULP=0
# Advanced
BUILD_NPM_UPDATE=0
BUILD_BOWER_PRUNE=0
BUILD_BOWER_INSTALL=1
BUILD_BOWER_UPDATE=1
status "Builders running..."
# read config
if [[ -f "./.builders" ]]; then
message 'Reading builders file'
source ./.builders
elif [[ -f "./.dokkubuild" ]]; then
warning '.dokkubuild file is deprecated, use .builders instead'
message 'Reading old builders file'
source ./.dokkubuild
fi
if [[ "$BUILD_BOWER$BUILD_COMPASS$BUILD_GULP$BUILD_GRUNT" -ne "0000" ]]; then
# internal variables
APP_DIR="/app"
PATH="$PATH:/app/vendor/node/bin"
if [[ "x$(which npm)" == "x" ]]; then
new_path="$(find / -name npm | grep -v /tmp | grep -v node_modules | tail -1 | xargs -I % sh -c "dirname %")" &&
PATH="$PATH:$new_path"
fi
PATH="$PATH:$(npm bin)"
# env rules
if [[ -f "./.profile.d/app-env.sh" ]]; then
message 'Running app-env.sh'
. ./.profile.d/app-env.sh | indent
fi
# npm
if [[ $BUILD_NPM_UPDATE -eq 1 ]]; then
message 'Updating npm packages'
npm update | indent
fi
# bower
if [[ $BUILD_BOWER -eq 1 ]]; then
if [[ -f "./bower.json" ]]; then
message 'Fetching bower components'
if [[ ! -f "./node_modules/bower/bin/bower" ]]; then
npm install bower | indent
fi
if [[ $BUILD_BOWER_PRUNE -eq 1 ]]; then
message 'Pruning cached components not specified in bower.json'
bower prune --allow-root --config.interactive=false | indent
fi
if [[ $BUILD_BOWER_INSTALL -eq 1 ]]; then
message 'Installing bower components'
bower install --allow-root --config.interactive=false | indent
fi
if [[ $BUILD_BOWER_UPDATE -eq 1 ]]; then
message 'Updating bower components'
bower update --allow-root --config.interactive=false | indent
fi
else
message 'Bower setup skipped: No bower.json file found.'
fi
fi
# compass via bundle
if [[ $BUILD_COMPASS -eq 1 ]]; then
if [[ -f "./Gemfile" ]]; then
export GEM_HOME=$APP_DIR/.gem/ruby/1.9.1
export PATH="$GEM_HOME/bin:$PATH"
(
# Install compass
message "Running Compass compile task"
if [[ -d $APP_DIR/.gem ]]; then
HOME=$APP_DIR gem update bundler --user-install --no-rdoc --no-ri 2>&1 | indent
else
HOME=$APP_DIR gem install bundler --user-install --no-rdoc --no-ri 2>&1 | indent
fi
# Run bundler
HOME=$APP_DIR bundle install 2>&1 | indent
# Run compass
HOME=$APP_DIR bundle exec compass compile | indent
)
else
message 'Compass setup skipped: No Gemfile file found.'
fi
fi
# grunt
if [[ $BUILD_GRUNT -eq 1 ]]; then
if [[ -f "./Gruntfile.js" || -f "./Gruntfile.coffee" || -f "./grunt.js" ]]; then
message 'Running Grunt build task'
if [[ ! -f "./node_modules/grunt-cli/bin/grunt" ]]; then
npm install grunt-cli | indent
fi
grunt build | indent
else
message 'Gruntfile build skipped: No Gruntfile.js/coffee file found.'
fi
fi
# gulp
if [[ $BUILD_GULP -eq 1 ]]; then
if [[ -f "./gulpfile.js" || -f "./gulpfile.coffee" ]]; then
if [[ -f "./node_modules/gulp/bin/gulp.js" ]]; then
message 'Running Gulp build task'
./node_modules/gulp/bin/gulp.js build | indent
else
warning 'Gulp build skipped: Gulp module not found.'
fi
else
message 'Gulp build skipped: No gulpfile.js/coffee file found.'
fi
fi
fi