Gruntfile.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. 'use strict';
  2. var fs = require('fs');
  3. module.exports = function(grunt) {
  4. // Project configuration.
  5. grunt.initConfig({
  6. // Metadata.
  7. pkg: grunt.file.readJSON('bootstrap-table.jquery.json'),
  8. banner: '/*\n' +
  9. '* <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
  10. '<%= pkg.homepage ? "* " + pkg.homepage : "" %>\n' +
  11. '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>\n' +
  12. '* Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n' +
  13. '*/\n',
  14. // Task configuration.
  15. clean: ['dist', 'docs/dist'],
  16. concat: {
  17. //basic_target: {
  18. // src: ['src/<%= pkg.name %>.js', 'src/extensions/**/*.js'],
  19. // dest: 'dist/<%= pkg.name %>-all.js'
  20. //},
  21. locale_target: {
  22. src: ['src/locale/**/*.js'],
  23. dest: 'dist/<%= pkg.name %>-locale-all.js'
  24. }
  25. },
  26. uglify: {
  27. options: {
  28. banner: '<%= banner %>'
  29. },
  30. basic_target: {
  31. files: {
  32. 'dist/<%= pkg.name %>.min.js': ['src/<%=pkg.name %>.js'],
  33. //'dist/<%= pkg.name %>-all.min.js': ['dist/<%=pkg.name %>-all.js'],
  34. 'dist/<%= pkg.name %>-locale-all.min.js': ['dist/<%=pkg.name %>-locale-all.js']
  35. }
  36. },
  37. locale_target: {
  38. files: [{
  39. expand: true,
  40. cwd: 'src/locale',
  41. src: '**/*.js',
  42. dest: 'dist/locale',
  43. ext: '.min.js' // replace .js to .min.js
  44. }]
  45. },
  46. extensions_target: {
  47. files: [{
  48. expand: true,
  49. cwd: 'src/extensions',
  50. src: '**/*.js',
  51. dest: 'dist/extensions',
  52. ext: '.min.js' // replace .js to .min.js
  53. }]
  54. }
  55. },
  56. cssmin: {
  57. add_banner: {
  58. options: {
  59. banner: '<%= banner %>'
  60. },
  61. files: {
  62. 'dist/<%= pkg.name %>.min.css': ['src/<%=pkg.name %>.css']
  63. }
  64. }
  65. },
  66. copy: {
  67. source: {
  68. cwd: 'src', // set working folder / root to copy
  69. src: ['**/*.js', '**/*.css'], // copy all files and subfolders
  70. dest: 'dist', // destination folder
  71. expand: true // required when using cwd
  72. },
  73. files: {
  74. cwd: 'dist', // set working folder / root to copy
  75. src: '**/*', // copy all files and subfolders
  76. dest: 'docs/dist', // destination folder
  77. expand: true // required when using cwd
  78. }
  79. },
  80. release: {
  81. options: {
  82. additionalFiles: ['bootstrap-table.jquery.json'],
  83. beforeRelease: ['docs', 'default']
  84. }
  85. }
  86. });
  87. var bumpVersion = function (path, version, startWith) {
  88. var lines = fs.readFileSync(path, 'utf8').split('\n');
  89. lines.forEach(function (line, i) {
  90. if (line.indexOf(startWith) === 0) {
  91. lines[i] = startWith + version;
  92. }
  93. });
  94. fs.writeFileSync(path, lines.join('\n'), 'utf8');
  95. grunt.log.ok('bumped version of ' + path + ' to ' + version);
  96. };
  97. grunt.registerTask('docs', 'build the docs', function () {
  98. var version = require('./package.json').version;
  99. bumpVersion('./_config.yml', version, 'current_version: ');
  100. bumpVersion('./src/bootstrap-table.js', version, ' * version: ');
  101. bumpVersion('./src/bootstrap-table.css', version, ' * version: ');
  102. var changeLog = fs.readFileSync('./CHANGELOG.md', 'utf8');
  103. var latestLogs = changeLog.split('### ')[1];
  104. var date = new Date();
  105. var lines = [
  106. '### Latest release (' +
  107. [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-') + ')',
  108. '',
  109. '#### v' + latestLogs
  110. ];
  111. fs.writeFileSync('./docs/_includes/latest-release.md', lines.join('\n'), 'utf8');
  112. grunt.log.ok('updated the latest-release.md to ' + version);
  113. });
  114. grunt.loadNpmTasks('grunt-contrib-clean');
  115. grunt.loadNpmTasks('grunt-contrib-concat');
  116. grunt.loadNpmTasks('grunt-contrib-uglify');
  117. grunt.loadNpmTasks('grunt-contrib-cssmin');
  118. grunt.loadNpmTasks('grunt-contrib-copy');
  119. grunt.loadNpmTasks('grunt-release');
  120. grunt.registerTask('default', ['clean', 'concat', 'uglify', 'cssmin', 'copy']);
  121. };