-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
385 lines (364 loc) · 10.2 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
module.exports = function(grunt) {
var concat_target = grunt.option('offline') ? 'offline' : 'all';
var modRewrite = require('connect-modrewrite');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
/**
* The `banner` is the comment that is placed at the top of our compiled
* source files.
*/
banner: '/*! \n* <%= pkg.title || pkg.name %> - v<%= pkg.version %>' +
'\n* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %> ' +
'\n* <%= pkg.homepage ? pkg.homepage : "" %> ' +
'\n*/ \n\n',
/**
* `vendor_files` contains patterns that reference vendor code (`vendor/`)
* that we need to place into the build process. We do this manually as we
* often do not want to include all vendor provided functionality.
*
* The `vendor_files.js` property holds references to vendor scripts to be
* added to our pages just before the </body> tag. This also merges together
* with our project app source.
*
* The `vendor_files.test_js` property holds references to vendor scripts
* required for running our Karma unit tests.
*
* By default Angular scripts are loaded from the Google CDN and referenced
* in our index.html. However, if yo uwant to develop offline you can add
* the command line open `--offline` which will load the vendor files listed
* in `vendor_files.offline_js`.
*
* The `vendor_files.assets` property holds any assets to be copied along
* with our app's assets. This structure is flattened, so it is not
* recommended that you use wildcards.
*
* Any vendor SCSS to be compiled is defined in `src/scss/styles.scss`.
*/
vendor_files: {
js: [],
test_js: [
'vendor/angular-mocks/angular-mocks.js'
],
offline_js: [
'vendor/angular/angular.js',
'vendor/angular-resource/angular-resource.js',
'vendor/angular-route/angular-route.js',
],
assets: []
},
/**
* These settings make it easier to reference specific file structures of
* our app.
*/
app_files: {
js: [
'default.config.js',
'config.js',
'src/app/**/*.js',
'tmp/templates.js',
'!src/app/**/*.spec.js'
],
templates: [
'src/app/components/**/*.html',
'src/app/common/**/*.html'
],
},
/**
* Empty our dist and tmp directories when `grunt clean` is executed.
*/
clean: {
dist: ['dist'],
tmp: ['tmp']
},
/**
* The `copy` task just copies files from A to B. We use it here to copy
* our project assets (images, fonts), root HTML files (i.e. index.html)
* and template HTML files.
*/
copy: {
app_assets: {
files: [
{
src: ['**'],
dest: 'dist/assets/',
cwd: 'src/assets',
expand: true
}
]
},
vendor_assets: {
files: [
{
src: ['<%= vendor_files.assets %>'],
dest: 'dist/assets/',
cwd: '.',
expand: true,
flatten: true
}
]
},
html: {
files: [
{
src: ['*.html'],
dest: 'dist/',
cwd: 'src/app',
expand: true,
}
]
},
templates: {
files: [
{
src: ['<%= app_files.templates %>'],
dest: 'tmp/',
expand: true,
flatten: true,
}
]
},
},
/**
* We use compass to compile our SCSS files. The `development` environment
* helps us debug our style whilst `production` minifies the compiled file.
* Any images that are generated via Compass (e.g. sprites) are output to
* `src/assets`.
*/
compass: {
dev: {
options: {
require: ['susy', 'breakpoint'],
environment: 'development',
sassDir: 'src/scss',
cssDir: 'dist/css',
imagesDir: 'src/scss/sprites',
generatedImagesDir: 'src/assets',
httpGeneratedImagesPath: '../assets',
fontsDir: 'src/assets/fonts',
httpFontsDir: '../assets/fonts',
}
},
prod: {
options: {
require: ['susy', 'breakpoint'],
environment: 'production',
sassDir: 'src/scss',
cssDir: 'dist/css',
imagesDir: 'src/scss/sprites',
generatedImagesDir: 'src/assets',
httpGeneratedImagesPath: '../assets',
fontsDir: 'src/assets/fonts',
httpFontsDir: '../assets/fonts',
}
},
},
/**
* `jshint` defines the rules of our linter as well as which files we
* should check.
*/
jshint: {
all: {
files: {
src: ['<%= app_files.js %>']
},
options: {
curly: true,
immed: true,
newcap: true,
noarg: true,
sub: true,
boss: true,
eqnull: true,
strict: false,
globalstrict: true,
globals: {
angular: false
},
},
}
},
/**
* Our Karma configuration.
*/
karma: {
options: {
files: [
'<%= vendor_files.js %>',
'<%= vendor_files.offline_js %>',
'<%= vendor_files.test_js %>',
'default.config.js',
'config.js',
'src/app/**/*.js',
],
browsers: ['PhantomJS'],
frameworks: ['jasmine'],
},
dev: {
reporters: 'dots',
background: true,
},
continuous: {
singleRun: true,
},
},
/**
* Combines and minifies our apps HTML templates into a single JS file to be
* added to our AngularJS `$templateCache`.
*/
ngtemplates: {
dmeApp: {
cwd: 'tmp',
src: '*.html',
dest: 'tmp/templates.js',
options: {
htmlmin: {
collapseWhitespace: true,
collapseBooleanAttributes: true
}
}
}
},
/**
* This concatenates all of our JS source files into a single file.
* When the --offline command line parameter is present, the `offline`
* target is used instead.
*/
concat: {
options: {
banner: '<%= banner %>'
},
all: {
src: [
'<%= vendor_files.js %>',
'module.prefix',
'<%= app_files.js %>',
'module.suffix'
],
dest: 'dist/js/dmeapp.js'
},
offline: {
src: [
'<%= vendor_files.js %>',
'<%= vendor_files.offline_js %>',
'module.prefix',
'<%= app_files.js %>',
'module.suffix'
],
dest: 'dist/js/dmeapp.js'
}
},
/**
* When the command line parameter --offline is present, we set the
* OFFLINE variable to true. We then preprocess our index.html file
* which can conditionally load external script files.
*/
preprocess: {
options: {
inline: true,
context: {
OFFLINE: grunt.option('offline') || false,
VERSION: 'v<%= pkg.version %>',
}
},
all: {
src: [
'dist/index.html',
],
},
},
/**
* Minify our concatenated JS file.
*/
uglify: {
compile: {
options: {
banner: '<%= banner %>'
},
files: {
'<%= concat.all.dest %>': '<%= concat.all.dest %>'
}
}
},
/**
* We use `connect` to host a local server. We add a custom middleware to
* rewrite any path that does not contain a '.' (period) to /index.html.
*/
connect: {
livereload: {
options: {
port: 9000,
hostname: 'localhost',
base: ['dist/'],
livereload: true,
middleware: function(connect, options) {
var middlewares = [];
middlewares.push(modRewrite(['^[^\\.]*$ /index.html [L]']));
options.base.forEach(function(base) {
middlewares.push(connect.static(base));
});
return middlewares;
}
}
}
},
/**
* Watch for changes in style or script files and re-compile as necessary.
*/
watch: {
options: {
livereload: true
},
compass: {
files: ['src/**/*.{scss,sass}'],
tasks: ['compass:dev']
},
js: {
files: ['<%= app_files.js %>'],
tasks: ['jshint', 'copy:templates', 'ngtemplates', 'concat:' + concat_target, 'clean:tmp']
},
html: {
files: ['src/app/*.html'],
tasks: ['copy:html', 'preprocess']
},
templates: {
files: ['<%= app_files.templates %>'],
tasks: ['copy:templates', 'ngtemplates', 'concat:' + concat_target, 'clean:tmp']
},
tests: {
files: ['src/app/**/*.js'],
tasks: ['karma:dev:run'],
}
},
});
/**
* Load our grunt plugins.
*/
grunt.loadNpmTasks('grunt-angular-templates');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-preprocess');
/**
* Default tasks.
*/
grunt.registerTask('default', ['clean', 'jshint', 'karma:dev', 'compass:dev', 'copy', 'ngtemplates', 'concat:' + concat_target, 'clean:tmp', 'preprocess', 'watch']);
/**
* Production tasks. Same as `default` except we minify JS and SCSS files.
*/
grunt.registerTask('prod', ['clean', 'jshint', 'karma:continuous', 'compass:prod', 'copy', 'ngtemplates', 'concat:all', 'clean:tmp', 'preprocess', 'uglify']);
/**
* Running `grunt server` runs our connect server until cancelled.
*/
grunt.registerTask('server', ['connect:livereload:keepalive']);
/**
* Running `grunt test` will run just the Karma unit tests.
*/
grunt.registerTask('test', ['karma:continuous']);
};