Gruntfile.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. 'use strict';
  2. module.exports = function(grunt) {
  3. /*jshint maxstatements:false */
  4. require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
  5. grunt.initConfig({
  6. config: {
  7. appName: 'etcd-dashboard',
  8. appPath: 'app',
  9. bowerPath: 'app/bower_components',
  10. tmpPath: '.tmp',
  11. distPath: 'dist'
  12. },
  13. watch: {
  14. css: {
  15. files: ['<%= config.appPath %>/{page,ui,style}/{**/,}*.scss'],
  16. tasks: ['sass']
  17. },
  18. html: {
  19. files: [
  20. '<%= config.appPath %>/{module,ui,page}/**/*.html'
  21. ],
  22. tasks: ['views']
  23. },
  24. js: {
  25. files: [
  26. '<%= config.appPath %>/{module,page}/**/*.js',
  27. '<%= config.appPath %>/*.js'
  28. ],
  29. tasks: ['jshint']
  30. }
  31. },
  32. concurrent: {
  33. dev: {
  34. tasks: ['watch', /*'test-watch'*/],
  35. options: {
  36. logConcurrentOutput: true
  37. }
  38. }
  39. },
  40. clean: {
  41. tmp: {
  42. files: [{
  43. dot: true,
  44. src: [
  45. '<%= config.tmpPath %>',
  46. '.sass-cache/**/*'
  47. ]
  48. }]
  49. },
  50. dist: {
  51. files: [{
  52. dot: true,
  53. src: [
  54. '<%= config.distPath %>/*'
  55. ]
  56. }]
  57. },
  58. 'dist-static': {
  59. files: [{
  60. dot: true,
  61. src: [
  62. '<%= config.distPath %>/cp/**'
  63. ]
  64. }]
  65. },
  66. compiled: {
  67. files: [{
  68. dot: true,
  69. src: [
  70. '<%= config.appPath %>/compiled/**'
  71. ]
  72. }]
  73. }
  74. },
  75. // JS code linting.
  76. jshint: {
  77. options: {
  78. camelcase: true,
  79. curly: true,
  80. eqeqeq: true,
  81. eqnull: true,
  82. forin: true,
  83. freeze: true,
  84. immed: true,
  85. indent: 2,
  86. latedef: true,
  87. maxcomplexity: 10,
  88. maxdepth: 3,
  89. maxlen: 80,
  90. maxparams: 20,
  91. maxstatements: 200,
  92. newcap: true,
  93. noarg: true,
  94. node: true,
  95. noempty: true,
  96. nonew: true,
  97. nonbsp: true,
  98. quotmark: 'single',
  99. strict: true,
  100. sub: true,
  101. trailing: true,
  102. undef: true,
  103. unused: true
  104. },
  105. src: {
  106. node: false,
  107. options: {
  108. globals: {
  109. angular: true,
  110. window: true
  111. }
  112. },
  113. files: {
  114. src: [
  115. '<%= config.appPath %>/*.js',
  116. '<%= config.appPath %>/{module,page}**/*.js',
  117. '!<%= config.appPath %>/vega.js'
  118. ]
  119. }
  120. }
  121. },
  122. // Compile SCSS to CSS.
  123. sass: {
  124. etcd: {
  125. options: {
  126. includePaths: ['<%= config.appPath %>/coreos-web/sass'],
  127. outputStyle: 'nested'
  128. },
  129. files: {
  130. '<%= config.appPath %>/compiled/main.css': '<%= config.appPath %>/main.scss'
  131. }
  132. }
  133. },
  134. /**
  135. * Generate grunt configs for concat, uglify, cssmin.
  136. */
  137. useminPrepare: {
  138. html: '<%= config.appPath %>/index.html',
  139. options: {
  140. dest: '<%= config.distPath %>'
  141. }
  142. },
  143. usemin: {
  144. html: ['<%= config.distPath %>/index.html']
  145. },
  146. // This block gets generated by usemin.
  147. cssmin: {
  148. },
  149. // This block gets generated by usemin.
  150. uglify: {
  151. },
  152. // This block gets generated by usemin.
  153. concat: {
  154. },
  155. // Make our angular code minification friendly.
  156. ngmin: {
  157. dist: {
  158. files: [{
  159. src: '<%= config.tmpPath %>/concat/app.js',
  160. dest: '<%= config.tmpPath %>/concat/app.js'
  161. }]
  162. }
  163. },
  164. copy: {
  165. dist: {
  166. files: [{
  167. expand: true,
  168. cwd: '<%= config.appPath %>',
  169. src: ['index.html'],
  170. dest: '<%= config.distPath %>'
  171. }]
  172. },
  173. images: {
  174. files: [{
  175. expand: true,
  176. cwd: '<%= config.appPath %>/img',
  177. src: ['**'],
  178. dest: '<%= config.distPath %>/img'
  179. }]
  180. },
  181. 'dist-static': {
  182. files: [
  183. {
  184. expand: true,
  185. flatten: true,
  186. src: [
  187. '<%= config.distPath %>/cp/static/*'
  188. ],
  189. dest: '<%= config.distPath %>'
  190. }
  191. ]
  192. }
  193. },
  194. // Precompile html views into a single javascript file.
  195. html2js: {
  196. options: {
  197. base: '<%= config.appPath %>',
  198. rename: function(moduleName) {
  199. return '/' + moduleName;
  200. }
  201. },
  202. views: {
  203. src: [
  204. '<%= config.appPath %>/{page,ui,module}/**/*.html'
  205. ],
  206. dest: '<%= config.appPath %>/compiled/views.js'
  207. }
  208. }
  209. });
  210. grunt.registerTask('clean-paths', 'clean up resource paths', function() {
  211. grunt.log.writeln('cleaning paths...');
  212. function clean(path) {
  213. return path.replace('cp/static/', '');
  214. }
  215. ['concat', 'uglify', 'cssmin'].forEach(function(task) {
  216. var config = grunt.config(task);
  217. config.generated.files.forEach(function(fileGroup) {
  218. fileGroup.dest = clean(fileGroup.dest);
  219. fileGroup.src = fileGroup.src.map(function(path) {
  220. return clean(path);
  221. });
  222. });
  223. grunt.config(task, config);
  224. grunt.log.ok(task + ' config is now:');
  225. grunt.log.writeln(util.inspect(grunt.config(task), false, 4, true));
  226. });
  227. });
  228. grunt.registerTask('test', [
  229. 'views',
  230. 'karma:unit'
  231. ]);
  232. grunt.registerTask('test-watch', [
  233. 'karma:dev'
  234. ]);
  235. grunt.registerTask('views', [
  236. 'html2js:views'
  237. ]);
  238. grunt.registerTask('dev', [
  239. 'clean',
  240. //'jshint',
  241. 'views',
  242. 'sass',
  243. 'concurrent:dev'
  244. ]);
  245. grunt.registerTask('build', [
  246. 'clean',
  247. 'jshint',
  248. 'views',
  249. 'test',
  250. 'sass',
  251. 'useminPrepare',
  252. 'clean-paths',
  253. 'concat',
  254. 'ngmin:dist',
  255. 'uglify',
  256. 'cssmin',
  257. 'copy:dist',
  258. 'usemin',
  259. 'copy:dist-static',
  260. 'clean:dist-static',
  261. 'copy:images'
  262. ]);
  263. grunt.registerTask('default', ['build']);
  264. };