| 1 | + | module.exports = function ( grunt ) { |
| 2 | + | |
| 3 | + | /** |
| 4 | + | * Load required Grunt tasks. These are installed based on the versions listed |
| 5 | + | * in `package.json` when you do `npm install` in this directory. |
| 6 | + | */ |
| 7 | + | grunt.loadNpmTasks('grunt-contrib-clean'); |
| 8 | + | grunt.loadNpmTasks('grunt-contrib-copy'); |
| 9 | + | grunt.loadNpmTasks('grunt-html-angular-validate'); |
| 10 | + | grunt.loadNpmTasks('grunt-eslint'); |
| 11 | + | grunt.loadNpmTasks('grunt-lesslint'); |
| 12 | + | grunt.loadNpmTasks('grunt-contrib-concat'); |
| 13 | + | grunt.loadNpmTasks('grunt-contrib-watch'); |
| 14 | + | grunt.loadNpmTasks('grunt-contrib-uglify'); |
| 15 | + | grunt.loadNpmTasks('grunt-contrib-coffee'); |
| 16 | + | grunt.loadNpmTasks('grunt-contrib-less'); |
| 17 | + | grunt.loadNpmTasks('grunt-conventional-changelog'); |
| 18 | + | grunt.loadNpmTasks('grunt-bump'); |
| 19 | + | grunt.loadNpmTasks('grunt-coffeelint'); |
| 20 | + | grunt.loadNpmTasks('grunt-karma'); |
| 21 | + | grunt.loadNpmTasks('grunt-ngmin'); |
| 22 | + | grunt.loadNpmTasks('grunt-html2js'); |
| 23 | + | |
| 24 | + | /** |
| 25 | + | * Load in our build configuration file. |
| 26 | + | */ |
| 27 | + | var userConfig = require( './build.config.js' ); |
| 28 | + | |
| 29 | + | /** |
| 30 | + | * This is the configuration object Grunt uses to give each plugin its |
| 31 | + | * instructions. |
| 32 | + | */ |
| 33 | + | var taskConfig = { |
| 34 | + | /** |
| 35 | + | * We read in our `package.json` file so we can access the package name and |
| 36 | + | * version. It's already there, so we don't repeat ourselves here. |
| 37 | + | */ |
| 38 | + | pkg: grunt.file.readJSON('package.json'), |
| 39 | + | |
| 40 | + | /** |
| 41 | + | * The banner is the comment that is placed at the top of our compiled |
| 42 | + | * source files. It is first processed as a Grunt template, where the `<%=` |
| 43 | + | * pairs are evaluated based on this very configuration object. |
| 44 | + | */ |
| 45 | + | meta: { |
| 46 | + | banner: |
| 47 | + | '/**\n' + |
| 48 | + | ' * <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' + |
| 49 | + | ' * <%= pkg.homepage %>\n' + |
| 50 | + | ' *\n' + |
| 51 | + | ' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' + |
| 52 | + | ' * Licensed <%= pkg.licenses.type %> <<%= pkg.licenses.url %>>\n' + |
| 53 | + | ' */\n' |
| 54 | + | }, |
| 55 | + | |
| 56 | + | /** |
| 57 | + | * Creates a changelog on a new version. |
| 58 | + | */ |
| 59 | + | changelog: { |
| 60 | + | options: { |
| 61 | + | dest: 'CHANGELOG.md', |
| 62 | + | template: 'changelog.tpl' |
| 63 | + | } |
| 64 | + | }, |
| 65 | + | |
| 66 | + | /** |
| 67 | + | * Increments the version number, etc. |
| 68 | + | */ |
| 69 | + | bump: { |
| 70 | + | options: { |
| 71 | + | files: [ |
| 72 | + | 'package.json', |
| 73 | + | 'bower.json' |
| 74 | + | ], |
| 75 | + | commit: false, |
| 76 | + | commitMessage: 'chore(release): v%VERSION%', |
| 77 | + | commitFiles: [ |
| 78 | + | 'package.json', |
| 79 | + | 'client/bower.json' |
| 80 | + | ], |
| 81 | + | createTag: false, |
| 82 | + | tagName: 'v%VERSION%', |
| 83 | + | tagMessage: 'Version %VERSION%', |
| 84 | + | push: false, |
| 85 | + | pushTo: 'origin' |
| 86 | + | } |
| 87 | + | }, |
| 88 | + | |
| 89 | + | /** |
| 90 | + | * The directories to delete when `grunt clean` is executed. |
| 91 | + | */ |
| 92 | + | clean: [ |
| 93 | + | '<%= build_dir %>', |
| 94 | + | '<%= compile_dir %>' |
| 95 | + | ], |
| 96 | + | |
| 97 | + | /** |
| 98 | + | * The `copy` task just copies files from A to B. We use it here to copy |
| 99 | + | * our project assets (images, fonts, etc.) and javascripts into |
| 100 | + | * `build_dir`, and then to copy the assets to `compile_dir`. |
| 101 | + | */ |
| 102 | + | copy: { |
| 103 | + | build_app_assets: { |
| 104 | + | files: [ |
| 105 | + | { |
| 106 | + | src: [ '**' ], |
| 107 | + | dest: '<%= build_dir %>/assets/', |
| 108 | + | cwd: 'src/assets', |
| 109 | + | expand: true |
| 110 | + | } |
| 111 | + | ] |
| 112 | + | }, |
| 113 | + | build_app_fonts: { |
| 114 | + | files: [ |
| 115 | + | { |
| 116 | + | src: [ '<%= app_files.fonts %>' ], |
| 117 | + | dest: '<%= build_dir %>/fonts/', |
| 118 | + | expand: true, |
| 119 | + | flatten: true |
| 120 | + | } |
| 121 | + | ] |
| 122 | + | }, |
| 123 | + | build_vendor_assets: { |
| 124 | + | files: [ |
| 125 | + | { |
| 126 | + | src: [ '<%= vendor_files.assets %>' ], |
| 127 | + | dest: '<%= build_dir %>/assets/', |
| 128 | + | cwd: '.', |
| 129 | + | expand: true, |
| 130 | + | flatten: true |
| 131 | + | } |
| 132 | + | ] |
| 133 | + | }, |
| 134 | + | build_vendor_fonts: { |
| 135 | + | files: [ |
| 136 | + | { |
| 137 | + | src: [ '<%= vendor_files.fonts %>' ], |
| 138 | + | dest: '<%= build_dir %>/fonts/', |
| 139 | + | expand: true, |
| 140 | + | flatten: true |
| 141 | + | } |
| 142 | + | ] |
| 143 | + | }, |
| 144 | + | build_appjs: { |
| 145 | + | files: [ |
| 146 | + | { |
| 147 | + | src: [ '<%= app_files.js %>' ], |
| 148 | + | dest: '<%= build_dir %>/', |
| 149 | + | cwd: '.', |
| 150 | + | expand: true |
| 151 | + | } |
| 152 | + | ] |
| 153 | + | }, |
| 154 | + | build_vendorjs: { |
| 155 | + | files: [ |
| 156 | + | { |
| 157 | + | src: [ '<%= vendor_files.js %>' ], |
| 158 | + | dest: '<%= build_dir %>/', |
| 159 | + | cwd: '.', |
| 160 | + | expand: true |
| 161 | + | } |
| 162 | + | ] |
| 163 | + | }, |
| 164 | + | build_vendorcss: { |
| 165 | + | files: [ |
| 166 | + | { |
| 167 | + | src: [ '<%= vendor_files.css %>' ], |
| 168 | + | dest: '<%= build_dir %>/', |
| 169 | + | cwd: '.', |
| 170 | + | expand: true |
| 171 | + | } |
| 172 | + | ] |
| 173 | + | }, |
| 174 | + | build_lang_files: { |
| 175 | + | files: [ |
| 176 | + | { |
| 177 | + | src: [ '<%= lang_files.json %>' ], |
| 178 | + | dest: '<%= build_dir %>/languages/', |
| 179 | + | expand: true, |
| 180 | + | flatten: true |
| 181 | + | } |
| 182 | + | ] |
| 183 | + | }, |
| 184 | + | compile_assets: { |
| 185 | + | files: [ |
| 186 | + | { |
| 187 | + | src: [ '**' ], |
| 188 | + | dest: '<%= compile_dir %>/assets', |
| 189 | + | cwd: '<%= build_dir %>/assets', |
| 190 | + | expand: true |
| 191 | + | }, |
| 192 | + | { |
| 193 | + | src: [ '<%= vendor_files.css %>' ], |
| 194 | + | dest: '<%= compile_dir %>/', |
| 195 | + | cwd: '.', |
| 196 | + | expand: true |
| 197 | + | }, |
| 198 | + | { |
| 199 | + | src: [ '<%= app_files.fonts %>' ], |
| 200 | + | dest: '<%= compile_dir %>/fonts', |
| 201 | + | expand: true, |
| 202 | + | flatten: true |
| 203 | + | }, |
| 204 | + | { |
| 205 | + | src: [ '<%= vendor_files.fonts %>' ], |
| 206 | + | dest: '<%= compile_dir %>/fonts', |
| 207 | + | expand: true, |
| 208 | + | flatten: true |
| 209 | + | }, |
| 210 | + | { |
| 211 | + | src: [ '<%= lang_files.json %>' ], |
| 212 | + | dest: '<%= compile_dir %>/languages', |
| 213 | + | expand: true, |
| 214 | + | flatten: true |
| 215 | + | } |
| 216 | + | ] |
| 217 | + | } |
| 218 | + | }, |
| 219 | + | |
| 220 | + | /** |
| 221 | + | * `grunt concat` concatenates multiple source files into a single file. |
| 222 | + | */ |
| 223 | + | concat: { |
| 224 | + | /** |
| 225 | + | * The `build_css` target concatenates compiled CSS and vendor CSS |
| 226 | + | * together. |
| 227 | + | */ |
| 228 | + | build_css: { |
| 229 | + | src: [ |
| 230 | + | '<%= vendor_files.css %>', |
| 231 | + | '<%= build_dir %>/assets/<%= pkg.name %>-<%= pkg.version %>.css' |
| 232 | + | ], |
| 233 | + | dest: '<%= build_dir %>/assets/<%= pkg.name %>-<%= pkg.version %>.css' |
| 234 | + | }, |
| 235 | + | /** |
| 236 | + | * The `compile_js` target is the concatenation of our application source |
| 237 | + | * code and all specified vendor source code into a single file. |
| 238 | + | */ |
| 239 | + | compile_js: { |
| 240 | + | options: { |
| 241 | + | banner: '<%= meta.banner %>' |
| 242 | + | }, |
| 243 | + | src: [ |
| 244 | + | '<%= vendor_files.js %>', |
| 245 | + | 'module.prefix', |
| 246 | + | '<%= build_dir %>/src/**/*.js', |
| 247 | + | '<%= html2js.app.dest %>', |
| 248 | + | '<%= html2js.common.dest %>', |
| 249 | + | 'module.suffix' |
| 250 | + | ], |
| 251 | + | dest: '<%= compile_dir %>/assets/<%= pkg.name %>-<%= pkg.version %>.js' |
| 252 | + | } |
| 253 | + | }, |
| 254 | + | |
| 255 | + | /** |
| 256 | + | * `grunt coffee` compiles the CoffeeScript sources. To work well with the |
| 257 | + | * rest of the build, we have a separate compilation task for sources and |
| 258 | + | * specs so they can go to different places. For example, we need the |
| 259 | + | * sources to live with the rest of the copied JavaScript so we can include |
| 260 | + | * it in the final build, but we don't want to include our specs there. |
| 261 | + | */ |
| 262 | + | coffee: { |
| 263 | + | source: { |
| 264 | + | options: { |
| 265 | + | bare: true |
| 266 | + | }, |
| 267 | + | expand: true, |
| 268 | + | cwd: '.', |
| 269 | + | src: [ '<%= app_files.coffee %>' ], |
| 270 | + | dest: '<%= build_dir %>', |
| 271 | + | ext: '.js' |
| 272 | + | } |
| 273 | + | }, |
| 274 | + | |
| 275 | + | /** |
| 276 | + | * `ng-min` annotates the sources before minifying. That is, it allows us |
| 277 | + | * to code without the array syntax. |
| 278 | + | */ |
| 279 | + | ngmin: { |
| 280 | + | compile: { |
| 281 | + | files: [ |
| 282 | + | { |
| 283 | + | src: [ '<%= app_files.js %>' ], |
| 284 | + | cwd: '<%= build_dir %>', |
| 285 | + | dest: '<%= build_dir %>', |
| 286 | + | expand: true |
| 287 | + | } |
| 288 | + | ] |
| 289 | + | } |
| 290 | + | }, |
| 291 | + | |
| 292 | + | /** |
| 293 | + | * Minify the sources! |
| 294 | + | */ |
| 295 | + | uglify: { |
| 296 | + | compile: { |
| 297 | + | options: { |
| 298 | + | banner: '<%= meta.banner %>' |
| 299 | + | }, |
| 300 | + | files: { |
| 301 | + | '<%= concat.compile_js.dest %>': '<%= concat.compile_js.dest %>' |
| 302 | + | } |
| 303 | + | } |
| 304 | + | }, |
| 305 | + | |
| 306 | + | /** |
| 307 | + | * `grunt-contrib-less` handles our LESS compilation and uglification automatically. |
| 308 | + | * Only our `main.less` file is included in compilation; all other files |
| 309 | + | * must be imported from this file. |
| 310 | + | */ |
| 311 | + | less: { |
| 312 | + | build: { |
| 313 | + | files: { |
| 314 | + | '<%= build_dir %>/assets/<%= pkg.name %>-<%= pkg.version %>.css': '<%= app_files.less %>' |
| 315 | + | } |
| 316 | + | }, |
| 317 | + | compile: { |
| 318 | + | files: { |
| 319 | + | '<%= build_dir %>/assets/<%= pkg.name %>-<%= pkg.version %>.css': '<%= app_files.less %>' |
| 320 | + | }, |
| 321 | + | options: { |
| 322 | + | cleancss: true, |
| 323 | + | compress: true |
| 324 | + | } |
| 325 | + | } |
| 326 | + | }, |
| 327 | + | |
| 328 | + | /** |
| 329 | + | * `lint5` defines the rules of our linter as well as which files we |
| 330 | + | * HTML5 should check. |
| 331 | + | */ |
| 332 | + | htmlangular: { |
| 333 | + | options: { |
| 334 | + | w3cproxy: '<%= proxy %>', |
| 335 | + | tmplext: 'tpl.html', |
| 336 | + | reportpath: 'report/html-angular-validate.json', |
| 337 | + | reportCheckstylePath: 'report/html-angular-validate-checkstyle.xml', |
| 338 | + | customattrs: ["*"] |
| 339 | + | }, |
| 340 | + | files: { |
| 341 | + | src: [ |
| 342 | + | '<%= app_files.atpl %>', '<%= app_files.ctpl %>' |
| 343 | + | ] |
| 344 | + | } |
| 345 | + | }, |
| 346 | + | |
| 347 | + | /** |
| 348 | + | * `eslint` defines the rules of our linter as well as which files we |
| 349 | + | * should check. This file, all javascript sources, and all our unit tests |
| 350 | + | * are linted based on the policies listed in `options`. |
| 351 | + | */ |
| 352 | + | eslint: { |
| 353 | + | src: [ |
| 354 | + | '<%= app_files.js %>' |
| 355 | + | ], |
| 356 | + | test: [ |
| 357 | + | '<%= app_files.jsunit %>' |
| 358 | + | ], |
| 359 | + | options: { |
| 360 | + | outputFile: 'report/eslint.txt' |
| 361 | + | } |
| 362 | + | }, |
| 363 | + | |
| 364 | + | /** |
| 365 | + | * `lesslint` defines the rules of our linter as well as which .less files we |
| 366 | + | * should check. |
| 367 | + | */ |
| 368 | + | lesslint: { |
| 369 | + | src: [ |
| 370 | + | '<%= app_files.less %>' |
| 371 | + | ], |
| 372 | + | options: { |
| 373 | + | formatters: [{ |
| 374 | + | id: 'csslint-xml', |
| 375 | + | dest: 'report/lesslint.xml' |
| 376 | + | }], |
| 377 | + | csslint: { |
| 378 | + | csslintrc: '.csslintrc' |
| 379 | + | }, |
| 380 | + | failOnWarning: false, |
| 381 | + | failOnError: false |
| 382 | + | } |
| 383 | + | }, |
| 384 | + | |
| 385 | + | /** |
| 386 | + | * `coffeelint` does the same as `eslint`, but for CoffeeScript. |
| 387 | + | * CoffeeScript is not the default in ngBoilerplate, so we're just using |
| 388 | + | * the defaults here. |
| 389 | + | */ |
| 390 | + | coffeelint: { |
| 391 | + | src: { |
| 392 | + | files: { |
| 393 | + | src: [ '<%= app_files.coffee %>' ] |
| 394 | + | } |
| 395 | + | }, |
| 396 | + | test: { |
| 397 | + | files: { |
| 398 | + | src: [ '<%= app_files.coffeeunit %>' ] |
| 399 | + | } |
| 400 | + | } |
| 401 | + | }, |
| 402 | + | |
| 403 | + | /** |
| 404 | + | * HTML2JS is a Grunt plugin that takes all of your template files and |
| 405 | + | * places them into JavaScript files as strings that are added to |
| 406 | + | * AngularJS's template cache. This means that the templates too become |
| 407 | + | * part of the initial payload as one JavaScript file. Neat! |
| 408 | + | */ |
| 409 | + | html2js: { |
| 410 | + | /** |
| 411 | + | * These are the templates from `src/app`. |
| 412 | + | */ |
| 413 | + | app: { |
| 414 | + | options: { |
| 415 | + | base: 'src/app' |
| 416 | + | }, |
| 417 | + | src: [ '<%= app_files.atpl %>' ], |
| 418 | + | dest: '<%= build_dir %>/templates-app.js' |
| 419 | + | }, |
| 420 | + | |
| 421 | + | /** |
| 422 | + | * These are the templates from `src/common`. |
| 423 | + | */ |
| 424 | + | common: { |
| 425 | + | options: { |
| 426 | + | base: 'src/common' |
| 427 | + | }, |
| 428 | + | src: [ '<%= app_files.ctpl %>' ], |
| 429 | + | dest: '<%= build_dir %>/templates-common.js' |
| 430 | + | } |
| 431 | + | }, |
| 432 | + | |
| 433 | + | /** |
| 434 | + | * The Karma configurations. |
| 435 | + | */ |
| 436 | + | karma: { |
| 437 | + | options: { |
| 438 | + | configFile: '<%= build_dir %>/karma-unit.js' |
| 439 | + | }, |
| 440 | + | unit: { |
| 441 | + | port: 9019, |
| 442 | + | background: true |
| 443 | + | }, |
| 444 | + | continuous: { |
| 445 | + | singleRun: true |
| 446 | + | } |
| 447 | + | }, |
| 448 | + | |
| 449 | + | /** |
| 450 | + | * The `index` task compiles the `index.html` file as a Grunt template. CSS |
| 451 | + | * and JS files co-exist here but they get split apart later. |
| 452 | + | */ |
| 453 | + | index: { |
| 454 | + | |
| 455 | + | /** |
| 456 | + | * During development, we don't want to have wait for compilation, |
| 457 | + | * concatenation, minification, etc. So to avoid these steps, we simply |
| 458 | + | * add all script files directly to the `<head>` of `index.html`. The |
| 459 | + | * `src` property contains the list of included files. |
| 460 | + | */ |
| 461 | + | build: { |
| 462 | + | dir: '<%= build_dir %>', |
| 463 | + | src: [ |
| 464 | + | '<%= vendor_files.js %>', |
| 465 | + | '<%= build_dir %>/src/**/*.js', |
| 466 | + | '<%= html2js.common.dest %>', |
| 467 | + | '<%= html2js.app.dest %>', |
| 468 | + | '<%= vendor_files.css %>', |
| 469 | + | '<%= lang_files.json %>', |
| 470 | + | '<%= build_dir %>/assets/<%= pkg.name %>-<%= pkg.version %>.css' |
| 471 | + | ] |
| 472 | + | }, |
| 473 | + | |
| 474 | + | /** |
| 475 | + | * When it is time to have a completely compiled application, we can |
| 476 | + | * alter the above to include only a single JavaScript and a single CSS |
| 477 | + | * file. Now we're back! |
| 478 | + | */ |
| 479 | + | compile: { |
| 480 | + | dir: '<%= compile_dir %>', |
| 481 | + | src: [ |
| 482 | + | '<%= concat.compile_js.dest %>', |
| 483 | + | '<%= vendor_files.css %>', |
| 484 | + | '<%= build_dir %>/assets/<%= pkg.name %>-<%= pkg.version %>.css' |
| 485 | + | ] |
| 486 | + | } |
| 487 | + | }, |
| 488 | + | |
| 489 | + | /** |
| 490 | + | * This task compiles the karma template so that changes to its file array |
| 491 | + | * don't have to be managed manually. |
| 492 | + | */ |
| 493 | + | karmaconfig: { |
| 494 | + | unit: { |
| 495 | + | dir: '<%= build_dir %>', |
| 496 | + | src: [ |
| 497 | + | '<%= vendor_files.js %>', |
| 498 | + | '<%= html2js.app.dest %>', |
| 499 | + | '<%= html2js.common.dest %>', |
| 500 | + | '<%= test_files.js %>' |
| 501 | + | ] |
| 502 | + | } |
| 503 | + | }, |
| 504 | + | |
| 505 | + | /** |
| 506 | + | * And for rapid development, we have a watch set up that checks to see if |
| 507 | + | * any of the files listed below change, and then to execute the listed |
| 508 | + | * tasks when they do. This just saves us from having to type "grunt" into |
| 509 | + | * the command-line every time we want to see what we're working on; we can |
| 510 | + | * instead just leave "grunt watch" running in a background terminal. Set it |
| 511 | + | * and forget it, as Ron Popeil used to tell us. |
| 512 | + | * |
| 513 | + | * But we don't need the same thing to happen for all the files. |
| 514 | + | */ |
| 515 | + | delta: { |
| 516 | + | /** |
| 517 | + | * By default, we want the Live Reload to work for all tasks; this is |
| 518 | + | * overridden in some tasks (like this file) where browser resources are |
| 519 | + | * unaffected. It runs by default on port 35729, which your browser |
| 520 | + | * plugin should auto-detect. |
| 521 | + | */ |
| 522 | + | options: { |
| 523 | + | livereload: true |
| 524 | + | }, |
| 525 | + | |
| 526 | + | /** |
| 527 | + | * When the Gruntfile changes, we just want to lint it. In fact, when |
| 528 | + | * your Gruntfile changes, it will automatically be reloaded! |
| 529 | + | */ |
| 530 | + | gruntfile: { |
| 531 | + | files: 'Gruntfile.js', |
| 532 | + | // tasks: [ 'eslint:gruntfile', 'lesslint:gruntfile' ], |
| 533 | + | options: { |
| 534 | + | livereload: false |
| 535 | + | } |
| 536 | + | }, |
| 537 | + | |
| 538 | + | /** |
| 539 | + | * When our JavaScript source files change, we want to run lint them and |
| 540 | + | * run our unit tests. |
| 541 | + | */ |
| 542 | + | jssrc: { |
| 543 | + | files: [ |
| 544 | + | '<%= app_files.js %>' |
| 545 | + | ], |
| 546 | + | tasks: [ /*'eslint:src',*/ 'karma:unit:run', 'copy:build_appjs' ] |
| 547 | + | }, |
| 548 | + | |
| 549 | + | /** |
| 550 | + | * When our CoffeeScript source files change, we want to run lint them and |
| 551 | + | * run our unit tests. |
| 552 | + | */ |
| 553 | + | coffeesrc: { |
| 554 | + | files: [ |
| 555 | + | '<%= app_files.coffee %>' |
| 556 | + | ], |
| 557 | + | tasks: [ 'coffeelint:src', 'coffee:source', 'karma:unit:run', 'copy:build_appjs' ] |
| 558 | + | }, |
| 559 | + | |
| 560 | + | /** |
| 561 | + | * When assets are changed, copy them. Note that this will *not* copy new |
| 562 | + | * files, so this is probably not very useful. |
| 563 | + | */ |
| 564 | + | assets: { |
| 565 | + | files: [ |
| 566 | + | 'src/assets/**/*' |
| 567 | + | ], |
| 568 | + | tasks: [ 'copy:build_app_assets', 'copy:build_vendor_assets', 'copy:build_app_fonts', 'copy:build_vendor_fonts' ] |
| 569 | + | }, |
| 570 | + | |
| 571 | + | /** |
| 572 | + | * When index.html changes, we need to compile it. |
| 573 | + | */ |
| 574 | + | html: { |
| 575 | + | files: [ '<%= app_files.html %>' ], |
| 576 | + | tasks: [ 'index:build' ] |
| 577 | + | }, |
| 578 | + | |
| 579 | + | /** |
| 580 | + | * When our templates change, we only rewrite the template cache. |
| 581 | + | */ |
| 582 | + | tpls: { |
| 583 | + | files: [ |
| 584 | + | '<%= app_files.atpl %>', |
| 585 | + | '<%= app_files.ctpl %>' |
| 586 | + | ], |
| 587 | + | tasks: [ 'html2js' ] |
| 588 | + | }, |
| 589 | + | |
| 590 | + | /** |
| 591 | + | * When the CSS files change, we need to compile and minify them. |
| 592 | + | */ |
| 593 | + | less: { |
| 594 | + | files: [ 'src/**/*.less' ], |
| 595 | + | tasks: [ 'less:build' ] |
| 596 | + | }, |
| 597 | + | |
| 598 | + | /** |
| 599 | + | * When a JavaScript unit test file changes, we only want to lint it and |
| 600 | + | * run the unit tests. We don't want to do any live reloading. |
| 601 | + | */ |
| 602 | + | jsunit: { |
| 603 | + | files: [ |
| 604 | + | '<%= app_files.jsunit %>' |
| 605 | + | ], |
| 606 | + | tasks: [ /*'eslint:test',*/ 'karma:unit:run' ], |
| 607 | + | options: { |
| 608 | + | livereload: false |
| 609 | + | } |
| 610 | + | }, |
| 611 | + | |
| 612 | + | /** |
| 613 | + | * When a CoffeeScript unit test file changes, we only want to lint it and |
| 614 | + | * run the unit tests. We don't want to do any live reloading. |
| 615 | + | */ |
| 616 | + | coffeeunit: { |
| 617 | + | files: [ |
| 618 | + | '<%= app_files.coffeeunit %>' |
| 619 | + | ], |
| 620 | + | tasks: [ 'coffeelint:test', 'karma:unit:run' ], |
| 621 | + | options: { |
| 622 | + | livereload: false |
| 623 | + | } |
| 624 | + | } |
| 625 | + | } |
| 626 | + | }; |
| 627 | + | |
| 628 | + | grunt.initConfig( grunt.util._.extend( taskConfig, userConfig ) ); |
| 629 | + | /** |
| 630 | + | * In order to make it safe to just compile or copy *only* what was changed, |
| 631 | + | * we need to ensure we are starting from a clean, fresh build. So we rename |
| 632 | + | * the `watch` task to `delta` (that's why the configuration var above is |
| 633 | + | * `delta`) and then add a new task called `watch` that does a clean build |
| 634 | + | * before watching for changes. |
| 635 | + | */ |
| 636 | + | grunt.renameTask( 'watch', 'delta' ); |
| 637 | + | grunt.registerTask( 'watch', [ 'build', 'karma:unit', 'delta' ] ); |
| 638 | + | |
| 639 | + | /** |
| 640 | + | * The default task is to build and compile. |
| 641 | + | */ |
| 642 | + | grunt.registerTask( 'default', [ 'build', 'compile' ] ); |
| 643 | + | |
| 644 | + | /** |
| 645 | + | * The `build` task gets your app ready to run for development and testing. |
| 646 | + | */ |
| 647 | + | grunt.registerTask( 'build', [ |
| 648 | + | 'clean', |
| 649 | + | 'html2js', |
| 650 | + | // 'htmlangular', |
| 651 | + | // 'eslint', |
| 652 | + | // 'lesslint', |
| 653 | + | // 'coffeelint', |
| 654 | + | // 'coffee', |
| 655 | + | 'less:build', |
| 656 | + | // 'concat:build_css', |
| 657 | + | 'copy:build_app_assets', |
| 658 | + | 'copy:build_app_fonts', |
| 659 | + | 'copy:build_vendor_assets', |
| 660 | + | 'copy:build_vendor_fonts', |
| 661 | + | 'copy:build_appjs', |
| 662 | + | 'copy:build_vendorjs', |
| 663 | + | 'copy:build_vendorcss', |
| 664 | + | 'copy:build_lang_files', |
| 665 | + | 'index:build', |
| 666 | + | 'karmaconfig', |
| 667 | + | 'karma:continuous' |
| 668 | + | ] ); |
| 669 | + | |
| 670 | + | /** |
| 671 | + | * The `compile` task gets your app ready for deployment by concatenating and |
| 672 | + | * minifying your code. |
| 673 | + | */ |
| 674 | + | grunt.registerTask( 'compile', [ |
| 675 | + | 'less:compile', |
| 676 | + | 'copy:compile_assets', |
| 677 | + | 'ngmin', |
| 678 | + | 'concat:compile_js', |
| 679 | + | 'uglify', |
| 680 | + | 'index:compile' |
| 681 | + | ] ); |
| 682 | + | |
| 683 | + | /** |
| 684 | + | * A utility function to get all app JavaScript sources. |
| 685 | + | */ |
| 686 | + | function filterForJS ( files ) { |
| 687 | + | return files.filter( function ( file ) { |
| 688 | + | return file.match( /\.js$/ ); |
| 689 | + | }); |
| 690 | + | } |
| 691 | + | |
| 692 | + | /** |
| 693 | + | * A utility function to get all app CSS sources. |
| 694 | + | */ |
| 695 | + | function filterForCSS ( files ) { |
| 696 | + | return files.filter( function ( file ) { |
| 697 | + | return file.match( /\.css$/ ); |
| 698 | + | }); |
| 699 | + | } |
| 700 | + | |
| 701 | + | /** |
| 702 | + | * The index.html template includes the stylesheet and javascript sources |
| 703 | + | * based on dynamic names calculated in this Gruntfile. This task assembles |
| 704 | + | * the list into variables for the template to use and then runs the |
| 705 | + | * compilation. |
| 706 | + | */ |
| 707 | + | grunt.registerMultiTask( 'index', 'Process index.html template', function () { |
| 708 | + | var dirRE = new RegExp( '^('+grunt.config('build_dir')+'|'+grunt.config('compile_dir')+')\/', 'g' ); |
| 709 | + | var jsFiles = filterForJS( this.filesSrc ).map( function ( file ) { |
| 710 | + | return file.replace( dirRE, '' ); |
| 711 | + | }); |
| 712 | + | var cssFiles = filterForCSS( this.filesSrc ).map( function ( file ) { |
| 713 | + | return file.replace( dirRE, '' ); |
| 714 | + | }); |
| 715 | + | // Set mode (development or production) |
| 716 | + | var mode = this.target === 'build' ? 'dev' : 'prod'; |
| 717 | + | |
| 718 | + | grunt.file.copy('src/index.html', this.data.dir + '/index.html', { |
| 719 | + | process: function ( contents ) { |
| 720 | + | return grunt.template.process( contents, { |
| 721 | + | data: { |
| 722 | + | scripts: jsFiles, |
| 723 | + | styles: cssFiles, |
| 724 | + | version: grunt.config( 'pkg.version' ), |
| 725 | + | mode: mode |
| 726 | + | } |
| 727 | + | }); |
| 728 | + | } |
| 729 | + | }); |
| 730 | + | }); |
| 731 | + | |
| 732 | + | /** |
| 733 | + | * In order to avoid having to specify manually the files needed for karma to |
| 734 | + | * run, we use grunt to manage the list for us. The `karma/*` files are |
| 735 | + | * compiled as grunt templates for use by Karma. Yay! |
| 736 | + | */ |
| 737 | + | grunt.registerMultiTask( 'karmaconfig', 'Process karma config templates', function () { |
| 738 | + | var jsFiles = filterForJS( this.filesSrc ); |
| 739 | + | |
| 740 | + | grunt.file.copy( 'karma/karma-unit.tpl.js', grunt.config( 'build_dir' ) + '/karma-unit.js', { |
| 741 | + | process: function ( contents ) { |
| 742 | + | return grunt.template.process( contents, { |
| 743 | + | data: { |
| 744 | + | scripts: jsFiles |
| 745 | + | } |
| 746 | + | }); |
| 747 | + | } |
| 748 | + | }); |
| 749 | + | }); |
| 750 | + | }; |
| 751 | + | |