-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-docs.js
55 lines (45 loc) · 1.38 KB
/
generate-docs.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
/**
* Requires jsdoc and jsdoc-to-markdown
*/
/* eslint-disable no-console */
import fs from "fs";
import path from "path";
import glob from "glob";
import { execSync } from "child_process";
/**
* Runs through packages folders looking for JSDoc and generates markdown docs
*/
function generateDocs() {
console.log("Generating package docs");
// Use glob to get all js/ts files
const pathPattern = path.join(process.cwd(), "./lib/**/*.[jt]s?(x)");
const filePaths = glob.sync(pathPattern, {
ignore: [
"**/node_modules/**",
"**/cypress/**",
"**/__tests__/**",
"**/*.test.js",
"**/*_spec.js",
],
});
for (const file of filePaths) {
const { base: fileName } = path.parse(file);
const relativePath = path.relative(process.cwd(), file);
const markdown = execSync(`./node_modules/.bin/jsdoc2md ${relativePath}`);
const writeDir = path.join(
process.cwd(),
`website/docs/api/${relativePath.replace(fileName, "")}`
);
// check if the directory exists
if (!fs.existsSync(writeDir)) {
// create the directory
fs.mkdirSync(writeDir, { recursive: true });
}
// write the markdown file
fs.writeFileSync(`${writeDir}/${fileName}.md`, markdown);
}
// Let the user know what step we're on
console.log("\u001B[32m", "✔️ Package docs generated", "\u001B[0m");
}
generateDocs();
process.exit(0);