-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
422 lines (382 loc) · 12.7 KB
/
Gruntfile.js
File metadata and controls
422 lines (382 loc) · 12.7 KB
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
"use strict";
module.exports = function(grunt) {
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Automatically load required Grunt tasks
require('jit-grunt')(grunt, {
ngtemplates: 'grunt-angular-templates',
htmllint: 'grunt-html'
});
// Configurable paths for the application
var appConfig = {
app: 'public',
dist: 'dist'
};
grunt.initConfig({
// Project settings
tprint: appConfig,
pkg: grunt.file.readJSON('package.json'),
// Watch modified files and launch associates tasks
watch: {
jsTest: {
files: ['test/**/*.test.js'],
tasks: ['newer:jshint:test', 'newer:jscs:test', 'karma']
},
js: {
options: {
livereload: true
},
files: ['server/**', 'Gruntfile.js', 'public/**/*.js'],
tasks: ['newer:jshint', 'newer:jscs:all', 'karma', 'build_dev']
},
html: {
options: {
livereload: true
},
files: ['public/**/*.html', 'public/index.html'],
tasks: ['newer:bootlint', 'newer:htmllint', 'build_dev']
},
css: {
options: {
livereload: true
},
files: ['public/styles/**/*.css', 'public/styles/*.css'],
tasks: ['newer:csslint:lax', 'build']
}
},
// Execute TU
karma: {
unit: {
configFile: 'karma.conf.js',
background: true,
singleRun: false
}
},
// The following *-min tasks will produce minified files in the dist folder
// 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.
// minify css from tmp to dist
cssmin: {
dist: {
files: {
'<%= tprint.dist %>/styles/main.css': [
'.tmp/styles/{,*/}*.css'
]
}
}
},
// uglify JS and html JS to tmp to dist
uglify: {
dist: {
files: {
'<%= tprint.dist %>/js/app.js': [
'.tmp/js/app.js'
],
'<%= tprint.dist %>/js/views.js': [
'.tmp/views/templateCache.js'
]
}
}
},
// Concat JS files public to dist
concat: {
dist: {
src: ['<%= tprint.app %>/js/**/*.js'],
dest: '<%= tprint.dist %>/js/app.js',
}
},
// Concat css files public to tmp
concat_css: {
options: {
// Task-specific options go here.
},
all: {
src: ['<%= tprint.app %>/**/*.css', '<%= tprint.app %>/*.css'],
dest: '.tmp/styles.css'
},
},
// minify images from public to dist
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= tprint.app %>/images',
src: '{,*/}*.{png,jpg,jpeg,gif}',
dest: '<%= tprint.dist %>/images'
}]
}
},
// minify svg from public to dist
svgmin: {
dist: {
files: [{
expand: true,
cwd: '<%= tprint.app %>/images',
src: '{,*/}*.svg',
dest: '<%= tprint.dist %>/images'
}]
}
},
// minify index.html from public to dist
htmlmin: {
dist: {
options: {
collapseWhitespace: true,
conservativeCollapse: true,
collapseBooleanAttributes: true,
removeCommentsFromCDATA: true
},
files: [{
expand: true,
cwd: '<%= tprint.app %>',
src: ['*.html'],
dest: '<%= tprint.dist %>'
}]
}
},
// Copies remaining files to places other tasks can use
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= tprint.app %>',
dest: '<%= tprint.dist %>',
src: [
'*.{ico,png,txt,json}',
'*.html',
'images/{,*/}*.{webp}',
'styles/fonts/{,*/}*.*'
]
}, {
expand: true,
cwd: '.tmp/images',
dest: '<%= tprint.dist %>/images',
src: ['generated/*']
}, {
expand: true,
cwd: 'bower_components/bootstrap/dist',
src: 'fonts/*',
dest: '<%= tprint.dist %>'
}]
},
styles: {
expand: true,
cwd: '<%= tprint.app %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
}
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [
'<%= tprint.dist %>/{,*/}*',
'!<%= tprint.dist %>/.git{,*/}*',
'!<%= tprint.dist %>/bower_components{,*/}*'
]
}]
},
server: '.tmp'
},
// run local server
express: {
all: {
options: {
server: 'server.js',
hostname: 'localhost',
bases: ['<%= tprint.dist %>'],
livereload: true
}
}
},
// Add vendor prefixed styles
postcss: {
options: {
processors: [
require('autoprefixer')({
browsers: ['last 1 version']
})
]
},
server: {
options: {
map: true
},
files: [{
expand: true,
cwd: '.tmp/styles/',
src: '{,*/}*.css',
dest: '.tmp/styles/'
}]
},
dist: {
files: [{
expand: true,
cwd: '.tmp/styles/',
src: '{,*/}*.css',
dest: '.tmp/styles/'
}]
}
},
// Analyse JS style
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: ['Gruntfile.js', '<%= tprint.app %>/scripts/**/*.js', 'server.js', 'server/**/*.js'],
test: ['<%= tprint.app %>/{,*/}*.test.js'],
},
// Analyse HTML style
htmllint: {
options: {
force: true,
ignore: [/Attribute “ng-[a-z-]+” not allowed on element “[a-z-]+” at this point./,
/Attribute “.*chart” not allowed on element “[a-z-]+” at this point./,
'Element “marquee” not allowed as child of element “div” in this context. (Suppressing further errors from this subtree.)',
/Element “head” is missing a required instance of child element “title”./,
/Bad value “{{.*}}” for attribute “.*” on element “.*”: Illegal character in path segment: “{” is not allowed./
]
},
src: ['<%= tprint.app %>/views/*.html']
},
//Format JS files
jsbeautifier: {
default: {
src: ['Gruntfile.js', 'server.js', 'server/**/*.js', '<%= tprint.app %>/**/*.js', '<%= tprint.app %>/**/*.html'],
files: ['<%= tprint.app %>/bower_components/**/*.js', '<%= tprint.app %>/bower_components/*.js', '<%= tprint.app %>/angular/**/*.js', '<%= tprint.app %>/angular/*.js']
},
js: {
src: ['Gruntfile.js', 'server.js', 'server/**/*.js', '<%= tprint.app %>/js/**/*.js'],
files: ['<%= tprint.app %>/bower_components/**/*.js', '<%= tprint.app %>/bower_components/*.js', '<%= tprint.app %>/angular/**/*.js', '<%= tprint.app %>/angular/*.js']
},
html: {
src: ['<%= tprint.app %>/views/**/*.html'],
files: ['<%= tprint.app %>/bower_components/**/*.js', '<%= tprint.app %>/bower_components/*.js', '<%= tprint.app %>/angular/**/*.js', '<%= tprint.app %>/angular/*.js']
},
css: {
src: ['<%= tprint.app %>/styles/**/*.css']
},
gitprecommit: {
src: ['<%= tprint.app %>/scripts/**/*.js'],
files: ['<%= tprint.app %>/bower_components/**/*.js', '<%= tprint.app %>/bower_components/*.js', '<%= tprint.app %>/angular/**/*.js', '<%= tprint.app %>/angular/*.js'],
options: {
mode: 'VERIFY_ONLY'
}
}
},
// Analyse css style
csslint: {
strict: {
options: {
import: 2
},
src: ['<%= tprint.app %>/styles/**/*.css']
},
lax: {
options: {
import: false
},
src: ['<%= tprint.app %>/styles/**/*.css']
}
},
// Run some tasks in parallel to speed up the build process
concurrent: {
server: [
'copy:styles'
],
test: [
'copy:styles'
],
dist: [
'jsbeautifier:default',
'copy:styles',
'newer:imagemin'
]
},
// Analyse bootstrap style
bootlint: {
options: {
stoponerror: false,
relaxerror: []
},
files: ['<%= tprint.app %>/index.html']
},
ngAnnotate: {
options: {
singleQuotes: true,
},
dist: {
files: {
'.tmp/js/app.js': ['<%= tprint.app %>/js/**/*.js']
}
}
},
// Make sure code styles are up to par
jscs: {
options: {
config: '.jscsrc'
},
all: {
src: [
'<%= tprint.app %>/js/{,*/}*.js'
]
},
test: {
src: ['test/spec/{,*/}*.js']
}
},
//convert HTML files to JS
ngtemplates: {
dist: {
options: {
module: 'myApp',
htmlmin: '<%= htmlmin.dist.options %>'
},
cwd: '<%= tprint.app %>',
src: 'views/{,*/}*.html',
dest: '.tmp/views/templateCache.js'
}
},
});
// default grunt task
grunt.registerTask('default', ['build', 'express', 'karma', 'watch']);
// beautify all Code
grunt.registerTask('beautify', ['jsbeautifier:default']);
// beautify js files
grunt.registerTask('js', ['express', 'jsbeautifier:js', 'watch:js']);
// beautify css files
grunt.registerTask('css', ['express', 'jsbeautifier:css', 'watch:css']);
// beautify html files
grunt.registerTask('html', ['express', 'jsbeautifier:html', 'watch:html']);
grunt.registerTask('test', ['karma']);
// tasks apply only on updated files
grunt.registerTask('build_dev', [
'newer:concurrent:dist',
'newer:copy:dist',
'newer:ngAnnotate',
'concat_css',
'newer:postcss:dist',
'newer:cssmin',
'ngtemplates',
'newer:uglify',
'newer:htmlmin'
]);
// tasks apply on all files
grunt.registerTask('build', [
'clean:dist',
'concurrent:dist',
'copy:dist',
'ngAnnotate',
'concat_css',
'postcss:dist',
'cssmin',
'ngtemplates',
'uglify',
'htmlmin'
]);
};