@@ -112,6 +112,7 @@ export function codeShift(platform) {
112112 const componentsProps = { }
113113 components . forEach ( ( component ) => {
114114 const { name } = component
115+ if ( name . toLowerCase ( ) !== 'actionsheet' ) return
115116 const componentDocumentPath = path . join (
116117 __dirname ,
117118 '../src/packages' ,
@@ -149,24 +150,37 @@ export function codeShift(platform) {
149150function addJSDoc ( propsJson , componentName , platform ) {
150151 const transform = ( file , api ) => {
151152 const j = api . jscodeshift . withParser ( 'ts' )
152- return j ( file . source )
153- . find ( j . TSInterfaceDeclaration , {
153+ const ast = j ( file . source )
154+ function addComment ( item ) {
155+ if ( ! item . key ) return
156+ const description = propsJson [ componentName . toLowerCase ( ) ] [ item . key . name ]
157+ if ( ! description ) return
158+ item [ 'comments' ] = [
159+ j . commentBlock ( `*\n* ${ description [ 'desc' ] } \n` ) ,
160+ ]
161+ }
162+ ast
163+ . find ( j . TSTypeAliasDeclaration ) . forEach ( ( path ) => {
164+ const annotationTypes = path . value . typeAnnotation . types
165+ if ( ! annotationTypes ) return
166+ const typeLiteral = annotationTypes [ annotationTypes . length - 1 ]
167+ typeLiteral . members . forEach ( ( item ) => {
168+ addComment ( item )
169+ } )
170+ } )
171+ ast . find ( j . TSInterfaceDeclaration , {
154172 id : {
155173 name : `Base${ componentName } ` ,
156174 type : 'Identifier' ,
157175 } ,
158176 } )
159177 . forEach ( ( path ) => {
160178 path . value ?. body ?. body ?. forEach ( ( item ) => {
161- if ( ! item . key ) return
162- const info = propsJson [ componentName . toLowerCase ( ) ] [ item . key . name ]
163- if ( ! info ) return
164- item [ 'comments' ] = [
165- j . commentBlock ( `*\n* ${ info [ 'desc' ] } \n` ) ,
166- ]
179+ addComment ( item )
167180 } )
168181 } )
169- . toSource ( )
182+
183+ return ast . toSource ( )
170184 }
171185 const baseType = path . join ( __dirname , `../release/${ platform || 'h5' } /dist/es/types/spec/${ componentName . toLowerCase ( ) } /base.d.ts` )
172186 const source = fse . readFileSync ( baseType , { encoding : 'utf8' } )
0 commit comments