forked from chaplinjs/chaplin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.coffee
330 lines (285 loc) · 7.14 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
module.exports = (grunt) ->
# Utilities
# =========
path = require 'path'
# Package
# =======
pkg = require './package.json'
# Modules
# =======
# TODO: Remove this as soon as uRequire releases 0.3 which will able to
# do this for us in the right order magically.
modules = [
'src/lib/support.coffee'
'src/lib/utils.coffee'
'src/lib/helpers.coffee'
'src/lib/history.coffee'
'src/lib/route.coffee'
'src/lib/router.coffee'
'src/lib/composition.coffee'
'src/lib/sync_machine.coffee'
'src/controllers/controller.coffee'
'src/models/model.coffee'
'src/models/collection.coffee'
'src/views/view.coffee'
'src/views/layout.coffee'
'src/views/collection_view.coffee'
'src/dispatcher.coffee'
'src/composer.coffee'
'src/application.coffee'
]
test_modules = [
'test/spec/application_spec.coffee'
'test/spec/model_spec.coffee'
'test/spec/collection_spec.coffee'
'test/spec/sync_machine_spec.coffee'
'test/spec/view_spec.coffee'
'test/spec/collection_view_spec.coffee'
'test/spec/layout_spec.coffee'
'test/spec/controller_spec.coffee'
# 'test/spec/dispatcher_spec.coffee'- should rewrite the specs completely
'test/spec/router_spec.coffee'
]
# Configuration
# =============
grunt.initConfig
# Package
# -------
pkg: pkg
# Clean
# -----
clean:
build: 'build'
temp: 'temp'
components: 'components'
test: ['test/temp*', 'test/coverage']
# Compilation
# -----------
coffee:
compile:
files: [
expand: true
dest: 'build/'
cwd: 'temp'
src: '*.coffee'
ext: '.js'
]
test:
files: [
expand: true
dest: 'test/'
cwd: 'test/temp'
src: '**/*.coffee'
ext: '.js'
]
options:
bare: false
# Module concatenation
# --------------------
concat:
universal:
files: [
dest: 'temp/<%= pkg.name %>.coffee'
src: modules
]
options:
banner: '''
window.Mildred = {}
'''
tests:
files: [
dest: 'test/temp/tests.coffee'
src: test_modules
]
# Lint
# ----
coffeelint:
source: 'src/**/*.coffee'
grunt: 'Gruntfile.coffee'
# Instrumentation
# ---------------
instrument:
files: [
'test/temp/mildred/*.js'
]
options:
basePath: '.'
storeCoverage:
options:
dir : '.'
json : 'coverage.json'
coverageVar : '__coverage__'
makeReport:
src: 'coverage.json'
options:
type: 'html'
dir: 'test/coverage'
# Browser dependencies
# --------------------
bower:
install:
options:
targetDir: './test/bower_components'
cleanup: true
# Test runner
# -----------
mocha:
index:
src: ['test/index.html']
# options:
# grep: 'autoAttach'
# mocha:
# grep: 'autoAttach'
# Minify
# ------
uglify:
options:
mangle: false
universal:
files:
'build/mildred.min.js': 'build/mildred.js'
# Compression
# -----------
compress:
files: [
src: 'build/mildred.min.js'
dest: 'build/mildred.min.js.gz'
]
# Watching for changes
# --------------------
watch:
coffee:
files: ['src/*.coffee']
tasks: [
'coffee:compile'
'copy:test'
'mocha'
]
test:
files: ['test/spec/*.coffee'],
tasks: [
'coffee:test'
'mocha'
]
# Events
# ======
grunt.event.on 'mocha.coverage', (coverage) ->
# This is needed so the coverage reporter will find the coverage variable.
global.__coverage__ = coverage
# Dependencies
# ============
for name of pkg.devDependencies when name.substring(0, 6) is 'grunt-'
grunt.loadNpmTasks name
# Tasks
# =====
# Prepare
# -------
grunt.registerTask 'prepare', [
'clean'
'bower'
'clean:components'
]
# Build
# -----
grunt.registerTask 'build', [
'concat:universal'
'coffee:compile'
'uglify'
]
# Lint
# ----
grunt.registerTask 'lint', 'coffeelint'
# Test
# ----
grunt.registerTask 'test', [
'concat:universal'
'coffee:compile'
'concat:tests'
'coffee:test'
'mocha'
]
# Coverage
# --------
grunt.registerTask 'cover', [
'coffee:compile'
'copy:test'
'coffee:test'
'copy:beforeInstrument'
'instrument'
'mocha'
'storeCoverage'
'copy:afterInstrument'
'makeReport'
]
# Test Watcher
# ------------
grunt.registerTask 'test-watch', [
'test'
'watch'
]
# Releasing
# ---------
grunt.registerTask 'release:git', 'Check context, commit and tag for release.', ->
prompt = require 'prompt'
prompt.start()
prompt.message = prompt.delimiter = ''
prompt.colors = false
# Command/query wrapper, turns description object for `spawn` into runner
command = (desc, message) ->
(next) ->
grunt.log.writeln message if message
grunt.util.spawn desc, (err, result, code) -> next(err)
query = (desc) ->
(next) -> grunt.util.spawn desc, (err, result, code) -> next(err, result)
# Help checking input from prompt. Returns a callback that calls the
# original callback `next` only if the input was as expected
checkInput = (expectation, next) ->
(err, input) ->
unless input and input.question is expectation
grunt.fail.warn "Aborted: Expected #{expectation}, got #{input}"
next()
steps = []
continuation = this.async()
# Check for master branch
steps.push query(cmd: 'git', args: ['rev-parse', '--abbrev-ref', 'HEAD'])
steps.push (result, next) ->
result = result.toString().trim()
if result is 'master'
next()
else
prompt.get([
description: "Current branch is #{result}, not master. 'ok' to continue, Ctrl-C to quit."
pattern: /^ok$/, required: true
],
checkInput('ok', next)
)
# List dirty files, ask for confirmation
steps.push query(cmd: 'git', args: ['status', '--porcelain'])
steps.push (result, next) ->
grunt.fail.warn "Nothing to commit." unless result.toString().length
grunt.log.writeln "The following dirty files will be committed:"
grunt.log.writeln result
prompt.get([
description: "Commit these files? 'ok' to continue, Ctrl-C to quit.",
pattern: /^ok$/, required: true
],
checkInput('ok', next)
)
# Commit
steps.push command(cmd: 'git', args: ['commit', '-a', '-m', "Release #{pkg.version}"])
# Tag
steps.push command(cmd: 'git', args: ['tag', '-a', pkg.version, '-m', "Version #{pkg.version}"])
grunt.util.async.waterfall steps, continuation
grunt.registerTask 'release', [
'check:versions',
'release:git',
'build',
]
# Default
# -------
grunt.registerTask 'default', [
'lint'
'clean'
'build'
'test'
]