gruntfile.js 6.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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.
 */

19 20
'use strict';

21 22
var git = require('git-rev');

23
module.exports = function(grunt) {
24 25
    var classPathSep = (process.platform === "win32") ? ';' : ':',
        gitHash = '',
26
        pkg = grunt.file.readJSON('package.json'),
27 28 29 30 31
        distPath = 'dist',
        isDashboardDirectory = grunt.file.isDir('public'),
        modulesPath = 'public/';
    if (!isDashboardDirectory)
        modulesPath = '../public/'
32

33 34 35
    grunt.initConfig({
        watch: {
            options: {
36
                livereload: 35729
37 38
            },
            js: {
39
                files: ['public/**/*.js', '!public/lib/**', '!public/dist/**', '!public/js/app.min.js'],
40
                tasks: ['shell']
41 42
            },
            html: {
sanjay-patel-1991 committed
43 44
                files: ['public/**/*.html'],
                tasks: ['copy:dist']
45 46
            },
            css: {
sanjay-patel-1991 committed
47 48 49 50 51 52
                files: ['public/**/*.css'],
                tasks: ['copy:dist']
            },
            image: {
                files: ['public/**/*.{ico,gif,png}'],
                tasks: ['copy:dist']
53 54 55 56
            }
        },
        jshint: {
            all: {
57
                src: ['gruntfile.js', 'package.json', 'server.js', 'server/**/*.js', 'public/**/*.js', '!public/lib/**', '!public/dist/**', '!public/**/app.min.js'],
58 59 60 61 62 63
                options: {
                    jshintrc: true
                }
            }
        },
        concurrent: {
64
            tasks: ['watch', 'proxitserver'],
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
            options: {
                logConcurrentOutput: true
            }
        },
        jsbeautifier: {
            'default': {
                src: ['<%= jshint.all.src %>', 'bower.json'],
                options: {
                    js: {
                        preserveNewlines: true,
                        maxPreserveNewlines: 2
                    }
                }
            },
            'build': {
                src: '<%= jsbeautifier.default.src %>',
                options: {
                    mode: 'VERIFY_ONLY',
                    js: '<%= jsbeautifier.default.options.js%>'
                }
            }
        },
        bower: {
            install: {
                options: {
90 91
                    verbose: true,
                    targetDir: '.bower-components'
92 93
                }
            }
94
        },
95
        dist: distPath + '/js/app.min.js',
96
        modules: grunt.file.expand(
97
            modulesPath + 'js/app.js',
98
            modulesPath + 'js/config.js',
99 100 101 102
            modulesPath + 'js/routes.js',
            modulesPath + 'modules/**/*Module.js',
            modulesPath + 'modules/**/*.js',
            modulesPath + 'js/init.js'
103 104 105 106
        ).join(' '),
        shell: {
            min: {
                command: 'java ' +
107 108
                    '-cp ' + distPath + '/lib/closure-compiler/compiler.jar' + classPathSep +
                    '' + distPath + '/lib/ng-closure-runner/ngcompiler.jar ' +
109 110
                    'org.angularjs.closurerunner.NgClosureRunner ' +
                    '--compilation_level SIMPLE_OPTIMIZATIONS ' +
111
                    //'--formatting PRETTY_PRINT ' +
112 113 114 115 116
                    '--language_in ECMASCRIPT5_STRICT ' +
                    '--angular_pass ' +
                    '--manage_closure_dependencies ' +
                    '--js <%= modules %> ' +
                    '--js_output_file <%= dist %>'
117 118 119 120 121 122 123 124
            }
        },
        devUpdate: {
            main: {
                options: {
                    updateType: 'force'
                }
            }
Vishal Kadam committed
125 126
        },
        compress: {
127
            release: {
Vishal Kadam committed
128
                options: {
129
                    archive: function() {
130 131
                        return [pkg.name, pkg.version, gitHash].join('_') + '.tgz';
                    }
Vishal Kadam committed
132 133 134
                },
                src: ['node_modules/**', 'package.json', 'server.js', 'server/**', 'public/**', '!public/js/**', '!public/modules/**/*.js']
            }
135
        },
136
        copy: {
137 138
            dist: {
                expand: true,
139
                cwd: modulesPath,
140
                src: ['**', '!js/**/*.js', '!modules/**/*.js'],
141 142 143 144
                dest: distPath
            }
        },
        clean: {
145
            build: [distPath],
146
            options: {
147
                force: true
148
            }
149
        },
sanjay-patel-1991 committed
150 151 152
        proxit: {
            dev: {
                options: {
153
                    'port': 3010,
154 155 156 157
                    'verbose': true,
                    'hosts': [{
                        'hostnames': ['*'],
                        'routes': {
158
                            '/': distPath
sanjay-patel-1991 committed
159
                        }
160
                    }]
sanjay-patel-1991 committed
161 162 163
                }
            }
        }
164 165 166
    });

    require('load-grunt-tasks')(grunt);
167
    grunt.registerTask('default', ['devUpdate', 'bower', 'jshint', 'jsbeautifier:default']);
168

169 170
    grunt.registerTask('server', ['jshint', 'clean', 'bower', 'copy:dist', 'minify', 'concurrent']);
    grunt.registerTask('build', ['copy:dist', 'minify']);
171

172
    grunt.registerTask('minify', 'Minify the all js', function() {
173
        var done = this.async();
174 175 176
        grunt.task.run(['shell:min']);
        done();
    });
sanjay-patel-1991 committed
177 178
    grunt.loadNpmTasks('proxit');
    grunt.registerTask('proxitserver', 'Proxit', function() {
179
        var done = this.async();
sanjay-patel-1991 committed
180
        grunt.task.run(['proxit:dev']);
181 182
        done();
    });
183
    grunt.registerTask('release', 'Create release package', function() {
184
        var done = this.async();
185
        git.short(function(str) {
186
            gitHash = str;
187
            grunt.task.run(['minify', 'compress:release']);
188 189 190
            done();
        });
    });
191
};