gruntfile.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright 2015 rain1017.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  12. // implied. See the License for the specific language governing
  13. // permissions and limitations under the License. See the AUTHORS file
  14. // for names of contributors.
  15. 'use strict';
  16. module.exports = function(grunt) {
  17. // Unified Watch Object
  18. var watchFiles = {
  19. serverJS: ['gruntfile.js', 'app.js', 'app/**/*.js'],
  20. testJS: ['test/**/*.js'],
  21. };
  22. // Project Configuration
  23. grunt.initConfig({
  24. pkg: grunt.file.readJSON('package.json'),
  25. watch: {
  26. serverJS: {
  27. files: watchFiles.serverJS,
  28. tasks: ['jshint'],
  29. options: {
  30. livereload: true
  31. }
  32. }
  33. },
  34. jshint: {
  35. all: {
  36. src: watchFiles.serverJS.concat(watchFiles.testJS),
  37. options: {
  38. jshintrc: true
  39. }
  40. }
  41. },
  42. env: {
  43. test: {
  44. NODE_ENV: 'test'
  45. }
  46. },
  47. mochaTest: {
  48. test : {
  49. src: watchFiles.testJS,
  50. options : {
  51. reporter: 'spec',
  52. timeout: 5 * 1000,
  53. require: 'test/blanket'
  54. }
  55. },
  56. coverage: {
  57. src: watchFiles.testJS,
  58. options : {
  59. reporter: 'html-cov',
  60. quiet: true,
  61. captureFile: 'coverage.html'
  62. }
  63. }
  64. },
  65. nodemon: {
  66. dev: {
  67. script: 'app.js',
  68. options: {
  69. nodeArgs: ['--debug'],
  70. ext: 'js,html',
  71. watch: watchFiles.serverJS
  72. }
  73. }
  74. },
  75. 'node-inspector': {
  76. custom: {
  77. options: {
  78. 'web-port': 8088,
  79. 'web-host': 'localhost',
  80. 'debug-port': 5858,
  81. 'save-live-edit': true,
  82. 'no-preload': true,
  83. 'stack-trace-limit': 50,
  84. 'hidden': []
  85. }
  86. }
  87. },
  88. concurrent: {
  89. default: ['nodemon', 'watch'],
  90. debug: ['nodemon', 'watch', 'node-inspector'],
  91. options: {
  92. logConcurrentOutput: true,
  93. limit: 10
  94. }
  95. },
  96. clean: {
  97. 'coverage.html' : {
  98. src: ['coverage.html']
  99. }
  100. }
  101. });
  102. // Load NPM tasks
  103. require('load-grunt-tasks')(grunt);
  104. // Making grunt default to force in order not to break the project.
  105. grunt.option('force', true);
  106. // Lint task(s).
  107. grunt.registerTask('lint', ['jshint']);
  108. // Default task(s).
  109. grunt.registerTask('default', ['clean', 'lint', 'concurrent:default']);
  110. // Debug task.
  111. grunt.registerTask('debug', ['clean', 'lint', 'concurrent:debug']);
  112. // Test task.
  113. grunt.registerTask('test', ['clean', 'env:test', 'lint', 'mochaTest']);
  114. };