forked from este/este
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.coffee
306 lines (263 loc) · 7.32 KB
/
Gruntfile.coffee
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
module.exports = (grunt) ->
stylusStyles = [
'bower_components/este-library/este/**/*.styl'
'client/app/css/**/*.styl'
]
coffeeScripts = [
'bower_components/este-library/este/**/*.coffee'
'client/app/js/**/*.coffee'
'server/**/*.coffee'
]
soyTemplates = [
'bower_components/este-library/este/**/*.soy'
'client/app/js/**/*.soy'
]
clientDirs = [
'bower_components/closure-library'
'bower_components/closure-templates'
'bower_components/este-library/este'
'client/app/js'
]
clientDepsPath =
'client/deps.js'
clientDepsPrefix =
'../../../../'
grunt.initConfig
# build tasks
clean:
app:
options:
force: true
src: [
'bower_components/este-library/este/**/*.{js,css}'
'client/**/build/**.*'
'client/**/{js,css}/**/*.{js,css}'
'server/**/*.js'
]
stylus:
options:
'include css': true
'compress': false
all:
files: [
expand: true
src: stylusStyles
ext: '.css'
]
app:
files: [
expand: true
src: 'client/app/css/app.styl'
ext: '.css'
]
coffee:
options:
bare: true
app:
files: [
expand: true
src: coffeeScripts
ext: '.js'
]
coffee2closure:
app:
files: [
expand: true
src: coffeeScripts
ext: '.js'
]
esteTemplates:
app:
src: soyTemplates
esteDeps:
all:
options:
outputFile: clientDepsPath
prefix: clientDepsPrefix
root: clientDirs
esteUnitTests:
options:
depsPath: clientDepsPath
prefix: clientDepsPrefix
app:
src: [
'bower_components/este-library/este/**/*_test.js'
'client/**/*_test.js'
]
# build --stage tasks
cssmin:
app:
files:
'client/app/build/app.css': 'client/app/css/app.css'
esteBuilder:
options:
root: clientDirs
depsPath: clientDepsPath
# Enable faster compilation for Windows with Java 1.7+.
# javaFlags: ['-XX:+TieredCompilation']
compilerFlags: do ->
# Default compiler settings. You will love advanced compilation with
# verbose warning level.
flags = [
'--output_wrapper=(function(){%output%})();'
'--compilation_level=ADVANCED_OPTIMIZATIONS'
'--warning_level=VERBOSE'
# experimental stuff
# '--use_types_for_optimization'
]
# Remove some code workarounds for ancient browsers.
# IE<8 and very old Gecko and Webkit.
flags = flags.concat [
'--define=goog.net.XmlHttp.ASSUME_NATIVE_XHR=true'
'--define=este.json.SUPPORTS_NATIVE_JSON=true'
'--define=goog.style.GET_BOUNDING_CLIENT_RECT_ALWAYS_EXISTS=true'
]
# Enable debug compiled mode for --stage=debug.
if grunt.option('stage') == 'debug'
flags = flags.concat [
'--debug=true'
'--formatting=PRETTY_PRINT'
'--define=goog.DEBUG=true'
]
else
flags = flags.concat [
'--define=goog.DEBUG=false'
]
# Compiler Externs. They allow us to use thirdparty code without []
# syntax.
flags.concat [
'--externs=bower_components/este-library/externs/react.js'
]
app:
options:
namespace: 'app.start'
outputFilePath: 'client/app/build/app.js'
# Use this task to build specific language, /client/build/app_de.js etc.
# appLocalized:
# options:
# namespace: 'app.start'
# outputFilePath: 'client/app/build/app.js'
# messagesPath: 'messages/app'
# locales: ['cs', 'de']
# run tasks
replace:
esteLibraryVersion:
src: 'server/app/views/index.jade'
overwrite: true
replacements: [
from: /\(v.+\)/g
to: ->
version = require('./bower_components/este-library/bower.json').version
"(v#{version})"
]
env:
development:
NODE_ENV: 'development'
stage:
NODE_ENV: 'stage'
production:
NODE_ENV: 'production'
bgShell:
app:
cmd: 'node server/app'
bg: true
esteWatch:
options:
dirs: [
'bower_components/closure-library/**/'
'bower_components/este-library/este/**/'
'client/**/{js,css}/**/'
'server/**/'
]
coffee: (filepath) ->
files = [
expand: true
src: filepath
ext: '.js'
];
grunt.config ['coffee', 'app', 'files'], files
grunt.config ['coffee2closure', 'app', 'files'], files
['coffee:app', 'coffee2closure:app']
soy: (filepath) ->
grunt.config ['esteTemplates', 'app'], filepath
['esteTemplates:app']
js: (filepath) ->
grunt.config ['esteDeps', 'all', 'src'], filepath
grunt.config ['esteUnitTests', 'app', 'src'], filepath
tasks = ['esteDeps:all', 'esteUnitTests:app']
if grunt.option 'stage'
tasks.push 'esteBuilder:app'
tasks
styl: (filepath) ->
grunt.config ['stylus', 'all', 'files'], [
expand: true
src: filepath
ext: '.css'
]
['stylus:all', 'stylus:app']
css: (filepath) ->
if grunt.option('stage')
return 'cssmin:app'
# other tasks
esteExtractMessages:
app:
options:
root: [
'bower_components/este-library/este'
'client/app/js'
]
messagesPath: 'messages/app'
languages: ['en', 'cs']
release:
options:
bump: true
add: true
commit: true
tag: true
push: true
pushTags: true
npm: false
'npm-contributors':
options:
file: 'package.json'
commit: false
commitMessage: 'Update contributors'
grunt.loadNpmTasks 'grunt-bg-shell'
grunt.loadNpmTasks 'grunt-contrib-clean'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-cssmin'
grunt.loadNpmTasks 'grunt-contrib-stylus'
grunt.loadNpmTasks 'grunt-env'
grunt.loadNpmTasks 'grunt-este'
grunt.loadNpmTasks 'grunt-este-watch'
grunt.loadNpmTasks 'grunt-npm'
grunt.loadNpmTasks 'grunt-release'
grunt.loadNpmTasks 'grunt-text-replace'
grunt.registerTask 'build', 'Build app.', (app = 'app') ->
tasks = [
"clean:#{app}"
"stylus:all"
"coffee:#{app}"
"coffee2closure:#{app}"
"esteTemplates:#{app}"
"esteDeps"
"esteUnitTests:#{app}"
]
if grunt.option 'stage'
tasks = tasks.concat [
"cssmin:#{app}"
"esteBuilder:#{app}"
]
grunt.task.run tasks
grunt.registerTask 'run', 'Run stack.', (app = 'app') ->
grunt.task.run [
"replace:esteLibraryVersion"
if grunt.option 'stage' then 'env:stage' else 'env:development'
"bgShell:#{app}"
"esteWatch"
]
grunt.registerTask 'default', 'Build app and run stack.', (app = 'app') ->
grunt.task.run [
"build:#{app}"
"run:#{app}"
]