Gruntfile.js 7.4 KB

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