* Print diff in human-readable format.
(result: DiffResult, options: DiffOptions)
| 304 | * Print diff in human-readable format. |
| 305 | */ |
| 306 | function printDiff(result: DiffResult, options: DiffOptions): void { |
| 307 | const c = getChalk() |
| 308 | output(c.bold(`Comparing: ${result.file1}`)) |
| 309 | output(c.bold(` with: ${result.file2}`)) |
| 310 | output('') |
| 311 | |
| 312 | const hasChanges = |
| 313 | result.summary.notebooksAdded > 0 || result.summary.notebooksRemoved > 0 || result.summary.notebooksModified > 0 |
| 314 | |
| 315 | if (!hasChanges) { |
| 316 | output(c.green('No structural differences found.')) |
| 317 | return |
| 318 | } |
| 319 | |
| 320 | output(c.bold('Notebooks:')) |
| 321 | |
| 322 | const changedNotebooks = result.notebooks.filter((nb): nb is ChangedNotebookDiff => nb.status !== 'unchanged') |
| 323 | |
| 324 | for (const nb of changedNotebooks) { |
| 325 | const statusIcon = getStatusIcon(nb.status) |
| 326 | const statusColor = getStatusColor(nb.status, c) |
| 327 | |
| 328 | if (nb.status === 'added') { |
| 329 | output(statusColor(` ${statusIcon} Added: "${nb.name}" (${nb.blockCount} blocks)`)) |
| 330 | } else if (nb.status === 'removed') { |
| 331 | output(statusColor(` ${statusIcon} Removed: "${nb.name}" (${nb.blockCount} blocks)`)) |
| 332 | } else if (nb.status === 'modified') { |
| 333 | if (nb.oldName) { |
| 334 | output(statusColor(` ${statusIcon} Renamed: "${nb.oldName}" → "${nb.name}"`)) |
| 335 | } else { |
| 336 | output(statusColor(` ${statusIcon} Modified: "${nb.name}"`)) |
| 337 | } |
| 338 | |
| 339 | for (const bd of (nb.blockDiffs ?? []).filter(isChangedBlock)) { |
| 340 | const blockStatusIcon = getStatusIcon(bd.status) |
| 341 | const blockStatusColor = getStatusColor(bd.status, c) |
| 342 | output(blockStatusColor(` ${blockStatusIcon} ${bd.type} (${bd.id})`)) |
| 343 | |
| 344 | if (options.content && bd.contentDiff) { |
| 345 | printContentDiff(bd.contentDiff.before, bd.contentDiff.after, c) |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | output('') |
| 352 | output(c.bold('Summary:')) |
| 353 | if (result.summary.notebooksAdded > 0) { |
| 354 | output(c.green(` + ${result.summary.notebooksAdded} notebook(s) added`)) |
| 355 | } |
| 356 | if (result.summary.notebooksRemoved > 0) { |
| 357 | output(c.red(` - ${result.summary.notebooksRemoved} notebook(s) removed`)) |
| 358 | } |
| 359 | if (result.summary.notebooksModified > 0) { |
| 360 | output(c.yellow(` ~ ${result.summary.notebooksModified} notebook(s) modified`)) |
| 361 | } |
| 362 | if (result.summary.blocksAdded > 0) { |
| 363 | output(c.green(` + ${result.summary.blocksAdded} block(s) added`)) |
no test coverage detected