-
Notifications
You must be signed in to change notification settings - Fork 53
/
gulpfile.js
46 lines (41 loc) · 1.57 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var gulp = require('gulp');
var initGulpTasks = require('react-pack');
var request = require('request');
var cheerio = require('cheerio');
var fs = require('fs');
var taskConfig = require('./config');
initGulpTasks(gulp, taskConfig);
gulp.task('getoptions', function () {
request('http://www.daterangepicker.com/', function (error, response, body) {
var $ = cheerio.load(body);
var options = $('#options ul li code').map(function () {
return $(this).text().trim();
}).get();
// add options that aren't documented
options.push('template');
// de-dupe and sort
options = options.filter(function (item, index) {
return options.indexOf(item) === index;
}).sort();
fs.writeFile('./src/get-options.js', [
'/* generated by gulpfile.js */',
'module.exports = exports = function () {',
'\treturn ' + JSON.stringify(options, null, '\t\t') + ';',
'};'
].join('\n'), 'utf-8');
// fix options that contain html strings
options = options.map(function (option) {
return option.replace(/\</gi, '<').replace(/\>/gi, '>');
});
// update README.md
var before = 'You can pass all the same props as the original plugin:',
after = 'You can listen to the following 7 events:',
readme = fs.readFileSync('./README.md').toString(),
newReadme = readme.slice(0, readme.indexOf(before) + before.length) +
'\n\n- **' +
wrap(options.join(', ')).slice(2) +
'**\n\n' +
readme.slice(readme.indexOf(after));
fs.writeFileSync('./README.md', newReadme, 'utf-8');
});
});