/** Gruntfile - control build and deploy tasks */ var _ = require('underscore'); module.exports = function(grunt) { // TASKS grunt.registerTask('default', ['compile']); grunt.registerTask('compile', ['jshint:lint-sources' ,'htmlhint:lint' ,'coffeelint:lint' ,'less:compile' ,'usebanner:generated-css' ,'coffee:compile' ,'usebanner:generated-js' ,'jshint:lint-generated' //,'amd-check' // too smart about plugins, r.js can't find them ]); grunt.registerTask('build', ['clean:build' ,'copy:build' ,'dojo:build' ]); grunt.registerTask('deploy', []); // FILES AND FOLDERS var srcDir = 'src/'; var buildDir = 'build/'; var coffeeMap = grunt.file.expandMapping( [ 'client/qed-client/**/*.coffee', 'server/**/*.coffee' ], srcDir, { cwd: srcDir, ext: '.js' }); var lessMap = grunt.file.expandMapping( [ 'client/qed-client/css/qed.less' ], srcDir, { cwd: srcDir, ext: '.css' }); // TASK CONFIG grunt.initConfig({ 'amd-check': { files: [ srcDir+'client/qed-client/**/*.js' ] }, clean: { build: { src: [buildDir] } }, coffee: { options: { bare: true }, compile: { files: coffeeMap } }, coffeelint: { lint: { options: require('./'+srcDir+'.coffeelint.json'), files: coffeeMap } }, copy: { build: { files: [{ expand: true, cwd: srcDir, src: ['**', '!client/*/**' ], dest: buildDir }]} }, dojo: { build: { options: { dojo: srcDir+'client/dojo/dojo.js', profile: srcDir+'client/client.profile.js', releaseDir: '../../../'+buildDir }} }, htmlhint: { options: { htmlhintrc: srcDir+".htmlhintrc" }, lint: { files: [{ expand: true, cwd: srcDir, src: ['client/*.html', 'client/qed-client/**/*.html'] }]} }, jshint: { 'lint-sources': { options: { jshintrc: srcDir+".jshintrc" }, files: { src: [ srcDir+'client/qed-client/**/*.js', srcDir+'server/**/*.js' ].concat(exclude(dest(coffeeMap))) }}, 'lint-generated': { options: { jshintrc: srcDir+".jshintrc-generated" }, files: { src: dest(coffeeMap) }} }, less: { options: { strictImports: false, dumpLineNumbers: "all" }, compile: { files: lessMap } }, requirejs: { basePath: srcDir+'client/', packages: [ { name: "dojo", location: "dojo" }, { name: "dijit", location: "dijit" }, { name: "dojox", location: "dojox" }, { name: "qed-client", location: "qed-client" } ] }, usebanner: { 'generated-css': { options: { position: 'top', banner: '/* This CSS file is generated. All edits will be lost on recompile. */'}, files: { src: dest(lessMap) }}, 'generated-js': { options: { position: 'top', banner: '/* This JS file is generated, All edits will be lost on recompile. */'}, files: { src: dest(coffeeMap) }} } }); // LOAD TASKS grunt.loadNpmTasks('grunt-amd-check'); grunt.loadNpmTasks('grunt-banner'); grunt.loadNpmTasks('grunt-coffeelint'); grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-contrib-coffee'); grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-less'); grunt.loadNpmTasks('grunt-dojo'); grunt.loadNpmTasks('grunt-htmlhint'); grunt.loadTasks('./grunt-tasks'); // UTIL FUNCTIONS function dest(files) { return _.chain(files) .map(function(item){ return item.dest; }) .flatten() .value(); } function exclude(dest) { return _.map(dest, function(dest){ return '!'+dest; }); } };