source: Dev/trunk/Gruntfile.js @ 510

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

Added linting of json files.

File size: 5.8 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'
[505]15                                  ,'jsonlint:lint'
[487]16                                  //,'tv4:lint'
[469]17                                  ,'less:compile'
18                                  ,'usebanner:generated-css'
19                                  ,'coffee:compile'
20                                  ,'usebanner:generated-js'
21                                  ,'jshint:lint-generated'
[474]22                                //,'amd-check' // too smart about plugins, r.js can't find them
[469]23                                  ]);
[487]24    grunt.registerTask('build', ['compile'
25                                ,'clean:build'
[469]26                                ,'copy:build'
27                                ,'dojo:build'
28                                ]);
29
30    // FILES AND FOLDERS
31   
[464]32    var srcDir   = 'src/';
[463]33    var buildDir = 'build/';
[469]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' });
[453]42
[469]43    // TASK CONFIG
44   
[443]45    grunt.initConfig({
[469]46        'amd-check': {
47            files: [ srcDir+'client/qed-client/**/*.js' ]
48        },
[458]49        clean: {
[469]50            build: { src: [buildDir] }
[458]51        },
[463]52        coffee: {
[469]53            options: { bare: true },
54            compile: { files: coffeeMap }
[453]55        },
[466]56        coffeelint: {
[469]57            lint: { options: require('./'+srcDir+'.coffeelint.json'),
58                    files: coffeeMap }
[466]59        },
[463]60        copy: {
[469]61            build: { files: [{ expand: true,
62                               cwd: srcDir,
63                               src: ['**', '!client/*/**' ],
64                               dest: buildDir }]}
[458]65        },
[453]66        dojo: {
[469]67            build: { options: { dojo: srcDir+'client/dojo/dojo.js',
68                                profile: srcDir+'client/client.profile.js',
[471]69                                releaseDir: '../../'+buildDir }}
[453]70        },
71        htmlhint: {
[469]72            options: { htmlhintrc: srcDir+".htmlhintrc" },
73            lint: { files: [{ expand: true,
74                              cwd: srcDir,
75                              src: ['client/*.html', 'client/qed-client/**/*.html'] }]}
[443]76        },
77        jshint: {
[469]78            'lint-sources': { options: { jshintrc: srcDir+".jshintrc" },
[505]79                              files: { src: [ srcDir+'client/qed-client/**/*.js', srcDir+'server/**/*.js' ].concat(exclude(dest(coffeeMap))) } },
[469]80            'lint-generated': { options: { jshintrc: srcDir+".jshintrc-generated" },
[505]81                                files: { src: dest(coffeeMap) } }
[443]82        },
[505]83        jsonlint: {
84            'lint': { files: { src: [ srcDir+'client/qed-client/**/*.json', srcDir+'server/**/*.json' ] } },
85        },
[453]86        less: {
[469]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        },
[474]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        },
[487]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        },
[469]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) }}
[443]131        }
132    });
133
[469]134    // LOAD TASKS
135
136    grunt.loadNpmTasks('grunt-amd-check');
137    grunt.loadNpmTasks('grunt-banner');
[466]138    grunt.loadNpmTasks('grunt-coffeelint');
[458]139    grunt.loadNpmTasks('grunt-contrib-clean');
[463]140    grunt.loadNpmTasks('grunt-contrib-coffee');
[453]141    grunt.loadNpmTasks('grunt-contrib-copy');
142    grunt.loadNpmTasks('grunt-contrib-jshint');
[443]143    grunt.loadNpmTasks('grunt-contrib-less');
[453]144    grunt.loadNpmTasks('grunt-dojo');
[443]145    grunt.loadNpmTasks('grunt-htmlhint');
[505]146    grunt.loadNpmTasks('grunt-jsonlint');
[487]147    grunt.loadNpmTasks('grunt-tv4');
[469]148    grunt.loadTasks('./grunt-tasks');
[443]149
[469]150    // UTIL FUNCTIONS
[464]151
[469]152    function dest(files) {
153        return _.chain(files)
154            .map(function(item){ return item.dest; })
155            .flatten()
156            .value();
157    }
[464]158
[469]159    function exclude(dest) {
160        return _.map(dest, function(dest){ return '!'+dest; });
161    }
162   
[443]163};
Note: See TracBrowser for help on using the repository browser.