-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathgenerate-readme.js
59 lines (58 loc) · 1.65 KB
/
generate-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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const CWD_PATH = `${__dirname}/`;
const TOP_LEVEL_PATH = CWD_PATH + '../../';
const DOCS_PATH = TOP_LEVEL_PATH + 'docs/markdown/';
const inputFiles = [
DOCS_PATH + '_intro.md',
DOCS_PATH + '_toc.md',
DOCS_PATH + '0_setup.md',
DOCS_PATH + '1_react.md',
DOCS_PATH + '2_redux.md',
DOCS_PATH + '3_tools.md',
DOCS_PATH + '4_recipes.md',
DOCS_PATH + '5_faq.md',
DOCS_PATH + '6_links.md',
DOCS_PATH + '_contributors.md',
DOCS_PATH + '_license.md',
];
const outputFile = TOP_LEVEL_PATH + 'README.md';
const result = inputFiles
.map(filePath => fs.readFileSync(filePath, 'utf8'))
.map(includeExamples)
.map(includeUsages)
.join('\n---\n\n');
fs.writeFileSync(outputFile, result, 'utf8');
function includeExamples(text) {
const INCLUDE_PATTERN = /::example='(.+?)'::/g;
return text.replace(INCLUDE_PATTERN, getReplacerWithWrapper(withCodeWrapper));
}
function includeUsages(text) {
const INCLUDE_PATTERN = /::usage='(.+?)'::/g;
return text.replace(INCLUDE_PATTERN, getReplacerWithWrapper(withDetailsWrapper));
}
function getReplacerWithWrapper(wrapper) {
return (match, filePath) => {
console.log(CWD_PATH + filePath);
const buffer = fs.readFileSync(CWD_PATH + filePath, 'utf8');
return wrapper(buffer);
};
}
function withCodeWrapper(text) {
return `
${'```tsx'}
${text}
${'```'}
`.trim();
}
function withDetailsWrapper(text) {
return `
<details><summary>show usage</summary><p>
${'```tsx'}
${text}
${'```'}
</p></details>
`.trim();
}
//# sourceMappingURL=generate-readme.js.map