-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
typedoc-md-to-readme.js
33 lines (29 loc) · 1.26 KB
/
typedoc-md-to-readme.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
// stupid quick script to extract markdown documentation of a specific function
// from a typedoc generated markdown file and insert it into README.md
// done because I want to document the most important main function in the README, rest of
// the documentation is in the documentation site
const fs = require('fs');
const extractText = (file, start, end) => {
const text = fs.readFileSync(file, 'utf8');
const regex = new RegExp(`(?=${start})([\\s\\S]*)${end}`, 'gm');
return regex.exec(text)[1].trim();
};
const replaceMdLinks = (text) => {
const regex = /\(([\w/]+)\.md(?:#\w*?)?\)/g;
const link = 'https://0x464e.github.io/slideshow-video/';
return text.replace(regex, `(${link}$1)`);
};
const updateText = (file, start, end, text) => {
const textFile = fs.readFileSync(file, 'utf8');
const regex = new RegExp(`${start}([\\s\\S]*)${end}`, 'gm');
const newTextFile = textFile.replace(regex, `${start}\n${text}\n${end}`);
fs.writeFileSync(file, newTextFile, 'utf8');
};
const extractedText = extractText('docs-md/modules.md', '### createSlideshow', '#### Defined in');
const replacedText = replaceMdLinks(extractedText);
updateText(
'README.md',
'<!-- createSlideshow begin -->',
'<!-- createSlideshow end -->',
replacedText
);