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
Line 
1/** Gruntfile - control build and deploy tasks
2 */
3
4var _ = require('underscore');
5
6module.exports = function(grunt) {
7
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   
29    var srcDir   = 'src/';
30    var buildDir = 'build/';
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' });
39
40    // TASK CONFIG
41   
42    grunt.initConfig({
43        'amd-check': {
44            files: [ srcDir+'client/qed-client/**/*.js' ]
45        },
46        clean: {
47            build: { src: [buildDir] }
48        },
49        coffee: {
50            options: { bare: true },
51            compile: { files: coffeeMap }
52        },
53        coffeelint: {
54            lint: { options: require('./'+srcDir+'.coffeelint.json'),
55                    files: coffeeMap }
56        },
57        copy: {
58            build: { files: [{ expand: true,
59                               cwd: srcDir,
60                               src: ['**', '!client/*/**' ],
61                               dest: buildDir }]}
62        },
63        dojo: {
64            build: { options: { dojo: srcDir+'client/dojo/dojo.js',
65                                profile: srcDir+'client/client.profile.js',
66                                releaseDir: '../../../'+buildDir }}
67        },
68        htmlhint: {
69            options: { htmlhintrc: srcDir+".htmlhintrc" },
70            lint: { files: [{ expand: true,
71                              cwd: srcDir,
72                              src: ['client/*.html', 'client/qed-client/**/*.html'] }]}
73        },
74        jshint: {
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) }}
79        },
80        less: {
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) }}
101        }
102    });
103
104    // LOAD TASKS
105
106    grunt.loadNpmTasks('grunt-amd-check');
107    grunt.loadNpmTasks('grunt-banner');
108    grunt.loadNpmTasks('grunt-coffeelint');
109    grunt.loadNpmTasks('grunt-contrib-clean');
110    grunt.loadNpmTasks('grunt-contrib-coffee');
111    grunt.loadNpmTasks('grunt-contrib-copy');
112    grunt.loadNpmTasks('grunt-contrib-jshint');
113    grunt.loadNpmTasks('grunt-contrib-less');
114    grunt.loadNpmTasks('grunt-dojo');
115    grunt.loadNpmTasks('grunt-htmlhint');
116    grunt.loadTasks('./grunt-tasks');
117
118    // UTIL FUNCTIONS
119
120    function dest(files) {
121        return _.chain(files)
122            .map(function(item){ return item.dest; })
123            .flatten()
124            .value();
125    }
126
127    function exclude(dest) {
128        return _.map(dest, function(dest){ return '!'+dest; });
129    }
130   
131};
Note: See TracBrowser for help on using the repository browser.