Gruntfile.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. module.exports = function(grunt) {
  2. var DEV_SERVER_PORT = 8383;
  3. var TEST_SERVER_PORT = 8387;
  4. // Tell our Express server that Grunt launched it
  5. process.env.GRUNTED = true;
  6. // Project configuration.
  7. grunt.initConfig({
  8. pkg: grunt.file.readJSON('package.json'),
  9. font: {
  10. icons: {
  11. src: ['front/src/fonts/svg-icons/*.svg'],
  12. destCss: 'front/src/less/icons.less',
  13. destFonts: 'front/src/fonts/icons.woff',
  14. // Optional: Custom routing of font filepaths for CSS
  15. cssRouter: function (fontpath) {
  16. var pathArray = fontpath.split('/');
  17. var fileName = pathArray[pathArray.length - 1];
  18. return '/front/fonts/' + fileName;
  19. }
  20. }
  21. },
  22. less: {
  23. all: {
  24. files: [
  25. {
  26. expand: true,
  27. cwd: 'front/src/less/',
  28. src: ['**/*.less'],
  29. dest: 'front/src/css/',
  30. ext: '.css'
  31. }
  32. ]
  33. }
  34. },
  35. jshint: {
  36. all: [
  37. '*.js',
  38. 'app/lib/*.js',
  39. 'bin/*.js',
  40. 'lib/**/*.js',
  41. 'app/nodeControllers/*.js',
  42. 'app/public/scripts/*.js',
  43. 'phantomas_custom/**/*.js',
  44. 'test/**/*.js',
  45. 'front/src/js/**/*.js'
  46. ]
  47. },
  48. clean: {
  49. icons: {
  50. src: ['tmp']
  51. },
  52. dev: {
  53. src: ['front/src/css']
  54. },
  55. coverage: {
  56. src: ['coverage/']
  57. }
  58. },
  59. copy: {
  60. coverage: {
  61. files: [
  62. {src: ['test/**'], dest: 'coverage/'},
  63. {src: ['lib/metadata/**'], dest: 'coverage/'},
  64. {src: ['bin/**'], dest: 'coverage/'}
  65. ]
  66. }
  67. },
  68. blanket: {
  69. coverageApp: {
  70. src: ['app/'],
  71. dest: 'coverage/app/'
  72. },
  73. coverageLib: {
  74. src: ['lib/'],
  75. dest: 'coverage/lib/'
  76. },
  77. coverageBin: {
  78. src: ['bin/'],
  79. dest: 'coverage/bin/'
  80. }
  81. },
  82. mochaTest: {
  83. test: {
  84. options: {
  85. reporter: 'spec',
  86. },
  87. src: ['coverage/test/core/*.js', 'coverage/test/api/*.js']
  88. },
  89. 'test-current-work': {
  90. options: {
  91. reporter: 'spec',
  92. },
  93. src: ['coverage/test/api/apiTest.js']
  94. },
  95. coverage: {
  96. options: {
  97. reporter: 'html-cov',
  98. quiet: true,
  99. captureFile: 'coverage/coverage.html'
  100. },
  101. src: ['coverage/test/core/*.js', 'coverage/test/api/*.js']
  102. }
  103. },
  104. express: {
  105. dev: {
  106. options: {
  107. port: 8383,
  108. server: './bin/server.js',
  109. serverreload: true,
  110. showStack: true
  111. }
  112. },
  113. test: {
  114. options: {
  115. port: 8387,
  116. server: './coverage/bin/server.js',
  117. showStack: true
  118. }
  119. },
  120. testSuite: {
  121. options: {
  122. port: 8388,
  123. bases: 'test/www'
  124. }
  125. }
  126. }
  127. });
  128. // Custom task: copies the test settings.json file to the coverage folder, and checks if there's no missing fields
  129. grunt.registerTask('copy-test-server-settings', function() {
  130. var mainSettingsFile = './server_config/settings.json';
  131. var testSettingsFile = './test/fixtures/settings.json';
  132. var mainSettings = grunt.file.readJSON(mainSettingsFile);
  133. var testSettings = grunt.file.readJSON(testSettingsFile);
  134. // Recursively compare keys of two objects (not the values)
  135. function compareKeys(original, copy, context) {
  136. for (var key in original) {
  137. if (!copy[key] && copy[key] !== '' && copy[key] !== 0) {
  138. grunt.fail.warn('Settings file ' + testSettingsFile + ' doesn\'t contain key ' + context + '.' + key);
  139. }
  140. if (original[key] !== null && typeof original[key] === 'object') {
  141. compareKeys(original[key], copy[key], context + '.' + key);
  142. }
  143. }
  144. }
  145. compareKeys(mainSettings, testSettings, 'settings');
  146. var outputFile = './coverage/server_config/settings.json';
  147. grunt.file.write(outputFile, JSON.stringify(testSettings, null, 4));
  148. grunt.log.ok('File ' + outputFile + ' created');
  149. });
  150. require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
  151. grunt.registerTask('icons', [
  152. 'font:icons',
  153. 'less',
  154. 'clean:icons'
  155. ]);
  156. grunt.registerTask('build', [
  157. 'less'
  158. ]);
  159. grunt.registerTask('hint', [
  160. 'jshint'
  161. ]);
  162. grunt.registerTask('dev', [
  163. 'clean:dev',
  164. 'less'
  165. ]);
  166. grunt.registerTask('test', [
  167. 'build',
  168. 'jshint',
  169. 'express:testSuite',
  170. 'clean:coverage',
  171. 'copy-test-server-settings',
  172. 'blanket',
  173. 'copy:coverage',
  174. 'express:test',
  175. 'mochaTest:test',
  176. 'mochaTest:coverage'
  177. ]);
  178. grunt.registerTask('test-current-work', [
  179. 'build',
  180. 'jshint',
  181. 'express:testSuite',
  182. 'clean:coverage',
  183. 'copy-test-server-settings',
  184. 'blanket',
  185. 'copy:coverage',
  186. 'mochaTest:test-current-work'
  187. ]);
  188. };