1 import ts from "typescript"
2 import DefaultKindGenerator, { GetDocBlockOptions } from "./default.js"
3 import { DOCBLOCK_END_LINE, DOCBLOCK_START } from "../../constants.js"
4 import { shouldHaveCustomNamespace } from "../../utils/medusa-react-utils.js"
5
6 /**
7 * A generator used to retrieve doc blocks for a source file.
8 */
9 class SourceFileKindGenerator extends DefaultKindGenerator<ts.SourceFile> {
10 protected allowedKinds: ts.SyntaxKind[] = [ts.SyntaxKind.SourceFile]
11 public name = "source-file"
12
13 /**
14 * Retrieve the docblock of a source file.
15 *
16 * @param {ts.SourceFile | ts.Node} node - The node to retrieve its docblocks.
17 * @param {GetDocBlockOptions} options - The formatting options.
18 * @returns {string} The node's docblock.
19 */
20 async getDocBlock(
21 node: ts.SourceFile | ts.Node,
22 options?: GetDocBlockOptions
23 ): Promise<string> {
24 if (!this.isAllowed(node)) {
25 return await super.getDocBlock(node, options)
26 }
27
28 if (shouldHaveCustomNamespace(node)) {
29 return `${DOCBLOCK_START}${this.getCommonDocs(node, {
30 addDefaultSummary: true,
31 })}${DOCBLOCK_END_LINE}`
32 }
33
34 return ""
35 }
36 }
37
38 export default SourceFileKindGenerator