-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-api-toc.cjs
31 lines (25 loc) · 783 Bytes
/
generate-api-toc.cjs
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
// From https://github.com/hapijs/joi/blob/master/generate-readme-toc.js
const Toc = require('markdown-toc');
const Fs = require('fs');
const Package = require('./package.json');
const internals = {
filename: './README.md',
};
internals.generate = function generate() {
const api = Fs.readFileSync(internals.filename, 'utf8');
const tocOptions = {
bullets: '-',
slugify(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(internals.filename, output);
};
internals.generate();