forked from MikeFielden/The-MEAN-Stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
350 lines (311 loc) · 8.82 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
module.exports = function (grunt) {
/**
* Load the required Grunt tasks. These are installed based on the version listed in
* 'package.json' file when you do 'npm install'.
*/
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-ngmin');
/**
* Load any external Grunt tasks
* Ref: http://gruntjs.com/api/grunt.task#grunt.task.loadtasks
*/
grunt.loadTasks('grunt-tasks');
/**
* Grunt's configuration object basically tells Grunt what to do
*/
grunt.initConfig({
// Read in the package.json file to get config naming items
pkg: grunt.file.readJSON('package.json'),
env: grunt.file.readJSON('environment.json'),
mindir: 'public/min',
/**
* The banner is the comment that is placed at the top of our compiled
* source files. It is first processed as a Grunt template, where the `<%=`
* pairs are evaluated based on this very configuration object.
*/
meta: {
banner:
'/**\n' +
' * <%= pkg.title || pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
' * <%= pkg.homepage %>\n' +
' *\n' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' +
' */\n'
},
/**
* This is a collection of file definitions we use in the configuration of
* build tasks.
* `js` is all project javascript, less tests, library files and min'd files
* `atpl` contains our reusable components' template HTML files
* `ctpl` contains the same, but for our app's code
* `html` is just our main HTML file
* 'sass' is out main sass file (the one that includes all other scss files)
*/
src: {
js: [ 'public/**/*.js', '!public/**/*.spec.js', '!public/min/**' ],
atpl: [ 'public/app/**/*.tpl.html' ],
ctpl: [ 'public/components/**/*.tpl.html' ],
tpljs: [ 'public/min/tmp/**/*.js' ],
itpl: [ 'public/index.tpl.html' ],
sass: ['public/sass/**/*.scss'],
unit: [ 'public/**/*.spec.js' ]
},
/**
* The directory to clean when 'grunt clean' is executed
*/
clean: [ '<%= mindir %>/*.js'],
/**
* Use ngmin to annotate the angular sources prior to minifying
*/
ngmin: {
dist: {
src: ['<%= mindir %>/<%= pkg.name %>.concat.app.js'],
dest: '<%= mindir %>/<%= pkg.name %>.annotated.js'
}
},
/**
* This task will copy the main.css file to the same folder
* but will include a version number from the package.json file
*/
copy: {
css: {
files: [{
src: [ 'public/stylesheets/main.css' ],
dest: 'public/stylesheets/main.v<%= pkg.version %>.css',
expand: false
}]
}
},
concat: {
app: {
src: [
'module.prefix',
'<%= src.js %>',
'<%= src.tpljs %>',
'module.suffix'
],
dest: '<%= mindir %>/<%= pkg.name %>.concat.app.js'
},
libs: {
src: [
'<%= env.libFiles %>',
'<%= mindir %>/<%= pkg.name %>.annotated.js'
],
dest: '<%= mindir %>/<%= pkg.name %>.concat.full.js'
}
},
/**
* This is the compass task.
* The 'dist' obj min's the scss files
* The 'dev' obj just does a regular compass compile
*/
compass: {
dist: {
options: {
basePath: 'public/',
sassDir: 'sass',
cssDir: 'stylesheets/',
environment: 'production',
raw: "preferred_syntax = :scss\n",
specify: 'public/sass/main.scss'
}
},
dev: {
options: {
basePath: 'public/',
outputStyle: 'expanded',
sassDir: 'sass',
cssDir: 'stylesheets/',
environment: 'development',
raw: "preferred_syntax = :scss\n",
specify: 'public/sass/main.scss'
}
}
},
/**
* 'jshint' defines the rules that our linter will use.
* Exclude the components directory
*/
jshint: {
src: [
'Gruntfile.js',
'<%= src.js %>',
'<%= src.unit %>',
'!public/components/**'
],
test: [
'<%= src.unit %>'
],
gruntfile: [
'Gruntfile.js'
],
options: {
curly: true,
immed: true,
newcap: true,
noarg: true,
sub: true,
boss: true,
eqnull: true
},
globals: {}
},
/**
* HTML2JS is a Grunt plugin originally written by the AngularUI Booststrap
* team and updated to Grunt 0.4 by Josh Miller. It takes all of your template files
* and places them into JavaScript files as strings that are added to
* AngularJS's template cache. This means that the templates too become part
* of the initial payload as one JavaScript file.
*/
html2js: {
/**
* These are the templates from `public/app`.
*/
app: {
src: [ '<%= src.atpl %>' ],
base: 'public/app',
dest: '<%= mindir %>/tmp'
},
/**
* These are the templates from `public/components`.
*/
component: {
src: [ '<%= src.ctpl %>' ],
base: 'public/components',
dest: '<%= mindir %>/tmp'
}
},
/**
* Minify the sources!
*/
uglify: {
options: {
banner: '<%= meta.banner %>'
},
dist: {
files: {
'<%= mindir %>/<%= pkg.name %>.min.v<%= pkg.version %>.js': [ '<%= mindir %>/<%= pkg.name %>.concat.full.js' ]
}
}
},
/**
* Jasmine unit testing
*/
jasmine: {
src: '<%= src.js %>',
options: {
specs: '<%= src.unit %>',
vendor: ['<%= env.libFiles %>', '<%= env.testingLibs %>'],
helpers: '<%= src.tpljs %>'
}
},
/**
*
*/
delta: {
/**
* By default, we want the Live Reload to work for all tasks; this is
* overridden in some tasks (like this file) where browser resources are
* unaffected. It runs by default on port 35729.
*/
options: {
livereload: false
},
/**
* When the Gruntfile changes, we just want to lint it. That said, the
* watch will have to be restarted if it should take advantage of any of
* the changes.
*/
gruntfile: {
files: 'Gruntfile.js',
tasks: [ 'jshint:gruntfile' ],
options: {
livereload: false
}
},
/**
* When our source files or unit tests change, we want to run most of our build tasks
* (excepting uglification).
*/
src: {
files: [
'<%= src.js %>',
'<%= src.unit %>'
],
tasks: [ 'jshint:src', 'concat:app', 'ngmin:dist', 'concat:libs', 'uglify', 'jasmine' ]
},
/**
* When the CSS files change, we need to compile and minify just them.
*/
sass: {
files: [ 'public/sass/**/*.scss' ],
tasks: 'compassCompile'
},
index: {
files: [ '<%= src.itpl %>' ],
tasks: [ 'index' ]
},
/**
* When our templates change, we only add them to the template cache.
*/
tpls: {
files: [
'<%= src.atpl %>',
'<%= src.ctpl %>'
],
tasks: [ 'html2js', 'concat:app', 'ngmin:dist', 'concat:libs', 'uglify' ]
},
vendor: {
files: 'vendor/**',
tasks: [ 'concat:app', 'ngmin:dist', 'concat:libs', 'uglify' ]
},
envs: {
files: 'environment.json',
tasks: ['clean', 'compassCompile', 'index']
}
}
});
/**
* Grunt Tasks
*/
/**
* This allows us to watch what we want to watch and control what happens
*/
grunt.renameTask('watch', 'delta');
grunt.registerTask('watch', ['default', 'jasmine', 'delta']);
grunt.registerTask('default', ['build']);
grunt.registerTask('build', ['clean', 'html2js', 'jshint', 'concat:app', 'ngmin:dist', 'concat:libs', 'uglify', 'compassCompile', 'index', 'jasmine']);
grunt.registerTask('test', ['jasmine']);
/**
* Task for general compass items
* This task will determine which environment you have set and run that task
*/
grunt.registerTask('compassCompile', 'Compiling the sass files', function () {
var env = grunt.config.get("env");
grunt.log.writeln("Current environment: " + env.environment);
if (env.environment === "production") {
grunt.task.run('compass:dist');
} else {
grunt.task.run('compass:dev');
}
// If youd like the file with v0.0.1.css for cacheBusting
if (env.cssCacheBusting) {
grunt.task.run('copy:css');
}
});
/**
* The index.html template includes the stylesheet and javascript sources
* based on dynamic names calculated in this Gruntfile. This task compiles it.
*/
grunt.registerTask( 'index', 'Process index.html template', function () {
grunt.log.writeln("Converting index.html...");
grunt.file.copy('public/index.tpl.html', 'public/index.html', { process: grunt.template.process });
});
};