11import { ToolSchemaOptions } from '@push-based/models' ;
2- import { createHandler , BaseHandlerOptions } from '../shared/utils/handler-helpers.js' ;
2+ import {
3+ createHandler ,
4+ BaseHandlerOptions ,
5+ } from '../shared/utils/handler-helpers.js' ;
36import { COMMON_ANNOTATIONS } from '../shared/models/schema-helpers.js' ;
47import { getComponentPathsInfo } from './utils/paths-helpers.js' ;
58import { getComponentDocPathsForName } from './utils/doc-helpers.js' ;
@@ -32,7 +35,8 @@ export const listDsComponentsToolSchema: ToolSchemaOptions = {
3235 type : 'string' ,
3336 enum : [ 'implementation' , 'documentation' , 'stories' , 'all' ] ,
3437 } ,
35- description : 'Sections to include in the response. Options: "implementation", "documentation", "stories", "all". Defaults to ["all"] if not specified.' ,
38+ description :
39+ 'Sections to include in the response. Options: "implementation", "documentation", "stories", "all". Defaults to ["all"] if not specified.' ,
3640 default : [ 'all' ] ,
3741 } ,
3842 } ,
@@ -74,30 +78,37 @@ function getAllFilesInDirectory(dirPath: string): string[] {
7478}
7579
7680function kebabCaseToPascalCase ( kebabCase : string ) : string {
77- return 'Ds' + kebabCase
78- . split ( '-' )
79- . map ( ( part ) => part . charAt ( 0 ) . toUpperCase ( ) + part . slice ( 1 ) )
80- . join ( '' ) ;
81+ return (
82+ 'Ds' +
83+ kebabCase
84+ . split ( '-' )
85+ . map ( ( part ) => part . charAt ( 0 ) . toUpperCase ( ) + part . slice ( 1 ) )
86+ . join ( '' )
87+ ) ;
8188}
8289
8390function isValidComponentFolder ( folderPath : string ) : boolean {
8491 const packageJsonPath = path . join ( folderPath , 'package.json' ) ;
8592 const srcPath = path . join ( folderPath , 'src' ) ;
86-
87- return fs . existsSync ( packageJsonPath ) && fs . existsSync ( srcPath ) && fs . statSync ( srcPath ) . isDirectory ( ) ;
93+
94+ return (
95+ fs . existsSync ( packageJsonPath ) &&
96+ fs . existsSync ( srcPath ) &&
97+ fs . statSync ( srcPath ) . isDirectory ( )
98+ ) ;
8899}
89100
90101function findStoriesFiles ( componentPath : string ) : string [ ] {
91102 const storiesFiles : string [ ] = [ ] ;
92-
103+
93104 try {
94105 if ( fs . existsSync ( componentPath ) ) {
95106 const items = fs . readdirSync ( componentPath ) ;
96-
107+
97108 for ( const item of items ) {
98109 const fullPath = path . join ( componentPath , item ) ;
99110 const stat = fs . statSync ( fullPath ) ;
100-
111+
101112 if ( stat . isFile ( ) && item . endsWith ( '.stories.ts' ) ) {
102113 storiesFiles . push ( fullPath ) ;
103114 }
@@ -106,7 +117,7 @@ function findStoriesFiles(componentPath: string): string[] {
106117 } catch {
107118 return storiesFiles ;
108119 }
109-
120+
110121 return storiesFiles ;
111122}
112123
@@ -122,12 +133,14 @@ export const listDsComponentsHandler = createHandler<
122133 }
123134
124135 const componentsBasePath = resolveCrossPlatformPath ( cwd , uiRoot ) ;
125-
136+
126137 if ( ! fs . existsSync ( componentsBasePath ) ) {
127138 throw new Error ( `Components directory not found: ${ uiRoot } ` ) ;
128139 }
129140
130- const entries = fs . readdirSync ( componentsBasePath , { withFileTypes : true } ) ;
141+ const entries = fs . readdirSync ( componentsBasePath , {
142+ withFileTypes : true ,
143+ } ) ;
131144 const componentFolders = entries
132145 . filter ( ( entry ) => entry . isDirectory ( ) )
133146 . map ( ( entry ) => entry . name )
@@ -140,14 +153,16 @@ export const listDsComponentsHandler = createHandler<
140153 const docsBasePath = resolveCrossPlatformPath ( cwd , storybookDocsRoot ) ;
141154
142155 const includeAll = sections . includes ( 'all' ) ;
143- const includeImplementation = includeAll || sections . includes ( 'implementation' ) ;
144- const includeDocumentation = includeAll || sections . includes ( 'documentation' ) ;
156+ const includeImplementation =
157+ includeAll || sections . includes ( 'implementation' ) ;
158+ const includeDocumentation =
159+ includeAll || sections . includes ( 'documentation' ) ;
145160 const includeStories = includeAll || sections . includes ( 'stories' ) ;
146161
147162 for ( const folderName of componentFolders ) {
148163 try {
149164 const componentName = kebabCaseToPascalCase ( folderName ) ;
150-
165+
151166 const pathsInfo = getComponentPathsInfo ( componentName , uiRoot , cwd ) ;
152167
153168 let implementationFiles : string [ ] = [ ] ;
@@ -158,8 +173,11 @@ export const listDsComponentsHandler = createHandler<
158173
159174 const documentationFiles : string [ ] = [ ] ;
160175 if ( includeDocumentation ) {
161- const docPaths = getComponentDocPathsForName ( docsBasePath , componentName ) ;
162-
176+ const docPaths = getComponentDocPathsForName (
177+ docsBasePath ,
178+ componentName ,
179+ ) ;
180+
163181 if ( fs . existsSync ( docPaths . paths . api ) ) {
164182 documentationFiles . push ( `file://${ docPaths . paths . api } ` ) ;
165183 }
@@ -170,7 +188,10 @@ export const listDsComponentsHandler = createHandler<
170188
171189 let storiesFilePaths : string [ ] = [ ] ;
172190 if ( includeStories ) {
173- const storiesComponentFolderPath = path . join ( docsBasePath , folderName ) ;
191+ const storiesComponentFolderPath = path . join (
192+ docsBasePath ,
193+ folderName ,
194+ ) ;
174195 const storiesFiles = findStoriesFiles ( storiesComponentFolderPath ) ;
175196 storiesFilePaths = storiesFiles . map ( ( file ) => `file://${ file } ` ) ;
176197 }
@@ -184,21 +205,21 @@ export const listDsComponentsHandler = createHandler<
184205 importPath : pathsInfo . importPath ,
185206 } ) ;
186207 } catch ( ctx ) {
187- console . warn ( `Warning: Skipped component '${ folderName } ': ${ ( ctx as Error ) . message } ` ) ;
208+ console . warn (
209+ `Warning: Skipped component '${ folderName } ': ${ ( ctx as Error ) . message } ` ,
210+ ) ;
188211 }
189212 }
190213
191214 return components ;
192215 } catch ( ctx ) {
193- throw new Error (
194- `Error listing DS components: ${ ( ctx as Error ) . message } ` ,
195- ) ;
216+ throw new Error ( `Error listing DS components: ${ ( ctx as Error ) . message } ` ) ;
196217 }
197218 } ,
198219 ( components ) => {
199220 const response = {
200221 totalComponents : components ?. length || 0 ,
201- components : components || [ ]
222+ components : components || [ ] ,
202223 } ;
203224
204225 return [ JSON . stringify ( response , null , 2 ) ] ;
0 commit comments