@@ -30,9 +30,36 @@ function updateVisualsList() {
3030
3131 console . log ( `📁 Found ${ componentDirs . length } component directories: ${ componentDirs . join ( ', ' ) } \n` ) ;
3232
33- const updatedList = [ ] ;
33+ // Create a map of existing components by slug for quick lookup
34+ const existingComponentsMap = new Map ( ) ;
35+ existingList . forEach ( component => {
36+ existingComponentsMap . set ( component . slug , component ) ;
37+ } ) ;
38+
39+ // Track which components we've processed
40+ const processedSlugs = new Set ( ) ;
41+ const newComponents = [ ] ;
3442
43+ // First, process existing components to maintain their order
44+ for ( const existingComponent of existingList ) {
45+ const dirName = existingComponent . slug ;
46+ const componentDir = path . join ( visualsDir , dirName ) ;
47+
48+ if ( fs . existsSync ( componentDir ) ) {
49+ // Component still exists, keep it in the same position
50+ processedSlugs . add ( dirName ) ;
51+ console . log ( `✅ Kept existing component: ${ existingComponent . name } (${ dirName } )` ) ;
52+ } else {
53+ console . log ( `⚠️ Component directory removed: ${ dirName } ` ) ;
54+ }
55+ }
56+
57+ // Then, process new components and add them to the beginning
3558 for ( const dirName of componentDirs ) {
59+ if ( processedSlugs . has ( dirName ) ) {
60+ continue ; // Already processed
61+ }
62+
3663 const componentDir = path . join ( visualsDir , dirName ) ;
3764 const metadataPath = path . join ( componentDir , 'metadata.json' ) ;
3865
@@ -79,9 +106,10 @@ function updateVisualsList() {
79106 componentPath : `visuals/${ dirName } /component.tsx`
80107 } ;
81108
82- updatedList . push ( componentEntry ) ;
109+ newComponents . push ( componentEntry ) ;
110+ processedSlugs . add ( dirName ) ;
83111
84- console . log ( `✅ Processed ${ dirName } :` ) ;
112+ console . log ( `🆕 Added new component: ${ dirName } :` ) ;
85113 console . log ( ` Name: ${ componentEntry . name } ` ) ;
86114 console . log ( ` Author: ${ componentEntry . author } ` ) ;
87115 console . log ( ` Preview: ${ previewExists ? '✅' : '❌' } (${ previewExists ? 'exists' : 'missing' } )` ) ;
@@ -92,8 +120,10 @@ function updateVisualsList() {
92120 }
93121 }
94122
95- // Sort by name for consistent ordering
96- updatedList . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
123+ // Combine new components (at beginning) with existing components (maintaining order)
124+ const updatedList = [ ...newComponents , ...existingList . filter ( component =>
125+ fs . existsSync ( path . join ( visualsDir , component . slug ) )
126+ ) ] ;
97127
98128 // Write updated list
99129 fs . writeFileSync ( listPath , JSON . stringify ( updatedList , null , 2 ) ) ;
@@ -104,9 +134,15 @@ function updateVisualsList() {
104134 // Show summary
105135 console . log ( '\n📋 Final list:' ) ;
106136 updatedList . forEach ( ( component , index ) => {
107- console . log ( `${ index + 1 } . ${ component . name } (${ component . slug } ) - by ${ component . author } ` ) ;
137+ const isNew = newComponents . some ( newComp => newComp . slug === component . slug ) ;
138+ const marker = isNew ? '🆕' : '✅' ;
139+ console . log ( `${ index + 1 } . ${ marker } ${ component . name } (${ component . slug } ) - by ${ component . author } ` ) ;
108140 } ) ;
109141
142+ if ( newComponents . length > 0 ) {
143+ console . log ( `\n✨ Added ${ newComponents . length } new component(s) to the beginning of the list` ) ;
144+ }
145+
110146 } catch ( error ) {
111147 console . error ( '❌ Error updating visuals list:' , error . message ) ;
112148 process . exit ( 1 ) ;
0 commit comments