@@ -108,15 +108,13 @@ export default class MergeHandler {
108
108
deleted : [ ] ,
109
109
} ;
110
110
const selectedItems = await selectCustomPreferences ( module , this . branchCompareData [ module ] ) ;
111
- if ( ! selectedItems . length ) {
112
- cliux . print ( chalk . red ( 'No items were selected' ) ) ;
113
- process . exit ( 1 ) ;
111
+ if ( selectedItems ?. length ) {
112
+ forEach ( selectedItems , ( item ) => {
113
+ this . mergeSettings . mergeContent [ module ] [ item . status ] . push ( item . value ) ;
114
+ this . mergeSettings . itemMergeStrategies . push ( item . value ) ;
115
+ } ) ;
116
+ this . mergeSettings . strategy = 'ignore' ;
114
117
}
115
- forEach ( selectedItems , ( item ) => {
116
- this . mergeSettings . mergeContent [ module ] [ item . status ] . push ( item . value ) ;
117
- this . mergeSettings . itemMergeStrategies . push ( item . value ) ;
118
- } ) ;
119
- this . mergeSettings . strategy = 'ignore' ;
120
118
}
121
119
} else if ( this . strategy === 'merge_prefer_base' ) {
122
120
if ( this . strategySubOption === 'new' ) {
@@ -137,12 +135,25 @@ export default class MergeHandler {
137
135
} else if ( this . strategy === 'overwrite_with_compare' ) {
138
136
this . mergeSettings . strategy = 'overwrite_with_compare' ;
139
137
}
140
- if ( this . checkEmptySelection ( ) ) {
141
- cliux . print ( chalk . red ( 'No items selected' ) ) ;
142
- } else {
143
- await this . displayMergeSummary ( ) ;
144
- }
145
138
139
+ const { allEmpty, moduleStatus } = this . checkEmptySelection ( ) ;
140
+ const strategyName = this . mergeSettings . strategy ;
141
+
142
+ if ( allEmpty ) {
143
+ cliux . print ( chalk . red ( `No items selected according to the '${ strategyName } ' strategy.` ) ) ;
144
+ process . exit ( 1 ) ;
145
+ }
146
+
147
+ for ( const [ type , { exists, empty } ] of Object . entries ( moduleStatus ) ) {
148
+ if ( exists && empty ) {
149
+ const readable = type === 'contentType' ? 'Content Types' : 'Global fields' ;
150
+ cliux . print ( '\n' )
151
+ cliux . print ( chalk . yellow ( `Note: No ${ readable } selected according to the '${ strategyName } ' strategy.` ) ) ;
152
+ }
153
+ }
154
+
155
+ this . displayMergeSummary ( ) ;
156
+
146
157
if ( ! this . executeOption ) {
147
158
const executionResponse = await selectMergeExecution ( ) ;
148
159
if ( executionResponse === 'previous' ) {
@@ -160,17 +171,71 @@ export default class MergeHandler {
160
171
}
161
172
}
162
173
163
- checkEmptySelection ( ) {
164
- for ( let module in this . branchCompareData ) {
165
- if ( this . mergeSettings . mergeContent [ module ] ?. modified ?. length
166
- || this . mergeSettings . mergeContent [ module ] ?. added ?. length
167
- || this . mergeSettings . mergeContent [ module ] ?. deleted ?. length ) {
168
- return false ;
174
+ /**
175
+ * Checks whether the selection of modules in the compare branch data is empty.
176
+ *
177
+ * This method evaluates the branch compare data and determines if there are any changes
178
+ * (added, modified, or deleted) in the modules based on the merge strategy defined in the
179
+ * merge settings. It categorizes the status of each module as either existing and empty or
180
+ * not empty.
181
+ *
182
+ * @returns An object containing:
183
+ * - `allEmpty`: A boolean indicating whether all modules are either non-existent or empty.
184
+ * - `moduleStatus`: A record mapping module types (`contentType` and `globalField`) to their
185
+ * respective statuses, which include:
186
+ * - `exists`: A boolean indicating whether the module exists in the branch comparison data.
187
+ * - `empty`: A boolean indicating whether the module has no changes (added, modified, or deleted).
188
+ */
189
+ checkEmptySelection ( ) : {
190
+ allEmpty : boolean ;
191
+ moduleStatus : Record < string , { exists : boolean ; empty : boolean } > ;
192
+ } {
193
+ const strategy = this . mergeSettings . strategy ;
194
+
195
+ const useMergeContent = new Set ( [ 'custom_preferences' , 'ignore' ] ) ;
196
+ const modifiedOnlyStrategies = new Set ( [ 'merge_modified_only_prefer_base' , 'merge_modified_only_prefer_compare' ] ) ;
197
+ const addedOnlyStrategies = new Set ( [ 'merge_new_only' ] ) ;
198
+
199
+ const moduleStatus : Record < string , { exists : boolean ; empty : boolean } > = {
200
+ contentType : { exists : false , empty : true } ,
201
+ globalField : { exists : false , empty : true } ,
202
+ } ;
203
+
204
+ for ( const module in this . branchCompareData ) {
205
+ const content = useMergeContent . has ( strategy )
206
+ ? this . mergeSettings . mergeContent [ module ]
207
+ : this . branchCompareData [ module ] ;
208
+
209
+ if ( ! content ) continue ;
210
+
211
+ const isGlobalField = module === 'global_fields' ;
212
+ const type = isGlobalField ? 'globalField' : 'contentType' ;
213
+ moduleStatus [ type ] . exists = true ;
214
+
215
+ let hasChanges = false ;
216
+ if ( modifiedOnlyStrategies . has ( strategy ) ) {
217
+ hasChanges = Array . isArray ( content . modified ) && content . modified . length > 0 ;
218
+ } else if ( addedOnlyStrategies . has ( strategy ) ) {
219
+ hasChanges = Array . isArray ( content . added ) && content . added . length > 0 ;
220
+ } else {
221
+ hasChanges =
222
+ ( Array . isArray ( content . modified ) && content . modified . length > 0 ) ||
223
+ ( Array . isArray ( content . added ) && content . added . length > 0 ) ||
224
+ ( Array . isArray ( content . deleted ) && content . deleted . length > 0 ) ;
225
+ }
226
+
227
+ if ( hasChanges ) {
228
+ moduleStatus [ type ] . empty = false ;
169
229
}
170
230
}
171
- return true ;
231
+
232
+ const allEmpty = Object . values ( moduleStatus ) . every (
233
+ ( status ) => ! status . exists || status . empty
234
+ ) ;
235
+
236
+ return { allEmpty, moduleStatus } ;
172
237
}
173
-
238
+
174
239
displayMergeSummary ( ) {
175
240
if ( this . mergeSettings . strategy !== 'ignore' ) {
176
241
for ( let module in this . branchCompareData ) {
@@ -269,10 +334,10 @@ export default class MergeHandler {
269
334
} ;
270
335
271
336
const mergePreferencesMap = {
272
- ' existing_new' : 'merge_existing_new' ,
273
- ' new' : 'merge_new' ,
274
- ' existing' : 'merge_existing' ,
275
- ' ask_preference' : 'custom' ,
337
+ existing_new : 'merge_existing_new' ,
338
+ new : 'merge_new' ,
339
+ existing : 'merge_existing' ,
340
+ ask_preference : 'custom' ,
276
341
} ;
277
342
const selectedMergePreference = mergePreferencesMap [ mergePreference ] ;
278
343
@@ -301,7 +366,10 @@ export default class MergeHandler {
301
366
302
367
if ( scriptFolderPath !== undefined ) {
303
368
cliux . success ( `\nSuccess! We have generated entry migration files in the folder ${ scriptFolderPath } ` ) ;
304
- cliux . print ( '\nWARNING!!! Migration is not intended to be run more than once. Migrated(entries/assets) will be duplicated if run more than once' , { color : 'yellow' } ) ;
369
+ cliux . print (
370
+ '\nWARNING!!! Migration is not intended to be run more than once. Migrated(entries/assets) will be duplicated if run more than once' ,
371
+ { color : 'yellow' } ,
372
+ ) ;
305
373
306
374
let migrationCommand : string ;
307
375
if ( os . platform ( ) === 'win32' ) {
0 commit comments