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