gruntfile.js 6.35 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 98 99 100 101
            modulesPath + 'js/app.js',
            modulesPath + 'js/routes.js',
            modulesPath + 'modules/**/*Module.js',
            modulesPath + 'modules/**/*.js',
            modulesPath + 'js/init.js'
102 103 104 105
        ).join(' '),
        shell: {
            min: {
                command: 'java ' +
106 107
                    '-cp ' + distPath + '/lib/closure-compiler/compiler.jar' + classPathSep +
                    '' + distPath + '/lib/ng-closure-runner/ngcompiler.jar ' +
108 109
                    'org.angularjs.closurerunner.NgClosureRunner ' +
                    '--compilation_level SIMPLE_OPTIMIZATIONS ' +
110
                    //'--formatting PRETTY_PRINT ' +
111 112 113 114 115
                    '--language_in ECMASCRIPT5_STRICT ' +
                    '--angular_pass ' +
                    '--manage_closure_dependencies ' +
                    '--js <%= modules %> ' +
                    '--js_output_file <%= dist %>'
116 117 118 119 120 121 122 123
            }
        },
        devUpdate: {
            main: {
                options: {
                    updateType: 'force'
                }
            }
Vishal Kadam committed
124 125
        },
        compress: {
126
            release: {
Vishal Kadam committed
127
                options: {
128
                    archive: function() {
129 130
                        return [pkg.name, pkg.version, gitHash].join('_') + '.tgz';
                    }
Vishal Kadam committed
131 132 133
                },
                src: ['node_modules/**', 'package.json', 'server.js', 'server/**', 'public/**', '!public/js/**', '!public/modules/**/*.js']
            }
134
        },
135
        copy: {
136 137
            dist: {
                expand: true,
138
                cwd: modulesPath,
139
                src: ['**', '!js/**/*.js', '!modules/**/*.js'],
140 141 142 143
                dest: distPath
            }
        },
        clean: {
144
            build: [distPath],
145
            options: {
146
                force: true
147
            }
148
        },
sanjay-patel-1991 committed
149 150 151
        proxit: {
            dev: {
                options: {
152
                    'port': 3010,
153 154 155 156
                    'verbose': true,
                    'hosts': [{
                        'hostnames': ['*'],
                        'routes': {
157
                            '/': distPath,
158 159
                            //'/api': 'http://162.249.6.39:21000/api'
                             '/api': 'http://ec2-52-25-142-7.us-west-2.compute.amazonaws.com:21000/api'
sanjay-patel-1991 committed
160
                        }
161
                    }]
sanjay-patel-1991 committed
162 163 164
                }
            }
        }
165 166 167
    });

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

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

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