gruntfile.js 12.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';

var git = require('git-rev');
module.exports = function(grunt) {
    var classPathSep = (process.platform === "win32") ? ';' : ':',
        gitHash = '',
        pkg = grunt.file.readJSON('package.json'),
        distPath = 'dist',
        publicPath = 'public',
28
        libPath = distPath + '/js/libs',
29 30 31 32 33 34 35 36 37 38
        isDashboardDirectory = grunt.file.isDir('public'),
        modulesPath = 'public/';
    if (!isDashboardDirectory) {
        modulesPath = '../public/'
    }

    grunt.initConfig({
        watch: {
            js: {
                files: ['public/**/*.js'],
39
                tasks: ['copy:dist']
40 41 42 43 44 45
            },
            html: {
                files: ['public/**/*.html'],
                tasks: ['copy:dist']
            },
            css: {
46
                files: ['public/**/*.scss', 'public/**/*.css'],
47
                tasks: ['copy:dist', 'sass']
48 49 50 51 52 53 54 55 56 57
            },
            image: {
                files: ['public/**/*.{ico,gif,png}'],
                tasks: ['copy:dist']
            }
        },
        connect: {
            server: {
                options: {
                    port: 9999,
58
                    base: distPath,
59 60 61 62 63 64 65 66 67 68 69 70 71 72
                    // change this to '0.0.0.0' to access the server from outside
                    hostname: '0.0.0.0',
                    middleware: function(connect, options, defaultMiddleware) {
                        var proxy = require('grunt-connect-proxy/lib/utils').proxyRequest;
                        return [
                            // Include the proxy first
                            proxy
                        ].concat(defaultMiddleware);

                    }

                },
                proxies: [{
                    context: '/api', // the context of the data service
73
                    host: '127.0.0.1',
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
                    port: 21000, // the port that the data service is running on
                    ws: true,
                    changeOrigin: false,
                    https: false,
                    xforward: false,
                    //xforward: false
                }],
            },
        },
        devUpdate: {
            main: {
                options: {
                    updateType: 'force'
                }
            }
        },
        compress: {
            release: {
                options: {
                    archive: function() {
                        return [pkg.name, pkg.version, gitHash].join('_') + '.tgz';
                    }
                },
                src: ['node_modules/**', 'package.json', 'server.js', 'server/**', 'public/**', '!public/js/**', '!public/modules/**/*.js']
            }
        },
        npmcopy: {
            // Javascript 
            js: {
                options: {
                    destPrefix: libPath
                },
                files: {
                    'jquery/js': 'jquery/dist/jquery.min.js',
                    'requirejs': 'requirejs/require.js',
                    'requirejs-text': 'requirejs-text/text.js',
                    'underscore': 'underscore/underscore-min.js',
                    'bootstrap/js': 'bootstrap/dist/js/bootstrap.min.js',
                    'backbone': 'backbone/backbone-min.js',
                    'backbone-babysitter': 'backbone.babysitter/lib/backbone.babysitter.min.js',
                    'backbone-marionette': 'backbone.marionette/lib/backbone.marionette.min.js',
                    'backbone-paginator': 'backbone.paginator/lib/backbone.paginator.min.js',
                    'backbone-wreqr': 'backbone.wreqr/lib/backbone.wreqr.min.js',
                    'backgrid/js': 'backgrid/lib/backgrid.js',
                    'backgrid-filter/js': 'backgrid-filter/backgrid-filter.min.js',
                    'backgrid-orderable-columns/js': 'backgrid-orderable-columns/backgrid-orderable-columns.js',
                    'backgrid-paginator/js': 'backgrid-paginator/backgrid-paginator.min.js',
                    'backgrid-sizeable-columns/js': 'backgrid-sizeable-columns/backgrid-sizeable-columns.js',
122
                    'backgrid-columnmanager/js': 'backgrid-columnmanager/src/Backgrid.ColumnManager.js',
123 124 125
                    'jquery-asBreadcrumbs/js': 'jquery-asBreadcrumbs/dist/jquery-asBreadcrumbs.min.js',
                    'd3': 'd3/d3.min.js',
                    'd3/': 'd3-tip/index.js',
126
                    'dagre-d3': 'dagre-d3/dist/dagre-d3.min.js',
127
                    'select2': 'select2/dist/js/select2.full.min.js',
128 129 130
                    'backgrid-select-all': 'backgrid-select-all/backgrid-select-all.min.js',
                    'moment/js': 'moment/min/moment.min.js',
                    'jquery-placeholder/js': 'jquery-placeholder/jquery.placeholder.js',
131 132
                    'platform': 'platform/platform.js',
                    'jQueryQueryBuilder/js': 'jQuery-QueryBuilder/dist/js/query-builder.standalone.min.js',
133 134 135
                    'bootstrap-daterangepicker/js': 'bootstrap-daterangepicker/daterangepicker.js',
                    'nvd3': 'nvd3/build/nv.d3.min.js',
                    'sparkline': 'jquery-sparkline/jquery.sparkline.min.js'
136 137 138 139 140 141 142 143
                }
            },
            css: {
                options: {
                    destPrefix: libPath
                },
                files: {
                    'bootstrap/css': 'bootstrap/dist/css/bootstrap.min.css',
144
                    'bootstrap/fonts': 'bootstrap/fonts/glyphicons-halflings-regular.woff2',
145 146 147 148 149
                    'backgrid/css': 'backgrid/lib/backgrid.css',
                    'backgrid-filter/css': 'backgrid-filter/backgrid-filter.min.css',
                    'backgrid-orderable-columns/css': 'backgrid-orderable-columns/backgrid-orderable-columns.css',
                    'backgrid-paginator/css': 'backgrid-paginator/backgrid-paginator.css',
                    'backgrid-sizeable-columns/css': 'backgrid-sizeable-columns/backgrid-sizeable-columns.css',
150
                    'backgrid-columnmanager/css': 'backgrid-columnmanager/lib/Backgrid.ColumnManager.css',
151
                    'jquery-asBreadcrumbs/css': 'jquery-asBreadcrumbs/dist/css/asBreadcrumbs.min.css',
152
                    'select2/css': 'select2/dist/css/select2.min.css',
153 154
                    'backgrid-select-all': 'backgrid-select-all/backgrid-select-all.min.css',
                    'font-awesome/css': 'font-awesome/css/font-awesome.min.css',
155 156
                    'font-awesome/fonts': 'font-awesome/fonts',
                    'jQueryQueryBuilder/css': 'jQuery-QueryBuilder/dist/css/query-builder.default.min.css',
157 158
                    'bootstrap-daterangepicker/css': 'bootstrap-daterangepicker/daterangepicker.css',
                    'nvd3/css': 'nvd3/build/nv.d3.min.css'
159 160
                }

161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
            },
            license: {
                options: {
                    destPrefix: libPath
                },
                files: {
                    'jquery': 'jquery/LICENSE.txt',
                    'requirejs-text': 'requirejs-text/LICENSE',
                    'underscore': 'underscore/LICENSE',
                    'bootstrap': 'bootstrap/LICENSE',
                    'backbone-babysitter': 'backbone.babysitter/LICENSE.md',
                    'backbone-marionette': 'backbone.marionette/license.txt',
                    'backbone-paginator': 'backbone.paginator/LICENSE-MIT',
                    'backbone-wreqr': 'backbone.wreqr/LICENSE.md',
                    'backgrid': 'backgrid/LICENSE-MIT',
                    'backgrid-filter': 'backgrid-filter/LICENSE-MIT',
                    'backgrid-orderable-columns': 'backgrid-orderable-columns/LICENSE-MIT',
                    'backgrid-paginator': 'backgrid-paginator/LICENSE-MIT',
                    'backgrid-sizeable-columns': 'backgrid-sizeable-columns/LICENSE-MIT',
180
                    'backgrid-columnmanager': 'backgrid-columnmanager/LICENSE',
181
                    'jquery-asBreadcrumbs': 'jquery-asBreadcrumbs/LICENSE',
182 183 184
                    'd3': 'd3/LICENSE',
                    'd3/': 'd3-tip/LICENSE',
                    'dagre-d3': 'dagre-d3/LICENSE',
185 186
                    'backgrid-select-all': 'backgrid-select-all/LICENSE-MIT',
                    'jquery-placeholder': 'jquery-placeholder/LICENSE.txt',
187
                    'platform/': 'platform/LICENSE',
188 189
                    'jQueryQueryBuilder/': 'jQuery-QueryBuilder/LICENSE',
                    'nvd3/': 'nvd3/LICENSE.md'
190
                }
191 192
            }
        },
193 194
        sass: {
            dist: {
195 196 197 198 199
                files: {
                    'dist/css/style.css': 'public/css/scss/style.scss'
                }
            },
            build: {
200 201 202 203 204
                files: {
                    'dist/css/style.css': 'dist/css/scss/style.scss'
                }
            }
        },
205 206 207 208
        copy: {
            dist: {
                expand: true,
                cwd: modulesPath,
209 210 211 212 213 214 215
                src: ['**', '!**/scss/**'],
                dest: distPath
            },
            build: {
                expand: true,
                cwd: modulesPath,
                src: ['**'],
216 217 218 219 220 221 222 223
                dest: distPath
            }
        },
        clean: {
            build: [distPath, libPath],
            options: {
                force: true
            }
224 225 226
        },
        uglify: {
            build: {
227 228 229
                options: {
                    sourceMap: true
                },
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
                files: [{
                    expand: true,
                    cwd: 'dist/js',
                    src: '**/*.js',
                    dest: 'dist/js'
                }]
            }
        },
        cssmin: {
            build: {
                files: [{
                    expand: true,
                    cwd: 'dist/css',
                    src: '*.css',
                    dest: 'dist/css'
                }]
            }

        },
        htmlmin: {
            build: {
                options: {
                    removeComments: true,
                    collapseWhitespace: true
                },
                files: [{
                    expand: true,
                    cwd: 'dist/js/templates',
                    src: '**/*.html',
                    dest: 'dist/js/templates'
                }]
            }
262 263 264 265 266
        }
    });

    grunt.loadNpmTasks('grunt-connect-proxy');
    grunt.loadNpmTasks('grunt-contrib-connect');
267
    grunt.loadNpmTasks('grunt-contrib-watch');
268
    grunt.loadNpmTasks('grunt-npmcopy');
269 270 271
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-htmlmin');
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286

    require('load-grunt-tasks')(grunt);

    grunt.registerTask('default', [
        'devUpdate',
        'npmcopy:js',
        'npmcopy:css'
    ]);

    grunt.registerTask('server', ['clean', 'copy:dist', 'concurrent', 'watch']);

    grunt.registerTask('dev', [
        'clean',
        'npmcopy:js',
        'npmcopy:css',
287
        'npmcopy:license',
288
        'copy:dist',
289
        'sass:dist',
290 291
        'configureProxies:server',
        'connect:server',
292
        'watch'
293 294 295
    ]);

    grunt.registerTask('build', [
296 297 298 299 300 301 302 303 304 305
        'clean',
        'npmcopy:js',
        'npmcopy:css',
        'npmcopy:license',
        'copy:build',
        'sass:build'
    ]);

    grunt.registerTask('dev-minify', [
        'clean',
306 307
        'npmcopy:js',
        'npmcopy:css',
308
        'npmcopy:license',
309
        'copy:dist',
310 311 312 313 314 315
        'sass:dist',
        'uglify:build',
        'cssmin:build',
        'configureProxies:server',
        'connect:server',
        'watch'
316 317
    ]);

318 319 320 321 322 323 324 325
    grunt.registerTask('build-minify', [
        'clean',
        'npmcopy:js',
        'npmcopy:css',
        'npmcopy:license',
        'copy:build',
        'sass:build',
        'uglify:build',
326
        'cssmin:build'
327
    ]);
328
};