-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
executable file
·45 lines (41 loc) · 1.43 KB
/
index.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
#!/usr/bin/env node
import chokidar from "chokidar";
import { initialize } from "./functions/initialize.js";
import { getDataForMarkdown } from "./functions/get-data-for-markdown.js";
import { config } from "./config.js";
import { createMarkdown } from "./functions/create-markdown.js";
import { deleteMarkdown } from "./functions/delete-markdown.js";
import { filterByExtensions } from "./functions/utils.js";
import { validateConfig } from "./functions/validate-config.js";
export const startReactCommentDocs = () => {
validateConfig(config);
const [fileNames, templatePath, dynamicTemplatePath] = initialize(config);
fileNames.forEach((fileName) => {
const variables = getDataForMarkdown(fileName, config.fields);
createMarkdown(
fileName,
variables,
templatePath,
dynamicTemplatePath,
);
});
chokidar.watch(config.componentsDir).on("all", (event, fileName) => {
if (filterByExtensions([fileName], config.extensions).length) {
if (event === "add" || event === "change") {
const variables = getDataForMarkdown(fileName, config.fields);
createMarkdown(
fileName,
variables,
templatePath,
dynamicTemplatePath
);
console.log(`Docs for ${fileName} updated.`);
}
if (event === "unlink") {
deleteMarkdown(fileName);
console.log(`Docs for ${fileName} removed.`);
}
}
});
};
startReactCommentDocs();