Gruntfile.js 6.2 KB

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