PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/Gruntfile.js

https://bitbucket.org/juanpicado/portfolio
JavaScript | 306 lines | 194 code | 34 blank | 78 comment | 0 complexity | cb5c0b045ea7e39b756d957b6a0c3258 MD5 | raw file
  1. /*global require:false, module:false*/
  2. 'use strict';
  3. var path = require('path');
  4. var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;
  5. var folderMount = function folderMount(connect, point) {
  6. return connect['static'](path.resolve(point));
  7. };
  8. module.exports = function(grunt) {
  9. // Grunt project configuration
  10. grunt.initConfig({
  11. pkg: '<json:package.json>',
  12. dirs: {
  13. root: 'app/public',
  14. staging: 'temp/staging',
  15. dist: 'dist',
  16. sass : 'app/sass',
  17. test: 'app/test'
  18. },
  19. banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
  20. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  21. '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
  22. '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  23. ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
  24. // Task configuration
  25. // clean the distribution folder.
  26. clean: {
  27. dist: ['<%= dirs.staging %>','<%= dirs.dist %>']
  28. },
  29. // server
  30. server: {
  31. dev: {
  32. options: {
  33. port: 3001,
  34. base: '<%= dirs.root %>',
  35. keepalive: false,
  36. middleware: function(connect, options) {
  37. return [
  38. lrSnippet,
  39. folderMount(connect, options.base)
  40. ];
  41. }
  42. }
  43. },
  44. pro: {
  45. options: {
  46. port: 3002,
  47. base: '<%= dirs.dist %>/public',
  48. keepalive: true
  49. }
  50. }
  51. },
  52. // prepare files to be minimized,
  53. //read the embebed configuration for each html in the projject
  54. 'useminPrepare': {
  55. options: {
  56. dest: '<%= dirs.staging %>/step2'
  57. },
  58. html: '<%= dirs.staging %>/step1/*.html'
  59. },
  60. // files minimize process
  61. usemin: {
  62. options: {
  63. basedir: '<%= dirs.staging %>/step2'
  64. },
  65. html: {
  66. expand: true,
  67. cwd: '<%= dirs.staging %>/step2',
  68. src:['**/*.{html,css}']
  69. }
  70. },
  71. // copy task, define the build workflow
  72. copy: {
  73. 'dist-step-1': {
  74. expand: true,
  75. cwd: '<%= dirs.root %>',
  76. src: ['**','!css/style.css'],
  77. dest: '<%= dirs.staging %>/step1/'
  78. },
  79. 'dist-step-2': {
  80. expand: true,
  81. cwd: '<%= dirs.staging %>/step1',
  82. src: [
  83. "**",
  84. "**/*.js",
  85. "ico/**"
  86. ],
  87. dest: "<%= dirs.staging %>/step2/"
  88. },
  89. 'dist-step-3': {
  90. expand: true,
  91. cwd: '<%= dirs.staging %>/step2',
  92. src: [
  93. "**/*.html",
  94. "**",
  95. "js/*.js",
  96. 'lib/*modernizr.js'
  97. ],
  98. dest: "<%= dirs.staging %>/step3/"
  99. },
  100. 'dist-final': {
  101. expand: true,
  102. cwd: '<%= dirs.staging %>/step3',
  103. src: ["**"],
  104. dest: "<%= dirs.dist %>/public/"
  105. }
  106. },
  107. /**
  108. * Compass configuration
  109. * @property compass
  110. */
  111. compass: {
  112. options: {
  113. sassDir: '<%= dirs.sass %>',
  114. raw: 'images_dir = "app/public/img"\n' +
  115. 'http_images_path = "../img"\n' +
  116. 'http_javascripts_path = "../js"\n' +
  117. 'http_stylesheets_path = "."\n'
  118. },
  119. dev: {
  120. options: {
  121. cssDir: '<%= dirs.root %>/css',
  122. environment: 'development'
  123. }
  124. },
  125. dist: {
  126. options: {
  127. cssDir: '<%= dirs.staging %>/step1/css',
  128. environment: 'production',
  129. force: true
  130. }
  131. }
  132. },
  133. /**
  134. * File Revision Confiugration
  135. * @property
  136. */
  137. rev: {
  138. files: {
  139. expand: true,
  140. cwd: '<%= dirs.staging %>/step2',
  141. src: [ 'js/*.js',
  142. '!js/lib/*.js',
  143. 'js/modernizr.js',
  144. 'css/**/*.css',
  145. 'img/**/*.{png,jpg}',
  146. 'css/imgages/**/*.{png,jpg}', '!img/agsquare.png']
  147. }
  148. },
  149. /**
  150. * JSHint Configuration
  151. * @property
  152. */
  153. jshint: {
  154. options: {
  155. jshintrc: './.jshintrc'
  156. },
  157. gruntfile: ['Gruntfile.js'],
  158. js: ['<%= dirs.root %>js/modules/**/*.js'],
  159. 'test-unit': ['<%= dirs.test %>/unit/**/*.js'],
  160. dev: {
  161. src: [ '<%= jshint.gruntfile %>',
  162. '<%= jshint.js %>' ,
  163. "<%= jshint['test-unit'] %>" ]
  164. },
  165. build: {
  166. src: [ '<%= jshint.gruntfile %>',
  167. '<%= jshint.js %>' ]
  168. }
  169. },
  170. imagemin: {
  171. dist: {
  172. expand: true,
  173. cwd: '<%= dirs.staging %>/step1',
  174. src: 'img/**',
  175. dest: '<%= dirs.staging %>/step2/'
  176. }
  177. },
  178. manifest:{
  179. dest: '<%= dirs.staging %>/step3/manifest.appcache',
  180. port: 3002
  181. },
  182. htmlmin: {
  183. dist: {
  184. options: {
  185. removeComments: true,
  186. collapseWhitespace: true
  187. },
  188. expand: true,
  189. cwd: '<%= dirs.staging %>/step2',
  190. src: '**/*.html',
  191. dest: '<%= dirs.staging %>/step3/'
  192. }
  193. },
  194. // regarde configuration
  195. regarde: {
  196. html: {
  197. files: ['<%= dirs.root %>/*.html'],
  198. tasks: ['livereload'],
  199. spawn: false
  200. },
  201. js: {
  202. files: ['<%= dirs.root %>/js/**/*.js'],
  203. tasks: ['jshint:dev', 'jasmine', 'livereload', 'wait:100'],
  204. spawn: false
  205. },
  206. compass: {
  207. files: [ '<%= dirs.sass %>/*.sass', '<%= dirs.sass %>/*.scss' ],
  208. tasks: [ 'compass:dev', 'livereload'],
  209. spawn: false
  210. },
  211. 'test-unit': {
  212. files: ['<%= dirs.test %>/unit/**/*.js'],
  213. tasks: ['jshint:dev', 'wait:100'],
  214. spawn: false
  215. },
  216. gruntfile: {
  217. files: ['Gruntfile.js'],
  218. tasks: ['wait:100', 'jshint:dev'],
  219. spawn: false
  220. }
  221. }
  222. });
  223. // These plugins provide necessary tasks.
  224. grunt.loadNpmTasks('grunt-contrib-copy');
  225. grunt.loadNpmTasks('grunt-contrib-clean');
  226. grunt.loadNpmTasks('grunt-contrib-concat');
  227. grunt.loadNpmTasks('grunt-contrib-qunit');
  228. grunt.loadNpmTasks('grunt-contrib-jshint');
  229. grunt.loadNpmTasks('grunt-contrib-watch');
  230. grunt.loadNpmTasks('grunt-contrib-uglify');
  231. grunt.loadNpmTasks('grunt-contrib-cssmin');
  232. grunt.loadNpmTasks('grunt-regarde');
  233. grunt.loadNpmTasks('grunt-usemin');
  234. grunt.loadNpmTasks('grunt-contrib-compass');
  235. grunt.loadNpmTasks('grunt-rev');
  236. grunt.loadNpmTasks('grunt-contrib-imagemin');
  237. grunt.loadNpmTasks('grunt-contrib-htmlmin');
  238. grunt.loadNpmTasks('grunt-contrib-livereload');
  239. grunt.loadNpmTasks('grunt-contrib-connect');
  240. grunt.loadNpmTasks('grunt-contrib-manifest');
  241. // Default task.
  242. grunt.registerTask('production', [
  243. 'jshint:build',
  244. 'clean',
  245. 'copy:dist-step-1',
  246. 'compass:dist',
  247. 'useminPrepare',
  248. 'concat',
  249. 'cssmin',
  250. 'uglify',
  251. 'copy:dist-step-2',
  252. 'imagemin',
  253. 'rev',
  254. 'usemin',
  255. 'copy:dist-step-3',
  256. 'htmlmin:dist',
  257. 'manifest',
  258. 'copy:dist-final'
  259. ]);
  260. // server task
  261. grunt.renameTask('connect', 'server');
  262. grunt.registerTask('dev', ['jshint:dev', 'compass:dev', 'livereload-start' , 'server:dev', 'regarde']);
  263. grunt.registerTask('default', ['production']);
  264. grunt.registerTask('dist', ['server:pro']);
  265. };