Skip to content

Commit

Permalink
improve docs generation
Browse files Browse the repository at this point in the history
  • Loading branch information
pstadler committed Feb 15, 2014
1 parent 65def0f commit 779978a
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@ gulp.task('lint', function() {
});

gulp.task('docs', function(taskFinished) {
var files = ['lib/flightplan.js', 'lib/transport/transport.js'];
var sources = ['lib/flightplan.js', 'lib/transport/transport.js']
, readme = 'README.md'
, tmpFile = 'docs/API.md';

var options = {
output: 'docs/API.md',
template: 'docs/template.md.ejs'
template: 'docs/template.md.ejs',
output: tmpFile
};

markdox.process(files, options, function() {
var apidocs = fs.readFileSync(options.output, 'utf8');

apidocs = apidocs.replace(/'/g, "'").replace(/"/g, '"');

fs.writeFileSync(options.output, apidocs);
markdox.process(sources, options, function() {
var docsStr = fs.readFileSync(tmpFile, 'utf8')
, readmeStr = fs.readFileSync(readme, 'utf8');

var readme = fs.readFileSync('README.md', 'utf8');
readme = readme.replace(/<!-- DOCS -->(?:\r|\n|.)+<!-- ENDDOCS -->/gm, '<!-- DOCS -->' + apidocs +'<!-- ENDDOCS -->');
docsStr = docsStr.replace(/&#39;/g, "'").replace(/&quot;/g, '"');
readmeStr = readmeStr.replace(/(<!-- DOCS -->)(?:\r|\n|.)+(<!-- ENDDOCS -->)/gm
, "$1" + docsStr + "$2");

fs.writeFileSync('README.md', readme);
fs.writeFileSync(readme, readmeStr);
fs.unlinkSync(tmpFile);
console.log('Documentation generated.');
taskFinished();
});
Expand Down

0 comments on commit 779978a

Please sign in to comment.