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/i18n/{,*/}*.{json}',
284 '!<%= yeoman.dist %>/public/assets/images/tmp/*'
290 // Reads HTML for usemin blocks to enable smart builds that automatically
291 // concat, minify and revision files. Creates configurations in memory so
292 // additional tasks can operate on them
294 html: ['<%= yeoman.client %>/index.html'],
296 dest: '<%= yeoman.dist %>/public'
300 // Performs rewrites based on rev and the useminPrepare configuration
302 html: ['<%= yeoman.dist %>/public/{,*/}*.html'],
303 css: ['<%= yeoman.dist %>/public/{,*/}*.css'],
304 js: ['<%= yeoman.dist %>/public/{,*/}*.js'],
307 '<%= yeoman.dist %>/public',
308 '<%= yeoman.dist %>/public/assets'
310 // This is so we update image references in our ng-templates
313 [/(assets\/images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the JS to reference our revved images']
319 // The following *-min tasks produce minified files in the dist folder
324 cwd: '<%= yeoman.client %>/assets/images',
325 src: '{,*/}*.{png,jpg,jpeg,gif}',
326 dest: '<%= yeoman.dist %>/public/assets/images'
334 cwd: '<%= yeoman.client %>/assets/i18n',
335 src: '{,*/}*.{json}',
336 dest: '<%= yeoman.dist %>/public/assets/i18n'
345 cwd: '<%= yeoman.client %>/assets/images',
347 dest: '<%= yeoman.dist %>/public/assets/images'
352 // Allow the use of non-minsafe AngularJS files. Automatically makes it
353 // minsafe compatible so Uglify does not destroy the ng references
365 // Package all the html partials into a single javascript payload
373 // This should be the name of your apps angular module
376 collapseBooleanAttributes: true,
377 collapseWhitespace: true,
378 removeAttributeQuotes: true,
379 removeEmptyAttributes: true,
380 removeRedundantAttributes: true,
381 removeScriptTypeAttributes: true,
382 removeStyleLinkTypeAttributes: true
387 cwd: '<%= yeoman.client %>',
388 src: ['{app,components}/**/*.html'],
389 dest: '.tmp/templates.js'
393 src: ['{app,components}/**/*.html'],
394 dest: '.tmp/tmp-templates.js'
398 // Replace Google CDN references
401 html: ['<%= yeoman.dist %>/public/*.html']
405 // Copies remaining files to places other tasks can use
411 cwd: '<%= yeoman.client %>',
412 dest: '<%= yeoman.dist %>/public',
416 'bower_components/**/*',
417 'bower_components_external/**/*',
418 'assets/images/**/*',
426 dest: '<%= yeoman.dist %>/public/assets/images',
431 dest: '<%= yeoman.dist %>/public/assets/i18n',
438 dest: '<%= yeoman.dist %>',
447 cwd: '<%= yeoman.client %>',
449 src: ['{app,components}/**/*.css']
458 connectCommits: false,
459 message: 'Built %sourceName% from commit %sourceCommit% on branch %sourceBranch%'
475 // Run some tasks in parallel to speed up the build process
491 logConcurrentOutput: true
505 configFile: 'karma.conf.js',
514 src: ['server/**/*.spec.js']
519 configFile: 'protractor.conf.js'
535 NODE_ENV: 'production'
540 // Compiles ES6 to JavaScript using Babel
550 '{app,components}/**/*.js',
551 '!{app,components}/**/*.spec.js'
558 // Compiles Less to CSS
562 '<%= yeoman.client %>/bower_components',
563 '<%= yeoman.client %>/app',
564 '<%= yeoman.client %>/components'
569 '.tmp/app/app.css': '<%= yeoman.client %>/app/app.less'
576 // Inject application script files into index.html (doesn't include bower)
579 transform: function (filePath) {
580 filePath = filePath.replace('/client/', '');
581 filePath = filePath.replace('/.tmp/', '');
582 return '<script src="' + filePath + '"></script>';
584 starttag: '<!-- injector:js -->',
585 endtag: '<!-- endinjector -->'
588 '<%= yeoman.client %>/index.html': [
591 '.tmp/{app,components}/**/*.js',
593 '!{.tmp,<%= yeoman.client %>}/app/app.js',
594 '!{.tmp,<%= yeoman.client %>}/{app,components}/**/*.spec.js',
595 '!{.tmp,<%= yeoman.client %>}/{app,components}/**/*.mock.js'
601 // Inject component less into app.less
604 transform: function (filePath) {
605 filePath = filePath.replace('/client/app/', '');
606 filePath = filePath.replace('/client/components/', '');
607 return '@import \'' + filePath + '\';';
609 starttag: '// injector',
610 endtag: '// endinjector'
613 '<%= yeoman.client %>/app/app.less': [
614 '<%= yeoman.client %>/{app,components}/**/*.less',
615 '!<%= yeoman.client %>/app/app.less'
620 // Inject component css into index.html
623 transform: function (filePath) {
624 filePath = filePath.replace('/client/', '');
625 filePath = filePath.replace('/.tmp/', '');
626 return '<link rel="stylesheet" href="' + filePath + '">';
628 starttag: '<!-- injector:css -->',
629 endtag: '<!-- endinjector -->'
632 '<%= yeoman.client %>/index.html': [
633 '<%= yeoman.client %>/{app,components}/**/*.css'
639 //Project configuration task
643 dest: 'client/app/configurations.js',
646 constants: function () {
647 if (!grunt.option('env')) {
648 grunt.fail.warn('env parameter missing, please use --env=<environment configuration>, ex: grunt serve --env=mock');
652 conf: grunt.file.readJSON('client/configurations/' + grunt.option('env') + '.json')
658 delete: 'sshpass -p Aa123456 ssh root@remotehost rm -rf /var/lib/tomcat/webapps/ecompportal/public/',
659 copy: 'sshpass -p Aa123456 scp -r dist/public/ root@remotehost:/var/lib/tomcat/webapps/ecompportal/'
663 //Express server task
665 // Used for delaying livereload until after server has restarted
666 grunt.registerTask('wait', function () {
667 grunt.log.ok('Waiting for server reload...');
669 var done = this.async();
671 setTimeout(function () {
672 grunt.log.writeln('Done waiting!');
677 grunt.registerTask('express-keepalive', 'Keep grunt running', function () {
681 grunt.registerTask('serve', function (target) {
683 if (target === 'dist') {
684 return grunt.task.run(['build', 'env:all', 'env:prod', 'express:prod', 'express:mock', 'wait', 'open', 'express-keepalive']);
687 if (target === 'debug') {
688 return grunt.task.run([
701 var isDebug = grunt.option('dev_debug');
712 isDebug ? 'express:dev_debug' : 'express:dev',
720 grunt.registerTask('server', function () {
721 grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
722 grunt.task.run(['serve']);
725 grunt.registerTask('test', function (target) {
726 if (target === 'server') {
727 return grunt.task.run([
734 else if (target === 'client') {
735 return grunt.task.run([
747 else if (target === 'e2e') {
748 return grunt.task.run([
762 else grunt.task.run([
768 grunt.registerTask('build', [
788 grunt.registerTask('default', [
794 grunt.registerTask('deploy', [