source: Dev/trunk/Gruntfile.js @ 481

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

Auto-manage svn ignores for generated files.

File size: 5.2 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']);
[474]11    grunt.registerTask('compile', ['svn-ignore:compile'
12                                  ,'jshint:lint-sources'
[469]13                                  ,'htmlhint:lint'
14                                  ,'coffeelint:lint'
15                                  ,'less:compile'
16                                  ,'usebanner:generated-css'
17                                  ,'coffee:compile'
18                                  ,'usebanner:generated-js'
19                                  ,'jshint:lint-generated'
[474]20                                //,'amd-check' // too smart about plugins, r.js can't find them
[469]21                                  ]);
22    grunt.registerTask('build', ['clean:build'
23                                ,'copy:build'
24                                ,'dojo:build'
25                                ]);
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',
[471]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        },
[474]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        },
[469]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) }}
[443]116        }
117    });
118
[469]119    // LOAD TASKS
120
121    grunt.loadNpmTasks('grunt-amd-check');
122    grunt.loadNpmTasks('grunt-banner');
[466]123    grunt.loadNpmTasks('grunt-coffeelint');
[458]124    grunt.loadNpmTasks('grunt-contrib-clean');
[463]125    grunt.loadNpmTasks('grunt-contrib-coffee');
[453]126    grunt.loadNpmTasks('grunt-contrib-copy');
127    grunt.loadNpmTasks('grunt-contrib-jshint');
[443]128    grunt.loadNpmTasks('grunt-contrib-less');
[453]129    grunt.loadNpmTasks('grunt-dojo');
[443]130    grunt.loadNpmTasks('grunt-htmlhint');
[469]131    grunt.loadTasks('./grunt-tasks');
[443]132
[469]133    // UTIL FUNCTIONS
[464]134
[469]135    function dest(files) {
136        return _.chain(files)
137            .map(function(item){ return item.dest; })
138            .flatten()
139            .value();
140    }
[464]141
[469]142    function exclude(dest) {
143        return _.map(dest, function(dest){ return '!'+dest; });
144    }
145   
[443]146};
Note: See TracBrowser for help on using the repository browser.