@@ -337,68 +337,93 @@ export async function listDesignSystems(
337337 }
338338 for ( const entry of entries ) {
339339 if ( ! entry . isDirectory ( ) && ! entry . isSymbolicLink ( ) ) continue ;
340- const brandRoot = path . join ( root , entry . name ) ;
341- const manifest = await readProjectManifest ( brandRoot , entry . name ) ;
342- const designPath = path . join ( brandRoot , manifest ?. files . design ?? 'DESIGN.md' ) ;
343- try {
344- const stats = await stat ( designPath ) ;
345- if ( ! stats . isFile ( ) ) continue ;
346- const raw = await readFile ( designPath , 'utf8' ) ;
347- const metadata = await readUserMetadata ( root , entry . name ) ;
348- if ( ! designSystemVisibleFromWorkspace ( metadata . workspaceId , options . workspaceId ) ) continue ;
349- const { data : frontmatter , body } = parseFrontmatter ( raw ) ;
350- const titleMatch = / ^ # \s + ( .+ ?) \s * $ / m. exec ( body ) ;
351- const markdownTitle =
352- titleMatch ?. [ 1 ] !== undefined ? cleanTitle ( titleMatch [ 1 ] ) : '' ;
353- const fallbackTitle = markdownTitle || stringField ( frontmatter , 'name' ) || entry . name ;
354- const title = cleanTitle (
355- metadata . title
356- ?? manifest ?. name
357- ?? fallbackTitle ,
358- ) ;
359- const frontmatterCategory = stringField ( frontmatter , 'category' ) ;
360- const category = (
361- metadata . category
362- ?? manifest ?. category
363- ?? extractCategory ( body )
364- ?? frontmatterCategory
365- ) || 'Uncategorized' ;
366- const markdownSummary = summarize ( body ) ;
367- const markdownSwatches = extractSwatches ( body ) ;
368- const frontmatterSwatchRow = swatchesFromFrontmatter ( frontmatter ) ;
369- const swatches = pickFinalSwatchRow ( frontmatterSwatchRow , markdownSwatches ) ;
370- out . push ( {
371- id : `${ options . idPrefix ?? '' } ${ entry . name } ` ,
372- title,
373- category,
374- summary :
375- ( manifest ?. description ?. trim ( ) || markdownSummary )
376- || stringField ( frontmatter , 'description' )
377- || '' ,
378- swatches,
379- surface :
380- metadata . surface
381- ?? extractSurface ( body )
382- ?? frontmatterSurface ( frontmatter )
383- ?? 'web' ,
384- body : raw ,
385- source : options . source ?? 'built-in' ,
386- status : metadata . status ?? options . defaultStatus ?? 'published' ,
387- isEditable : options . isEditable ?? false ,
388- ...( metadata . createdAt ? { createdAt : metadata . createdAt } : { } ) ,
389- ...( metadata . updatedAt ? { updatedAt : metadata . updatedAt } : { } ) ,
390- ...( metadata . provenance ? { provenance : metadata . provenance } : { } ) ,
391- ...( metadata . projectId ? { projectId : metadata . projectId } : { } ) ,
392- ...( metadata . teamSynced ? { teamSynced : true } : { } ) ,
393- ...( metadata . workspaceId ? { workspaceId : metadata . workspaceId } : { } ) ,
394- } ) ;
395- } catch {
396- // Skip.
397- }
340+ const summary = await readDesignSystemSummaryFromDirectory ( root , entry . name , options ) ;
341+ if ( summary ) out . push ( summary ) ;
398342 }
399343 return out ;
400344}
401345
346+ export async function readDesignSystemSummary (
347+ root : string ,
348+ id : string ,
349+ options : DesignSystemListOptions = { } ,
350+ ) : Promise < DesignSystemSummary | null > {
351+ const dirId = stripPrefixAndValidateId ( id , options . idPrefix ) ;
352+ if ( ! dirId ) return null ;
353+ try {
354+ const entries = await readdir ( root ) ;
355+ if ( ! entries . includes ( dirId ) ) return null ;
356+ } catch {
357+ return null ;
358+ }
359+ return readDesignSystemSummaryFromDirectory ( root , dirId , options ) ;
360+ }
361+
362+ async function readDesignSystemSummaryFromDirectory (
363+ root : string ,
364+ dirId : string ,
365+ options : DesignSystemListOptions ,
366+ ) : Promise < DesignSystemSummary | null > {
367+ const brandRoot = path . join ( root , dirId ) ;
368+ const manifest = await readProjectManifest ( brandRoot , dirId ) ;
369+ const designPath = path . join ( brandRoot , manifest ?. files . design ?? 'DESIGN.md' ) ;
370+ try {
371+ const stats = await stat ( designPath ) ;
372+ if ( ! stats . isFile ( ) ) return null ;
373+ const raw = await readFile ( designPath , 'utf8' ) ;
374+ const metadata = await readUserMetadata ( root , dirId ) ;
375+ if ( ! designSystemVisibleFromWorkspace ( metadata . workspaceId , options . workspaceId ) ) return null ;
376+ const { data : frontmatter , body } = parseFrontmatter ( raw ) ;
377+ const titleMatch = / ^ # \s + ( .+ ?) \s * $ / m. exec ( body ) ;
378+ const markdownTitle =
379+ titleMatch ?. [ 1 ] !== undefined ? cleanTitle ( titleMatch [ 1 ] ) : '' ;
380+ const fallbackTitle = markdownTitle || stringField ( frontmatter , 'name' ) || dirId ;
381+ const title = cleanTitle (
382+ metadata . title
383+ ?? manifest ?. name
384+ ?? fallbackTitle ,
385+ ) ;
386+ const frontmatterCategory = stringField ( frontmatter , 'category' ) ;
387+ const category = (
388+ metadata . category
389+ ?? manifest ?. category
390+ ?? extractCategory ( body )
391+ ?? frontmatterCategory
392+ ) || 'Uncategorized' ;
393+ const markdownSummary = summarize ( body ) ;
394+ const markdownSwatches = extractSwatches ( body ) ;
395+ const frontmatterSwatchRow = swatchesFromFrontmatter ( frontmatter ) ;
396+ const swatches = pickFinalSwatchRow ( frontmatterSwatchRow , markdownSwatches ) ;
397+ return {
398+ id : `${ options . idPrefix ?? '' } ${ dirId } ` ,
399+ title,
400+ category,
401+ summary :
402+ ( manifest ?. description ?. trim ( ) || markdownSummary )
403+ || stringField ( frontmatter , 'description' )
404+ || '' ,
405+ swatches,
406+ surface :
407+ metadata . surface
408+ ?? extractSurface ( body )
409+ ?? frontmatterSurface ( frontmatter )
410+ ?? 'web' ,
411+ body : raw ,
412+ source : options . source ?? 'built-in' ,
413+ status : metadata . status ?? options . defaultStatus ?? 'published' ,
414+ isEditable : options . isEditable ?? false ,
415+ ...( metadata . createdAt ? { createdAt : metadata . createdAt } : { } ) ,
416+ ...( metadata . updatedAt ? { updatedAt : metadata . updatedAt } : { } ) ,
417+ ...( metadata . provenance ? { provenance : metadata . provenance } : { } ) ,
418+ ...( metadata . projectId ? { projectId : metadata . projectId } : { } ) ,
419+ ...( metadata . teamSynced ? { teamSynced : true } : { } ) ,
420+ ...( metadata . workspaceId ? { workspaceId : metadata . workspaceId } : { } ) ,
421+ } ;
422+ } catch {
423+ return null ;
424+ }
425+ }
426+
402427/**
403428 * Whether a design system claimed by `owner` should be listed while `scope` is
404429 * the active workspace.
0 commit comments