gruntfile.js 15.9 KB
Newer Older
1 2
/*
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements. See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership. The ASF licenses this file
6 7
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
8
 * with the License. You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11 12 13 14 15 16 17 18 19
 *
 * 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';
20
var sass = require('node-sass');
21
module.exports = function(grunt) {
22
    var buildTime = new Date().getTime(),
23 24
        distPath = './dist',
        libPath = distPath + '/js/libs/',
25
        isDashboardDirectory = grunt.file.isDir('public'),
26
        nodeModulePath = './node_modules/',
27 28 29 30 31 32 33 34 35
        modulesPath = 'public/';
    if (!isDashboardDirectory) {
        modulesPath = '../public/'
    }

    grunt.initConfig({
        watch: {
            js: {
                files: ['public/**/*.js'],
36
                tasks: ['copy:build']
37 38 39
            },
            html: {
                files: ['public/**/*.html'],
40
                tasks: ['copy:build']
41 42
            },
            css: {
43
                files: ['public/**/*.scss', 'public/**/*.css'],
44
                tasks: ['copy:build', 'sass']
45 46 47
            },
            image: {
                files: ['public/**/*.{ico,gif,png}'],
48
                tasks: ['copy:build']
49 50 51 52 53 54
            }
        },
        connect: {
            server: {
                options: {
                    port: 9999,
55
                    base: distPath,
56 57
                    // change this to '0.0.0.0' to access the server from outside
                    hostname: '0.0.0.0',
58 59 60
                    middleware: function(connect, options, middlewares) {
                        middlewares.unshift(require('grunt-middleware-proxy/lib/Utils').getProxyMiddleware());
                        return middlewares;
61 62 63 64
                    }
                },
                proxies: [{
                    context: '/api', // the context of the data service
65
                    host: '127.0.0.1',
66
                    auth: "admin:admin",
67
                    port: 21000, // the port that the data service is running on
68
                    https: false
69 70 71 72 73 74
                }],
            },
        },
        npmcopy: {
            js: {
                options: {
75 76
                    destPrefix: libPath,
                    srcPrefix: nodeModulePath
77 78
                },
                files: {
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
                    // FileName : {"src":"dest"}
                    'jquery.min.js': { 'jquery/dist': 'jquery/js' },
                    'require.js': { 'requirejs': 'requirejs' },
                    'text.js': { 'requirejs-text': 'requirejs-text' },
                    'underscore-min.js': { 'underscore': 'underscore' },
                    'bootstrap.min.js': { 'bootstrap/dist/js': 'bootstrap/js' },
                    'backbone-min.js': { 'backbone': 'backbone' },
                    'backbone.babysitter.min.js': { 'backbone.babysitter/lib': 'backbone-babysitter' },
                    'backbone.marionette.min.js': { 'backbone.marionette/lib': 'backbone-marionette' },
                    'backbone.paginator.min.js': { 'backbone.paginator/lib': 'backbone-paginator' },
                    'backbone.wreqr.min.js': { 'backbone.wreqr/lib': 'backbone-wreqr' },
                    'backgrid.js': { 'backgrid/lib': 'backgrid/js' },
                    'backgrid-filter.min.js': { 'backgrid-filter': 'backgrid-filter/js' },
                    'backgrid-orderable-columns.js': { 'backgrid-orderable-columns': 'backgrid-orderable-columns/js' },
                    'backgrid-paginator.min.js': { 'backgrid-paginator': 'backgrid-paginator/js' },
                    'backgrid-sizeable-columns.js': { 'backgrid-sizeable-columns': 'backgrid-sizeable-columns/js' },
                    'Backgrid.ColumnManager.js': { 'backgrid-columnmanager/src': 'backgrid-columnmanager/js' },
                    'jquery-asBreadcrumbs.min.js': { 'jquery-asBreadcrumbs/dist': 'jquery-asBreadcrumbs/js' },
97
                    'd3.min.js': { 'd3/dist': 'd3' },
98 99 100 101 102
                    'index.js': { 'd3-tip': 'd3/' },
                    'dagre-d3.min.js': { 'dagre-d3/dist': 'dagre-d3' },
                    'select2.full.min.js': { 'select2/dist/js': 'select2' },
                    'backgrid-select-all.min.js': { 'backgrid-select-all': 'backgrid-select-all' },
                    'moment.min.js': { 'moment/min': 'moment/js' },
103
                    'moment-timezone-with-data.min.js': { 'moment-timezone/builds': 'moment-timezone' },
104 105 106 107
                    'jquery.placeholder.js': { 'jquery-placeholder': 'jquery-placeholder/js' },
                    'platform.js': { 'platform': 'platform' },
                    'query-builder.standalone.min.js': { 'jQuery-QueryBuilder/dist/js': 'jQueryQueryBuilder/js' },
                    'daterangepicker.js': { 'bootstrap-daterangepicker': 'bootstrap-daterangepicker/js' },
108
                    'jquery.sparkline.min.js': { 'jquery-sparkline': 'sparkline' },
109
                    'table-dragger.js': { 'table-dragger/dist': 'table-dragger' },
110
                    'jstree.min.js': { 'jstree/dist': 'jstree' },
111
                    'jquery.steps.min.js': { 'jquery-steps/build': 'jquery-steps' },
112 113
                    'dropzone-amd-module.js': { 'dropzone/dist': "dropzone/js" },
                    'lossless-json.js': { 'lossless-json/dist': 'lossless-json' }
114
                }
115

116 117 118
            },
            css: {
                options: {
119 120
                    destPrefix: libPath,
                    srcPrefix: nodeModulePath
121 122
                },
                files: {
123 124 125 126 127 128 129 130 131 132 133 134
                    'bootstrap.min.css': { 'bootstrap/dist/css': 'bootstrap/css' },
                    'glyphicons-halflings-regular.woff2': { 'bootstrap/fonts': 'bootstrap/fonts' },
                    'backgrid.css': { 'backgrid/lib': 'backgrid/css' },
                    'backgrid-filter.min.css': { 'backgrid-filter': 'backgrid-filter/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' },
                    'Backgrid.ColumnManager.css': { 'backgrid-columnmanager/lib': 'backgrid-columnmanager/css' },
                    'asBreadcrumbs.min.css': { 'jquery-asBreadcrumbs/dist/css': 'jquery-asBreadcrumbs/css' },
                    'select2.min.css': { 'select2/dist/css': 'select2/css' },
                    'backgrid-select-all.min.css': { 'backgrid-select-all': 'backgrid-select-all' },
                    'font-awesome.min.css': { 'font-awesome/css': 'font-awesome/css' },
135
                    '*': [{
136 137 138 139 140
                        'expand': true,
                        'dot': true,
                        'cwd': nodeModulePath + 'font-awesome',
                        'src': ['fonts/*.*'],
                        'dest': libPath + 'font-awesome/'
141 142 143 144 145 146 147
                    }, {
                        'expand': true,
                        'dot': true,
                        'cwd': nodeModulePath + 'jstree/dist/themes/',
                        'src': ['**'],
                        'dest': libPath + 'jstree/css/'
                    }],
148 149
                    'query-builder.default.min.css': { 'jQuery-QueryBuilder/dist/css': 'jQueryQueryBuilder/css' },
                    'daterangepicker.css': { 'bootstrap-daterangepicker': 'bootstrap-daterangepicker/css' },
150 151
                    'pretty-checkbox.min.css': { 'pretty-checkbox/dist': 'pretty-checkbox/css' },
                    'dropzone.css': { 'dropzone/dist': "dropzone/css" }
152 153
                }

154 155 156
            },
            license: {
                options: {
157 158
                    destPrefix: libPath,
                    srcPrefix: nodeModulePath
159 160
                },
                files: {
161 162 163 164 165 166 167 168 169 170 171 172 173
                    'LICENSE.txt': [
                        { 'jquery': 'jquery' },
                        { 'jquery-placeholder': 'jquery-placeholder' }
                    ],
                    'LICENSE': [{ 'requirejs-text': 'requirejs-text' },
                        { 'underscore': 'underscore' },
                        { 'bootstrap': 'bootstrap' },
                        { 'backgrid-columnmanager': 'backgrid-columnmanager' },
                        { 'jquery-asBreadcrumbs': 'jquery-asBreadcrumbs' },
                        { 'd3': 'd3' },
                        { 'd3-tip': 'd3/' },
                        { 'dagre-d3': 'dagre-d3' },
                        { 'platform': 'platform/' },
174
                        { 'jQuery-QueryBuilder': 'jQueryQueryBuilder/' },
175 176
                        { 'moment-timezone': 'moment-timezone' },
                        { 'pretty-checkbox': 'pretty-checkbox' }
177 178 179
                    ],
                    'LICENSE.md': [{ 'backbone.babysitter': 'backbone-babysitter' },
                        { 'backbone.wreqr': 'backbone-wreqr' },
180
                        { 'lossless-json': 'lossless-json' }
181 182
                    ],
                    'license.txt': [{ 'backbone.marionette': 'backbone-marionette' }],
183
                    'license': [{ 'table-dragger': 'table-dragger' }],
184 185 186 187 188 189 190 191
                    'LICENSE-MIT': [{ 'backbone.paginator': 'backbone-paginator' },
                        { 'backgrid': 'backgrid' },
                        { 'backgrid-filter': 'backgrid-filter' },
                        { 'backgrid-orderable-columns': 'backgrid-orderable-columns' },
                        { 'backgrid-paginator': 'backgrid-paginator' },
                        { 'backgrid-sizeable-columns': 'backgrid-sizeable-columns' },
                        { 'backgrid-select-all': 'backgrid-select-all' }
                    ]
192
                }
193 194
            }
        },
