source: Dev/trunk/Gruntfile.js @ 516

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

Enable deployment with Grunt.

File size: 6.6 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'
[516]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                                ]);
[516]29    grunt.registerTask('deploy', ['path-check:deploy',
30                                  'svninfo',
31                                  'build',
32                                  'git_deploy:deploy']);
[469]33
34    // FILES AND FOLDERS
35   
[464]36    var srcDir   = 'src/';
[463]37    var buildDir = 'build/';
[469]38    var coffeeMap = grunt.file.expandMapping(
39        [ 'client/qed-client/**/*.coffee', 'server/**/*.coffee' ],
40        srcDir,
41        { cwd: srcDir, ext: '.js' });
42    var lessMap = grunt.file.expandMapping(
43        [ 'client/qed-client/css/qed.less' ],
44        srcDir,
45        { cwd: srcDir, ext: '.css' });
[453]46
[469]47    // TASK CONFIG
48   
[443]49    grunt.initConfig({
[469]50        'amd-check': {
51            files: [ srcDir+'client/qed-client/**/*.js' ]
52        },
[458]53        clean: {
[469]54            build: { src: [buildDir] }
[458]55        },
[463]56        coffee: {
[469]57            options: { bare: true },
58            compile: { files: coffeeMap }
[453]59        },
[466]60        coffeelint: {
[469]61            lint: { options: require('./'+srcDir+'.coffeelint.json'),
62                    files: coffeeMap }
[466]63        },
[463]64        copy: {
[469]65            build: { files: [{ expand: true,
66                               cwd: srcDir,
67                               src: ['**', '!client/*/**' ],
68                               dest: buildDir }]}
[458]69        },
[453]70        dojo: {
[469]71            build: { options: { dojo: srcDir+'client/dojo/dojo.js',
72                                profile: srcDir+'client/client.profile.js',
[471]73                                releaseDir: '../../'+buildDir }}
[453]74        },
[516]75        git_deploy: {
76            deploy: {
77                options: {
78                    url: 'git@heroku.com:quod-erat.git',
79                    branch: 'master',
80                    message: "Deployment of revision <%= svninfo.rev %> on <%= grunt.template.today() %>."
81                },
82                src: buildDir
83            }
84        },
[453]85        htmlhint: {
[469]86            options: { htmlhintrc: srcDir+".htmlhintrc" },
87            lint: { files: [{ expand: true,
88                              cwd: srcDir,
89                              src: ['client/*.html', 'client/qed-client/**/*.html'] }]}
[443]90        },
91        jshint: {
[469]92            'lint-sources': { options: { jshintrc: srcDir+".jshintrc" },
[505]93                              files: { src: [ srcDir+'client/qed-client/**/*.js', srcDir+'server/**/*.js' ].concat(exclude(dest(coffeeMap))) } },
[469]94            'lint-generated': { options: { jshintrc: srcDir+".jshintrc-generated" },
[505]95                                files: { src: dest(coffeeMap) } }
[443]96        },
[505]97        jsonlint: {
[516]98            'lint': { files: { src: [ srcDir+'client/qed-client/**/*.json', srcDir+'server/**/*.json' ] } }
[505]99        },
[453]100        less: {
[469]101            options: { strictImports: false,
102                       dumpLineNumbers: "all" },
103            compile: { files: lessMap }
104        },
[516]105        'path-check': {
106            'deploy': {
107                src: [ 'git', 'svn' ]
108            }
109        },
[469]110        requirejs: {
111            basePath: srcDir+'client/',
112            packages: [
113                { name: "dojo", location: "dojo" },
114                { name: "dijit", location: "dijit" },
115                { name: "dojox", location: "dojox" },
116                { name: "qed-client", location: "qed-client" }
117            ]
118        },
[474]119        'svn-ignore': {
120            compile: {
121                files: { src: dest(coffeeMap).concat(dest(lessMap)) }
122            }
123        },
124        'svn-ignore-clean': {
125            clean: {
126                files: [{
127                    expand: true,
128                    cwd: srcDir,
129                    src: ['**', '!node_modules/**', '!client/dojo/**', '!client/dijit/**', '!client/dojox/**', '!client/util/**'],
130                    filter: 'isDirectory'
131                }]
132            }
133        },
[487]134        tv4: {
135            lint: {
136                options: {
137                    root: grunt.file.readJSON('json-schema-draft-04.json'),
138                    multi: true
139                },
140                src: [srcDir+'server/config/couchdb-schema.json']
141            }
142        },
[469]143        usebanner: {
144            'generated-css': { options: { position: 'top',
145                                          banner: '/* This CSS file is generated. All edits will be lost on recompile. */'},
146                               files: { src: dest(lessMap) }},
147            'generated-js': { options: { position: 'top',
148                                         banner: '/* This JS file is generated, All edits will be lost on recompile. */'},
149                               files: { src: dest(coffeeMap) }}
[443]150        }
151    });
152
[469]153    // LOAD TASKS
154
155    grunt.loadNpmTasks('grunt-amd-check');
156    grunt.loadNpmTasks('grunt-banner');
[466]157    grunt.loadNpmTasks('grunt-coffeelint');
[458]158    grunt.loadNpmTasks('grunt-contrib-clean');
[463]159    grunt.loadNpmTasks('grunt-contrib-coffee');
[453]160    grunt.loadNpmTasks('grunt-contrib-copy');
161    grunt.loadNpmTasks('grunt-contrib-jshint');
[443]162    grunt.loadNpmTasks('grunt-contrib-less');
[453]163    grunt.loadNpmTasks('grunt-dojo');
[516]164    grunt.loadNpmTasks('grunt-git-deploy');
[443]165    grunt.loadNpmTasks('grunt-htmlhint');
[505]166    grunt.loadNpmTasks('grunt-jsonlint');
[516]167    grunt.loadNpmTasks('grunt-path-check');
168    grunt.loadNpmTasks('grunt-svninfo');
[487]169    grunt.loadNpmTasks('grunt-tv4');
[469]170    grunt.loadTasks('./grunt-tasks');
[443]171
[469]172    // UTIL FUNCTIONS
[464]173
[469]174    function dest(files) {
175        return _.chain(files)
176            .map(function(item){ return item.dest; })
177            .flatten()
178            .value();
179    }
[464]180
[469]181    function exclude(dest) {
182        return _.map(dest, function(dest){ return '!'+dest; });
183    }
184   
[443]185};
Note: See TracBrowser for help on using the repository browser.