Gruntfile.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 Commercial: <%= pkg.homepage %>/license/',
  21. ' * Non-commercial: http://creativecommons.org/licenses/by-nc-nd/3.0/',
  22. ' */\n'
  23. ].join('\n'),
  24. // ---
  25. // Tasks
  26. // ---
  27. copy: {
  28. main: {
  29. files: [
  30. { cwd: '<%= dirs.src %>/css', src: '**', dest: '<%= dirs.dist %>/css', expand: true, flatten: true, filter: 'isFile' },
  31. { cwd: '<%= dirs.src %>/js/language', src: '**', dest: '<%= dirs.dist %>/js/language', expand: true, flatten: true, filter: 'isFile' }
  32. ]
  33. }
  34. },
  35. cssmin: {
  36. minify: { expand: true, cwd: '<%= dirs.src %>/css/', src: ['*.css'], dest: '<%= dirs.dist %>/css/', ext: '.min.css' },
  37. add_banner: {
  38. options: {
  39. stripBanners: true,
  40. banner: '<%= banner %>'
  41. },
  42. files: {
  43. '<%= dirs.dist %>/css/bootstrapValidator.min.css': ['<%= dirs.src %>/css/bootstrapValidator.css']
  44. }
  45. }
  46. },
  47. concat: {
  48. source: {
  49. options: {
  50. separator: ';',
  51. stripBanners: true,
  52. banner: '<%= banner %>'
  53. },
  54. src: ['<%= dirs.src %>/js/bootstrapValidator.js', '<%= dirs.src %>/js/validator/*.js'],
  55. dest: '<%= dirs.dist %>/js/bootstrapValidator.js'
  56. },
  57. test: {
  58. src: ['<%= dirs.test %>/spec/*.js', '<%= dirs.test %>/spec/validator/*.js'],
  59. dest: '<%= dirs.test %>/spec.js'
  60. }
  61. },
  62. uglify: {
  63. options: {
  64. banner: '<%= banner %>'
  65. },
  66. build: {
  67. src: ['<%= dirs.dist %>/js/bootstrapValidator.js'],
  68. dest: '<%= dirs.dist %>/js/bootstrapValidator.min.js'
  69. }
  70. },
  71. jshint: {
  72. all: [
  73. '<%= dirs.src %>/js/**/*.js'
  74. ],
  75. options: {
  76. browser: true,
  77. camelcase: true,
  78. curly: true,
  79. eqeqeq: true,
  80. eqnull: true,
  81. es3: true,
  82. expr: true,
  83. laxbreak: true, // Allow line breaking before && or ||
  84. loopfunc: true,
  85. newcap: true,
  86. noarg: true,
  87. onevar: true,
  88. sub: true,
  89. undef: true,
  90. white: true
  91. }
  92. },
  93. watch: {
  94. source: {
  95. files: ['<%= dirs.src %>/css/**', '<%= dirs.src %>/js/**'],
  96. tasks: ['build'],
  97. options: {
  98. spawn: false
  99. }
  100. },
  101. test: {
  102. files: ['<%= dirs.test %>/spec/**'],
  103. tasks: ['concat:test']
  104. }
  105. }
  106. });
  107. grunt.registerTask('default', 'build');
  108. grunt.registerTask('build', ['copy', 'cssmin', 'concat', 'uglify']);
  109. grunt.loadNpmTasks('grunt-contrib-concat');
  110. grunt.loadNpmTasks('grunt-contrib-copy');
  111. grunt.loadNpmTasks('grunt-contrib-cssmin');
  112. grunt.loadNpmTasks('grunt-contrib-jshint');
  113. grunt.loadNpmTasks('grunt-contrib-uglify');
  114. grunt.loadNpmTasks('grunt-contrib-watch');
  115. };