forked from openstax/webview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.coffee
352 lines (313 loc) · 9 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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
module.exports = (grunt) ->
fs = require('fs')
pkg = require('./package.json')
alohaBuildConfig = grunt.file.read('bower_components/aloha-editor/build/aloha/build-profile-with-oer.js')
alohaBuildConfig = eval(alohaBuildConfig)
alohaBuildConfig.appDir = 'bower_components/aloha-editor/src/'
alohaBuildConfig.baseUrl = 'lib/'
alohaBuildConfig.dir = 'bower_components/aloha-editor/target/build-profile-with-oer/rjs-output'
alohaBuildConfig.mainConfigFile = 'bower_components/aloha-editor/build/aloha/build-profile-with-oer.js'
alohaBuildConfig.wrap =
startFile: 'bower_components/aloha-editor/build/aloha/closure-start.frag'
endFile: 'bower_components/aloha-editor/build/aloha/closure-end.frag'
alohaBuildConfig.skipDirOptimize = true
alohaBuildConfig.optimize = "uglify2"
alohaBuildConfig.optimizeCss = "standard"
alohaBuildConfig.separateCSS = false
alohaBuildConfig.preserveLicenseComments = false
# Project configuration.
grunt.initConfig
pkg: pkg
# Development nginx server
# ----
# Start with `grunt nginx:start`
nginx:
tasks: ['nginx']
options:
config: 'nginx.development.conf'
prefix: './'
# Lint
# ----
# JSHint
jshint:
options:
globals:
require: true
define: true
# test globals
beforeEach: true
describe: true
it: true
chai: true
sinon: true
# Enforcing options
camelcase: true
curly: true
eqeqeq: true
forin: true
immed: true
indent: 2
latedef: true
newcap: true
noarg: true
noempty: true
nonew: true
plusplus: false
quotmark: 'single'
undef: true
unused: true
strict: true
trailing: true
maxparams: 3
maxlen: 120
maxcomplexity: 10
# Relaxing options
asi: false
boss: false
debug: false
eqnull: false
evil: false
expr: true
funcscope: false
globalstrict: false
iterator: false
lastsemic: false
laxbreak: false
laxcomma: false
loopfunc: false
multistr: false
proto: false
scripturl: false
smarttabs: false
shadow: false
sub: false
supernew: false
validthis: false
# Environments
browser: true
devel: false
source: ['src/**/*.js', 'test/**/*.js']
# JS Beautifier
jsbeautifier:
files: ['src/**/*.js', 'test/**/*.js']
options:
mode: "VERIFY_ONLY"
js:
spaceAfterAnonFunction: true
wrapLineLength: 130
indentSize: 2
# CoffeeLint
coffeelint:
options:
arrow_spacing:
level: 'error'
line_endings:
level: 'error'
value: 'unix'
max_line_length:
level: 'error'
value: 120
source: ['src/**/*.coffee', 'test/**/*.coffee']
grunt: 'Gruntfile.coffee'
# Dist
# ----
# Requirejs Optimizer
requirejs:
compile:
options:
appDir: 'src'
baseUrl: 'scripts'
dir: 'dist'
mainConfigFile: 'src/scripts/config.js'
waitSeconds: 360 # Jenkins takes a while to build (when running multiple jobs)
findNestedDependencies: true
removeCombined: false
keepBuildDir: false
preserveLicenseComments: false
skipDirOptimize: true
generateSourceMaps: true
optimize: 'none'
stubModules: ['cs']
modules: [{
name: 'main'
include: [
'cs!pages/error/error'
'cs!pages/home/home'
'cs!pages/contents/contents'
'cs!pages/search/search'
'cs!pages/browse-content/browse-content'
'cs!pages/workspace/workspace'
'cs!pages/about/about'
'cs!pages/tos/tos'
'cs!pages/license/license'
'cs!pages/donate/donate'
'cs!pages/role-acceptance/role-acceptance'
# FIX: edit modules should be loaded in separate modules
'select2'
'bootstrapPopover'
'cs!modules/media/editbar/editbar'
'cs!helpers/backbone/views/editable'
'cs!configs/aloha'
]
exclude: ['coffee-script', 'less/normalize']
excludeShallow: ['settings']
}]
done: (done, output) ->
duplicates = require('rjs-build-analysis').duplicates(output)
if duplicates.length > 0
grunt.log.subhead('Duplicates found in requirejs build:')
grunt.log.warn(duplicates)
done(new Error('r.js built duplicate modules, please check the excludes option.'))
done()
aloha:
options: alohaBuildConfig
# Target HTML
targethtml:
dist:
files:
'dist/index.html': 'dist/index.html'
# Copy
copy:
require:
src: 'bower_components/requirejs/require.js'
dest: 'dist/scripts/require.js'
aloha:
src: 'bower_components/aloha-editor/target/build-profile-with-oer/rjs-output/lib/aloha.js'
dest: 'dist/scripts/aloha.js'
fonts:
expand: true
filter: 'isFile'
flatten: true
src: ['bower_components/font-awesome/fonts/**']
dest: 'dist/fonts/'
# Clean
clean:
files:
src: [
'dist/**/.*'
'dist/build.txt'
'dist/scripts/**/*'
'dist/styles/**/*.less'
'!dist/scripts/l20n.js'
'!dist/scripts/Template.js'
'!dist/scripts/browser.js'
'!dist/scripts/main.js'
'!dist/scripts/main.js.map'
'!dist/scripts/require.js'
'!dist/scripts/settings.js'
'!dist/scripts/aloha.js'
]
filter: 'isFile'
directories:
src: [
'dist/styles'
'dist/**/*'
]
filter: (filepath) ->
# Ignore files
if not grunt.file.isDir(filepath) then return false
# Remove /dist/test, and all directories inside /dist/scripts
if filepath.match(/^dist\/(scripts\/|test)/) then return true
# Remove empty directories
return fs.readdirSync(filepath).length is 0
# Uglify
uglify:
dist:
options:
sourceMap: true
sourceMapIncludeSources: true
sourceMapIn: 'dist/scripts/main.js.map'
files:
'dist/scripts/main.js': ['dist/scripts/main.js']
'dist/scripts/require.js': ['dist/scripts/require.js']
# HTML min
htmlmin:
dist:
options:
removeComments: true
collapseWhitespace: true
files:
'dist/index.html': 'dist/index.html'
'dist/maintenance.html': 'dist/maintenance.html'
# Imagemin
imagemin:
images:
options:
cache: false
optimizationLevel: 7
files: [{
expand: true
cwd: 'dist/images/'
src: ['**/*.{png,jpg,gif}']
dest: 'dist/images/'
}]
# String Replace (HACK to update aloha path)
'string-replace':
dist:
options:
replacements: [{
pattern: '../../bower_components/aloha-editor/target/build-profile-with-oer/rjs-output/lib/aloha'
replacement: 'aloha'
}]
files:
'dist/scripts/main.js': ['dist/scripts/main.js']
test:
options:
template: 'test/index.template.html'
runner: 'test/index.html'
files: 'test/**/*.js'
# Mocha for testing
mocha:
browser: ['test/index.html']
options:
reporter: 'Spec'
run: false
log: false
timeout: 15000
# Dependencies
# ============
for name of pkg.dependencies when name.substring(0, 6) is 'grunt-'
grunt.loadNpmTasks(name)
for name of pkg.devDependencies when name.substring(0, 6) is 'grunt-'
if grunt.file.exists("./node_modules/#{name}")
grunt.loadNpmTasks(name)
# Tasks
# =====
# Test
# -----
grunt.registerTask 'test', 'Run JS Unit tests', () ->
options = @options()
tests = grunt.file.expand(options.files).map((file) -> "../#{file}")
# build the template
template = grunt.file.read(options.template).replace('{{ tests }}', JSON.stringify(tests))
# write template to tests directory and run tests
grunt.file.write(options.runner, template)
grunt.task.run('jshint', 'jsbeautifier', 'coffeelint', 'mocha')
# Aloha
# -----
grunt.registerTask 'aloha', [
'requirejs:aloha'
]
# Dist
# -----
grunt.registerTask 'dist', [
'requirejs:compile'
'copy'
'string-replace'
'targethtml:dist'
'clean'
'uglify:dist'
'htmlmin:dist'
'imagemin'
]
# Default
# -----
grunt.registerTask 'default', [
'requirejs:compile'
'copy'
'targethtml:dist'
'clean'
'uglify:dist'
'htmlmin:dist'
'imagemin'
]