source: Dev/trunk/Gruntfile.js @ 518

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

Added descriptions and internal warning to grunt tasks.

File size: 10.2 KB
Line 
1/** Gruntfile - control build and deploy tasks
2 */
3
4var _ = require('underscore');
5
6module.exports = function(grunt) {
7
8    // TASKS
9
10    // default task
11    grunt.registerTask('default', ['compile']);
12    // development
13    grunt.registerTask('compile',
14                       "Lint all sources and compile Coffee and LESS sources.",
15                       ['path-check:svn'
16                       ,'svn-ignore:compile'
17                       ,'jshint:lint-sources'
18                       ,'htmlhint:lint'
19                       ,'coffeelint:lint'
20                       ,'jsonlint:lint'
21                     //,'tv4:lint'
22                       ,'less:compile'
23                       ,'usebanner:generated-css'
24                       ,'coffee:compile'
25                       ,'usebanner:generated-js'
26                       ,'jshint:lint-generated'
27                     //,'amd-check' // too smart about plugins, r.js can't find them
28                       ]);
29    grunt.registerTask('run',
30                       "Compile and start the server locally with foreman.",
31                       ['path-check:foreman'
32                       ,'compile'
33                       ,'foreman:dev']);
34    grunt.registerTask('build',
35                       "Compile and make a Dojo build of the client (compress sources).",
36                       ['compile'
37                       ,'clean:build'
38                       ,'copy:build'
39                       ,'dojo:build'
40                       ]);
41    grunt.registerTask('run-build',
42                       "Make a build and start server from build locally with foreman.",
43                       ['path-check:foreman'
44                       ,'build'
45                       ,'foreman:build']);
46    grunt.registerTask('deploy',
47                       "Make a build and deploy it to Heroku.",
48                       ['path-check:svn'
49                       ,'path-check:git'
50                       ,'svninfo'
51                       ,'build'
52                       ,'git_deploy:deploy']);
53    // database management
54    grunt.registerTask('db-backup-cloud-to-dated-local',
55                       "Backup the Heroku database to a timestamped local database.",
56                       ['path-check:heroku'
57                       ,'heroku-config'
58                       ,'http:db-backup-cloud-to-dated-local']);
59    grunt.registerTask('db-pull-cloud-to-local',
60                       "Synchronize local database with the Heroku database (pull changes).",
61                       ['path-check:heroku'
62                       ,'heroku-config'
63                       ,'http:db-pull-cloud-to-local']);
64    grunt.registerTask('db-push-local-to-cloud',
65                       "Synchronize the Heroku database with the local database (push changes).",
66                       ['path-check:heroku'
67                       ,'heroku-config'
68                       ,'http:db-push-local-to-cloud']);
69    grunt.registerTask('#',
70                       "---\nTASKS BELOW ARE INTERNAL AND SHOULD NOT USUALLY BE CALLED FROM THE COMMAND-LINE\n---",
71                       []);
72
73    // FILES AND FOLDERS
74   
75    var srcDir   = 'src/';
76    var buildDir = 'build/';
77    var coffeeMap = grunt.file.expandMapping(
78        [ 'client/qed-client/**/*.coffee', 'server/**/*.coffee' ],
79        srcDir,
80        { cwd: srcDir, ext: '.js' });
81    var lessMap = grunt.file.expandMapping(
82        [ 'client/qed-client/css/qed.less' ],
83        srcDir,
84        { cwd: srcDir, ext: '.css' });
85
86    // TASK CONFIG
87
88    grunt.initConfig({
89        localDbURL: "http://localhost:5984",
90        timestamp: "<%= grunt.template.today(\"UTC:yyyymmdd't'HHMMss'z'\") %>",
91
92        'amd-check': {
93            files: [ srcDir+'client/qed-client/**/*.js' ]
94        },
95        clean: {
96            build: { src: [buildDir] }
97        },
98        coffee: {
99            options: { bare: true },
100            compile: { files: coffeeMap }
101        },
102        coffeelint: {
103            lint: { options: require('./'+srcDir+'.coffeelint.json'),
104                    files: coffeeMap }
105        },
106        copy: {
107            build: { files: [{ expand: true,
108                               cwd: srcDir,
109                               src: ['**', '!client/*/**' ],
110                               dest: buildDir }]}
111        },
112        dojo: {
113            build: { options: { dojo: srcDir+'client/dojo/dojo.js',
114                                profile: srcDir+'client/client.profile.js',
115                                releaseDir: '../../'+buildDir }}
116        },
117        foreman: {
118            dev: {
119                options: {
120                    cwd: srcDir
121                }
122            },
123            build: {
124                options: {
125                    cwd: buildDir
126                }
127            }
128        },
129        git_deploy: {
130            deploy: {
131                options: {
132                    url: 'git@heroku.com:quod-erat.git',
133                    branch: 'master',
134                    message: "Deployment of revision <%= svninfo.rev %> on <%= grunt.template.today() %>."
135                },
136                src: buildDir
137            }
138        },
139        'heroku-config': {
140            options: {
141                app: 'quod-erat',
142                keys: ['CLOUDANT_URL']
143            }
144        },
145        htmlhint: {
146            options: { htmlhintrc: srcDir+".htmlhintrc" },
147            lint: { files: [{ expand: true,
148                              cwd: srcDir,
149                              src: ['client/*.html', 'client/qed-client/**/*.html'] }]}
150        },
151        http: {
152            'db-backup-cloud-to-dated-local': {
153                options: {
154                    url: "<%= localDbURL %>/_replicate",
155                    method: 'POST',
156                    body: {
157                        source: "<%= herokuConfig.CLOUDANT_URL %>/qed",
158                        target: "qed-<%= timestamp %>",
159                        create_target: true
160                    },
161                    json: true
162                }
163            },
164            'db-pull-cloud-to-local': {
165                options: {
166                    url: "<%= localDbURL %>/_replicate",
167                    method: 'POST',
168                    body: {
169                        source: "<%= herokuConfig.CLOUDANT_URL %>/qed",
170                        target: "qed"
171                    },
172                    json: true
173                }
174            },
175            'db-push-local-to-cloud': {
176                options: {
177                    url: "<%= localDbURL %>/_replicate",
178                    method: 'POST',
179                    body: {
180                        source: "qed",
181                        target: "<%= herokuConfig.CLOUDANT_URL %>/qed"
182                    },
183                    json: true
184                }
185            }
186        },
187        jshint: {
188            'lint-sources': { options: { jshintrc: srcDir+".jshintrc" },
189                              files: { src: [ srcDir+'client/qed-client/**/*.js', srcDir+'server/**/*.js' ].concat(exclude(dest(coffeeMap))) } },
190            'lint-generated': { options: { jshintrc: srcDir+".jshintrc-generated" },
191                                files: { src: dest(coffeeMap) } }
192        },
193        jsonlint: {
194            'lint': { files: { src: [ srcDir+'client/qed-client/**/*.json', srcDir+'server/**/*.json' ] } }
195        },
196        less: {
197            options: { strictImports: false,
198                       dumpLineNumbers: "all" },
199            compile: { files: lessMap }
200        },
201        'path-check': {
202            'heroku': {
203                src: ['heroku']
204            },
205            'foreman': {
206                src: ['foreman']
207            },
208            'svn': {
209                src: ['svn']
210            },
211            'git': {
212                src: ['git']
213            }
214        },
215        requirejs: {
216            basePath: srcDir+'client/',
217            packages: [
218                { name: "dojo", location: "dojo" },
219                { name: "dijit", location: "dijit" },
220                { name: "dojox", location: "dojox" },
221                { name: "qed-client", location: "qed-client" }
222            ]
223        },
224        'svn-ignore': {
225            compile: {
226                files: { src: dest(coffeeMap).concat(dest(lessMap)) }
227            }
228        },
229        'svn-ignore-clean': {
230            clean: {
231                files: [{
232                    expand: true,
233                    cwd: srcDir,
234                    src: ['**', '!node_modules/**', '!client/dojo/**', '!client/dijit/**', '!client/dojox/**', '!client/util/**'],
235                    filter: 'isDirectory'
236                }]
237            }
238        },
239        tv4: {
240            lint: {
241                options: {
242                    root: grunt.file.readJSON('json-schema-draft-04.json'),
243                    multi: true
244                },
245                src: [srcDir+'server/config/couchdb-schema.json']
246            }
247        },
248        usebanner: {
249            'generated-css': { options: { position: 'top',
250                                          banner: '/* This CSS file is generated. All edits will be lost on recompile. */'},
251                               files: { src: dest(lessMap) }},
252            'generated-js': { options: { position: 'top',
253                                         banner: '/* This JS file is generated, All edits will be lost on recompile. */'},
254                               files: { src: dest(coffeeMap) }}
255        }
256    });
257
258    // LOAD TASKS
259
260    grunt.loadNpmTasks('grunt-amd-check');
261    grunt.loadNpmTasks('grunt-banner');
262    grunt.loadNpmTasks('grunt-coffeelint');
263    grunt.loadNpmTasks('grunt-contrib-clean');
264    grunt.loadNpmTasks('grunt-contrib-coffee');
265    grunt.loadNpmTasks('grunt-contrib-copy');
266    grunt.loadNpmTasks('grunt-contrib-jshint');
267    grunt.loadNpmTasks('grunt-contrib-less');
268    grunt.loadNpmTasks('grunt-dojo');
269    grunt.loadNpmTasks('grunt-git-deploy');
270    grunt.loadNpmTasks('grunt-htmlhint');
271    grunt.loadNpmTasks('grunt-http');
272    grunt.loadNpmTasks('grunt-jsonlint');
273    grunt.loadNpmTasks('grunt-path-check');
274    grunt.loadNpmTasks('grunt-svninfo');
275    grunt.loadNpmTasks('grunt-tv4');
276    grunt.loadTasks('./grunt-tasks');
277
278    // UTIL FUNCTIONS
279
280    function dest(files) {
281        return _.chain(files)
282            .map(function(item){ return item.dest; })
283            .flatten()
284            .value();
285    }
286
287    function exclude(dest) {
288        return _.map(dest, function(dest){ return '!'+dest; });
289    }
290   
291};
Note: See TracBrowser for help on using the repository browser.