Gruntfile.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. // Generated on 2013-08-05 using generator-angular 0.3.1
  2. 'use strict';
  3. var LIVERELOAD_PORT = 35729;
  4. var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT });
  5. var mountFolder = function (connect, dir) {
  6. return connect.static(require('path').resolve(dir));
  7. };
  8. // # Globbing
  9. // for performance reasons we're only matching one level down:
  10. // 'test/spec/{,*/}*.js'
  11. // use this if you want to recursively match all subfolders:
  12. // 'test/spec/**/*.js'
  13. module.exports = function (grunt) {
  14. // load all grunt tasks
  15. require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
  16. // configurable paths
  17. var yeomanConfig = {
  18. app: 'app',
  19. dist: 'dist'
  20. };
  21. try {
  22. yeomanConfig.app = require('./bower.json').appPath || yeomanConfig.app;
  23. } catch (e) {}
  24. grunt.initConfig({
  25. yeoman: yeomanConfig,
  26. watch: {
  27. coffee: {
  28. files: ['<%= yeoman.app %>/scripts/{,*/}*.coffee'],
  29. tasks: ['coffee:dist']
  30. },
  31. coffeeTest: {
  32. files: ['test/spec/{,*/}*.coffee'],
  33. tasks: ['coffee:test']
  34. },
  35. compass: {
  36. files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
  37. tasks: ['compass:server']
  38. },
  39. livereload: {
  40. options: {
  41. livereload: LIVERELOAD_PORT
  42. },
  43. files: [
  44. '<%= yeoman.app %>/{,*/}*.html',
  45. '{.tmp,<%= yeoman.app %>}/styles/{,*/}*.css',
  46. '{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
  47. '<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
  48. ]
  49. }
  50. },
  51. connect: {
  52. options: {
  53. port: 9000,
  54. // Change this to '0.0.0.0' to access the server from outside.
  55. hostname: 'localhost'
  56. },
  57. livereload: {
  58. options: {
  59. middleware: function (connect) {
  60. return [
  61. lrSnippet,
  62. mountFolder(connect, '.tmp'),
  63. mountFolder(connect, yeomanConfig.app)
  64. ];
  65. }
  66. }
  67. },
  68. test: {
  69. options: {
  70. middleware: function (connect) {
  71. return [
  72. mountFolder(connect, '.tmp'),
  73. mountFolder(connect, 'test')
  74. ];
  75. }
  76. }
  77. },
  78. dist: {
  79. options: {
  80. middleware: function (connect) {
  81. return [
  82. mountFolder(connect, yeomanConfig.dist)
  83. ];
  84. }
  85. }
  86. }
  87. },
  88. open: {
  89. server: {
  90. url: 'http://localhost:<%= connect.options.port %>'
  91. }
  92. },
  93. clean: {
  94. dist: {
  95. files: [{
  96. dot: true,
  97. src: [
  98. '.tmp',
  99. '<%= yeoman.dist %>/*',
  100. '!<%= yeoman.dist %>/.git*'
  101. ]
  102. }]
  103. },
  104. server: '.tmp'
  105. },
  106. jshint: {
  107. options: {
  108. jshintrc: '.jshintrc'
  109. },
  110. all: [
  111. 'Gruntfile.js',
  112. '<%= yeoman.app %>/scripts/{,*/}*.js'
  113. ]
  114. },
  115. coffee: {
  116. dist: {
  117. files: [{
  118. expand: true,
  119. cwd: '<%= yeoman.app %>/scripts',
  120. src: '{,*/}*.coffee',
  121. dest: '.tmp/scripts',
  122. ext: '.js'
  123. }]
  124. },
  125. test: {
  126. files: [{
  127. expand: true,
  128. cwd: 'test/spec',
  129. src: '{,*/}*.coffee',
  130. dest: '.tmp/spec',
  131. ext: '.js'
  132. }]
  133. }
  134. },
  135. compass: {
  136. options: {
  137. sassDir: '<%= yeoman.app %>/styles',
  138. cssDir: '.tmp/styles',
  139. generatedImagesDir: '.tmp/images/generated',
  140. imagesDir: '<%= yeoman.app %>/images',
  141. javascriptsDir: '<%= yeoman.app %>/scripts',
  142. fontsDir: '<%= yeoman.app %>/styles/fonts',
  143. importPath: '<%= yeoman.app %>/bower_components',
  144. httpImagesPath: '/images',
  145. httpGeneratedImagesPath: '/images/generated',
  146. httpFontsPath: '/styles/fonts',
  147. relativeAssets: false
  148. },
  149. dist: {},
  150. server: {
  151. options: {
  152. debugInfo: true
  153. }
  154. }
  155. },
  156. // not used since Uglify task does concat,
  157. // but still available if needed
  158. /*concat: {
  159. dist: {}
  160. },*/
  161. rev: {
  162. dist: {
  163. files: {
  164. src: [
  165. '<%= yeoman.dist %>/scripts/{,*/}*.js',
  166. '<%= yeoman.dist %>/styles/{,*/}*.css',
  167. '<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
  168. '<%= yeoman.dist %>/styles/fonts/*'
  169. ]
  170. }
  171. }
  172. },
  173. useminPrepare: {
  174. html: '<%= yeoman.app %>/index.html',
  175. options: {
  176. dest: '<%= yeoman.dist %>'
  177. }
  178. },
  179. usemin: {
  180. html: ['<%= yeoman.dist %>/{,*/}*.html'],
  181. css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
  182. options: {
  183. dirs: ['<%= yeoman.dist %>']
  184. }
  185. },
  186. imagemin: {
  187. dist: {
  188. files: [{
  189. expand: true,
  190. cwd: '<%= yeoman.app %>/images',
  191. src: '{,*/}*.{png,jpg,jpeg}',
  192. dest: '<%= yeoman.dist %>/images'
  193. }]
  194. }
  195. },
  196. svgmin: {
  197. dist: {
  198. files: [{
  199. expand: true,
  200. cwd: '<%= yeoman.app %>/images',
  201. src: '{,*/}*.svg',
  202. dest: '<%= yeoman.dist %>/images'
  203. }]
  204. }
  205. },
  206. cssmin: {
  207. // By default, your `index.html` <!-- Usemin Block --> will take care of
  208. // minification. This option is pre-configured if you do not wish to use
  209. // Usemin blocks.
  210. // dist: {
  211. // files: {
  212. // '<%= yeoman.dist %>/styles/main.css': [
  213. // '.tmp/styles/{,*/}*.css',
  214. // '<%= yeoman.app %>/styles/{,*/}*.css'
  215. // ]
  216. // }
  217. // }
  218. },
  219. htmlmin: {
  220. dist: {
  221. options: {
  222. /*removeCommentsFromCDATA: true,
  223. // https://github.com/yeoman/grunt-usemin/issues/44
  224. //collapseWhitespace: true,
  225. collapseBooleanAttributes: true,
  226. removeAttributeQuotes: true,
  227. removeRedundantAttributes: true,
  228. useShortDoctype: true,
  229. removeEmptyAttributes: true,
  230. removeOptionalTags: true*/
  231. },
  232. files: [{
  233. expand: true,
  234. cwd: '<%= yeoman.app %>',
  235. src: ['*.html', 'views/*.html'],
  236. dest: '<%= yeoman.dist %>'
  237. }]
  238. }
  239. },
  240. // Put files not handled in other tasks here
  241. copy: {
  242. dist: {
  243. files: [{
  244. expand: true,
  245. dot: true,
  246. cwd: '<%= yeoman.app %>',
  247. dest: '<%= yeoman.dist %>',
  248. src: [
  249. '*.{ico,png,txt}',
  250. '.htaccess',
  251. 'bower_components/**/*',
  252. 'images/{,*/}*.{gif,webp}',
  253. 'styles/fonts/*'
  254. ]
  255. }, {
  256. expand: true,
  257. cwd: '.tmp/images',
  258. dest: '<%= yeoman.dist %>/images',
  259. src: [
  260. 'generated/*'
  261. ]
  262. }]
  263. }
  264. },
  265. concurrent: {
  266. server: [
  267. 'coffee:dist',
  268. 'compass:server'
  269. ],
  270. test: [
  271. 'coffee',
  272. 'compass'
  273. ],
  274. dist: [
  275. 'coffee',
  276. 'compass:dist',
  277. 'imagemin',
  278. 'svgmin',
  279. 'htmlmin'
  280. ]
  281. },
  282. karma: {
  283. unit: {
  284. configFile: 'karma.conf.js',
  285. singleRun: true
  286. }
  287. },
  288. cdnify: {
  289. dist: {
  290. html: ['<%= yeoman.dist %>/*.html']
  291. }
  292. },
  293. ngmin: {
  294. dist: {
  295. files: [{
  296. expand: true,
  297. cwd: '<%= yeoman.dist %>/scripts',
  298. src: '*.js',
  299. dest: '<%= yeoman.dist %>/scripts'
  300. }]
  301. }
  302. },
  303. uglify: {
  304. dist: {
  305. files: {
  306. '<%= yeoman.dist %>/scripts/scripts.js': [
  307. '<%= yeoman.dist %>/scripts/scripts.js'
  308. ]
  309. }
  310. }
  311. }
  312. });
  313. grunt.registerTask('server', function (target) {
  314. if (target === 'dist') {
  315. return grunt.task.run(['build', 'open', 'connect:dist:keepalive']);
  316. }
  317. grunt.task.run([
  318. 'clean:server',
  319. 'concurrent:server',
  320. 'connect:livereload',
  321. 'open',
  322. 'watch'
  323. ]);
  324. });
  325. grunt.registerTask('test', [
  326. 'clean:server',
  327. 'concurrent:test',
  328. 'connect:test',
  329. 'karma'
  330. ]);
  331. grunt.registerTask('build', [
  332. 'clean:dist',
  333. 'useminPrepare',
  334. 'concurrent:dist',
  335. 'concat',
  336. 'copy',
  337. 'cdnify',
  338. 'ngmin',
  339. 'cssmin',
  340. 'uglify',
  341. 'rev',
  342. 'usemin'
  343. ]);
  344. grunt.registerTask('default', [
  345. 'jshint',
  346. 'test',
  347. 'build'
  348. ]);
  349. };