|
1 | 1 | 'use strict'; |
2 | 2 |
|
| 3 | +var fs = require('fs'); |
| 4 | + |
3 | 5 | module.exports = function(grunt) { |
4 | 6 |
|
5 | 7 | // Project configuration. |
@@ -77,14 +79,54 @@ module.exports = function(grunt) { |
77 | 79 | dest: 'docs/dist', // destination folder |
78 | 80 | expand: true // required when using cwd |
79 | 81 | } |
| 82 | + }, |
| 83 | + release: { |
| 84 | + options: { |
| 85 | + additionalFiles: ['bootstrap-table.jquery.json'], |
| 86 | + beforeRelease: ['docs', 'default'] |
| 87 | + } |
80 | 88 | } |
81 | 89 | }); |
82 | 90 |
|
| 91 | + var bumpVersion = function (path, version, startWith) { |
| 92 | + var lines = fs.readFileSync(path, 'utf8').split('\n'); |
| 93 | + lines.forEach(function (line, i) { |
| 94 | + if (line.indexOf(startWith) === 0) { |
| 95 | + lines[i] = startWith + version; |
| 96 | + } |
| 97 | + }); |
| 98 | + fs.writeFileSync(path, lines.join('\n'), 'utf8'); |
| 99 | + |
| 100 | + grunt.log.ok('bumped version of ' + path + ' to ' + version); |
| 101 | + }; |
| 102 | + |
| 103 | + grunt.registerTask('docs', 'build the docs', function () { |
| 104 | + var version = require('./package.json').version; |
| 105 | + bumpVersion('./_config.yml', version, 'current_version: '); |
| 106 | + bumpVersion('./src/bootstrap-table.js', version, ' * version: '); |
| 107 | + bumpVersion('./src/bootstrap-table.css', version, ' * version: '); |
| 108 | + |
| 109 | + var changeLog = fs.readFileSync('./CHANGELOG.md', 'utf8'); |
| 110 | + var latestLogs = changeLog.split('### ')[1]; |
| 111 | + var date = new Date(); |
| 112 | + |
| 113 | + var lines = [ |
| 114 | + '### Latest release (' + |
| 115 | + [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-') + ')', |
| 116 | + '', |
| 117 | + '#### v' + latestLogs |
| 118 | + ]; |
| 119 | + fs.writeFileSync('./docs/_includes/latest-release.md', lines.join('\n'), 'utf8'); |
| 120 | + |
| 121 | + grunt.log.ok('updated the latest-release.md to ' + version); |
| 122 | + }); |
| 123 | + |
83 | 124 | grunt.loadNpmTasks('grunt-contrib-clean'); |
84 | 125 | grunt.loadNpmTasks('grunt-contrib-concat'); |
85 | 126 | grunt.loadNpmTasks('grunt-contrib-uglify'); |
86 | 127 | grunt.loadNpmTasks('grunt-contrib-cssmin'); |
87 | 128 | grunt.loadNpmTasks('grunt-contrib-copy'); |
| 129 | + grunt.loadNpmTasks('grunt-release'); |
88 | 130 |
|
89 | 131 | grunt.registerTask('default', ['clean', 'concat', 'uglify', 'cssmin', 'copy']); |
90 | 132 | }; |
0 commit comments