source: Dev/trunk/Gruntfile.js @ 477

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

Auto-manage svn ignores for generated files.

File size: 5.2 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', ['svn-ignore:compile'
12                                  ,'jshint:lint-sources'
13                                  ,'htmlhint:lint'
14                                  ,'coffeelint:lint'
15                                  ,'less:compile'
16                                  ,'usebanner:generated-css'
17                                  ,'coffee:compile'
18                                  ,'usebanner:generated-js'
19                                  ,'jshint:lint-generated'
20                                //,'amd-check' // too smart about plugins, r.js can't find them
21                                  ]);
22    grunt.registerTask('build', ['clean:build'
23                                ,'copy:build'
24                                ,'dojo:build'
25                                ]);
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        'svn-ignore': {
95            compile: {
96                files: { src: dest(coffeeMap).concat(dest(lessMap)) }
97            }
98        },
99        'svn-ignore-clean': {
100            clean: {
101                files: [{
102                    expand: true,
103                    cwd: srcDir,
104                    src: ['**', '!node_modules/**', '!client/dojo/**', '!client/dijit/**', '!client/dojox/**', '!client/util/**'],
105                    filter: 'isDirectory'
106                }]
107            }
108        },
109        usebanner: {
110            'generated-css': { options: { position: 'top',
111                                          banner: '/* This CSS file is generated. All edits will be lost on recompile. */'},
112                               files: { src: dest(lessMap) }},
113            'generated-js': { options: { position: 'top',
114                                         banner: '/* This JS file is generated, All edits will be lost on recompile. */'},
115                               files: { src: dest(coffeeMap) }}
116        }
117    });
118
119    // LOAD TASKS
120
121    grunt.loadNpmTasks('grunt-amd-check');
122    grunt.loadNpmTasks('grunt-banner');
123    grunt.loadNpmTasks('grunt-coffeelint');
124    grunt.loadNpmTasks('grunt-contrib-clean');
125    grunt.loadNpmTasks('grunt-contrib-coffee');
126    grunt.loadNpmTasks('grunt-contrib-copy');
127    grunt.loadNpmTasks('grunt-contrib-jshint');
128    grunt.loadNpmTasks('grunt-contrib-less');
129    grunt.loadNpmTasks('grunt-dojo');
130    grunt.loadNpmTasks('grunt-htmlhint');
131    grunt.loadTasks('./grunt-tasks');
132
133    // UTIL FUNCTIONS
134
135    function dest(files) {
136        return _.chain(files)
137            .map(function(item){ return item.dest; })
138            .flatten()
139            .value();
140    }
141
142    function exclude(dest) {
143        return _.map(dest, function(dest){ return '!'+dest; });
144    }
145   
146};
Note: See TracBrowser for help on using the repository browser.