Gruntfile.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. module.exports = function(grunt) {
  2. grunt.initConfig({
  3. // ---
  4. // Variables
  5. // ---
  6. pkg: grunt.file.readJSON('package.json'),
  7. dirs: {
  8. src: 'src',
  9. dist: 'dist',
  10. test: 'test'
  11. },
  12. banner: [
  13. '/*!',
  14. ' * BootstrapValidator (<%= pkg.homepage %>)',
  15. ' * <%= pkg.description %>',
  16. ' *',
  17. ' * @version v<%= pkg.version %>, built on <%= grunt.template.today("yyyy-mm-dd h:MM:ss TT") %>',
  18. ' * @author <%= pkg.author.url %>',
  19. ' * @copyright (c) 2013 - <%= grunt.template.today("yyyy") %> Nguyen Huu Phuoc',
  20. ' * @license MIT',
  21. ' */\n'
  22. ].join('\n'),
  23. // ---
  24. // Tasks
  25. // ---
  26. copy: {
  27. main: {
  28. files: [
  29. { cwd: '<%= dirs.src %>/css', src: '**', dest: '<%= dirs.dist %>/css', expand: true, flatten: true, filter: 'isFile' },
  30. { cwd: '<%= dirs.src %>/js/language', src: '**', dest: '<%= dirs.dist %>/js/language', expand: true, flatten: true, filter: 'isFile' }
  31. ]
  32. }
  33. },
  34. cssmin: {
  35. minify: { expand: true, cwd: '<%= dirs.src %>/css/', src: ['*.css'], dest: '<%= dirs.dist %>/css/', ext: '.min.css' },
  36. add_banner: {
  37. options: {
  38. stripBanners: true,
  39. banner: '<%= banner %>'
  40. },
  41. files: {
  42. '<%= dirs.dist %>/css/bootstrapValidator.min.css': ['<%= dirs.src %>/css/bootstrapValidator.css']
  43. }
  44. }
  45. },
  46. concat: {
  47. source: {
  48. options: {
  49. separator: ';',
  50. stripBanners: true,
  51. banner: '<%= banner %>'
  52. },
  53. src: ['<%= dirs.src %>/js/bootstrapValidator.js', '<%= dirs.src %>/js/validator/*.js'],
  54. dest: '<%= dirs.dist %>/js/bootstrapValidator.js'
  55. },
  56. test: {
  57. src: ['<%= dirs.test %>/spec/*.js', '<%= dirs.test %>/spec/validator/*.js'],
  58. dest: '<%= dirs.test %>/spec.js'
  59. }
  60. },
  61. uglify: {
  62. options: {
  63. banner: '<%= banner %>'
  64. },
  65. build: {
  66. src: ['<%= dirs.dist %>/js/bootstrapValidator.js'],
  67. dest: '<%= dirs.dist %>/js/bootstrapValidator.min.js'
  68. }
  69. },
  70. jshint: {
  71. all: [
  72. '<%= dirs.src %>/js/**/*.js'
  73. ],
  74. options: {
  75. browser: true,
  76. camelcase: true,
  77. curly: true,
  78. eqeqeq: true,
  79. eqnull: true,
  80. es3: true,
  81. expr: true,
  82. laxbreak: true, // Allow line breaking before && or ||
  83. loopfunc: true,
  84. newcap: true,
  85. noarg: true,
  86. onevar: true,
  87. sub: true,
  88. undef: true,
  89. white: true
  90. }
  91. },
  92. watch: {
  93. source: {
  94. files: ['<%= dirs.src %>/css/**', '<%= dirs.src %>/js/**'],
  95. tasks: ['build'],
  96. options: {
  97. spawn: false
  98. }
  99. },
  100. test: {
  101. files: ['<%= dirs.test %>/spec/**'],
  102. tasks: ['concat:test']
  103. }
  104. }
  105. });
  106. grunt.registerTask('default', 'build');
  107. grunt.registerTask('build', ['copy', 'cssmin', 'concat', 'uglify']);
  108. grunt.loadNpmTasks('grunt-contrib-concat');
  109. grunt.loadNpmTasks('grunt-contrib-copy');
  110. grunt.loadNpmTasks('grunt-contrib-cssmin');
  111. grunt.loadNpmTasks('grunt-contrib-jshint');
  112. grunt.loadNpmTasks('grunt-contrib-uglify');
  113. grunt.loadNpmTasks('grunt-contrib-watch');
  114. };