@@ -116,16 +116,19 @@ export function diffModels(apiModels, webflowItems) {
116116 continue ;
117117 }
118118
119- const hasChanges = Object . keys ( model . fields ) . some ( ( key ) => {
120- if ( FIELDS_MANAGED_OUTSIDE_DIFF . has ( key ) ) return false ;
119+ const changedFields = [ ] ;
120+ for ( const key of Object . keys ( model . fields ) ) {
121+ if ( FIELDS_MANAGED_OUTSIDE_DIFF . has ( key ) ) continue ;
121122 const apiVal = model . fields [ key ] ;
122123 const wfVal = existing . fieldData [ key ] ;
123- if ( ( apiVal === '' || apiVal == null ) && ( wfVal === '' || wfVal == null ) ) return false ;
124- return JSON . stringify ( apiVal ) !== JSON . stringify ( wfVal ) ;
125- } ) ;
124+ if ( ( apiVal === '' || apiVal == null ) && ( wfVal === '' || wfVal == null ) ) continue ;
125+ if ( JSON . stringify ( apiVal ) !== JSON . stringify ( wfVal ) ) {
126+ changedFields . push ( { field : key , from : wfVal , to : apiVal } ) ;
127+ }
128+ }
126129
127- if ( hasChanges ) {
128- toUpdate . push ( { id : existing . id , fieldData : model . fields } ) ;
130+ if ( changedFields . length > 0 ) {
131+ toUpdate . push ( { id : existing . id , fieldData : model . fields , changedFields } ) ;
129132 } else {
130133 unchanged ++ ;
131134 }
@@ -295,6 +298,17 @@ async function buildModelFieldData(models, categoryMap, existingItems) {
295298 return apiModels ;
296299}
297300
301+ function truncate ( val , maxLen = 80 ) {
302+ const str = typeof val === 'string' ? val : JSON . stringify ( val ) ;
303+ return str . length > maxLen ? str . slice ( 0 , maxLen ) + '...' : str ;
304+ }
305+
306+ function logChangedFields ( changedFields ) {
307+ for ( const { field, from, to } of changedFields ) {
308+ console . log ( ` ${ field } : ${ truncate ( from ) } → ${ truncate ( to ) } ` ) ;
309+ }
310+ }
311+
298312async function applyChanges ( collectionId , { toCreate, toUpdate, toDelete } ) {
299313 if ( toCreate . length > 0 ) {
300314 console . log ( `Creating ${ toCreate . length } models...` ) ;
@@ -304,7 +318,10 @@ async function applyChanges(collectionId, { toCreate, toUpdate, toDelete }) {
304318
305319 if ( toUpdate . length > 0 ) {
306320 console . log ( `Updating ${ toUpdate . length } models...` ) ;
307- for ( const item of toUpdate ) console . log ( ` Updating: ${ item . fieldData . slug } ` ) ;
321+ for ( const item of toUpdate ) {
322+ console . log ( ` Updating: ${ item . fieldData . slug } ` ) ;
323+ logChangedFields ( item . changedFields ) ;
324+ }
308325 await wf . updateItems ( collectionId , toUpdate ) ;
309326 }
310327
@@ -321,7 +338,10 @@ function logDryRunSummary({ toCreate, toUpdate, toDelete, unchanged }) {
321338 }
322339 if ( toUpdate . length > 0 ) {
323340 console . log ( `[dry run] Would update ${ toUpdate . length } models:` ) ;
324- for ( const item of toUpdate ) console . log ( ` ${ item . fieldData . slug } ` ) ;
341+ for ( const item of toUpdate ) {
342+ console . log ( ` ${ item . fieldData . slug } ` ) ;
343+ logChangedFields ( item . changedFields ) ;
344+ }
325345 }
326346 if ( toDelete . length > 0 ) {
327347 console . log ( `[dry run] Would delete ${ toDelete . length } models` ) ;
0 commit comments