Gruntfile.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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('package.json'),
  8. banner: '/*\n' +
  9. '* bootstrap-table - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
  10. 'https://github.com/wenzhixin/bootstrap-table\n' +
  11. '* Copyright (c) 2017 zhixin wen\n' +
  12. '* Licensed MIT License\n' +
  13. '*/\n',
  14. // Task configuration.
  15. clean: ['dist', 'docs/dist'],
  16. concat: {
  17. //basic_target: {
  18. // src: ['src/bootstrap-table.js', 'src/extensions/**/*.js'],
  19. // dest: 'dist/bootstrap-table-all.js'
  20. //},
  21. locale_target: {
  22. src: ['src/locale/**/*.js'],
  23. dest: 'dist/bootstrap-table-locale-all.js'
  24. }
  25. },
  26. uglify: {
  27. options: {
  28. banner: '<%= banner %>'
  29. },
  30. basic_target: {
  31. files: {
  32. 'dist/bootstrap-table.min.js': ['src/bootstrap-table.js'],
  33. //'dist/bootstrap-table-all.min.js': ['dist/bootstrap-table-all.js'],
  34. 'dist/bootstrap-table-locale-all.min.js': ['dist/bootstrap-table-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/bootstrap-table.min.css': ['src/bootstrap-table.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. });
  81. var bumpVersion = function (path, version, startWith) {
  82. var lines = fs.readFileSync(path, 'utf8').split('\n');
  83. lines.forEach(function (line, i) {
  84. if (line.indexOf(startWith) === 0) {
  85. lines[i] = startWith + version;
  86. }
  87. });
  88. fs.writeFileSync(path, lines.join('\n'), 'utf8');
  89. grunt.log.ok('bumped version of ' + path + ' to ' + version);
  90. };
  91. grunt.registerTask('docs', 'build the docs', function () {
  92. var version = require('./package.json').version;
  93. bumpVersion('./_config.yml', version, 'current_version: ');
  94. bumpVersion('./src/bootstrap-table.js', version, ' * version: ');
  95. bumpVersion('./src/bootstrap-table.css', version, ' * version: ');
  96. var changeLog = fs.readFileSync('./CHANGELOG.md', 'utf8');
  97. var latestLogs = changeLog.split('### ')[1];
  98. var date = new Date();
  99. var lines = [
  100. '### Latest release (' +
  101. [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-') + ')',
  102. '',
  103. '#### v' + latestLogs
  104. ];
  105. fs.writeFileSync('./docs/_includes/latest-release.md', lines.join('\n'), 'utf8');
  106. grunt.log.ok('updated the latest-release.md to ' + version);
  107. });
  108. grunt.loadNpmTasks('grunt-contrib-clean');
  109. grunt.loadNpmTasks('grunt-contrib-concat');
  110. grunt.loadNpmTasks('grunt-contrib-uglify');
  111. grunt.loadNpmTasks('grunt-contrib-cssmin');
  112. grunt.loadNpmTasks('grunt-contrib-copy');
  113. grunt.registerTask('default', ['clean', 'concat', 'uglify', 'cssmin', 'copy']);
  114. };