195 196 197
        rename: {
            main: {
                files: [
198 199
                    { src: [libPath + 'jstree/css/default/style.min.css'], dest: libPath + 'jstree/css/default/default-theme.min.css' },
                    { src: [libPath + 'jstree/css/default-dark/style.min.css'], dest: libPath + 'jstree/css/default-dark/default-dark-theme.min.css' },
200 201 202
                ]
            }
        },
203
        sass: {
204 205 206 207
            options: {
                implementation: sass,
                sourceMap: false
            },
208
            build: {
209
                files: {
210
                    [distPath + '/css/style.css']: modulesPath + 'css/scss/style.scss',
211
                    [distPath + '/css/migration-style.css']: modulesPath + 'css/scss/migration-style.scss',
212
                    [distPath + '/css/login.css']: modulesPath + 'css/scss/login.scss'
213 214 215
                }
            }
        },
216
        copy: {
217 218 219
            build: {
                expand: true,
                cwd: modulesPath,
220
                src: ['**', '!**/scss/**', "!**/atlas-lineage/**", "**/atlas-lineage/dist/**", "!index.html.tpl"],
221 222 223 224 225 226 227 228
                dest: distPath
            }
        },
        clean: {
            build: [distPath, libPath],
            options: {
                force: true
            }
229 230
        },
        uglify: {
231 232 233 234 235 236 237 238
            buildlibs: {
                options: {
                    mangle: true,
                    compress: true,
                    beautify: false
                },
                files: [{
                    expand: true,
239
                    cwd: distPath + '/js',
240
                    src: ['external_lib/**/*.js', 'libs/**/*.js'],
241
                    dest: distPath + '/js'
242 243 244
                }]
            },
            buildjs: {
245
                options: {
246 247 248
                    mangle: false,
                    compress: true,
                    beautify: true
249
                },
250 251
                files: [{
                    expand: true,
252
                    cwd: distPath + '/js',
253
                    src: ['**/*.js', '!libs/**', '!external_lib/**'],
254
                    dest: distPath + '/js'
255 256 257 258 259 260 261
                }]
            }
        },
        cssmin: {
            build: {
                files: [{
                    expand: true,
262
                    cwd: distPath + '/css',
263
                    src: '*.css',
264
                    dest: distPath + '/css'
265 266 267 268 269 270 271 272 273 274 275
                }]
            }
        },
        htmlmin: {
            build: {
                options: {
                    removeComments: true,
                    collapseWhitespace: true
                },
                files: [{
                    expand: true,
276
                    cwd: distPath + '/js/templates',
277
                    src: '**/*.html',
278
                    dest: distPath + '/js/templates'
279 280
                }]
            }
281 282 283 284 285 286 287 288 289
        },
        template: {
            build: {
                options: {
                    data: {
                        'bust': buildTime
                    }
                },
                files: {
290 291
                    [distPath + '/index.html']: [modulesPath + 'index.html.tpl'],
                    [distPath + '/migration-status.html']: [modulesPath + 'migration-status.html.tpl']
292 293
                }
            }
294 295 296
        }
    });

