-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathgenerate-jsdoc.ts
31 lines (26 loc) · 990 Bytes
/
generate-jsdoc.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
import fs from 'fs-extra';
import path from 'path';
import jsdoc2md from 'jsdoc-to-markdown';
const MDX_EXTENSION = '.mdx';
const outputDir = path.join(process.cwd(), 'api_reference/javascript');
const jsFiles = ['scripts/CCIPLocalSimulatorFork.js'];
const generateMarkdownDocs = async (
files: string[],
outputDirectory: string
) => {
await fs.ensureDir(outputDirectory);
for (const file of files) {
const absoluteFilePath = path.join(process.cwd(), file);
const fileName = path.basename(file, path.extname(file));
const outputPath = path.join(
outputDirectory,
`${fileName}${MDX_EXTENSION}`
);
const markdown = await jsdoc2md.render({ files: absoluteFilePath });
const fixedMarkdown = markdown.replace(/<\{/g, '<\\{');
await fs.outputFile(outputPath, fixedMarkdown);
}
};
generateMarkdownDocs(jsFiles, outputDir)
.then(() => console.log('Markdown documentation generated successfully.'))
.catch(err => console.error(err));