source: Dev/trunk/Gruntfile.js @ 469

Last change on this file since 469 was 469, checked in by hendrikvanantwerpen, 12 years ago

Speed-up build process.

Dropped the development build for generating files in the source
tree. This is a bit more messy, since these files will be checked in
as well. Teh extra copy to build/development was very slow though and
annoying when rapid test cycles were needed. A copy-on-newer function
did not improve much, traversing in Node/grunt seems to take time.

File size: 4.7 KB
RevLine 
[464]1/** Gruntfile - control build and deploy tasks
[453]2 */
[443]3
[469]4var _ = require('underscore');
5
[443]6module.exports = function(grunt) {
7
[469]8    // TASKS
9
10    grunt.registerTask('default', ['compile']);
11    grunt.registerTask('compile', ['jshint:lint-sources'
12                                  ,'htmlhint:lint'
13                                  ,'coffeelint:lint'
14                                  ,'less:compile'
15                                  ,'usebanner:generated-css'
16                                  ,'coffee:compile'
17                                  ,'usebanner:generated-js'
18                                  ,'jshint:lint-generated'
19                                  //,'amd-check' // too smart about plugins, r.js can't find them
20                                  ]);
21    grunt.registerTask('build', ['clean:build'
22                                ,'copy:build'
23                                ,'dojo:build'
24                                ]);
25    grunt.registerTask('deploy', []);
26
27    // FILES AND FOLDERS
28   
[464]29    var srcDir   = 'src/';
[463]30    var buildDir = 'build/';
[469]31    var coffeeMap = grunt.file.expandMapping(
32        [ 'client/qed-client/**/*.coffee', 'server/**/*.coffee' ],
33        srcDir,
34        { cwd: srcDir, ext: '.js' });
35    var lessMap = grunt.file.expandMapping(
36        [ 'client/qed-client/css/qed.less' ],
37        srcDir,
38        { cwd: srcDir, ext: '.css' });
[453]39
[469]40    // TASK CONFIG
41   
[443]42    grunt.initConfig({
[469]43        'amd-check': {
44            files: [ srcDir+'client/qed-client/**/*.js' ]
45        },
[458]46        clean: {
[469]47            build: { src: [buildDir] }
[458]48        },
[463]49        coffee: {
[469]50            options: { bare: true },
51            compile: { files: coffeeMap }
[453]52        },
[466]53        coffeelint: {
[469]54            lint: { options: require('./'+srcDir+'.coffeelint.json'),
55                    files: coffeeMap }
[466]56        },
[463]57        copy: {
[469]58            build: { files: [{ expand: true,
59                               cwd: srcDir,
60                               src: ['**', '!client/*/**' ],
61                               dest: buildDir }]}
[458]62        },
[453]63        dojo: {
[469]64            build: { options: { dojo: srcDir+'client/dojo/dojo.js',
65                                profile: srcDir+'client/client.profile.js',
66                                releaseDir: '../../../'+buildDir }}
[453]67        },
68        htmlhint: {
[469]69            options: { htmlhintrc: srcDir+".htmlhintrc" },
70            lint: { files: [{ expand: true,
71                              cwd: srcDir,
72                              src: ['client/*.html', 'client/qed-client/**/*.html'] }]}
[443]73        },
74        jshint: {
[469]75            'lint-sources': { options: { jshintrc: srcDir+".jshintrc" },
76                              files: { src: [ srcDir+'client/qed-client/**/*.js', srcDir+'server/**/*.js' ].concat(exclude(dest(coffeeMap))) }},
77            'lint-generated': { options: { jshintrc: srcDir+".jshintrc-generated" },
78                                files: { src: dest(coffeeMap) }}
[443]79        },
[453]80        less: {
[469]81            options: { strictImports: false,
82                       dumpLineNumbers: "all" },
83            compile: { files: lessMap }
84        },
85        requirejs: {
86            basePath: srcDir+'client/',
87            packages: [
88                { name: "dojo", location: "dojo" },
89                { name: "dijit", location: "dijit" },
90                { name: "dojox", location: "dojox" },
91                { name: "qed-client", location: "qed-client" }
92            ]
93        },
94        usebanner: {
95            'generated-css': { options: { position: 'top',
96                                          banner: '/* This CSS file is generated. All edits will be lost on recompile. */'},
97                               files: { src: dest(lessMap) }},
98            'generated-js': { options: { position: 'top',
99                                         banner: '/* This JS file is generated, All edits will be lost on recompile. */'},
100                               files: { src: dest(coffeeMap) }}
[443]101        }
102    });
103
[469]104    // LOAD TASKS
105
106    grunt.loadNpmTasks('grunt-amd-check');
107    grunt.loadNpmTasks('grunt-banner');
[466]108    grunt.loadNpmTasks('grunt-coffeelint');
[458]109    grunt.loadNpmTasks('grunt-contrib-clean');
[463]110    grunt.loadNpmTasks('grunt-contrib-coffee');
[453]111    grunt.loadNpmTasks('grunt-contrib-copy');
112    grunt.loadNpmTasks('grunt-contrib-jshint');
[443]113    grunt.loadNpmTasks('grunt-contrib-less');
[453]114    grunt.loadNpmTasks('grunt-dojo');
[443]115    grunt.loadNpmTasks('grunt-htmlhint');
[469]116    grunt.loadTasks('./grunt-tasks');
[443]117
[469]118    // UTIL FUNCTIONS
[464]119
[469]120    function dest(files) {
121        return _.chain(files)
122            .map(function(item){ return item.dest; })
123            .flatten()
124            .value();
125    }
[464]126
[469]127    function exclude(dest) {
128        return _.map(dest, function(dest){ return '!'+dest; });
129    }
130   
[443]131};
Note: See TracBrowser for help on using the repository browser.