tellform/gruntfile.js

355 lines
9.6 KiB
JavaScript
Raw Permalink Normal View History

2015-06-29 22:51:29 +00:00
'use strict';
2017-04-11 07:10:36 +00:00
var bowerArray = ['public/lib/angular/angular.min.js',
'public/lib/angular-scroll/angular-scroll.min.js',
'public/lib/angular-ui-select/dist/select.min.js',
'public/lib/v-button/dist/v-button.min.js',
'public/lib/angular-resource/angular-resource.min.js',
'public/lib/angular-ui-router/release/angular-ui-router.min.js',
'public/lib/angular-bootstrap/ui-bootstrap-tpls.js',
'public/lib/angular-translate/angular-translate.min.js',
'public/lib/ng-file-upload/ng-file-upload-all.min.js',
'public/lib/angular-ui-date/src/date.js',
'public/lib/angular-input-stars/angular-input-stars.js',
'public/lib/jsep/build/jsep.min.js',
'public/lib/raven-js/dist/raven.min.js',
'public/lib/lodash/lodash.min.js',
'public/lib/mobile-detect/mobile-detect.js',
2017-04-11 11:04:48 +00:00
'public/lib/js-yaml/dist/js-yaml.js',
2017-04-11 07:10:36 +00:00
'public/lib/angular-sanitize/angular-sanitize.min.js'];
2016-05-10 06:30:09 +00:00
2015-06-29 22:51:29 +00:00
module.exports = function(grunt) {
2015-12-12 20:08:48 +00:00
require('jit-grunt')(grunt);
2015-06-29 22:51:29 +00:00
// Unified Watch Object
var watchFiles = {
serverViews: ['app/views/**/*.pug'],
2015-06-29 22:51:29 +00:00
serverJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js', '!app/tests/'],
2016-05-05 19:12:40 +00:00
clientViews: ['public/modules/**/*.html', 'public/form_modules/forms/base/**/*.html', '!public/modules/forms/base/**/*.html',],
2017-10-29 15:43:20 +00:00
clientJS: ['public/form_modules/**/*.js', 'public/modules/**/*.js'],
2017-10-11 05:07:13 +00:00
clientCSS: ['public/modules/**/*.css'],
2016-05-05 19:12:40 +00:00
2015-11-23 19:19:02 +00:00
serverTests: ['app/tests/**/*.js'],
2017-10-11 05:07:13 +00:00
clientTests: ['public/modules/**/tests/*.js']
2015-06-29 22:51:29 +00:00
};
2016-05-05 19:12:40 +00:00
watchFiles.allTests = watchFiles.serverTests.concat(watchFiles.clientTests);
2015-06-29 22:51:29 +00:00
// Project Configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
serverViews: {
files: watchFiles.serverViews,
options: {
livereload: true,
spawn: false
2015-06-29 22:51:29 +00:00
}
},
serverJS: {
files: watchFiles.serverJS,
tasks: ['newer:jshint'],
2015-06-29 22:51:29 +00:00
options: {
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: {
livereload: true,
spawn: false
2015-06-29 22:51:29 +00:00
}
},
clientJS: {
files: watchFiles.clientJS,
tasks: ['newer:jshint'],
2015-06-29 22:51:29 +00:00
options: {
livereload: true,
spawn: false
2015-06-29 22:51:29 +00:00
}
},
clientCSS: {
files: watchFiles.clientCSS,
tasks: ['newer:csslint'],
2015-06-29 22:51:29 +00:00
options: {
livereload: true,
spawn: false
2015-06-29 22:51:29 +00:00
}
},
mochaTests: {
2015-11-23 19:19:02 +00:00
files: watchFiles.serverTests,
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: {
2017-04-11 07:10:36 +00:00
productionAdmin: {
2016-05-10 06:30:09 +00:00
options: {
2017-04-11 07:10:36 +00:00
compress: true,
mangled: true
2016-05-10 06:30:09 +00:00
},
files: {
2016-06-20 22:35:41 +00:00
'public/dist/application.min.js': 'public/dist/application.js',
'public/dist/form-application.min.js': 'public/dist/form-application.js'
2016-05-10 06:30:09 +00:00
}
2017-04-11 07:10:36 +00:00
},
productionForms: {
options: {
mangled: true,
compress: true
2017-04-11 07:10:36 +00:00
},
files: {
2017-11-12 03:56:41 +00:00
'public/dist/form-vendor.min.js': bowerArray
2017-04-11 07:10:36 +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)
}
}
},
ngAnnotate: {
2017-10-29 15:43:20 +00:00
options:{
add: true,
remove: true
},
2016-05-10 06:30:09 +00:00
production: {
files: {
2017-11-06 00:05:58 +00:00
'public/dist/application.js': '<%= applicationJavaScriptFiles %>',
'public/dist/form-application.js': '<%= formApplicationJavaScriptFiles %>'
2016-05-05 19:12:40 +00:00
}
}
},
2016-05-01 09:03:55 +00:00
concurrent: {
default: ['nodemon', 'watch'],
2017-10-11 05:07:13 +00:00
debug: ['nodemon', 'watch'],
2016-05-05 19:12:40 +00:00
options: {
2016-05-01 09:03:55 +00:00
logConcurrentOutput: true,
limit: 10
}
2016-04-29 03:07:51 +00:00
},
2016-05-10 06:30:09 +00:00
env: {
2017-10-11 05:25:39 +00:00
src: '.env',
2016-05-10 06:30:09 +00:00
test: {
NODE_ENV: 'test',
2015-06-29 22:51:29 +00:00
},
secure: {
2016-04-12 04:35:28 +00:00
NODE_ENV: 'secure',
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',
},
dev: {
NODE_ENV: 'development',
2016-05-10 06:30:09 +00:00
}
2015-06-29 22:51:29 +00:00
},
mochaTest: {
src: watchFiles.serverTests,
2015-06-29 22:51:29 +00:00
options: {
reporter: 'spec',
quiet: false,
2015-10-06 20:14:38 +00:00
require: 'server.js',
2017-07-29 00:04:16 +00:00
ui: 'bdd',
2017-10-11 05:07:13 +00:00
debug: false
2015-06-29 22:51:29 +00:00
}
},
karma: {
unit: {
2016-04-21 18:59:42 +00:00
configFile: 'karma.conf.js',
singleRun: true
},
debug: {
configFile: 'karma.conf.js',
browserConsoleLogOptions: {
level: 'log',
terminal: true
},
singleRun: true
}
2015-08-18 21:44:36 +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: {
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: {
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: {
2016-05-05 19:12:40 +00:00
base: 'public',
2016-05-10 06:30:09 +00:00
watch: true,
singleModule: true,
useStrict: true,
htmlmin: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true
}
},
2017-03-27 20:32:06 +00:00
forms: {
options: {
module: 'TellForm-Form.form_templates'
2017-03-27 20:32:06 +00:00
},
src: ['public/form_modules/**/views/**.html', 'public/form_modules/**/views/**/*.html'],
dest: 'public/dist/form_populate_template_cache.js'
},
2016-05-10 06:30:09 +00:00
main: {
2017-03-27 20:32:06 +00:00
options: {
module: 'TellForm.templates'
},
src: ['public/modules/**/views/**.html', 'public/modules/**/views/**/*.html', 'public/form_modules/forms/base/**/*.html', '!public/modules/forms/base/**/*.html'],
2016-05-10 06:30:09 +00:00
dest: 'public/dist/populate_template_cache.js'
}
},
execute: {
target: {
src: ['./scripts/setup.js']
}
2017-10-27 19:52:39 +00:00
},
2015-11-23 19:19:02 +00:00
});
2015-11-23 19:19:02 +00:00
grunt.event.on('coverage', function(lcov, done){
var coveralls = require('coveralls');
2017-03-27 20:32:06 +00:00
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
2017-04-23 20:11:30 +00:00
grunt.task.registerTask('loadConfig', 'Task that loads the config into a grunt option.', function() {
2017-04-23 02:46:35 +00:00
require('./config/init')();
2015-06-29 22:51:29 +00:00
var config = require('./config/config');
grunt.config.set('applicationJavaScriptFiles', config.assets.js);
2016-06-20 22:35:41 +00:00
grunt.config.set('formApplicationJavaScriptFiles', config.assets.form_js);
2015-06-29 22:51:29 +00:00
grunt.config.set('applicationCSSFiles', config.assets.css);
2017-04-23 20:11:30 +00:00
});
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']);
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).
2017-11-06 00:05:58 +00:00
grunt.registerTask('default', ['lint', 'loadConfig', 'ngAnnotate', 'uglify', 'html2js:main', 'html2js:forms', 'env', 'concurrent:default']);
grunt.registerTask('dev', ['lint', 'html2js:main', 'html2js:forms', 'env:dev', 'concurrent:default']);
2016-05-10 06:30:09 +00:00
2015-06-29 22:51:29 +00:00
// Debug task.
grunt.registerTask('debug', ['lint', 'html2js:main', 'html2js:forms', 'concurrent:debug']);
2017-11-21 21:35:59 +00:00
2015-06-29 22:51:29 +00:00
// Lint task(s).
grunt.registerTask('lint', ['jshint', 'csslint', 'i18nlint:client', 'i18nlint:server']);
grunt.registerTask('lint:tests', ['jshint:allTests']);
2015-06-29 22:51:29 +00:00
// Build task(s).
grunt.registerTask('build', ['lint', 'loadConfig', 'cssmin', 'ngAnnotate', 'uglify', 'html2js:main', 'html2js:forms']);
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']);
grunt.registerTask('test:client', ['lint:tests', 'html2js:main', 'html2js:forms', 'env:test', 'karma:unit']);
grunt.registerTask('testdebug', ['env:test', 'karma:debug']);
2015-06-29 22:51:29 +00:00
};