Creazione organizza
[YouAndWeb_TwoToc] / Gruntfile.js
1 // Generated on 2015-08-31 using generator-angular-fullstack 3.0.0-rc5
2 'use strict';
3
4 module.exports = function (grunt) {
5   var localConfig;
6   try {
7     localConfig = require('./server/config/local.env');
8   } catch(e) {
9     localConfig = {};
10   }
11
12   // Load grunt tasks automatically, when needed
13   require('jit-grunt')(grunt, {
14     express: 'grunt-express-server',
15     useminPrepare: 'grunt-usemin',
16     ngtemplates: 'grunt-angular-templates',
17     cdnify: 'grunt-google-cdn',
18     protractor: 'grunt-protractor-runner',
19     buildcontrol: 'grunt-build-control',
20     istanbul_check_coverage: 'grunt-mocha-istanbul'
21   });
22
23   // Time how long tasks take. Can help when optimizing build times
24   require('time-grunt')(grunt);
25
26   // Define the configuration for all the tasks
27   grunt.initConfig({
28
29     // Project settings
30     pkg: grunt.file.readJSON('package.json'),
31     yeoman: {
32       // configurable paths
33       client: require('./bower.json').appPath || 'client',
34       dist: 'dist'
35     },
36     express: {
37       options: {
38         port: process.env.PORT || 9000
39       },
40       dev: {
41         options: {
42           script: 'server',
43           debug: true
44         }
45       },
46       prod: {
47         options: {
48           script: 'dist/server'
49         }
50       }
51     },
52     open: {
53       server: {
54         url: 'http://localhost:<%= express.options.port %>'
55       }
56     },
57     watch: {
58       injectJS: {
59         files: [
60           '<%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).js',
61           '!<%= yeoman.client %>/app/app.js'
62         ],
63         tasks: ['injector:scripts']
64       },
65       injectCss: {
66         files: ['<%= yeoman.client %>/{app,components}/**/*.css'],
67         tasks: ['injector:css']
68       },
69       mochaTest: {
70         files: ['server/**/*.{spec,integration}.js'],
71         tasks: ['env:test', 'mochaTest']
72       },
73       jsTest: {
74         files: ['<%= yeoman.client %>/{app,components}/**/*.{spec,mock}.js'],
75         tasks: ['newer:jshint:all', 'wiredep:test', 'karma']
76       },
77       injectSass: {
78         files: ['<%= yeoman.client %>/{app,components}/**/*.{scss,sass}'],
79         tasks: ['injector:sass']
80       },
81       sass: {
82         files: ['<%= yeoman.client %>/{app,components}/**/*.{scss,sass}'],
83         tasks: ['sass', 'postcss']
84       },
85       gruntfile: {
86         files: ['Gruntfile.js']
87       },
88       livereload: {
89         files: [
90           '{.tmp,<%= yeoman.client %>}/{app,components}/**/*.{css,html}',
91           '{.tmp,<%= yeoman.client %>}/{app,components}/**/!(*.spec|*.mock).js',
92           '<%= yeoman.client %>/assets/images/{,*//*}*.{png,jpg,jpeg,gif,webp,svg}'
93         ],
94         options: {
95           livereload: true
96         }
97       },
98       express: {
99         files: ['server/**/*.{js,json}'],
100         tasks: ['express:dev', 'wait'],
101         options: {
102           livereload: true,
103           spawn: false //Without this option specified express won't be reloaded
104         }
105       },
106       bower: {
107         files: ['bower.json'],
108         tasks: ['wiredep']
109       },
110     },
111
112     // Make sure code styles are up to par and there are no obvious mistakes
113     jshint: {
114       options: {
115         jshintrc: '<%= yeoman.client %>/.jshintrc',
116         reporter: require('jshint-stylish')
117       },
118       server: {
119         options: {
120           jshintrc: 'server/.jshintrc'
121         },
122         src: ['server/**/!(*.spec|*.integration).js']
123       },
124       serverTest: {
125         options: {
126           jshintrc: 'server/.jshintrc-spec'
127         },
128         src: ['server/**/*.{spec,integration}.js']
129       },
130       all: ['<%= yeoman.client %>/{app,components}/**/!(*.spec|*.mock).js'],
131       test: {
132         src: ['<%= yeoman.client %>/{app,components}/**/*.{spec,mock}.js']
133       }
134     },
135
136     jscs: {
137       options: {
138         config: ".jscs.json"
139       },
140       main: {
141         files: {
142           src: [
143             '<%= yeoman.client %>/app/**/*.js',
144             'server/**/*.js'
145           ]
146         }
147       }
148     },
149
150     // Empties folders to start fresh
151     clean: {
152       dist: {
153         files: [{
154           dot: true,
155           src: [
156             '.tmp',
157             '<%= yeoman.dist %>/!(.git*|.openshift|Procfile)**'
158           ]
159         }]
160       },
161       server: '.tmp'
162     },
163
164     // Add vendor prefixed styles
165     postcss: {
166       options: {
167         map: true,
168         processors: [
169           require('autoprefixer-core')({browsers: ['last 1 version']})
170         ]
171       },
172       dist: {
173         files: [{
174           expand: true,
175           cwd: '.tmp/',
176           src: '{,*/}*.css',
177           dest: '.tmp/'
178         }]
179       }
180     },
181
182     // Debugging with node inspector
183     'node-inspector': {
184       custom: {
185         options: {
186           'web-host': 'localhost'
187         }
188       }
189     },
190
191     // Use nodemon to run server in debug mode with an initial breakpoint
192     nodemon: {
193       debug: {
194         script: 'server',
195         options: {
196           nodeArgs: ['--debug-brk'],
197           env: {
198             PORT: process.env.PORT || 9000
199           },
200           callback: function (nodemon) {
201             nodemon.on('log', function (event) {
202               console.log(event.colour);
203             });
204
205             // opens browser on initial server start
206             nodemon.on('config:update', function () {
207               setTimeout(function () {
208                 require('open')('http://localhost:8080/debug?port=5858');
209               }, 500);
210             });
211           }
212         }
213       }
214     },
215
216     // Automatically inject Bower components into the app and karma.conf.js
217     wiredep: {
218       options: {
219         exclude: [
220           /bootstrap.js/,
221           '/json3/',
222           '/es5-shim/',
223           /font-awesome\.css/,
224           /bootstrap\.css/,
225           /bootstrap-sass-official/
226         ]
227       },
228       client: {
229         src: '<%= yeoman.client %>/index.html',
230         ignorePath: '<%= yeoman.client %>/',
231       },
232       test: {
233         src: './karma.conf.js',
234         devDependencies: true
235       }
236     },
237
238     // Renames files for browser caching purposes
239     filerev: {
240       dist: {
241         src: [
242           '<%= yeoman.dist %>/client/!(bower_components){,*/}*.{js,css}',
243           // '<%= yeoman.dist %>/client/assets/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
244           '<%= yeoman.dist %>/client/assets/fonts/*'
245         ]
246       }
247     },
248
249     // Reads HTML for usemin blocks to enable smart builds that automatically
250     // concat, minify and revision files. Creates configurations in memory so
251     // additional tasks can operate on them
252     useminPrepare: {
253       html: ['<%= yeoman.client %>/index.html'],
254       options: {
255         dest: '<%= yeoman.dist %>/client'
256       }
257     },
258
259     // Performs rewrites based on rev and the useminPrepare configuration
260     usemin: {
261       html: ['<%= yeoman.dist %>/client/!(bower_components){,*/}*.html'],
262       css: ['<%= yeoman.dist %>/client/!(bower_components){,*/}*.css'],
263       js: ['<%= yeoman.dist %>/client/!(bower_components){,*/}*.js'],
264       options: {
265         assetsDirs: [
266           '<%= yeoman.dist %>/client',
267           '<%= yeoman.dist %>/client/assets/images'
268         ],
269         // This is so we update image references in our ng-templates
270         patterns: {
271           js: [
272             [/(assets\/images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the JS to reference our revved images']
273           ]
274         }
275       }
276     },
277
278     // The following *-min tasks produce minified files in the dist folder
279     imagemin: {
280       dist: {
281         files: [{
282           expand: true,
283           cwd: '<%= yeoman.client %>/assets/images',
284           src: '{,*/}*.{png,jpg,jpeg,gif,svg}',
285           dest: '<%= yeoman.dist %>/client/assets/images'
286         }]
287       }
288     },
289
290     // Allow the use of non-minsafe AngularJS files. Automatically makes it
291     // minsafe compatible so Uglify does not destroy the ng references
292     ngAnnotate: {
293       dist: {
294         files: [{
295           expand: true,
296           cwd: '.tmp/concat',
297           src: '**/*.js',
298           dest: '.tmp/concat'
299         }]
300       }
301     },
302
303     // Package all the html partials into a single javascript payload
304     ngtemplates: {
305       options: {
306         // This should be the name of your apps angular module
307         module: 'dashboardApp',
308         htmlmin: {
309           collapseBooleanAttributes: true,
310           collapseWhitespace: true,
311           removeAttributeQuotes: true,
312           removeEmptyAttributes: true,
313           removeRedundantAttributes: true,
314           removeScriptTypeAttributes: true,
315           removeStyleLinkTypeAttributes: true
316         },
317         usemin: 'app/app.js'
318       },
319       main: {
320         cwd: '<%= yeoman.client %>',
321         src: ['{app,components}/**/*.html'],
322         dest: '.tmp/templates.js'
323       },
324       tmp: {
325         cwd: '.tmp',
326         src: ['{app,components}/**/*.html'],
327         dest: '.tmp/tmp-templates.js'
328       }
329     },
330
331     // Replace Google CDN references
332     cdnify: {
333       dist: {
334         html: ['<%= yeoman.dist %>/client/*.html']
335       }
336     },
337
338     // Copies remaining files to places other tasks can use
339     copy: {
340       dist: {
341         files: [{
342           expand: true,
343           dot: true,
344           cwd: '<%= yeoman.client %>',
345           dest: '<%= yeoman.dist %>/client',
346           src: [
347             '*.{ico,png,txt}',
348             '.htaccess',
349             'bower_components/**/*',
350             'assets/images/{,*/}*.{webp}',
351             'assets/fonts/**/*',
352             'assets/langs/*',
353             'index.html'
354           ]
355         }, {
356           expand: true,
357           cwd: '.tmp/images',
358           dest: '<%= yeoman.dist %>/client/assets/images',
359           src: ['generated/*']
360         }, {
361           expand: true,
362           dest: '<%= yeoman.dist %>',
363           src: [
364             'package.json',
365             'server/**/*'
366           ]
367         }]
368       },
369       styles: {
370         expand: true,
371         cwd: '<%= yeoman.client %>',
372         dest: '.tmp/',
373         src: ['{app,components}/**/*.css']
374       }
375     },
376
377     buildcontrol: {
378       options: {
379         dir: 'dist',
380         commit: true,
381         push: true,
382         connectCommits: false,
383         message: 'Built %sourceName% from commit %sourceCommit% on branch %sourceBranch%'
384       },
385       heroku: {
386         options: {
387           remote: 'heroku',
388           branch: 'master'
389         }
390       },
391       openshift: {
392         options: {
393           remote: 'openshift',
394           branch: 'master'
395         }
396       }
397     },
398
399     // Run some tasks in parallel to speed up the build process
400     concurrent: {
401       server: [
402         'sass',
403       ],
404       test: [
405         'sass',
406       ],
407       debug: {
408         tasks: [
409           'nodemon',
410           'node-inspector'
411         ],
412         options: {
413           logConcurrentOutput: true
414         }
415       },
416       dist: [
417         'sass',
418         'imagemin'
419       ]
420     },
421
422     // Test settings
423     karma: {
424       unit: {
425         configFile: 'karma.conf.js',
426         singleRun: true
427       }
428     },
429
430     mochaTest: {
431       options: {
432         reporter: 'spec',
433         require: 'mocha.conf.js',
434         timeout: 5000 // set default mocha spec timeout
435       },
436       unit: {
437         src: ['server/**/*.spec.js']
438       },
439       integration: {
440         src: ['server/**/*.integration.js']
441       }
442     },
443
444     mocha_istanbul: {
445       unit: {
446         options: {
447           excludes: ['**/*.{spec,mock,integration}.js'],
448           reporter: 'spec',
449           require: ['mocha.conf.js'],
450           mask: '**/*.spec.js',
451           coverageFolder: 'coverage/server/unit'
452         },
453         src: 'server'
454       },
455       integration: {
456         options: {
457           excludes: ['**/*.{spec,mock,integration}.js'],
458           reporter: 'spec',
459           require: ['mocha.conf.js'],
460           mask: '**/*.integration.js',
461           coverageFolder: 'coverage/server/integration'
462         },
463         src: 'server'
464       }
465     },
466
467     istanbul_check_coverage: {
468       default: {
469         options: {
470           coverageFolder: 'coverage/**',
471           check: {
472             lines: 80,
473             statements: 80,
474             branches: 80,
475             functions: 80
476           }
477         }
478       }
479     },
480
481     protractor: {
482       options: {
483         configFile: 'protractor.conf.js'
484       },
485       chrome: {
486         options: {
487           args: {
488             browser: 'chrome'
489           }
490         }
491       }
492     },
493
494     env: {
495       test: {
496         NODE_ENV: 'test'
497       },
498       prod: {
499         NODE_ENV: 'production'
500       },
501       all: localConfig
502     },
503
504     // Compiles Sass to CSS
505     sass: {
506       server: {
507         options: {
508           compass: false
509         },
510         files: {
511           '.tmp/app/app.css' : '<%= yeoman.client %>/app/app.scss'
512         }
513       }
514     },
515
516     injector: {
517       options: {
518
519       },
520       // Inject application script files into index.html (doesn't include bower)
521       scripts: {
522         options: {
523           transform: function(filePath) {
524             filePath = filePath.replace('/client/', '');
525             filePath = filePath.replace('/.tmp/', '');
526             return '<script src="' + filePath + '"></script>';
527           },
528           starttag: '<!-- injector:js -->',
529           endtag: '<!-- endinjector -->'
530         },
531         files: {
532           '<%= yeoman.client %>/index.html': [
533                [
534                  '{.tmp,<%= yeoman.client %>}/{app,components}/**/!(*.spec|*.mock).js',
535                  '!{.tmp,<%= yeoman.client %>}/app/app.js'
536                ]
537             ]
538         }
539       },
540
541       // Inject component scss into app.scss
542       sass: {
543         options: {
544           transform: function(filePath) {
545             filePath = filePath.replace('/client/app/', '');
546             filePath = filePath.replace('/client/components/', '../components/');
547             return '@import \'' + filePath + '\';';
548           },
549           starttag: '// injector',
550           endtag: '// endinjector'
551         },
552         files: {
553           '<%= yeoman.client %>/app/app.scss': [
554             '<%= yeoman.client %>/{app,components}/**/*.{scss,sass}',
555             '!<%= yeoman.client %>/app/app.{scss,sass}'
556           ]
557         }
558       },
559
560       // Inject component css into index.html
561       css: {
562         options: {
563           transform: function(filePath) {
564             filePath = filePath.replace('/client/', '');
565             filePath = filePath.replace('/.tmp/', '');
566             return '<link rel="stylesheet" href="' + filePath + '">';
567           },
568           starttag: '<!-- injector:css -->',
569           endtag: '<!-- endinjector -->'
570         },
571         files: {
572           '<%= yeoman.client %>/index.html': [
573             '<%= yeoman.client %>/{app,components}/**/*.css'
574           ]
575         }
576       }
577     },
578   });
579
580   // Used for delaying livereload until after server has restarted
581   grunt.registerTask('wait', function () {
582     grunt.log.ok('Waiting for server reload...');
583
584     var done = this.async();
585
586     setTimeout(function () {
587       grunt.log.writeln('Done waiting!');
588       done();
589     }, 1500);
590   });
591
592   grunt.registerTask('express-keepalive', 'Keep grunt running', function() {
593     this.async();
594   });
595
596   grunt.registerTask('serve', function (target) {
597     if (target === 'dist') {
598       return grunt.task.run(['build', 'env:all', 'env:prod', 'express:prod', 'wait', 'open', 'express-keepalive']);
599     }
600
601     if (target === 'debug') {
602       return grunt.task.run([
603         'clean:server',
604         'env:all',
605         'injector:sass',
606         'concurrent:server',
607         'injector',
608         'wiredep:client',
609         'postcss',
610         'concurrent:debug'
611       ]);
612     }
613
614     grunt.task.run([
615       'clean:server',
616       'env:all',
617       'injector:sass',
618       'concurrent:server',
619       'injector',
620       'wiredep:client',
621       'postcss',
622       'express:dev',
623       'wait',
624       'open',
625       'watch'
626     ]);
627   });
628
629   grunt.registerTask('server', function () {
630     grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
631     grunt.task.run(['serve']);
632   });
633
634   grunt.registerTask('test', function(target, option) {
635     if (target === 'server') {
636       return grunt.task.run([
637         'env:all',
638         'env:test',
639         'mochaTest:unit',
640         'mochaTest:integration'
641       ]);
642     }
643
644     else if (target === 'client') {
645       return grunt.task.run([
646         'clean:server',
647         'env:all',
648         'injector:sass',
649         'concurrent:test',
650         'injector',
651         'postcss',
652         'wiredep:test',
653         'karma'
654       ]);
655     }
656
657     else if (target === 'e2e') {
658
659       if (option === 'prod') {
660         return grunt.task.run([
661           'build',
662           'env:all',
663           'env:prod',
664           'express:prod',
665           'protractor'
666         ]);
667       }
668
669       else {
670         return grunt.task.run([
671           'clean:server',
672           'env:all',
673           'env:test',
674           'injector:sass',
675           'concurrent:test',
676           'injector',
677           'wiredep:client',
678           'postcss',
679           'express:dev',
680           'protractor'
681         ]);
682       }
683     }
684
685     else if (target === 'coverage') {
686
687       if (option === 'unit') {
688         return grunt.task.run([
689           'env:all',
690           'env:test',
691           'mocha_istanbul:unit'
692         ]);
693       }
694
695       else if (option === 'integration') {
696         return grunt.task.run([
697           'env:all',
698           'env:test',
699           'mocha_istanbul:integration'
700         ]);
701       }
702
703       else if (option === 'check') {
704         return grunt.task.run([
705           'istanbul_check_coverage'
706         ]);
707       }
708
709       else {
710         return grunt.task.run([
711           'env:all',
712           'env:test',
713           'mocha_istanbul',
714           'istanbul_check_coverage'
715         ]);
716       }
717
718     }
719
720     else grunt.task.run([
721       'test:server',
722       'test:client'
723     ]);
724   });
725
726   grunt.registerTask('build', [
727     'clean:dist',
728     'injector:sass',
729     'concurrent:dist',
730     'injector',
731     'wiredep:client',
732     'useminPrepare',
733     'postcss',
734     'ngtemplates',
735     'concat',
736     'ngAnnotate',
737     'copy:dist',
738     'cdnify',
739     'cssmin',
740     'uglify',
741     'filerev',
742     'usemin'
743   ]);
744
745   grunt.registerTask('default', [
746     'newer:jshint',
747     'test',
748     'build'
749   ]);
750 };