297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
    // Dynamically add copy-task using npmcopy
    var npmCopy = grunt.config.get('npmcopy'),
        libFiles = [],
        createPath = function(options) {
            var obj = options.obj,
                fileName = options.fileName,
                pathPrefix = options.pathPrefix;
            if (obj.length) {
                for (var i in obj) {
                    createPath({
                        'obj': obj[i],
                        'libFiles': options.libFiles,
                        'pathPrefix': pathPrefix,
                        'fileName': fileName
                    });
                }
            } else {
314 315 316 317 318 319
                if (fileName == "*") {
                    options.libFiles.push(obj);
                } else {
                    key = Object.keys(obj);
                    options.libFiles.push({ 'src': pathPrefix.srcPrefix + key + "/" + fileName, 'dest': pathPrefix.destPrefix + obj[key] + "/" + fileName });
                }
320 321 322 323 324 325 326
            }
        };

    for (var key in npmCopy) {
        var options = npmCopy[key].options,
            files = npmCopy[key].files;
        for (var fileName in files) {
327 328 329 330 331 332
            createPath({
                'obj': files[fileName],
                'libFiles': libFiles,
                'pathPrefix': options,
                'fileName': fileName
            });
333 334 335 336
        }
    };
    grunt.config.set('copy.libs', { files: libFiles });

