@@ -2,19 +2,47 @@ import * as fs from 'fs'
2
2
import * as path from 'path'
3
3
import { parseComponent , SFCDescriptor } from 'vue-template-compiler'
4
4
import { Documentation } from './Documentation'
5
- import parseScript from './parse-script'
6
- import parseTemplate from './parse-template'
7
- import handlers from './script-handlers'
5
+ import parseScript , { Handler as ScriptHandler } from './parse-script'
6
+ import parseTemplate , { Handler as TemplateHandler } from './parse-template'
7
+ import scriptHandlers from './script-handlers'
8
8
import templateHandlers from './template-handlers'
9
9
import cacher from './utils/cacher'
10
10
11
11
const ERROR_EMPTY_DOCUMENT = 'The passed source is empty'
12
12
13
- export interface ParseOptions {
13
+ export { ScriptHandler , TemplateHandler }
14
+
15
+ export interface ParseOptions extends DocGenOptions {
14
16
filePath : string
17
+ /**
18
+ * In what language is the component written
19
+ * @default undefined - let the system decide
20
+ */
15
21
lang ?: 'ts' | 'js'
22
+ }
23
+
24
+ export interface DocGenOptions {
25
+ /**
26
+ * Which exported variables should be looked at
27
+ * @default undefined - means treat all dependencies
28
+ */
16
29
nameFilter ?: string [ ]
17
- aliases ?: { [ alias : string ] : string }
30
+ /**
31
+ * What alias should be replaced in requires and imports
32
+ */
33
+ alias ?: { [ alias : string ] : string }
34
+ /**
35
+ * What directories should be searched when resolving modules
36
+ */
37
+ modules ?: string [ ]
38
+ /**
39
+ * Handlers that will be added at the end of the script analysis
40
+ */
41
+ addScriptHandlers ?: ScriptHandler [ ]
42
+ /**
43
+ * Handlers that will be added at the end of the template analysis
44
+ */
45
+ addTemplateHandlers ?: TemplateHandler [ ]
18
46
}
19
47
20
48
/**
@@ -50,7 +78,13 @@ export function parseSource(documentation: Documentation, source: string, opt: P
50
78
51
79
// get slots and props from template
52
80
if ( parts && parts . template ) {
53
- parseTemplate ( parts . template , documentation , templateHandlers , opt . filePath )
81
+ const addTemplateHandlers : TemplateHandler [ ] = opt . addTemplateHandlers || [ ]
82
+ parseTemplate (
83
+ parts . template ,
84
+ documentation ,
85
+ [ ...templateHandlers , ...addTemplateHandlers ] ,
86
+ opt . filePath ,
87
+ )
54
88
}
55
89
56
90
const scriptSource = parts ? ( parts . script ? parts . script . content : undefined ) : source
@@ -60,8 +94,8 @@ export function parseSource(documentation: Documentation, source: string, opt: P
60
94
/ \. t s x ? $ / i. test ( path . extname ( opt . filePath ) )
61
95
? 'ts'
62
96
: 'js'
63
-
64
- parseScript ( scriptSource , documentation , handlers , opt )
97
+ const addScriptHandlers : ScriptHandler [ ] = opt . addScriptHandlers || [ ]
98
+ parseScript ( scriptSource , documentation , [ ... scriptHandlers , ... addScriptHandlers ] , opt )
65
99
}
66
100
67
101
if ( ! documentation . get ( 'displayName' ) ) {
0 commit comments