kibana/tasks/compile_dist_readme.js
Chris Cowan 5d39d334ea Closes #355 - Make bin/kibana executable in the tar and zip archives
grunt-compress is broken it does not honor the `mode` option when tyring
to set the permissions on a file. This is broken through out the entire
Grunt project (grunt-contrib-copy doesn't honor it, grunt-replace
doesn't honor it... as far as I can tell nothing does). SO instead of
wasting more time trying to get it to work (I already wasted an hour on
it) I decided to fall back to just writing a 10 minute script that
actually works. If you are intent on using a pure Grunt task to make it
work feel free to go do that rabit hole.
2014-09-23 07:02:34 -07:00

61 lines
1.6 KiB
JavaScript

var marked = require('marked');
var Promise = require('bluebird');
var join = require('path').join;
var TextRenderer = require('marked-text-renderer');
var _ = require('lodash');
var fs = require('fs');
var entities = new (require('html-entities').AllHtmlEntities)();
var readFile = Promise.promisify(fs.readFile);
var writeFile = Promise.promisify(fs.writeFile);
TextRenderer.prototype.heading = function (text, level, raw) {
return '\n\n' + text + '\n' + _.map(text, function () { return '='; }).join('') + '\n';
};
var process = function (input) {
var output = input.replace(/<\!\-\- [^\-]+ \-\->/g, '\n');
output = marked(output);
return entities.decode(output);
};
module.exports = function (grunt) {
grunt.registerTask('compile_dist_readme', function () {
var done = this.async();
var root = grunt.config.get('root');
var build = grunt.config.get('build');
var srcReadme = join(root, 'README.md');
var distReadme = join(build, 'dist', 'kibana', 'README.txt');
var srcLicense = join(root, 'LICENSE.md');
var distLicense = join(build, 'dist', 'kibana', 'LICENSE.txt');
marked.setOptions({
renderer: new TextRenderer(),
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
});
readFile(srcReadme, 'utf-8')
.then(function (data) {
return writeFile(distReadme, process(data.toString()));
})
.then(function () {
return readFile(srcLicense, 'utf-8');
})
.then(function (data) {
return writeFile(distLicense, process(data.toString()));
})
.then(done)
.catch(done);
});
};