UNPKG

3.02 kBTypeScriptView Raw
1import * as bt from '@babel/types';
2import type Map from 'ts-map';
3import type { NodePath } from 'ast-types/lib/node-path';
4import type { TemplateChildNode } from '@vue/compiler-dom';
5import type { Options as PugOptions } from 'pug';
6import type { Descriptor, Documentation } from './Documentation';
7export type ParseFileFunction = (opt: ParseOptions, documentation?: Documentation) => Promise<Documentation[]>;
8export type HandlerExecutorsFunction = (componentDefinitions: Map<string, NodePath>, ast: bt.File, options: ParseOptions, deps: {
9 parseFile: ParseFileFunction;
10}, documentation?: Documentation, forceSingleExport?: boolean) => Promise<Documentation[] | undefined>;
11export type ScriptHandler = (doc: Documentation, componentDefinition: NodePath, ast: bt.File, opt: ParseOptions, deps: {
12 parseFile: ParseFileFunction;
13 addDefaultAndExecuteHandlers: HandlerExecutorsFunction;
14}) => Promise<void>;
15export interface TemplateParserOptions {
16 functional: boolean;
17}
18export type TemplateHandler = (documentation: Documentation, templateAst: TemplateChildNode, siblings: TemplateChildNode[], options: TemplateParserOptions) => void;
19export interface ParseOptions extends DocGenOptions, Descriptor {
20 validExtends: (fullFilePath: string) => boolean;
21 filePath: string;
22 /**
23 * In what language is the component written
24 * @default undefined - let the system decide
25 */
26 lang?: 'ts' | 'js';
27}
28export interface DocGenOptions {
29 /**
30 * Which exported variables should be looked at
31 * @default undefined - means treat all exports
32 */
33 nameFilter?: string[];
34 /**
35 * What alias should be replaced in requires and imports
36 */
37 alias?: {
38 [alias: string]: string | string[];
39 };
40 /**
41 * What directories should be searched when resolving modules
42 */
43 modules?: string[];
44 /**
45 * Handlers that will be added at the end of the script analysis
46 */
47 addScriptHandlers?: ScriptHandler[];
48 /**
49 * Handlers that will be added at the end of the template analysis
50 */
51 addTemplateHandlers?: TemplateHandler[];
52 /**
53 * Handlers that will replace the extend and mixins analyzer
54 * They will be run before the main component analysis to avoid bleeding onto the main
55 */
56 scriptPreHandlers?: ScriptHandler[];
57 /**
58 * Handlers that will replace the main script analysis
59 */
60 scriptHandlers?: ScriptHandler[];
61 /**
62 * Handlers that will replace the template analysis
63 */
64 templateHandlers?: TemplateHandler[];
65 /**
66 * Does parsed components use jsx?
67 * @default true - if you do not disable it, babel will fail with `(<any>window).$`
68 */
69 jsx?: boolean;
70 /**
71 * Should extended components be parsed?
72 * @default `fullFilePath=>!/[\\/]node_modules[\\/]/.test(fullFilePath)`
73 */
74 validExtends?: (fullFilePath: string) => boolean;
75 /**
76 * all pug options passed to the pug compiler if you use it
77 */
78 pugOptions?: PugOptions;
79}