2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
2016-05-10 06:30:09 +00:00
|
|
|
var spawn = require('child_process').spawn;
|
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
module.exports = function(grunt) {
|
2015-12-12 20:08:48 +00:00
|
|
|
require('jit-grunt')(grunt);
|
2016-04-23 15:07:34 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
// Unified Watch Object
|
|
|
|
var watchFiles = {
|
|
|
|
serverViews: ['app/views/**/*.*'],
|
|
|
|
serverJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js', '!app/tests/'],
|
|
|
|
clientViews: ['public/modules/**/views/**/*.html'],
|
2016-05-01 09:03:55 +00:00
|
|
|
clientJS: ['public/js/*.js', 'public/modules/**/*.js', '!public/modules/**/gruntfile.js'],
|
2015-06-29 22:51:29 +00:00
|
|
|
clientCSS: ['public/modules/**/*.css'],
|
2015-11-23 19:19:02 +00:00
|
|
|
serverTests: ['app/tests/**/*.js'],
|
|
|
|
clientTests: ['public/modules/**/tests/*.js'],
|
|
|
|
allTests: ['public/modules/**/tests/*.js', 'app/tests/**/*.js'],
|
2015-06-29 22:51:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Project Configuration
|
|
|
|
grunt.initConfig({
|
|
|
|
pkg: grunt.file.readJSON('package.json'),
|
|
|
|
watch: {
|
|
|
|
serverViews: {
|
|
|
|
files: watchFiles.serverViews,
|
|
|
|
options: {
|
2015-07-03 19:25:02 +00:00
|
|
|
livereload: true,
|
|
|
|
spawn: false
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
serverJS: {
|
|
|
|
files: watchFiles.serverJS,
|
2015-07-03 19:25:02 +00:00
|
|
|
tasks: ['newer:jshint'],
|
2015-06-29 22:51:29 +00:00
|
|
|
options: {
|
2015-07-03 19:25:02 +00:00
|
|
|
livereload: true,
|
|
|
|
spawn: false
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
clientViews: {
|
|
|
|
files: watchFiles.clientViews,
|
2015-11-23 19:19:02 +00:00
|
|
|
tasks: ['html2js:main'],
|
2015-06-29 22:51:29 +00:00
|
|
|
options: {
|
2015-07-03 19:25:02 +00:00
|
|
|
livereload: true,
|
|
|
|
spawn: false
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
clientJS: {
|
|
|
|
files: watchFiles.clientJS,
|
2015-07-03 19:25:02 +00:00
|
|
|
tasks: ['newer:jshint'],
|
2015-06-29 22:51:29 +00:00
|
|
|
options: {
|
2015-07-03 19:25:02 +00:00
|
|
|
livereload: true,
|
|
|
|
spawn: false
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
clientCSS: {
|
|
|
|
files: watchFiles.clientCSS,
|
2015-07-03 19:25:02 +00:00
|
|
|
tasks: ['newer:csslint'],
|
2015-06-29 22:51:29 +00:00
|
|
|
options: {
|
2015-07-03 19:25:02 +00:00
|
|
|
livereload: true,
|
|
|
|
spawn: false
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mochaTests: {
|
2015-11-23 19:19:02 +00:00
|
|
|
files: watchFiles.serverTests,
|
2015-08-12 18:38:12 +00:00
|
|
|
tasks: ['test:server'],
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
jshint: {
|
|
|
|
all: {
|
|
|
|
src: watchFiles.clientJS.concat(watchFiles.serverJS),
|
|
|
|
options: {
|
|
|
|
jshintrc: true
|
|
|
|
}
|
2016-05-10 06:30:09 +00:00
|
|
|
},
|
|
|
|
allTests: {
|
2015-11-23 21:06:02 +00:00
|
|
|
src: watchFiles.allTests,
|
|
|
|
options: {
|
2016-05-10 06:30:09 +00:00
|
|
|
jshintrc: true
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
2016-05-10 06:30:09 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
csslint: {
|
|
|
|
options: {
|
2016-04-29 03:07:51 +00:00
|
|
|
csslintrc: '.csslintrc'
|
2016-05-10 06:30:09 +00:00
|
|
|
},
|
|
|
|
all: {
|
2016-04-29 03:07:51 +00:00
|
|
|
src: watchFiles.clientCSS
|
2016-05-10 06:30:09 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
uglify: {
|
|
|
|
production: {
|
|
|
|
options: {
|
|
|
|
mangle: false
|
|
|
|
},
|
|
|
|
files: {
|
|
|
|
'public/dist/application.min.js': 'public/dist/application.js'
|
|
|
|
}
|
2016-05-01 09:03:55 +00:00
|
|
|
}
|
2016-05-10 06:30:09 +00:00
|
|
|
},
|
|
|
|
cssmin: {
|
|
|
|
combine: {
|
|
|
|
files: {
|
|
|
|
'public/dist/application.min.css': '<%= applicationCSSFiles %>'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
nodemon: {
|
|
|
|
dev: {
|
|
|
|
script: 'server.js',
|
|
|
|
options: {
|
|
|
|
nodeArgs: ['--debug'],
|
|
|
|
ext: 'js,html',
|
|
|
|
watch: watchFiles.serverViews.concat(watchFiles.serverJS)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'node-inspector': {
|
|
|
|
custom: {
|
|
|
|
options: {
|
|
|
|
'web-port': 1337,
|
|
|
|
'web-host': 'localhost',
|
|
|
|
'debug-port': 5858,
|
|
|
|
'save-live-edit': true,
|
|
|
|
'no-preload': true,
|
|
|
|
'stack-trace-limit': 50,
|
|
|
|
'hidden': []
|
|
|
|
}
|
2016-05-01 09:03:55 +00:00
|
|
|
}
|
2016-05-10 06:30:09 +00:00
|
|
|
},
|
|
|
|
ngAnnotate: {
|
|
|
|
production: {
|
|
|
|
files: {
|
|
|
|
'public/dist/application.js': '<%= applicationJavaScriptFiles %>'
|
2016-05-01 09:03:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-05-10 06:30:09 +00:00
|
|
|
concurrent: {
|
2016-04-29 03:07:51 +00:00
|
|
|
default: ['nodemon', 'watch'],
|
2016-05-10 06:30:09 +00:00
|
|
|
debug: ['nodemon', 'watch', 'node-inspector'],
|
2016-05-01 09:03:55 +00:00
|
|
|
options: {
|
2016-05-10 06:30:09 +00:00
|
|
|
logConcurrentOutput: true,
|
2016-05-01 09:03:55 +00:00
|
|
|
limit: 10
|
|
|
|
}
|
2016-04-29 03:07:51 +00:00
|
|
|
},
|
2016-05-10 06:30:09 +00:00
|
|
|
env: {
|
|
|
|
test: {
|
|
|
|
NODE_ENV: 'test',
|
2016-05-01 09:03:55 +00:00
|
|
|
src: '.env'
|
2015-06-29 22:51:29 +00:00
|
|
|
},
|
|
|
|
secure: {
|
2016-04-12 04:35:28 +00:00
|
|
|
NODE_ENV: 'secure',
|
2016-04-29 02:48:02 +00:00
|
|
|
src: '/opt/deploy/.env'
|
2015-07-27 20:33:43 +00:00
|
|
|
},
|
2016-04-12 05:55:10 +00:00
|
|
|
production: {
|
2016-04-29 02:48:02 +00:00
|
|
|
NODE_ENV: 'production',
|
|
|
|
src: '/opt/deploy/.env'
|
|
|
|
},
|
|
|
|
dev: {
|
|
|
|
NODE_ENV: 'development',
|
2016-04-29 07:51:34 +00:00
|
|
|
src: '.env'
|
2016-05-10 06:30:09 +00:00
|
|
|
}
|
2015-06-29 22:51:29 +00:00
|
|
|
},
|
|
|
|
mochaTest: {
|
2015-11-23 20:12:10 +00:00
|
|
|
src: watchFiles.serverTests,
|
2015-06-29 22:51:29 +00:00
|
|
|
options: {
|
|
|
|
reporter: 'spec',
|
2016-04-23 15:07:34 +00:00
|
|
|
quiet: false,
|
2015-10-06 20:14:38 +00:00
|
|
|
require: 'server.js',
|
|
|
|
ui: 'bdd'
|
2015-06-29 22:51:29 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
karma: {
|
|
|
|
unit: {
|
2016-04-21 18:59:42 +00:00
|
|
|
configFile: 'karma.conf.js',
|
|
|
|
singleRun: true
|
|
|
|
}
|
2015-08-18 21:44:36 +00:00
|
|
|
},
|
2015-08-25 21:33:52 +00:00
|
|
|
protractor: {
|
|
|
|
options: {
|
|
|
|
configFile: 'protractor.conf.js',
|
|
|
|
keepAlive: true,
|
|
|
|
noColor: false
|
|
|
|
},
|
|
|
|
e2e: {
|
|
|
|
options: {
|
|
|
|
args: {} // Target-specific arguments
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-11-23 19:19:02 +00:00
|
|
|
mocha_istanbul: {
|
|
|
|
coverage: {
|
|
|
|
src: watchFiles.allTests, // a folder works nicely
|
|
|
|
options: {
|
2015-11-23 20:12:10 +00:00
|
|
|
mask: '*.test.js',
|
2016-04-29 06:30:28 +00:00
|
|
|
require: ['server.js']
|
2015-11-23 19:19:02 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
coverageClient: {
|
|
|
|
src: watchFiles.clientTests, // specifying file patterns works as well
|
|
|
|
options: {
|
|
|
|
coverageFolder: 'coverageClient',
|
|
|
|
mask: '*.test.js',
|
2016-04-29 06:30:28 +00:00
|
|
|
require: ['server.js']
|
2015-11-23 19:19:02 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
coverageServer: {
|
|
|
|
src: watchFiles.serverTests,
|
|
|
|
options: {
|
|
|
|
coverageFolder: 'coverageServer',
|
|
|
|
mask: '*.test.js',
|
2016-04-29 06:30:28 +00:00
|
|
|
require: ['server.js']
|
2015-11-23 19:19:02 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
coveralls: {
|
|
|
|
src: watchFiles.allTests, // multiple folders also works
|
|
|
|
options: {
|
2015-11-23 20:12:10 +00:00
|
|
|
require: ['server.js'],
|
|
|
|
coverage: true, // this will make the grunt.event.on('coverage') event listener to be triggered
|
2015-11-23 19:19:02 +00:00
|
|
|
root: './lib', // define where the cover task should consider the root of libraries that are covered by tests
|
|
|
|
reportFormats: ['cobertura','lcovonly']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
istanbul_check_coverage: {
|
|
|
|
default: {
|
|
|
|
options: {
|
|
|
|
coverageFolder: 'coverage*', // will check both coverage folders and merge the coverage results
|
|
|
|
check: {
|
|
|
|
lines: 80,
|
|
|
|
statements: 80
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-05-10 06:30:09 +00:00
|
|
|
html2js: {
|
|
|
|
options: {
|
|
|
|
base: 'NodeForm',
|
|
|
|
watch: true,
|
|
|
|
module: 'NodeForm.templates',
|
|
|
|
singleModule: true,
|
|
|
|
useStrict: true,
|
|
|
|
htmlmin: {
|
|
|
|
collapseBooleanAttributes: true,
|
|
|
|
collapseWhitespace: true,
|
|
|
|
removeAttributeQuotes: true,
|
|
|
|
removeComments: true,
|
|
|
|
removeEmptyAttributes: true,
|
|
|
|
removeRedundantAttributes: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
main: {
|
|
|
|
src: ['public/modules/**/views/**.html', 'public/modules/**/views/**/*.html'],
|
|
|
|
dest: 'public/dist/populate_template_cache.js'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
execute: {
|
|
|
|
target: {
|
|
|
|
src: ['./scripts/setup.js']
|
|
|
|
}
|
2015-11-23 19:19:02 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
grunt.event.on('coverage', function(lcov, done){
|
2015-11-23 22:00:21 +00:00
|
|
|
var coveralls = require('coveralls');
|
2016-04-24 17:19:31 +00:00
|
|
|
console.log(lcov);
|
|
|
|
coveralls.handleInput(lcov, function(err){
|
2015-11-23 19:19:02 +00:00
|
|
|
if (err) {
|
2016-04-17 02:45:17 +00:00
|
|
|
grunt.log.error('Failed to submit lcov file to coveralls: ' + err);
|
2015-11-23 19:19:02 +00:00
|
|
|
return done(err);
|
|
|
|
}
|
2016-04-17 02:45:17 +00:00
|
|
|
grunt.verbose.ok('Successfully submitted lcov file to coveralls');
|
2015-11-23 19:19:02 +00:00
|
|
|
done();
|
|
|
|
});
|
2015-06-29 22:51:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Making grunt default to force in order not to break the project.
|
|
|
|
grunt.option('force', true);
|
|
|
|
|
|
|
|
// A Task for loading the configuration object
|
|
|
|
grunt.task.registerTask('loadConfig', 'Task that loads the config into a grunt option.', function() {
|
|
|
|
var init = require('./config/init')();
|
|
|
|
var config = require('./config/config');
|
|
|
|
|
|
|
|
grunt.config.set('applicationJavaScriptFiles', config.assets.js);
|
|
|
|
grunt.config.set('applicationCSSFiles', config.assets.css);
|
|
|
|
});
|
2015-11-23 19:19:02 +00:00
|
|
|
|
|
|
|
// Code coverage tasks.
|
2016-04-24 17:19:31 +00:00
|
|
|
grunt.registerTask('coveralls', ['env:test','mocha_istanbul:coveralls']);
|
2015-11-23 20:12:10 +00:00
|
|
|
grunt.registerTask('coverage', ['env:test', 'mocha_istanbul:coverage']);
|
|
|
|
grunt.registerTask('coverage:client', ['env:test', 'mocha_istanbul:coverageClient']);
|
|
|
|
grunt.registerTask('coverage:server', ['env:test', 'mocha_istanbul:coverageServer']);
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
// Default task(s).
|
2016-04-12 05:48:46 +00:00
|
|
|
grunt.registerTask('default', ['lint', 'html2js:main', 'env', 'concurrent:default']);
|
2016-04-29 02:48:02 +00:00
|
|
|
grunt.registerTask('dev', ['lint', 'html2js:main', 'env:dev', 'concurrent:default']);
|
2016-05-10 06:30:09 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
// Debug task.
|
2015-11-23 19:19:02 +00:00
|
|
|
grunt.registerTask('debug', ['lint', 'html2js:main', 'concurrent:debug']);
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2016-05-10 06:30:09 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
// Secure task(s).
|
2015-11-23 19:19:02 +00:00
|
|
|
grunt.registerTask('secure', ['env:secure', 'lint', 'html2js:main', 'concurrent:default']);
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
// Lint task(s).
|
2015-11-23 21:06:02 +00:00
|
|
|
grunt.registerTask('lint', ['jshint', 'csslint']);
|
|
|
|
grunt.registerTask('lint:tests', ['jshint:allTests']);
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
// Build task(s).
|
2016-04-28 23:47:50 +00:00
|
|
|
grunt.registerTask('build', ['lint', 'loadConfig', 'cssmin', 'ngAnnotate', 'uglify', 'html2js:main']);
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2016-05-10 06:30:09 +00:00
|
|
|
//Setup task(s).
|
|
|
|
grunt.registerTask('setup', ['execute']);
|
|
|
|
|
2016-04-24 17:19:31 +00:00
|
|
|
// Test task(s).
|
2015-11-23 21:06:02 +00:00
|
|
|
grunt.registerTask('test', ['lint:tests', 'test:server', 'test:client']);
|
2015-12-12 20:08:48 +00:00
|
|
|
grunt.registerTask('test:server', ['lint:tests', 'env:test', 'mochaTest']);
|
2015-11-23 21:06:02 +00:00
|
|
|
grunt.registerTask('test:client', ['lint:tests', 'html2js:main', 'env:test', 'karma:unit']);
|
2015-06-29 22:51:29 +00:00
|
|
|
};
|