source: Dev/trunk/Gruntfile.js @ 512

Last change on this file since 512 was 505, checked in by hendrikvanantwerpen, 11 years ago

Added linting of json files.

File size: 5.8 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                                  ,'jsonlint:lint'
16                                  //,'tv4:lint'
17                                  ,'less:compile'
18                                  ,'usebanner:generated-css'
19                                  ,'coffee:compile'
20                                  ,'usebanner:generated-js'
21                                  ,'jshint:lint-generated'
22                                //,'amd-check' // too smart about plugins, r.js can't find them
23                                  ]);
24    grunt.registerTask('build', ['compile'
25                                ,'clean:build'
26                                ,'copy:build'
27                                ,'dojo:build'
28                                ]);
29
30    // FILES AND FOLDERS
31   
32    var srcDir   = 'src/';
33    var buildDir = 'build/';
34    var coffeeMap = grunt.file.expandMapping(
35        [ 'client/qed-client/**/*.coffee', 'server/**/*.coffee' ],
36        srcDir,
37        { cwd: srcDir, ext: '.js' });
38    var lessMap = grunt.file.expandMapping(
39        [ 'client/qed-client/css/qed.less' ],
40        srcDir,
41        { cwd: srcDir, ext: '.css' });
42
43    // TASK CONFIG
44   
45    grunt.initConfig({
46        'amd-check': {
47            files: [ srcDir+'client/qed-client/**/*.js' ]
48        },
49        clean: {
50            build: { src: [buildDir] }
51        },
52        coffee: {
53            options: { bare: true },
54            compile: { files: coffeeMap }
55        },
56        coffeelint: {
57            lint: { options: require('./'+srcDir+'.coffeelint.json'),
58                    files: coffeeMap }
59        },
60        copy: {
61            build: { files: [{ expand: true,
62                               cwd: srcDir,
63                               src: ['**', '!client/*/**' ],
64                               dest: buildDir }]}
65        },
66        dojo: {
67            build: { options: { dojo: srcDir+'client/dojo/dojo.js',
68                                profile: srcDir+'client/client.profile.js',
69                                releaseDir: '../../'+buildDir }}
70        },
71        htmlhint: {
72            options: { htmlhintrc: srcDir+".htmlhintrc" },
73            lint: { files: [{ expand: true,
74                              cwd: srcDir,
75                              src: ['client/*.html', 'client/qed-client/**/*.html'] }]}
76        },
77        jshint: {
78            'lint-sources': { options: { jshintrc: srcDir+".jshintrc" },
79                              files: { src: [ srcDir+'client/qed-client/**/*.js', srcDir+'server/**/*.js' ].concat(exclude(dest(coffeeMap))) } },
80            'lint-generated': { options: { jshintrc: srcDir+".jshintrc-generated" },
81                                files: { src: dest(coffeeMap) } }
82        },
83        jsonlint: {
84            'lint': { files: { src: [ srcDir+'client/qed-client/**/*.json', srcDir+'server/**/*.json' ] } },
85        },
86        less: {
87            options: { strictImports: false,
88                       dumpLineNumbers: "all" },
89            compile: { files: lessMap }
90        },
91        requirejs: {
92            basePath: srcDir+'client/',
93            packages: [
94                { name: "dojo", location: "dojo" },
95                { name: "dijit", location: "dijit" },
96                { name: "dojox", location: "dojox" },
97                { name: "qed-client", location: "qed-client" }
98            ]
99        },
100        'svn-ignore': {
101            compile: {
102                files: { src: dest(coffeeMap).concat(dest(lessMap)) }
103            }
104        },
105        'svn-ignore-clean': {
106            clean: {
107                files: [{
108                    expand: true,
109                    cwd: srcDir,
110                    src: ['**', '!node_modules/**', '!client/dojo/**', '!client/dijit/**', '!client/dojox/**', '!client/util/**'],
111                    filter: 'isDirectory'
112                }]
113            }
114        },
115        tv4: {
116            lint: {
117                options: {
118                    root: grunt.file.readJSON('json-schema-draft-04.json'),
119                    multi: true
120                },
121                src: [srcDir+'server/config/couchdb-schema.json']
122            }
123        },
124        usebanner: {
125            'generated-css': { options: { position: 'top',
126                                          banner: '/* This CSS file is generated. All edits will be lost on recompile. */'},
127                               files: { src: dest(lessMap) }},
128            'generated-js': { options: { position: 'top',
129                                         banner: '/* This JS file is generated, All edits will be lost on recompile. */'},
130                               files: { src: dest(coffeeMap) }}
131        }
132    });
133
134    // LOAD TASKS
135
136    grunt.loadNpmTasks('grunt-amd-check');
137    grunt.loadNpmTasks('grunt-banner');
138    grunt.loadNpmTasks('grunt-coffeelint');
139    grunt.loadNpmTasks('grunt-contrib-clean');
140    grunt.loadNpmTasks('grunt-contrib-coffee');
141    grunt.loadNpmTasks('grunt-contrib-copy');
142    grunt.loadNpmTasks('grunt-contrib-jshint');
143    grunt.loadNpmTasks('grunt-contrib-less');
144    grunt.loadNpmTasks('grunt-dojo');
145    grunt.loadNpmTasks('grunt-htmlhint');
146    grunt.loadNpmTasks('grunt-jsonlint');
147    grunt.loadNpmTasks('grunt-tv4');
148    grunt.loadTasks('./grunt-tasks');
149
150    // UTIL FUNCTIONS
151
152    function dest(files) {
153        return _.chain(files)
154            .map(function(item){ return item.dest; })
155            .flatten()
156            .value();
157    }
158
159    function exclude(dest) {
160        return _.map(dest, function(dest){ return '!'+dest; });
161    }
162   
163};
Note: See TracBrowser for help on using the repository browser.