-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
456 lines (374 loc) · 9.62 KB
/
Gruntfile.js
File metadata and controls
456 lines (374 loc) · 9.62 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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/*
Katalyst Playground v0.5
*/
var path, lrSnippet,
mountFolder, LIVERELOAD_PORT;
LIVERELOAD_PORT = 35729;
path = require('path');
lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT });
// lrSnippet = require('grunt-contrib-watch/lib').livereloadSnippet,
mountFolder = function( connect, dir ) {
return connect.static(path.resolve(dir));
};
module.exports = function(grunt) {
'use strict';
// show elapsed time at the end
require('time-grunt')(grunt);
// DEPENDENT PLUGINS =========================/
// These plugins provide necessary tasks
grunt.loadNpmTasks("grunt-extend-config");
grunt.loadNpmTasks("grunt-notify");
grunt.loadNpmTasks("grunt-open");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-usemin");
grunt.loadNpmTasks("grunt-contrib-sass");
grunt.loadNpmTasks("grunt-contrib-compass");
grunt.loadNpmTasks("grunt-contrib-cssmin");
grunt.loadNpmTasks("grunt-contrib-connect");
grunt.loadNpmTasks("grunt-contrib-watch");
// Or fast load all grunt tasks
// require('load-grunt-tasks')(grunt);
// App file paths
var projectConfig = {
app: ['app'],
www: ['www'],
dist: ['dist']
};
var src = {
js: ['app/**/*.js'],
templates: ['app/partials/**/*.html']
};
// Project config
grunt.initConfig({
project: projectConfig,
// Metadata
pkg: grunt.file.readJSON('package.json'),
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>;' +
' Licensed under the <%= pkg.license %> License */\n',
// CONFIG ===================================/
// Before generating any new files, remove any previously-created files.
clean: {
dist: [ 'dist/', '.temp/' ]
},
// js code inspection
jshint: {
options: {
jshintrc: '.jshintrc',
reporterOutput: ''
},
// all: [
// 'Gruntfile.js',
// '<%= project.app %>/{,*/}*.js'
// ],
all: [
'Gruntfile.js',
'<%= project.app %>/{,*/}*.js',
'<%= project.www %>/js/{,*/}*.js',
'!dist/**'
]
},
// Concat models
concat: {
models: {
src: 'app/models/*.js',
dest: 'dist/models/models.bundle.js'
},
controllers: {
src: 'app/controllers/*.js',
dest: 'dist/controllers/controllers.bundle.js'
}
},
// Usemin (NEW)
// TODO: finish
useminPrepare: {
html: 'dist/index.html',
options: {
root: 'dist',
dest: 'dist'
}
},
usemin: {
html: 'dist/index.html'
},
// sass pre-processor
// TODO: clean this up
// compass: {
// options: {
// sassDir: 'app/scss',
// cssDir: 'www/css',
// imagesDir: 'www/img',
// fontsDir: 'app/scss/fonts',
// httpImagesPath: '/img',
// relativeAssets: false,
// debugInfo: false
// },
// dist: {}
// },
// watch files
watch: {
options: {
spawn: false,
livereload: true // Set livereload to trigger a reload upon change
},
// config files
configFiles: {
options: {
spawn: true,
reload: true
},
files: [
'Gruntfile.js',
'tasks/**/*.js',
'test/**/*.js',
'config/*.js'
],
tasks: [ 'jshint', 'notify:gruntReloaded' ]
},
// sass
css: {
files: [ 'app/scss/{,**/}*.{scss,sass}' ],
tasks: [ 'katalyst-compile-sass', 'copy:css' ],
options: {
spawn: false,
livereload: true // Set livereload to trigger a reload upon change
}
},
// js
js: {
files: [ 'app/**/*.js', 'www/**/*.js' ],
tasks: [ 'jshint', 'copy:js_from_app', 'concat:models', 'concat:controllers' ],
options: {
spawn: false,
livereload: true
}
},
// html
// html: {
// files: [
// 'www/index.html'
// ],
// tasks: [ 'katalyst-compress', 'notify:katalystCompress' ],
// options: {
// livereload: true // Set livereload to trigger a reload upon change
// }
// },
// all
all: {
files: [
//'www/**/*'
'www/**/{,*/}*.{html,css,js,png,jpg,gif,svg}'
//'www/{,*/}*.html'
//'www/{,*/}*.{css,js,png,jpg,gif,svg}'
],
tasks: [ 'copy:www', 'notify:copywww' ],
options: {
spawn: false,
livereload: true // Set livereload to trigger a reload upon change
}
},
// livereload
livereload: {
files: [
'dist/{,*/}*.html',
'dist/{,*/}*.{css,js,png,jpg,gif,svg}'
],
tasks: [ 'notify:livereload' ],
options: {
spawn: false,
livereload: true
}
}
// misc
// livereload: {
// files: ['www/**/*'],
// options: {
// livereload: true
// }
// }
},
// static web server
connect: {
options: {
hostname: '0.0.0.0', // access the server from outside.
port: 4000
},
// normal way
dev: {
options: {
base: 'dist',
keepalive: false
}
},
// middleware man + livereload
livereload: {
options: {
middleware: function( connect ) {
return [
lrSnippet,
mountFolder(connect, './dist')
];
}
}
}
},
// open your browser at the project's URL
open: {
dev: {
url: 'http://localhost:<%= connect.options.port %>'
}
}
});
// Extend config test
grunt.extendConfig({
//
// Copy
//
copy: {
// Html
html: {
expand: true,
cwd: 'www/',
src: [ '**/*.html' ],
dest: 'dist/'
},
// Copy CSS from www/ to dist/
css: {
expand: true,
cwd: 'www/css',
src: [ '**/*.css' ],
dest: 'dist/css'
},
// Copy JS from app/ to dist/
js_from_app: {
expand: true,
cwd: 'app/',
src: [ '**/*.js' ],
dest: 'dist/'
},
// Copy files from www/ to dist/ (except for .scss)
www: {
expand: true,
cwd: 'www/',
src: [ '**/*.*', '!**/*.scss' ],
dest: 'dist/'
}
},
//
// Notify test messages
//
notify: {
server: {
options: {
message: 'Server is up!'
}
},
gruntReloaded: {
options: {
title: 'Grunt config update',
message: 'Reload complete'
}
},
copywww: {
options: {
title: 'WWW updated',
message: 'Creating dist/'
}
},
katalystCompress: {
options: {
title: 'index.html updated',
message: 'Compressing to /dist'
}
},
livereload: {
options: {
title: 'Live reload active',
message: 'Serving /dist'
}
}
}
});
// TASKS =====================================/
// Load all tasks from folder
// grunt.loadTasks('tasks');
// sass compiler
grunt.registerTask("katalyst-compile-sass", "Compile SASS if they exist", function() {
var sassFiles;
// Extend config test
grunt.extendConfig({
// sass: {
// dist: {
// files: [
// {
// expand: true,
// cwd: 'app/',
// src: ['**/!(_*).scss', '**/!(_*).sass'],
// dest: 'dist/',
// ext: '.css'
// }, {
// expand: true,
// cwd: 'www/',
// src: ['**/!(_*).scss', '**/!(_*).sass'],
// dest: 'dist/',
// ext: '.css'
// }
// ]
// }
// }
compass: {
options: {
sassDir: 'app/scss',
cssDir: 'www/css',
imagesDir: 'www/img',
fontsDir: 'app/scss/fonts',
httpImagesPath: '/img',
relativeAssets: false,
debugInfo: false
},
dist: {}
}
});
sassFiles = grunt.file.expand(["www/**/*.scss", "www/**/*.sass", "app/**/*.scss", "app/**/*.sass"]);
if (sassFiles.length > 0) {
grunt.log.writeln("SASS files found, compiling to dist/ ...");
return grunt.task.run("compass");
} else {
return grunt.log.writeln("No .scss or .sass files found in app/ or www/, skipping SASS compile.");
}
});
// compressor
grunt.registerTask("katalyst-compress", "Concat, minify, uglify + references update", [
'useminPrepare',
'concat:generated',
//'cssmin',
'uglify:generated',
'usemin'
]);
// Server task
grunt.registerTask('server', [
'clean',
'jshint',
'katalyst-compile-sass',
'copy:js_from_app',
'copy:www',
'concat:models',
'concat:controllers',
'connect:livereload',
//'open:dev',
'notify:server',
'watch'
]);
// Build task (to do)
grunt.registerTask('build', [
'katalyst-compress'
]);
// Default task
grunt.registerTask('default', [ 'server' ]);
};