-
Notifications
You must be signed in to change notification settings - Fork 34
/
GruntFile.js
426 lines (396 loc) · 10.1 KB
/
GruntFile.js
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/*
* grunt
* http://gruntjs.com/
*
* Copyright (c) 2013 "Cowboy" Ben Alman
* Licensed under the MIT license.
* https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
*/
// This is the default port that livereload listens on;
// change it if you configure livereload to use another port.
var LIVERELOAD_PORT = 35729;
// lrSnippet is just a function.
// It's a piece of Connect middleware that injects
// a script into the static served html.
var lrSnippet = require('connect-livereload')({
port: LIVERELOAD_PORT
});
// All the middleware necessary to serve static files.
var livereloadMiddleware = function(connect, options) {
return [
// Inject a livereloading script into static files.
lrSnippet,
// Serve static files.
connect.static(options.base[0]),
// Make empty directories browsable.
connect.directory(options.base[0])
];
};
// The first part is the "wrapper" function, which encapsulates your Grunt configuration
module.exports = function(grunt) {
'use strict';
// Load grunt tasks automatically
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
var plugins = ['karma-mocha'];
var browsers = [];
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Define the configuration for all the tasks
grunt.initConfig({
// Next we can read in the project settings from the package.json file into the pkg property. This allows us to refer to the values of properties within our package.json file.
pkg: grunt.file.readJSON('package.json'),
// Project settings
jsb: {
// Configurable paths
app: 'src',
dist: 'dist',
test: 'test'
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= jsb.dist %>/*',
'!<%= jsb.dist %>/.git*'
]
}]
},
server: '.tmp'
},
// sass: {
// dist: {
// files: {
// '<%= jsb.dist %>/css/style.min.css': '<%= jsb.app %>/css/style.scss'
// }
// }
// },
// By default, your `index.html`'s <!-- Usemin block --> will take care of
// minification. These next options are pre-configured if you do not wish
// to use the Usemin blocks.
// cssmin: {
// dist: {
// options: {
// keepSpecialComments: 0,
// report: "min",
// selectorsMergeMode: "ie8"
// },
// files: { // Dictionary of files
// '<%= jsb.dist %>/css/style.min.css': ['<%= jsb.app %>/css/style.css'],
// '<%= jsb.dist %>/demo/css/style.min.css': ['<%= jsb.app %>/demo/css/style.css']
// }
// }
// },
// uglify: {
// options: {
// // The banner is inserted at the top of the output
// banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
// },
// dist: { // Target
// files: { // Dictionary of files
// 'dist/js/<%= pkg.name %>.min.js': ['src/js/_.config.js', 'src/js/_.main.js', 'src/js/_.helper.js'],
// 'dist/demo/js/fb.friends.min.js': ['src/demo/js/fb.config.js', 'src/demo/js/fb.friends.list.js'],
// 'dist/js/libs/jquery.min.js': ['src/js/libs/jquery.js'],
// 'dist/js/libs/require.min.js': ['src/js/libs/require.js']
// }
// }
// },
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
// Define the files to lint
all: [
'Gruntfile.js',
'<%= jsb.app %>/js/*.js',
'<%= jsb.app %>/demo/js/*.js'
],
// Configure JSHint (documented at http://www.jshint.com/docs/)
options: {
// More options here if you want to override JSHint defaults
jshintrc: '.jshintrc'
}
},
// Compiles Sass to CSS and generates necessary files if requested
compass: {
options: {
sassDir: '<%= jsb.app %>/css',
cssDir: '.tmp/css',
// generatedImagesDir: '.tmp/images/generated',
// imagesDir: '<%= jsb.app %>/images',
// javascriptsDir: '<%= jsb.app %>/scripts',
// fontsDir: '<%= jsb.app %>/styles/fonts',
// importPath: '<%= jsb.app %>/bower_components',
// httpImagesPath: '/images',
// httpGeneratedImagesPath: '/images/generated',
// httpFontsPath: '/styles/fonts',
relativeAssets: false,
assetCacheBuster: false
},
dist: {
options: {
//generatedImagesDir: '<%= jsb.dist %>/images/generated'
}
},
server: {
options: {
debugInfo: true
}
}
},
// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
options: {
dest: '<%= jsb.dist %>'
},
//staging: '.tmp',
html: ['<%= jsb.app %>/index.html']
},
// Performs rewrites based on rev and the useminPrepare configuration
usemin: {
options: {
assetsDirs: ['<%= jsb.dist %>']
},
html: ['<%= jsb.dist %>/{,*/}*.html'],
css: ['<%= jsb.dist %>/css/{,*/}*.css']
},
htmlmin: {
dist: {
options: {
collapseBooleanAttributes: true,
collapseWhitespace: false,
removeAttributeQuotes: false,
removeCommentsFromCDATA: false,
removeEmptyAttributes: false,
removeOptionalTags: false,
removeRedundantAttributes: false,
useShortDoctype: false
},
files: [{
expand: true,
cwd: '<%= jsb.dist %>',
src: '{,*/}*.html',
dest: '<%= jsb.dist %>'
}]
}
},
// Compare CSS output's
compare_size: {
files: [
'<%= jsb.app %>/css/**',
'<%= jsb.dist %>/css/**'
]
},
open: {
server: {
path: 'http://localhost:9000'
}
},
connect: {
client: {
options: {
// The server's port, and the folder to serve from:
// Ex: 'localhost:9000' would serve up 'client/index.html'
port: 9000,
// change this to '0.0.0.0' to access the server from outside
hostname: 'localhost',
base: '<%= jsb.app %>',
// Custom middleware for the HTTP server:
// The injected JavaScript reloads the page.
middleware: livereloadMiddleware
}
}
},
// Watches files for changes and runs tasks based on the changed files
watch: {
js: {
files: ['<%= jsb.app %>/scripts/{,*/}*.js', 'Gruntfile.js'],
tasks: ['jshint'],
options: {
livereload: true
}
},
gruntfile: {
files: ['Gruntfile.js']
},
client: {
// '**' is used to include all subdirectories
// and subdirectories of subdirectories, and so on, recursively.
files: ['<%= jsb.app %>/**/*'],
// In our case, we don't configure any additional tasks,
// since livereload is built into the watch task,
// and since the browser refresh is handled by the snippet.
// Any other tasks to run (e.g. compile CoffeeScript) go here:
tasks: [],
options: {
livereload: LIVERELOAD_PORT
}
},
compass: {
files: ['<%= jsb.app %>/css/{,*/}*.{scss,sass}'],
tasks: ['compass:server', 'autoprefixer']
},
watch: {
files: '<%= jsb.test %>/unit/**/*.js',
tasks: ['jasmine']
}
},
notify: {
task_name: {
options: {
// Task-specific options go here.
}
},
watch: {
options: {
title: 'Task Complete', // optional
message: 'SASS and Uglify finished running' //required
}
},
server: {
options: {
message: 'Server is ready!'
}
},
connect: {
options: {
message: 'Connected to server!'
}
}
},
// shell: {
// docco: {
// command: 'docco -o jsdocumentation -l linear src/js/*.js'
// }
// },
jsdoc: {
dist: {
src: ['<%= jsb.app %>/js/_.main.js'],
options: {
destination: '<%= jsb.dist %>/doc'
}
}
},
// Removed unused css
uncss: {
dist: {
files: {
'<%= jsb.dist %>/css/style.min.css': ['<%= jsb.app %>/index.html'],
'<%= jsb.dist %>/demo/css/style.min.css': ['<%= jsb.app %>/demo/facebook_friends_list.html']
}
},
options: {
compress: true,
report: 'min'
}
},
// Copies remaining files to places other tasks can use
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= jsb.app %>',
dest: '<%= jsb.dist %>',
src: [
'*.{ico,png,txt}',
'.htaccess',
'images/{,*/}*.webp',
'{,*/}*.html'
]
}]
},
styles: {
expand: true,
dot: true,
cwd: '<%= jsb.app %>/css',
dest: '.tmp/css/',
src: '{,*/}*.css'
}
},
// Run some tasks in parallel to speed up build process
concurrent: {
server: [
'compass:server',
'copy:styles'
],
test: [
'copy:styles'
],
dist: [
'compass',
'copy:styles'
]
},
karma: {
unit: {
configFile: 'test/karma.conf.js'
}
},
jasmine: {
src: 'src/js/*.js',
options: {
specs: 'test/unit/**/*.js',
//helpers: ['src/js/_.config.js'],
keepRunner: true,
//host : 'http://127.0.0.1:8000/',
// summary: true,
vendor: [
"src/js/libs/*.js"
//"http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
]
}
// watch: {
// pivotal: {
// files: ['<%= jsb.app %>/js/*.js','<%= jsb.test %>/unit/**/*.js'],
// tasks: 'jasmine:pivotal:build'
// }
// }
},
});
//
/* Don't need to load the individual tasks anymore as we have been using
'matchdep' task in the start to load all the tasks from node_modules automatically */
// Let's set up some tasks
grunt.registerTask('server', [
'open',
'connect:client',
'watch:client',
]);
// The default task can be run just by typing "grunt" on the command line
grunt.registerTask('default', [
'clean:dist',
'useminPrepare',
'concurrent:dist',
'jshint',
'concat',
'cssmin',
//'uncss',
'uglify',
'copy:dist',
'usemin',
'htmlmin',
//'sass',
'compare_size',
'test',
'notify:server'
]);
grunt.registerTask('build-uncss', [
'default',
'uncss'
]);
// Let's generate the JavaScript documentation
grunt.registerTask('js-doc', [
'jsdoc'
]);
grunt.registerTask('test', [
'jshint',
'jasmine'
]);
// To debug the values
// grunt.event.on('watch', function(action, filepath, target) {
// grunt.log.writeln(target + ': ' + filepath + ' has ' + action);
// });
};