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
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    grunt.registerTask('deploy', ['path-check:deploy',
30                                  'svninfo',
31                                  'build',
32                                  'git_deploy:deploy']);
33
34    // FILES AND FOLDERS
35   
36    var srcDir   = 'src/';
37    var buildDir = 'build/';
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' });
46
47    // TASK CONFIG
48   
49    grunt.initConfig({
50        'amd-check': {
51            files: [ srcDir+'client/qed-client/**/*.js' ]
52        },
53        clean: {
54            build: { src: [buildDir] }
55        },
56        coffee: {
57            options: { bare: true },
58            compile: { files: coffeeMap }
59        },
60        coffeelint: {
61            lint: { options: require('./'+srcDir+'.coffeelint.json'),
62                    files: coffeeMap }
63        },
64        copy: {
65            build: { files: [{ expand: true,
66                               cwd: srcDir,
67                               src: ['**', '!client/*/**' ],
68                               dest: buildDir }]}
69        },
70        dojo: {
71            build: { options: { dojo: srcDir+'client/dojo/dojo.js',
72                                profile: srcDir+'client/client.profile.js',
73                                releaseDir: '../../'+buildDir }}
74        },
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        },
85        htmlhint: {
86            options: { htmlhintrc: srcDir+".htmlhintrc" },
87            lint: { files: [{ expand: true,
88                              cwd: srcDir,
89                              src: ['client/*.html', 'client/qed-client/**/*.html'] }]}
90        },
91        jshint: {
92            'lint-sources': { options: { jshintrc: srcDir+".jshintrc" },
93                              files: { src: [ srcDir+'client/qed-client/**/*.js', srcDir+'server/**/*.js' ].concat(exclude(dest(coffeeMap))) } },
94            'lint-generated': { options: { jshintrc: srcDir+".jshintrc-generated" },
95                                files: { src: dest(coffeeMap) } }
96        },
97        jsonlint: {
98            'lint': { files: { src: [ srcDir+'client/qed-client/**/*.json', srcDir+'server/**/*.json' ] } }
99        },
100        less: {
101            options: { strictImports: false,
102                       dumpLineNumbers: "all" },
103            compile: { files: lessMap }
104        },
105        'path-check': {
106            'deploy': {
107                src: [ 'git', 'svn' ]
108            }
109        },
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        },
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        },
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        },
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) }}
150        }
151    });
152
153    // LOAD TASKS
154
155    grunt.loadNpmTasks('grunt-amd-check');
156    grunt.loadNpmTasks('grunt-banner');
157    grunt.loadNpmTasks('grunt-coffeelint');
158    grunt.loadNpmTasks('grunt-contrib-clean');
159    grunt.loadNpmTasks('grunt-contrib-coffee');
160    grunt.loadNpmTasks('grunt-contrib-copy');
161    grunt.loadNpmTasks('grunt-contrib-jshint');
162    grunt.loadNpmTasks('grunt-contrib-less');
163    grunt.loadNpmTasks('grunt-dojo');
164    grunt.loadNpmTasks('grunt-git-deploy');
165    grunt.loadNpmTasks('grunt-htmlhint');
166    grunt.loadNpmTasks('grunt-jsonlint');
167    grunt.loadNpmTasks('grunt-path-check');
168    grunt.loadNpmTasks('grunt-svninfo');
169    grunt.loadNpmTasks('grunt-tv4');
170    grunt.loadTasks('./grunt-tasks');
171
172    // UTIL FUNCTIONS
173
174    function dest(files) {
175        return _.chain(files)
176            .map(function(item){ return item.dest; })
177            .flatten()
178            .value();
179    }
180
181    function exclude(dest) {
182        return _.map(dest, function(dest){ return '!'+dest; });
183    }
184   
185};
Note: See TracBrowser for help on using the repository browser.