blob: 812fc80931d26a6a62c7ddd62912f79ff663eef3 [file] [log] [blame]
st782sb54df0d2017-05-04 07:48:42 -04001// Generated on 2015-09-27 using generator-angular-fullstack 2.1.1
2'use strict';
3
4module.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,
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 'index.html'
410 ]
411 }, {
412 expand: true,
413 cwd: '.tmp/images',
414 dest: '<%= yeoman.dist %>/public/assets/images',
415 src: ['generated/*']
416 }, {
417 expand: true,
418 dest: '<%= yeoman.dist %>',
419 src: [
420 'package.json',
421 'server/**/*'
422 ]
423 }]
424 },
425 styles: {
426 expand: true,
427 cwd: '<%= yeoman.client %>',
428 dest: '.tmp/',
429 src: ['{app,components}/**/*.css']
430 }
431 },
432
433 buildcontrol: {
434 options: {
435 dir: 'dist',
436 commit: true,
437 push: true,
438 connectCommits: false,
439 message: 'Built %sourceName% from commit %sourceCommit% on branch %sourceBranch%'
440 },
441 heroku: {
442 options: {
443 remote: 'heroku',
444 branch: 'master'
445 }
446 },
447 openshift: {
448 options: {
449 remote: 'openshift',
450 branch: 'master'
451 }
452 }
453 },
454
455 // Run some tasks in parallel to speed up the build process
456 concurrent: {
457 server: [
458 'babel',
459 'less',
460 ],
461 test: [
462 'babel',
463 'less',
464 ],
465 debug: {
466 tasks: [
467 'nodemon'
468 //'node-inspector'
469 ],
470 options: {
471 logConcurrentOutput: true
472 }
473 },
474 dist: [
475 'babel',
476 'less',
477 //'imagemin',
478 'svgmin'
479 ]
480 },
481
482 // Test settings
483 karma: {
484 unit: {
485 configFile: 'karma.conf.js',
486 singleRun: true
487 }
488 },
489
490 mochaTest: {
491 options: {
492 reporter: 'spec'
493 },
494 src: ['server/**/*.spec.js']
495 },
496
497 protractor: {
498 options: {
499 configFile: 'protractor.conf.js'
500 },
501 chrome: {
502 options: {
503 args: {
504 browser: 'chrome'
505 }
506 }
507 }
508 },
509
510 env: {
511 test: {
512 NODE_ENV: 'test'
513 },
514 prod: {
515 NODE_ENV: 'production'
516 },
517 all: localConfig
518 },
519
520 // Compiles ES6 to JavaScript using Babel
521 babel: {
522 options: {
523 sourceMap: true
524 },
525 server: {
526 files: [{
527 expand: true,
528 cwd: 'client',
529 src: [
530 '{app,components}/**/*.js',
531 '!{app,components}/**/*.spec.js'
532 ],
533 dest: '.tmp'
534 }]
535 }
536 },
537
538 // Compiles Less to CSS
539 less: {
540 options: {
541 paths: [
542 '<%= yeoman.client %>/bower_components',
543 '<%= yeoman.client %>/app',
544 '<%= yeoman.client %>/components'
545 ]
546 },
547 server: {
548 files: {
549 '.tmp/app/app.css': '<%= yeoman.client %>/app/app.less'
550 }
551 },
552 },
553
554 injector: {
555 options: {},
556 // Inject application script files into index.html (doesn't include bower)
557 scripts: {
558 options: {
559 transform: function (filePath) {
560 filePath = filePath.replace('/client/', '');
561 filePath = filePath.replace('/.tmp/', '');
562 return '<script src="' + filePath + '"></script>';
563 },
564 starttag: '<!-- injector:js -->',
565 endtag: '<!-- endinjector -->'
566 },
567 files: {
568 '<%= yeoman.client %>/index.html': [
569 [
570
571 '.tmp/{app,components}/**/*.js',
572
573 '!{.tmp,<%= yeoman.client %>}/app/app.js',
574 '!{.tmp,<%= yeoman.client %>}/{app,components}/**/*.spec.js',
575 '!{.tmp,<%= yeoman.client %>}/{app,components}/**/*.mock.js'
576 ]
577 ]
578 }
579 },
580
581 // Inject component less into app.less
582 less: {
583 options: {
584 transform: function (filePath) {
585 filePath = filePath.replace('/client/app/', '');
586 filePath = filePath.replace('/client/components/', '');
587 return '@import \'' + filePath + '\';';
588 },
589 starttag: '// injector',
590 endtag: '// endinjector'
591 },
592 files: {
593 '<%= yeoman.client %>/app/app.less': [
594 '<%= yeoman.client %>/{app,components}/**/*.less',
595 '!<%= yeoman.client %>/app/app.less'
596 ]
597 }
598 },
599
600 // Inject component css into index.html
601 css: {
602 options: {
603 transform: function (filePath) {
604 filePath = filePath.replace('/client/', '');
605 filePath = filePath.replace('/.tmp/', '');
606 return '<link rel="stylesheet" href="' + filePath + '">';
607 },
608 starttag: '<!-- injector:css -->',
609 endtag: '<!-- endinjector -->'
610 },
611 files: {
612 '<%= yeoman.client %>/index.html': [
613 '<%= yeoman.client %>/{app,components}/**/*.css'
614 ]
615 }
616 }
617 },
618
619 //Project configuration task
620 ngconstant: {
621 main: {
622 options: {
623 dest: 'client/app/configurations.js',
624 name: 'ecomp.conf'
625 },
626 constants: function () {
627 if (!grunt.option('env')) {
628 grunt.fail.warn('env parameter missing, please use --env=<environment configuration>, ex: grunt serve --env=mock');
629 }
630
631 return {
632 conf: grunt.file.readJSON('client/configurations/' + grunt.option('env') + '.json')
633 }
634 }
635 }
636 },
637 exec: {
638 delete: 'sshpass -p Aa123456 ssh root@remotehost rm -rf /var/lib/tomcat/webapps/ecompportal/public/',
639 copy: 'sshpass -p Aa123456 scp -r dist/public/ root@remotehost:/var/lib/tomcat/webapps/ecompportal/'
640 }
641 });
642
643 //Express server task
644
645 // Used for delaying livereload until after server has restarted
646 grunt.registerTask('wait', function () {
647 grunt.log.ok('Waiting for server reload...');
648
649 var done = this.async();
650
651 setTimeout(function () {
652 grunt.log.writeln('Done waiting!');
653 done();
654 }, 1500);
655 });
656
657 grunt.registerTask('express-keepalive', 'Keep grunt running', function () {
658 this.async();
659 });
660
661 grunt.registerTask('serve', function (target) {
662
663 if (target === 'dist') {
664 return grunt.task.run(['build', 'env:all', 'env:prod', 'express:prod', 'express:mock', 'wait', 'open', 'express-keepalive']);
665 }
666
667 if (target === 'debug') {
668 return grunt.task.run([
669 'clean:server',
670 'env:all',
671 'injector:less',
672 'concurrent:server',
673 'express:mock',
674 'injector',
675 'wiredep',
676 'autoprefixer',
677 'concurrent:debug'
678 ]);
679 }
680
681 var isDebug = grunt.option('dev_debug');
682
683 grunt.task.run([
684 'clean:server',
685 'env:all',
686 'ngconstant',
687 'injector:less',
688 'concurrent:server',
689 'injector',
690 'wiredep',
691 'autoprefixer',
692 isDebug ? 'express:dev_debug' : 'express:dev',
693 'express:mock',
694 'wait',
695 'open',
696 'watch'
697 ]);
698 });
699
700 grunt.registerTask('server', function () {
701 grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
702 grunt.task.run(['serve']);
703 });
704
705 grunt.registerTask('test', function (target) {
706 if (target === 'server') {
707 return grunt.task.run([
708 'env:all',
709 'env:test',
710 'mochaTest'
711 ]);
712 }
713
714 else if (target === 'client') {
715 return grunt.task.run([
716 'clean:server',
717 'env:all',
718 'injector:less',
719 'concurrent:test',
720 'injector',
721 'ngtemplates:main',
722 'autoprefixer',
723 'karma'
724 ]);
725 }
726
727 else if (target === 'e2e') {
728 return grunt.task.run([
729 'clean:server',
730 'env:all',
731 'env:test',
732 'injector:less',
733 'concurrent:test',
734 'injector',
735 'wiredep',
736 'autoprefixer',
737 'express:dev',
738 'protractor'
739 ]);
740 }
741
742 else grunt.task.run([
743 'test:server',
744 'test:client'
745 ]);
746 });
747
748 grunt.registerTask('build', [
749 'clean:dist',
750 'injector:less',
751 'ngconstant',
752 'concurrent:dist',
753 'injector',
754 'wiredep',
755 'useminPrepare',
756 'autoprefixer',
757 'ngtemplates',
758 'concat',
759 'ngAnnotate',
760 'copy:dist',
761 //'cdnify',
762 'cssmin',
763 'uglify',
764 'rev',
765 'usemin'
766 ]);
767
768 grunt.registerTask('default', [
769 'newer:jshint',
770 'test',
771 'build'
772 ]);
773
774 grunt.registerTask('deploy', [
775 'build',
776 'exec'
777 ]);
778};