github.com/sym3tri/etcd@v0.2.1-0.20140422215517-a563d82f95d6/mod/dashboard/Gruntfile.js (about) 1 'use strict'; 2 3 var util = require('util'); 4 5 module.exports = function(grunt) { 6 /*jshint maxstatements:false */ 7 8 require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); 9 10 grunt.initConfig({ 11 12 config: { 13 appName: 'etcd-dashboard', 14 appPath: 'app', 15 bowerPath: 'app/bower_components', 16 tmpPath: '.tmp', 17 distPath: 'dist' 18 }, 19 20 watch: { 21 css: { 22 files: ['<%= config.appPath %>/{page,ui,style}/{**/,}*.scss'], 23 tasks: ['sass'] 24 }, 25 html: { 26 files: [ 27 '<%= config.appPath %>/{module,ui,page}/**/*.html' 28 ], 29 tasks: ['views'] 30 }, 31 js: { 32 files: [ 33 '<%= config.appPath %>/{module,page}/**/*.js', 34 '<%= config.appPath %>/*.js' 35 ], 36 tasks: ['jshint'] 37 } 38 }, 39 40 concurrent: { 41 dev: { 42 tasks: [ 43 'watch', 44 //'test-watch' 45 ], 46 options: { 47 logConcurrentOutput: true 48 } 49 } 50 }, 51 52 clean: { 53 tmp: { 54 files: [{ 55 dot: true, 56 src: [ 57 '<%= config.tmpPath %>', 58 '.sass-cache/**/*' 59 ] 60 }] 61 }, 62 dist: { 63 files: [{ 64 dot: true, 65 src: [ 66 '<%= config.distPath %>/*' 67 ] 68 }] 69 }, 70 'dist-static': { 71 files: [{ 72 dot: true, 73 src: [ 74 '<%= config.distPath %>/cp/**' 75 ] 76 }] 77 }, 78 compiled: { 79 files: [{ 80 dot: true, 81 src: [ 82 '<%= config.appPath %>/compiled/**' 83 ] 84 }] 85 } 86 }, 87 88 // JS code linting. 89 jshint: { 90 options: { 91 camelcase: true, 92 curly: true, 93 eqeqeq: true, 94 eqnull: true, 95 forin: true, 96 freeze: true, 97 immed: true, 98 indent: 2, 99 latedef: true, 100 maxcomplexity: 10, 101 maxdepth: 3, 102 maxlen: 80, 103 maxparams: 20, 104 maxstatements: 200, 105 newcap: true, 106 noarg: true, 107 node: true, 108 noempty: true, 109 nonew: true, 110 nonbsp: true, 111 quotmark: 'single', 112 strict: true, 113 sub: true, 114 trailing: true, 115 undef: true, 116 unused: true 117 }, 118 src: { 119 node: false, 120 options: { 121 globals: { 122 angular: true, 123 window: true 124 } 125 }, 126 files: { 127 src: [ 128 '<%= config.appPath %>/*.js', 129 '<%= config.appPath %>/{module,page}**/*.js', 130 '!<%= config.appPath %>/vega.js' 131 ] 132 } 133 } 134 }, 135 136 // Compile SCSS to CSS. 137 sass: { 138 etcd: { 139 options: { 140 includePaths: ['<%= config.appPath %>/coreos-web/sass'], 141 outputStyle: 'nested' 142 }, 143 files: { 144 '<%= config.appPath %>/compiled/main.css': '<%= config.appPath %>/main.scss' 145 } 146 } 147 }, 148 149 /** 150 * Generate grunt configs for concat, uglify, cssmin. 151 */ 152 useminPrepare: { 153 html: '<%= config.appPath %>/index.html', 154 options: { 155 dest: '<%= config.distPath %>' 156 } 157 }, 158 159 usemin: { 160 html: ['<%= config.distPath %>/index.html'] 161 }, 162 163 // This block gets generated by usemin. 164 cssmin: { 165 }, 166 167 // This block gets generated by usemin. 168 uglify: { 169 }, 170 171 // This block gets generated by usemin. 172 concat: { 173 }, 174 175 // Make our angular code minification friendly. 176 ngmin: { 177 dist: { 178 files: [{ 179 src: '<%= config.tmpPath %>/concat/app.js', 180 dest: '<%= config.tmpPath %>/concat/app.js' 181 }] 182 } 183 }, 184 185 copy: { 186 dist: { 187 files: [{ 188 expand: true, 189 cwd: '<%= config.appPath %>', 190 src: ['index.html'], 191 dest: '<%= config.distPath %>' 192 }] 193 }, 194 images: { 195 files: [{ 196 expand: true, 197 cwd: '<%= config.appPath %>/img', 198 src: ['**'], 199 dest: '<%= config.distPath %>/img' 200 }] 201 }, 202 'coreos-web': { 203 files: [{ 204 cwd: '<%= config.appPath %>/coreos-web', 205 expand: true, 206 src: [ 207 'fonts/*', 208 'img/*' 209 ], 210 dest: '<%= config.distPath %>/coreos-web' 211 }] 212 }, 213 'dist-static': { 214 files: [ 215 { 216 expand: true, 217 flatten: true, 218 src: [ 219 '<%= config.distPath %>/cp/static/*' 220 ], 221 dest: '<%= config.distPath %>' 222 } 223 ] 224 } 225 }, 226 227 // Precompile html views into a single javascript file. 228 html2js: { 229 options: { 230 base: '<%= config.appPath %>', 231 rename: function(moduleName) { 232 return '/' + moduleName; 233 } 234 }, 235 views: { 236 src: [ 237 '<%= config.appPath %>/{page,ui,module}/**/*.html' 238 ], 239 dest: '<%= config.appPath %>/compiled/views.js' 240 } 241 } 242 243 }); 244 245 grunt.registerTask('clean-paths', 'clean up resource paths', function() { 246 grunt.log.writeln('cleaning paths...'); 247 function clean(path) { 248 return path.replace('mod/dashboard/static/', ''); 249 } 250 ['concat', 'uglify', 'cssmin'].forEach(function(task) { 251 var config = grunt.config(task); 252 253 config.generated.files.forEach(function(fileGroup) { 254 fileGroup.dest = clean(fileGroup.dest); 255 fileGroup.src = fileGroup.src.map(function(path) { 256 return clean(path); 257 }); 258 }); 259 grunt.config(task, config); 260 grunt.log.ok(task + ' config is now:'); 261 grunt.log.writeln(util.inspect(grunt.config(task), false, 4, true)); 262 }); 263 }); 264 265 grunt.registerTask('test', [ 266 'views', 267 'karma:unit' 268 ]); 269 270 grunt.registerTask('test-watch', [ 271 'karma:dev' 272 ]); 273 274 grunt.registerTask('views', [ 275 'html2js:views' 276 ]); 277 278 grunt.registerTask('dev', [ 279 'clean', 280 'jshint', 281 'views', 282 'sass', 283 'concurrent:dev' 284 ]); 285 286 grunt.registerTask('build', [ 287 'clean', 288 'jshint', 289 'views', 290 //'test', 291 'sass', 292 'useminPrepare', 293 'clean-paths', 294 'concat', 295 'ngmin:dist', 296 'uglify', 297 'cssmin', 298 'copy:dist', 299 'usemin', 300 'copy:dist-static', 301 'clean:dist-static', 302 'copy:images', 303 'copy:coreos-web' 304 ]); 305 306 grunt.registerTask('default', ['build']); 307 };