forked from galenandrew/relish
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate-docs.js
More file actions
34 lines (29 loc) · 1.06 KB
/
generate-docs.js
File metadata and controls
34 lines (29 loc) · 1.06 KB
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
'use strict'
const Toc = require('markdown-toc')
const Fs = require('fs')
const Package = require('./package.json')
const internals = {
api: {
filename: './API.md',
contents: Fs.readFileSync('./API.md', 'utf8')
},
readme: {
filename: './README.md',
contents: Fs.readFileSync('./README.md', 'utf8')
}
}
const tocOptions = {
bullets: '-',
slugify: function (text) {
return text.toLowerCase()
.replace(/\s/g, '-')
.replace(/[^\w-]/g, '')
}
}
// generate table of contents and version label docs
const api = Toc.insert(internals.api.contents, tocOptions)
.replace(/<!-- version -->(.|\n)*<!-- versionstop -->/, `<!-- version -->\nAPI Documentation - \`v${Package.version}\`\n---\n<!-- versionstop -->`)
Fs.writeFileSync(internals.api.filename, api)
// create absolute URL for versioned docs
const readme = internals.readme.contents.replace(/\[API Documentation\]\(.*\)/g, `[API Documentation](${Package.homepage || ''}/blob/v${Package.version}/${internals.api.filename.substr(2)})`)
Fs.writeFileSync(internals.readme.filename, readme)