source: Dev/trunk/Gruntfile.js @ 517

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

Deployment and database management now done through Grunt. Look mom, no shell\!

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