|
| 1 | +// Build configurations. |
| 2 | +module.exports = function (grunt) { |
| 3 | + grunt.loadNpmTasks('grunt-karma'); |
| 4 | + grunt.loadNpmTasks('grunt-babel'); |
| 5 | + grunt.loadNpmTasks('grunt-contrib-connect'); |
| 6 | + grunt.loadNpmTasks('grunt-contrib-watch'); |
| 7 | + grunt.loadNpmTasks('grunt-contrib-jshint'); |
| 8 | + grunt.loadNpmTasks('grunt-contrib-concat'); |
| 9 | + grunt.loadNpmTasks('grunt-contrib-uglify'); |
| 10 | + |
| 11 | + grunt.initConfig({ |
| 12 | + packageBower: grunt.file.readJSON('./bower.json'), |
| 13 | + timestamp: (new Date()).toISOString(), |
| 14 | + releaseData: '/*!\n' + |
| 15 | + ' * <%= packageBower.name %>\n' + |
| 16 | + ' * <%= packageBower.homepage %>\n' + |
| 17 | + ' * Version: <%= packageBower.version %> -- <%= timestamp %>\n' + |
| 18 | + ' * License: <%= packageBower.license %>\n' + |
| 19 | + ' */\n', |
| 20 | + connect: { |
| 21 | + app: { |
| 22 | + options: { |
| 23 | + base: './', |
| 24 | + middleware: require('./server/middleware'), |
| 25 | + port: 5001 |
| 26 | + } |
| 27 | + } |
| 28 | + }, |
| 29 | + watch: { |
| 30 | + options: { |
| 31 | + livereload: false |
| 32 | + } |
| 33 | + }, |
| 34 | + karma: { |
| 35 | + unit: { |
| 36 | + options: { |
| 37 | + autoWatch: true, |
| 38 | + colors: true, |
| 39 | + configFile: './test/karma.conf.js', |
| 40 | + keepalive: true, |
| 41 | + port: 8081, |
| 42 | + runnerPort: 9100 |
| 43 | + } |
| 44 | + }, |
| 45 | + travis: { |
| 46 | + options: { |
| 47 | + colors: true, |
| 48 | + configFile: './test/karma.conf.js', |
| 49 | + runnerPort: 9100, |
| 50 | + singleRun: true |
| 51 | + } |
| 52 | + } |
| 53 | + }, |
| 54 | + babel: { |
| 55 | + options: { |
| 56 | + //sourceMap: true, |
| 57 | + babelrc: false, |
| 58 | + presets: ['es2015'] |
| 59 | + }, |
| 60 | + dist: { |
| 61 | + files: [ |
| 62 | + { |
| 63 | + expand: true, |
| 64 | + cwd: 'src/', |
| 65 | + src: ['**/*.js'], |
| 66 | + dest: 'temp/', |
| 67 | + ext: '.js' |
| 68 | + } |
| 69 | + ] |
| 70 | + } |
| 71 | + }, |
| 72 | + concat: { |
| 73 | + options: { |
| 74 | + banner: '<%= releaseData %> \n\n (function () {\n', |
| 75 | + footer: '}());', |
| 76 | + stripBanners: true, |
| 77 | + process: function (src, filepath) { |
| 78 | + var singleQuotes, strings; |
| 79 | + console.log("Processing " + filepath + " ..."); |
| 80 | + strings = /("(?:(?:\\")|[^"])*")/g; |
| 81 | + singleQuotes = /'/g; |
| 82 | + return src.replace(strings, function (match) { |
| 83 | + var result; |
| 84 | + console.log("match: " + match); |
| 85 | + result = "'" + match.substring(1, match.length - 1).replace(singleQuotes, "\\'") + "'"; |
| 86 | + console.log("replaced with: " + result); |
| 87 | + return result; |
| 88 | + }); |
| 89 | + } |
| 90 | + }, |
| 91 | + dynamic_mappings: { |
| 92 | + files: { |
| 93 | + 'dist/ui-scroll.js': ['./temp/**/ui-scroll.js'], |
| 94 | + 'dist/ui-scroll-jqlite.js': ['./temp/**/ui-scroll-jqlite.js'] |
| 95 | + } |
| 96 | + } |
| 97 | + }, |
| 98 | + uglify: { |
| 99 | + options: { |
| 100 | + banner: '<%= releaseData %>' |
| 101 | + }, |
| 102 | + common: { |
| 103 | + files: { |
| 104 | + './dist/ui-scroll.min.js': ['./dist/ui-scroll.js'], |
| 105 | + './dist/ui-scroll-jqlite.min.js': ['./dist/ui-scroll-jqlite.js'] |
| 106 | + } |
| 107 | + } |
| 108 | + }, |
| 109 | + jshint: { |
| 110 | + dist: { |
| 111 | + files: { |
| 112 | + src: [ |
| 113 | + './dist/ui-scroll.js', |
| 114 | + './dist/ui-scroll-jqlite.js' |
| 115 | + ] |
| 116 | + }, |
| 117 | + options: { |
| 118 | + jshintrc: '.jshintrc' |
| 119 | + } |
| 120 | + }, |
| 121 | + src: { |
| 122 | + files: { |
| 123 | + src: [ |
| 124 | + './src/ui-scroll.js', |
| 125 | + './src/ui-scroll-jqlite.js' |
| 126 | + ] |
| 127 | + }, |
| 128 | + options: grunt.util._.extend({}, grunt.file.readJSON('.jshintrc'), grunt.file.readJSON('./src/.jshintrc')) |
| 129 | + }, |
| 130 | + test: { |
| 131 | + files: { |
| 132 | + src: ['./test/*Spec.js'] |
| 133 | + }, |
| 134 | + options: grunt.util._.extend({}, grunt.file.readJSON('.jshintrc'), { |
| 135 | + node: true, |
| 136 | + globals: { |
| 137 | + angular: false, |
| 138 | + inject: false, |
| 139 | + jQuery: false, |
| 140 | + jasmine: false, |
| 141 | + afterEach: false, |
| 142 | + beforeEach: false, |
| 143 | + ddescribe: false, |
| 144 | + describe: false, |
| 145 | + expect: false, |
| 146 | + iit: false, |
| 147 | + it: false, |
| 148 | + spyOn: false, |
| 149 | + xdescribe: false, |
| 150 | + xit: false |
| 151 | + } |
| 152 | + }) |
| 153 | + } |
| 154 | + } |
| 155 | + }); |
| 156 | + |
| 157 | + /** |
| 158 | + * Starts a web server |
| 159 | + * Enter the following command at the command line to execute this task: |
| 160 | + * grunt server |
| 161 | + */ |
| 162 | + grunt.registerTask('server', [ |
| 163 | + 'connect', |
| 164 | + 'watch' |
| 165 | + ]); |
| 166 | + |
| 167 | + grunt.registerTask('default', ['server']); |
| 168 | + |
| 169 | + grunt.registerTask('test', [ |
| 170 | + 'babel', |
| 171 | + 'karma:unit' |
| 172 | + ]); |
| 173 | + |
| 174 | + grunt.registerTask('build', [ |
| 175 | + 'jshint:test', |
| 176 | + 'jshint:src', |
| 177 | + 'babel', |
| 178 | + 'karma:travis', |
| 179 | + 'concat', |
| 180 | + 'uglify:common' |
| 181 | + ]); |
| 182 | + |
| 183 | + grunt.registerTask('travis', [ |
| 184 | + 'babel', |
| 185 | + 'karma:travis' |
| 186 | + ]); |
| 187 | +}; |
0 commit comments