337
    grunt.loadNpmTasks('grunt-contrib-connect');
338
    grunt.loadNpmTasks('grunt-middleware-proxy');
339
    grunt.loadNpmTasks('grunt-contrib-watch');
340 341 342
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-htmlmin');
343
    grunt.loadNpmTasks('grunt-template');
344
    grunt.loadNpmTasks('grunt-contrib-rename');
345 346 347 348 349

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

    grunt.registerTask('dev', [
        'clean',
350
        'copy:libs',
351
        'copy:build',
352
        'rename',
353
        'sass:build',
354
        'template',
355
        'setupProxies:server',
356
        'connect:server',
357
        'watch'
358 359 360
    ]);

    grunt.registerTask('build', [
361
        'clean',
362
        'copy:libs',
363
        'copy:build',
364
        'rename',
365 366
        'sass:build',
        'template'
367 368 369 370
    ]);

    grunt.registerTask('dev-minify', [
        'clean',
371
        'copy:libs',
372
        'copy:build',
373
        'rename',
374
        'sass:build',
375 376
        'uglify',
        'cssmin',
377
        'template',
378
        'setupProxies:server',
379 380
        'connect:server',
        'watch'
381 382
    ]);

383 384
    grunt.registerTask('build-minify', [
        'clean',
385
        'copy:libs',
386
        'copy:build',
387
        'rename',
388
        'sass:build',
389 390
        'uglify',
        'cssmin',
391
        'template'
392
    ]);
393
};