forked from paed01/bpmn-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-api-toc.js
37 lines (27 loc) · 885 Bytes
/
generate-api-toc.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
'use strict';
// From https://github.com/hapijs/joi/blob/master/generate-readme-toc.js
// Load modules
const Toc = require('markdown-toc');
const Fs = require('fs');
const Package = require('./package.json');
// Declare internals
const filenames = getFileNames();
function getFileNames() {
const arg = process.argv[2] || './API.md';
return arg.split(',');
}
function generate(filename) {
const api = Fs.readFileSync(filename, 'utf8');
const tocOptions = {
bullets: '-',
slugify: function(text) {
return text.toLowerCase()
.replace(/\s/g, '-')
.replace(/[^\w-]/g, '');
}
};
const output = Toc.insert(api, tocOptions)
.replace(/<!-- version -->(.|\n)*<!-- versionstop -->/, '<!-- version -->\n# ' + Package.version + ' API Reference\n<!-- versionstop -->');
Fs.writeFileSync(filename, output);
}
filenames.forEach(generate);