@@ -9,6 +9,7 @@ import type {
9
9
DocsMethodParam ,
10
10
DocsJsDoc ,
11
11
DocsInterfaceProperty ,
12
+ DocsConfigInterface ,
12
13
DocsTypeAlias ,
13
14
DocsTypeAliasReference ,
14
15
} from './types' ;
@@ -30,9 +31,17 @@ export function parse(opts: DocsParseOptions) {
30
31
const interfaces : DocsInterface [ ] = [ ] ;
31
32
const enums : DocsEnum [ ] = [ ] ;
32
33
const typeAliases : DocsTypeAlias [ ] = [ ] ;
34
+ const pluginConfigs : DocsInterface [ ] = [ ] ;
33
35
34
36
tsSourceFiles . forEach ( tsSourceFile => {
35
- parseSourceFile ( tsSourceFile , typeChecker , interfaces , typeAliases , enums ) ;
37
+ parseSourceFile (
38
+ tsSourceFile ,
39
+ typeChecker ,
40
+ interfaces ,
41
+ typeAliases ,
42
+ enums ,
43
+ pluginConfigs ,
44
+ ) ;
36
45
} ) ;
37
46
38
47
return ( api : string ) => {
@@ -43,6 +52,7 @@ export function parse(opts: DocsParseOptions) {
43
52
interfaces : [ ] ,
44
53
enums : [ ] ,
45
54
typeAliases : [ ] ,
55
+ pluginConfigs,
46
56
} ;
47
57
48
58
if ( apiInterface ) {
@@ -108,11 +118,13 @@ function parseSourceFile(
108
118
interfaces : DocsInterface [ ] ,
109
119
typeAliases : DocsTypeAlias [ ] ,
110
120
enums : DocsEnum [ ] ,
121
+ pluginConfigs : DocsInterface [ ] ,
111
122
) {
112
123
const statements = tsSourceFile . statements ;
113
124
const interfaceDeclarations = statements . filter ( ts . isInterfaceDeclaration ) ;
114
125
const typeAliasDeclarations = statements . filter ( ts . isTypeAliasDeclaration ) ;
115
126
const enumDeclarations = statements . filter ( ts . isEnumDeclaration ) ;
127
+ const moduleDeclarations = statements . filter ( ts . isModuleDeclaration ) ;
116
128
117
129
interfaceDeclarations . forEach ( interfaceDeclaration => {
118
130
interfaces . push ( getInterface ( typeChecker , interfaceDeclaration ) ) ;
@@ -125,6 +137,12 @@ function parseSourceFile(
125
137
typeAliasDeclarations . forEach ( typeAliasDeclaration => {
126
138
typeAliases . push ( getTypeAlias ( typeChecker , typeAliasDeclaration ) ) ;
127
139
} ) ;
140
+
141
+ moduleDeclarations
142
+ . filter ( m => m ?. name ?. text === '@capacitor/cli' )
143
+ . forEach ( moduleDeclaration => {
144
+ getPluginsConfig ( typeChecker , moduleDeclaration , pluginConfigs ) ;
145
+ } ) ;
128
146
}
129
147
130
148
function getInterface (
@@ -338,6 +356,49 @@ function getInterfaceProperty(
338
356
return p ;
339
357
}
340
358
359
+ function getPluginsConfig (
360
+ typeChecker : ts . TypeChecker ,
361
+ moduleDeclaration : ts . ModuleDeclaration ,
362
+ pluginConfigs : DocsConfigInterface [ ] ,
363
+ ) {
364
+ const body = moduleDeclaration . body as ts . ModuleBlock ;
365
+ if ( ! Array . isArray ( body . statements ) ) {
366
+ return ;
367
+ }
368
+
369
+ const pluginConfigInterfaces = body . statements . filter (
370
+ ( s : ts . InterfaceDeclaration ) =>
371
+ s ?. name ?. text === 'PluginsConfig' &&
372
+ Array . isArray ( s ?. members ) &&
373
+ s . members . length > 0 ,
374
+ ) as ts . InterfaceDeclaration [ ] ;
375
+
376
+ pluginConfigInterfaces . forEach ( pluginConfigInterface => {
377
+ pluginConfigInterface . members
378
+ . filter ( ts . isPropertySignature )
379
+ . filter ( p => p ?. type && ( p ?. type as ts . TypeLiteralNode ) . members )
380
+ . forEach ( properytSignature => {
381
+ const typeLiteral = properytSignature . type as ts . TypeLiteralNode ;
382
+
383
+ const nm = properytSignature . name . getText ( ) ;
384
+ const i : DocsConfigInterface = {
385
+ name : nm ,
386
+ slug : slugify ( nm ) ,
387
+ properties : typeLiteral . members
388
+ . filter ( ts . isPropertySignature )
389
+ . map ( propertySignature => {
390
+ return getInterfaceProperty ( typeChecker , propertySignature ) ;
391
+ } )
392
+ . filter ( p => p != null ) as DocsInterfaceProperty [ ] ,
393
+ } ;
394
+
395
+ if ( i . properties . length > 0 ) {
396
+ pluginConfigs . push ( i ) ;
397
+ }
398
+ } ) ;
399
+ } ) ;
400
+ }
401
+
341
402
function typeToString (
342
403
checker : ts . TypeChecker ,
343
404
type : ts . Type ,
0 commit comments