1 // Generated on 2015-09-27 using generator-angular-fullstack 2.1.1
4 module.exports = function (grunt) {
7 localConfig = require('./server/config/local.env');
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'
23 // Time how long tasks take. Can help when optimizing build times
24 require('time-grunt')(grunt);
26 grunt.loadNpmTasks('grunt-exec');
28 // Define the configuration for all the tasks
32 pkg: grunt.file.readJSON('package.json'),
35 client: require('./bower.json').appPath || 'client',
40 port: process.env.PORT || 9000
44 script: 'server/app.js',
46 grunt.option('min') ? '' : '--unmin',
47 grunt.option('server-conf') ? '--server-conf=' + grunt.option('server-conf') : '--server-conf=development'
53 script: 'server/app.js',
56 grunt.option('min') ? '' : '--unmin',
57 grunt.option('server-conf') ? '--server-conf=' + grunt.option('server-conf') : '--server-conf=development'
63 script: 'mock/server.js'
68 script: 'dist/server/app.js'
74 url: 'http://localhost:<%= express.options.port %>/ecompportal/applicationsHome'
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']
88 '<%= yeoman.client %>/{app,components}/**/*.css'
90 tasks: ['injector:css']
93 files: ['server/**/*.spec.js'],
94 tasks: ['env:test', 'mochaTest']
98 '<%= yeoman.client %>/{app,components}/**/*.spec.js',
99 '<%= yeoman.client %>/{app,components}/**/*.mock.js'
101 tasks: ['newer:jshint:all', 'karma']
105 '<%= yeoman.client %>/{app,components}/**/*.less'],
106 tasks: ['injector:less']
110 '<%= yeoman.client %>/{app,components}/**/*.less'],
111 tasks: ['less', 'autoprefixer']
115 '<%= yeoman.client %>/{app,components}/**/*.js',
116 '!<%= yeoman.client %>/{app,components}/**/*.spec.js'
121 files: ['Gruntfile.js']
125 '{.tmp,<%= yeoman.client %>}/{app,components}/**/*.css',
126 '{.tmp,<%= yeoman.client %>}/{app,components}/**/*.html',
128 '.tmp/{app,components}/**/*.js',
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}'
140 'server/**/*.{js,json}'
142 tasks: ['express:dev', 'wait'],
145 spawn: false //Without this option specified express won't be reloaded
152 tasks:['express:mock'],
159 'client/configurations/*.json'
161 tasks: ['ngconstant']
165 // Make sure code styles are up to par and there are no obvious mistakes
168 jshintrc: '<%= yeoman.client %>/.jshintrc',
169 reporter: require('jshint-stylish')
173 jshintrc: 'server/.jshintrc'
177 '!server/**/*.spec.js'
182 jshintrc: 'server/.jshintrc-spec'
184 src: ['server/**/*.spec.js']
187 '<%= yeoman.client %>/{app,components}/**/*.js',
188 '!<%= yeoman.client %>/{app,components}/**/*.spec.js',
189 '!<%= yeoman.client %>/{app,components}/**/*.mock.js'
193 '<%= yeoman.client %>/{app,components}/**/*.spec.js',
194 '<%= yeoman.client %>/{app,components}/**/*.mock.js'
199 // Empties folders to start fresh
206 '<%= yeoman.dist %>/*',
207 '!<%= yeoman.dist %>/.git*',
208 '!<%= yeoman.dist %>/.openshift',
209 '!<%= yeoman.dist %>/Procfile'
216 // Add vendor prefixed styles
219 browsers: ['last 1 version']
231 // // Debugging with node inspector
232 // 'node-inspector': {
235 // 'web-host': 'localhost'
240 // Use nodemon to run server in debug mode with an initial breakpoint
243 script: 'server/app.js',
245 nodeArgs: ['--debug-brk'],
247 PORT: process.env.PORT || 9000
249 callback: function (nodemon) {
250 nodemon.on('log', function (event) {
251 console.log(event.colour);
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');
265 // Automatically inject Bower components into the app
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/]
274 // Renames files for browser caching purposes
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/*'
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
293 html: ['<%= yeoman.client %>/index.html'],
295 dest: '<%= yeoman.dist %>/public'
299 // Performs rewrites based on rev and the useminPrepare configuration
301 html: ['<%= yeoman.dist %>/public/{,*/}*.html'],
302 css: ['<%= yeoman.dist %>/public/{,*/}*.css'],
303 js: ['<%= yeoman.dist %>/public/{,*/}*.js'],
306 '<%= yeoman.dist %>/public',
307 '<%= yeoman.dist %>/public/assets'
309 // This is so we update image references in our ng-templates
312 [/(assets\/images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the JS to reference our revved images']
318 // The following *-min tasks produce minified files in the dist folder
323 cwd: '<%= yeoman.client %>/assets/images',
324 src: '{,*/}*.{png,jpg,jpeg,gif}',
325 dest: '<%= yeoman.dist %>/public/assets/images'
334 cwd: '<%= yeoman.client %>/assets/images',
336 dest: '<%= yeoman.dist %>/public/assets/images'
341 // Allow the use of non-minsafe AngularJS files. Automatically makes it
342 // minsafe compatible so Uglify does not destroy the ng references
354 // Package all the html partials into a single javascript payload
362 // This should be the name of your apps angular module
365 collapseBooleanAttributes: true,
366 collapseWhitespace: true,
367 removeAttributeQuotes: true,
368 removeEmptyAttributes: true,
369 removeRedundantAttributes: true,
370 removeScriptTypeAttributes: true,
371 removeStyleLinkTypeAttributes: true
376 cwd: '<%= yeoman.client %>',
377 src: ['{app,components}/**/*.html'],
378 dest: '.tmp/templates.js'
382 src: ['{app,components}/**/*.html'],
383 dest: '.tmp/tmp-templates.js'
387 // Replace Google CDN references
390 html: ['<%= yeoman.dist %>/public/*.html']
394 // Copies remaining files to places other tasks can use
400 cwd: '<%= yeoman.client %>',
401 dest: '<%= yeoman.dist %>/public',
405 'bower_components/**/*',
406 'bower_components_external/**/*',
407 'assets/images/**/*',
414 dest: '<%= yeoman.dist %>/public/assets/images',
418 dest: '<%= yeoman.dist %>',
427 cwd: '<%= yeoman.client %>',
429 src: ['{app,components}/**/*.css']
438 connectCommits: false,
439 message: 'Built %sourceName% from commit %sourceCommit% on branch %sourceBranch%'
455 // Run some tasks in parallel to speed up the build process
471 logConcurrentOutput: true
485 configFile: 'karma.conf.js',
494 src: ['server/**/*.spec.js']
499 configFile: 'protractor.conf.js'
515 NODE_ENV: 'production'
520 // Compiles ES6 to JavaScript using Babel
530 '{app,components}/**/*.js',
531 '!{app,components}/**/*.spec.js'
538 // Compiles Less to CSS
542 '<%= yeoman.client %>/bower_components',
543 '<%= yeoman.client %>/app',
544 '<%= yeoman.client %>/components'
549 '.tmp/app/app.css': '<%= yeoman.client %>/app/app.less'
556 // Inject application script files into index.html (doesn't include bower)
559 transform: function (filePath) {
560 filePath = filePath.replace('/client/', '');
561 filePath = filePath.replace('/.tmp/', '');
562 return '<script src="' + filePath + '"></script>';
564 starttag: '<!-- injector:js -->',
565 endtag: '<!-- endinjector -->'
568 '<%= yeoman.client %>/index.html': [
571 '.tmp/{app,components}/**/*.js',
573 '!{.tmp,<%= yeoman.client %>}/app/app.js',
574 '!{.tmp,<%= yeoman.client %>}/{app,components}/**/*.spec.js',
575 '!{.tmp,<%= yeoman.client %>}/{app,components}/**/*.mock.js'
581 // Inject component less into app.less
584 transform: function (filePath) {
585 filePath = filePath.replace('/client/app/', '');
586 filePath = filePath.replace('/client/components/', '');
587 return '@import \'' + filePath + '\';';
589 starttag: '// injector',
590 endtag: '// endinjector'
593 '<%= yeoman.client %>/app/app.less': [
594 '<%= yeoman.client %>/{app,components}/**/*.less',
595 '!<%= yeoman.client %>/app/app.less'
600 // Inject component css into index.html
603 transform: function (filePath) {
604 filePath = filePath.replace('/client/', '');
605 filePath = filePath.replace('/.tmp/', '');
606 return '<link rel="stylesheet" href="' + filePath + '">';
608 starttag: '<!-- injector:css -->',
609 endtag: '<!-- endinjector -->'
612 '<%= yeoman.client %>/index.html': [
613 '<%= yeoman.client %>/{app,components}/**/*.css'
619 //Project configuration task
623 dest: 'client/app/configurations.js',
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');
632 conf: grunt.file.readJSON('client/configurations/' + grunt.option('env') + '.json')
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/'
643 //Express server task
645 // Used for delaying livereload until after server has restarted
646 grunt.registerTask('wait', function () {
647 grunt.log.ok('Waiting for server reload...');
649 var done = this.async();
651 setTimeout(function () {
652 grunt.log.writeln('Done waiting!');
657 grunt.registerTask('express-keepalive', 'Keep grunt running', function () {
661 grunt.registerTask('serve', function (target) {
663 if (target === 'dist') {
664 return grunt.task.run(['build', 'env:all', 'env:prod', 'express:prod', 'express:mock', 'wait', 'open', 'express-keepalive']);
667 if (target === 'debug') {
668 return grunt.task.run([
681 var isDebug = grunt.option('dev_debug');
692 isDebug ? 'express:dev_debug' : 'express:dev',
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']);
705 grunt.registerTask('test', function (target) {
706 if (target === 'server') {
707 return grunt.task.run([
714 else if (target === 'client') {
715 return grunt.task.run([
727 else if (target === 'e2e') {
728 return grunt.task.run([
742 else grunt.task.run([
748 grunt.registerTask('build', [
768 grunt.registerTask('default', [
774 grunt.registerTask('deploy', [