Gruntfile.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. module.exports = function(grunt) {
  2. // Load all grunt modules
  3. require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
  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. settings: grunt.file.readJSON('./server_config/settings.json'),
  10. less: {
  11. all: {
  12. files: [
  13. {
  14. expand: true,
  15. cwd: 'front/src/less/',
  16. src: ['**/*.less'],
  17. dest: 'front/src/css/',
  18. ext: '.css'
  19. }
  20. ]
  21. }
  22. },
  23. jshint: {
  24. all: [
  25. '*.js',
  26. 'app/lib/*.js',
  27. 'bin/*.js',
  28. 'lib/**/*.js',
  29. 'app/nodeControllers/*.js',
  30. 'app/public/scripts/*.js',
  31. 'phantomas_custom/**/*.js',
  32. 'test/api/*.js',
  33. 'test/core/*.js',
  34. 'test/fixtures/*.js',
  35. 'front/src/js/**/*.js'
  36. ],
  37. options: {
  38. esversion: 6
  39. }
  40. },
  41. clean: {
  42. tmp: {
  43. src: ['.tmp']
  44. },
  45. dev: {
  46. src: ['front/src/css']
  47. },
  48. build: {
  49. src: ['front/build']
  50. }
  51. },
  52. copy: {
  53. build: {
  54. files: [
  55. {src: ['./front/src/main.html'], dest: './front/build/main.html'},
  56. {src: ['./front/src/img/favicon.png'], dest: './front/build/img/favicon.png'},
  57. {src: ['./front/src/img/logo-large.png'], dest: './front/build/img/logo-large.png'},
  58. ]
  59. },
  60. favicons: {
  61. files: [
  62. {src: ['./front/src/img/favicon.png'], dest: './front/build/img/favicon.png'},
  63. {src: ['./front/src/img/favicon-fail.png'], dest: './front/build/img/favicon-fail.png'},
  64. {src: ['./front/src/img/favicon-success.png'], dest: './front/build/img/favicon-success.png'},
  65. ]
  66. }
  67. },
  68. mochaTest: {
  69. test: {
  70. options: {
  71. reporter: 'spec',
  72. },
  73. src: ['test/core/*.js', 'test/api/*.js']
  74. },
  75. 'test-current-work': {
  76. options: {
  77. reporter: 'spec',
  78. },
  79. src: ['test/core/mediaQueriesCheckerTest.js']
  80. }
  81. },
  82. env: {
  83. dev: {
  84. NODE_ENV: 'development'
  85. },
  86. built: {
  87. NODE_ENV: 'production'
  88. }
  89. },
  90. express: {
  91. dev: {
  92. options: {
  93. port: 8383,
  94. server: './bin/server.js',
  95. serverreload: true,
  96. showStack: true
  97. }
  98. },
  99. built: {
  100. options: {
  101. port: 8383,
  102. server: './bin/server.js',
  103. serverreload: true,
  104. showStack: true
  105. }
  106. },
  107. test: {
  108. options: {
  109. port: 8387,
  110. server: './bin/server.js',
  111. showStack: true
  112. }
  113. },
  114. 'test-current-work': {
  115. options: {
  116. port: 8387,
  117. server: './bin/server.js',
  118. showStack: true
  119. }
  120. },
  121. testSuite: {
  122. options: {
  123. port: 8388,
  124. bases: 'test/www'
  125. }
  126. }
  127. },
  128. useminPrepare: {
  129. html: './front/src/main.html',
  130. options: {
  131. dest: './front/build',
  132. root: ['./', './front/src']
  133. }
  134. },
  135. usemin: {
  136. html: './front/build/main.html',
  137. css: './front/build/css/*.css',
  138. options: {
  139. assetsDirs: ['front/build']
  140. }
  141. },
  142. htmlmin: {
  143. options: {
  144. removeComments: true,
  145. collapseWhitespace: true,
  146. conservativeCollapse: true
  147. },
  148. main: {
  149. files: [{
  150. expand: true,
  151. cwd: './front/build/',
  152. src: 'main.html',
  153. flatten: true,
  154. dest: './front/build'
  155. }]
  156. },
  157. views: {
  158. files: [{
  159. expand: true,
  160. cwd: './front/src/views',
  161. src: '*.html',
  162. flatten: true,
  163. dest: '.tmp/views/'
  164. }]
  165. }
  166. },
  167. inline_angular_templates: {
  168. build: {
  169. options: {
  170. base: '.tmp',
  171. method: 'append',
  172. unescape: {
  173. '&lt;': '<',
  174. '&gt;': '>'
  175. }
  176. },
  177. files: {
  178. './front/build/main.html': ['.tmp/views/*.html']
  179. }
  180. }
  181. },
  182. filerev: {
  183. options: {
  184. algorithm: 'md5',
  185. length: 8
  186. },
  187. assets: {
  188. src: './front/build/*/*.*'
  189. }
  190. }
  191. });
  192. // Custom task that sets a variable for tests
  193. grunt.registerTask('test-settings', function() {
  194. process.env.IS_TEST = true;
  195. });
  196. grunt.registerTask('build', [
  197. 'jshint',
  198. 'clean:build',
  199. 'copy:build',
  200. 'less',
  201. 'useminPrepare',
  202. 'concat',
  203. 'uglify',
  204. 'cssmin',
  205. 'htmlmin:views',
  206. 'inline_angular_templates',
  207. 'filerev',
  208. 'usemin',
  209. 'htmlmin:main',
  210. 'clean:tmp',
  211. 'copy:favicons'
  212. ]);
  213. grunt.registerTask('hint', [
  214. 'jshint'
  215. ]);
  216. grunt.registerTask('dev', [
  217. 'env:dev',
  218. 'express:dev'
  219. ]);
  220. grunt.registerTask('built', [
  221. 'env:built',
  222. 'express:built'
  223. ]);
  224. grunt.registerTask('test', [
  225. 'test-settings',
  226. 'build',
  227. 'express:testSuite',
  228. 'express:test',
  229. 'mochaTest:test',
  230. 'clean:tmp'
  231. ]);
  232. grunt.registerTask('test-current-work', [
  233. 'test-settings',
  234. 'jshint',
  235. 'express:testSuite',
  236. 'express:test-current-work',
  237. 'mochaTest:test-current-work',
  238. 'clean:tmp'
  239. ]);
  240. };