/
generate-api-docs.ts
48 lines (40 loc) · 1.48 KB
/
generate-api-docs.ts
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
import { readdirSync, readFileSync, writeFileSync } from 'fs';
import { resolve } from 'path';
import { Application } from 'typedoc';
const packagesDir = resolve(__dirname, '..', '..', 'packages');
const apiDocsDir = resolve(__dirname, '..', '..', 'website', 'docs', 'api');
let dirs = readdirSync(packagesDir);
// Do not build the docs for these packages
const excludeDirs = ['database-tests', 'e2e', 'error', 'types'];
// Config for typedoc;
const app = new Application({
theme: 'markdown',
module: 'commonjs',
mode: 'file',
ignoreCompilerErrors: true,
excludePrivate: true,
excludeNotExported: true,
tsconfig: 'tsconfig.json',
});
// Do not build the docs for these packages
dirs = dirs.filter(dir => !excludeDirs.includes(dir));
dirs.forEach(dir => {
// Generate the api doc for each package
app.generateDocs(
app.expandInputFiles([resolve(packagesDir, dir, 'src')]),
resolve(apiDocsDir, dir)
);
// For each generated files we fix the links
const docFiles = readdirSync(resolve(apiDocsDir, dir));
docFiles.forEach(file => {
let fileContent = readFileSync(resolve(apiDocsDir, dir, file), { encoding: 'utf8' });
fileContent = fileContent
.replace(/\((api-\S+)\)/gm, '(/docs/api/' + dir + '/$1)')
.replace(new RegExp('.md', 'g'), '');
writeFileSync(resolve(apiDocsDir, dir, file), fileContent, { encoding: 'utf8' });
});
});
// console.log(`generated docs for packages:`);
// dirs.forEach(dir => {
// console.log(`"api/${dir}/api-readme",`);
// });