mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[grunt] remove unneeded render_readme task
This commit is contained in:
parent
f25f85089c
commit
e154c485e9
1 changed files with 0 additions and 84 deletions
|
@ -1,84 +0,0 @@
|
|||
module.exports = function (grunt) {
|
||||
var expect = require('expect.js');
|
||||
var root = require('path').join.bind(null, __dirname, '../');
|
||||
|
||||
var README = root('README.md');
|
||||
var RE_COMMENT = /<!--(.+?)-->/g;
|
||||
|
||||
var tags = {
|
||||
render: function (args) {
|
||||
return grunt.config.process(args.template);
|
||||
},
|
||||
include: function (args) {
|
||||
return grunt.file.read(args.path);
|
||||
}
|
||||
};
|
||||
|
||||
grunt.registerTask('render_readme', function () {
|
||||
var input = grunt.file.read(README);
|
||||
var chunks = [];
|
||||
|
||||
var comments = findAndParseComments(input);
|
||||
|
||||
|
||||
for (var i = 0; i < comments.length; i += 2) {
|
||||
var open = comments[i];
|
||||
var close = comments[i + 1];
|
||||
|
||||
expect(close.tag).to.be('/' + open.tag);
|
||||
|
||||
if (!tags[open.tag]) {
|
||||
throw new TypeError('unkown tag name ' + open.tag);
|
||||
}
|
||||
|
||||
chunks.push(input.substring(open.i0, open.i1));
|
||||
chunks.push('\n' + tags[open.tag](open.args).trim() + '\n');
|
||||
chunks.push(input.substring(close.i0, close.i1));
|
||||
|
||||
// add the text between this and the next tag
|
||||
if (comments.length > i + 2) {
|
||||
var next = comments[i + 2];
|
||||
chunks.push(input.substring(close.i1, next.i0));
|
||||
}
|
||||
}
|
||||
|
||||
var output = chunks.join('');
|
||||
if (output === input) {
|
||||
grunt.log.ok('no update to the readme');
|
||||
return;
|
||||
}
|
||||
|
||||
grunt.log.ok('readme updated and added to git');
|
||||
grunt.file.write(README, output);
|
||||
grunt.util.spawn({
|
||||
cmd: 'git',
|
||||
args: ['add', README]
|
||||
}, this.async());
|
||||
});
|
||||
|
||||
function findAndParseComments(input) {
|
||||
var comments = [];
|
||||
var match;
|
||||
var comment;
|
||||
|
||||
while (match = RE_COMMENT.exec(input)) {
|
||||
var parts = match[1].trim().split(/\s+/);
|
||||
comment = {
|
||||
tag: parts.shift().trim(),
|
||||
args: parts.join(' ').trim(),
|
||||
i0: match.index,
|
||||
i1: match.index + match[0].length
|
||||
};
|
||||
|
||||
if (comment.args) {
|
||||
comment.args = JSON.parse(comment.args);
|
||||
} else {
|
||||
comment.args = null;
|
||||
}
|
||||
|
||||
comments.push(comment);
|
||||
}
|
||||
|
||||
return comments;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue